impexpAction4App.jsp
6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<%@page language="java" contentType="text/html;charset=UTF-8"%>
<%@page import="weaver.formmode.exttools.impexp.common.StringUtils" %>
<%@page import="weaver.formmode.exttools.impexp.exp.service.ExpDataService" %>
<%@page import="weaver.formmode.exttools.impexp.exp.service.ImpDataService"%>
<%@page import="weaver.file.FileUpload"%>
<%@page import="weaver.file.FileManage"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="weaver.general.GCONST"%>
<%@page import="java.io.File"%>
<%@page import="weaver.hrm.HrmUserVarify"%>
<%@page import="weaver.hrm.User"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="weaver.formmode.exttools.impexp.exp.service.ProgressStatus"%>
<%@page import="java.util.Map"%>
<%@page import="weaver.formmode.exttools.impexp.exp.service.OperateThread4app"%>
<%@page import="weaver.formmode.exttools.impexp.common.FileUtils"%>
<%@page import="java.util.*"%>
<%@page import="ln.LN" %>
<%
String type = StringUtils.null2String(request.getParameter("type"));
String id = StringUtils.null2String(request.getParameter("id"));
String appNo = StringUtils.null2String(request.getParameter("appNo"));
String pageid=appNo;
LN ln=new LN();
User user = HrmUserVarify.getUser(request, response);
String sessionid = session.getId();
int userid = user.getUID();
JSONObject jsonObject = new JSONObject();
String version="";
if (ln.getEcologyBigVersion().equals("7")) {
version="7";
}
if("0".equals(type)){//导出
ProgressStatus.create(sessionid,pageid,userid,0);
int ptype = StringUtils.getIntValue(StringUtils.null2String(request.getParameter("ptype")));
Thread thread = new Thread(new OperateThread4app(id,userid,sessionid,ptype,appNo));
thread.start();
out.print(jsonObject.toString());
return;
}else if("1".equals(type)){//导入
ProgressStatus.create(sessionid, pageid, userid, 1);
//System.out.println("---111--------sessionid:"+sessionid+"---------pageid:"+pageid);
String isadd = StringUtils.null2String(request.getParameter("isadd"));
String ptype = StringUtils.null2String(request.getParameter("ptype"));
RecordSet rs = new RecordSet();
int fileid = 0;
String xmlfilepath = "";
if ("0".equals(ptype)) {
try {
rs.executeProc("SequenceIndex_SelectFileid", "");
if (rs.next()) {
fileid = StringUtils.getIntValue(rs.getString(1),-1);
}
} catch (Exception e) {
fileid = -1;
e.printStackTrace();
}
xmlfilepath = GCONST.getRootPath() + "cloudstore"
+ File.separator + "app" + File.separator + appNo
+ File.separator + "resource" + File.separator
+ appNo + ".zip";
char separator = StringUtils.getSeparator();
String fileName = appNo + ".zip";
String para = "" + fileid + separator + fileName
+ separator + "" + separator + "1" + separator
+ xmlfilepath + separator + "0" + separator + "0"
+ separator + "1000";
rs.executeProc("ImageFile_Insert", para);
} else {
FileUpload fu = new FileUpload(request, false);
FileManage fm = new FileManage();
fileid = StringUtils.getIntValue(fu.uploadFiles("filename"), 0);
String filename = "data.zip";
String sql = "select * from imagefile where imagefileid = " + fileid;
rs.executeSql(sql);
String uploadfilepath = "", isaesencrypt = "", aescode = "";
if (rs.next()) {
uploadfilepath = rs.getString("filerealpath");
isaesencrypt = rs.getString("isaesencrypt");
aescode = rs.getString("aescode");
}
String exceptionMsg = "";
if (!uploadfilepath.equals("")) {
try {
xmlfilepath = GCONST.getRootPath() + "formmode"
+ File.separatorChar + "import"
+ File.separatorChar + filename;
File oldfile = new File(xmlfilepath);
if (oldfile.exists()) {
oldfile.delete();
}
if ("1".equals(isaesencrypt)) {
uploadfilepath = FileUtils.aesDesEncrypt(uploadfilepath, aescode);
}
fm.copy(uploadfilepath, xmlfilepath);
} catch (Exception e) {
exceptionMsg = "读取文件失败!";//读取文件失败!
System.out.println(exceptionMsg);
ProgressStatus.finish(sessionid, pageid);
}
}
}
boolean add = "1".equals(isadd) ? true : false;
Thread thread = new Thread(new OperateThread4app(id, userid,
xmlfilepath, fileid, sessionid, add, version, pageid,
appNo));
thread.start();
out.print(jsonObject.toString());
} else if ("2".equals(type)) {//查看导入/导出日志明细
int logid = StringUtils.getIntValue(request
.getParameter("logid"));
//System.out.println("logid="+logid);
String sql = "select * from mode_impexp_logdetail where logid='"
+ logid + "' order by id";
RecordSet rs = new RecordSet();
rs.executeSql(sql);
String str = "";
int i = 1;
while (rs.next()) {
String message = StringUtils.null2String(rs.getString("message"));
str += (i++) + ":" + message + "\n";
}
out.clear();
out.print(str);
return;
} else if ("3".equals(type)) {//获取导入导出进度
jsonObject.put("inprocess", false);
Map<String, Object> progressStatusMap = ProgressStatus.get(sessionid, pageid);
//System.out.println("--------sessionid:"+sessionid+"---------pageid:"+pageid);
if (progressStatusMap != null) {
int persent = ProgressStatus.getCurrentProgressPersent(sessionid, pageid);
int ptype = ProgressStatus.getPtype(sessionid, pageid);
String logid = ProgressStatus.getLogid(sessionid, pageid);
jsonObject.put("inprocess", true);
jsonObject.put("process", persent);
jsonObject.put("ptype", ptype);
jsonObject.put("logid", logid);
jsonObject.put("error", progressStatusMap.get("error"));
if (progressStatusMap.containsKey("datatype")) {
if ("app".equals(StringUtils.null2String(progressStatusMap.get("datatype")))) {
jsonObject.put("datatype", "应用");
} else if ("mode".equals(StringUtils.null2String(progressStatusMap.get("datatype")))) {
jsonObject.put("datatype", "模块");
}
}
String fileid = StringUtils.null2String(progressStatusMap.get("fileid"));
if (!"".equals(fileid)) {
jsonObject.put("fileid", fileid);
}
}
//System.out.println("-----------jsonObject.toString()"+jsonObject.toString());
out.print(jsonObject.toString());
} else if ("4".equals(type)) {
ProgressStatus.finish(sessionid, pageid);
return;
}
%>