impexpAction.jsp
12.9 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<%@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.OperateThread"%>
<%@page import="weaver.formmode.exttools.impexp.common.FileUtils"%>
<%@page import="weaver.formmode.exttools.impexp.common.XmlUtils"%>
<%@page import="org.dom4j.Element"%>
<%@page import="weaver.formmode.exttools.impexp.entity.FormDataXmlBean"%>
<%@page import="java.util.List"%>
<%@page import="weaver.formmode.exttools.impexp.log.LogRecordService"%>
<%@page import="weaver.formmode.exttools.impexp.entity.WorkFlowSetXmlBean"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.ArrayList"%>
<%
String type = StringUtils.null2String(request.getParameter("type"));
String id = StringUtils.null2String(request.getParameter("id"));
String subCompanyId = StringUtils.null2String(request.getParameter("subCompanyId"));
User user = HrmUserVarify.getUser(request, response);
String sessionid = session.getId();
int userid = user.getUID();
String pageid = StringUtils.null2String(request.getParameter("pageid"));
JSONObject jsonObject = new JSONObject();
if("0".equals(type)){//导出
ProgressStatus.create(sessionid,pageid,userid,0);
int ptype = StringUtils.getIntValue(StringUtils.null2String(request.getParameter("ptype")));
String modeids = StringUtils.null2String(request.getParameter("modeids"));
OperateThread operateThread = new OperateThread(id,userid,sessionid,ptype,pageid,modeids);
Thread thread = new Thread(operateThread);
OperateThread.putThread(sessionid, pageid, operateThread);
thread.start();
out.print(jsonObject.toString());
return;
}else if("1".equals(type)){//导入
ProgressStatus.create(sessionid,pageid,userid,1);
String isadd = StringUtils.null2String(request.getParameter("isadd"));
String version = StringUtils.null2String(request.getParameter("version"));
String isall = StringUtils.null2String(request.getParameter("all"));
String impFormids = StringUtils.null2String(request.getParameter("impFormids"));
boolean all = "1".equals(isall)?true:false;
RecordSet rs = new RecordSet();
FileUpload fu = new FileUpload(request,false);
FileManage fm = new FileManage();
String xmlfilepath="";
int fileid = 0 ;
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 = "读取文件失败!";//读取文件失败!
ProgressStatus.finish(sessionid,pageid);
}
}
boolean add = "1".equals(isadd)?true:false;
String workToModeSet=StringUtils.null2String(request.getSession().getAttribute("workToModeSet"));
String modeTriggerWorkflow=StringUtils.null2String(request.getSession().getAttribute("modeTriggerWorkflow"));
Thread thread = new Thread(new OperateThread(id,userid,xmlfilepath,fileid,sessionid,add,version,pageid,subCompanyId,all,impFormids,workToModeSet,modeTriggerWorkflow));
thread.start();
out.print(jsonObject.toString());
}else if("2".equals(type)){//查看导入/导出日志明细
int logid = StringUtils.getIntValue(request.getParameter("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> progressStatus = ProgressStatus.get(sessionid,pageid);
//System.out.println(progressStatus);
if(progressStatus!=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",progressStatus.get("error"));
if(progressStatus.containsKey("datatype")){
if("app".equals(StringUtils.null2String(progressStatus.get("datatype")))){
jsonObject.put("datatype","应用");
}else if("mode".equals(StringUtils.null2String(progressStatus.get("datatype")))){
jsonObject.put("datatype","模块");
}
}
String fileid = StringUtils.null2String(progressStatus.get("fileid"));
if(!"".equals(fileid)){
jsonObject.put("fileid",fileid);
}
if(persent>=100){
request.getSession().setAttribute("workToModeSet","");
request.getSession().setAttribute("modeTriggerWorkflow","");
}
}
out.print(jsonObject.toString());
}else if("4".equals(type)){
ProgressStatus.finish(sessionid,pageid);
request.getSession().setAttribute("workToModeSet","");
request.getSession().setAttribute("modeTriggerWorkflow","");
return;
} else if("5".equals(type)) {
OperateThread.removeThread(sessionid, pageid);
ProgressStatus.finish(sessionid,pageid);
request.getSession().setAttribute("workToModeSet","");
request.getSession().setAttribute("modeTriggerWorkflow","");
return;
}else if("6".equals(type)) {
FileUpload fu = new FileUpload(request,false);
String xmlfilepath="";
String filename = "data.zip";
RecordSet rs = new RecordSet();
FileManage fm = new FileManage();
int fileid = 0 ;
fileid = StringUtils.getIntValue(fu.uploadFiles("filename"),0);
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 = "读取文件失败!";//读取文件失败!
ProgressStatus.finish(sessionid,pageid);
}
}
xmlfilepath = GCONST.getRootPath()+"formmode"+File.separatorChar+"import"+File.separatorChar+filename ;
String zipfolderpath = FileUtils.unZip(xmlfilepath,StringUtils.getUnquieID());
XmlUtils xmlUtils = new XmlUtils();
String workFlowSetXmlpath = zipfolderpath + File.separator + "workFlowSet.xml";
Element dataRoot = xmlUtils.parseXml(workFlowSetXmlpath);
int haveData=0;
if(dataRoot != null){
WorkFlowSetXmlBean workFlowSetXmlBean=new WorkFlowSetXmlBean();
workFlowSetXmlBean.fromDocument(dataRoot);
Map<String, List<Map<String, String>>> valueMap=workFlowSetXmlBean.getValueMap();
List<Map<String, String>> list1=valueMap.get("mode_workflowtomodeset");
List<Map<String, String>> list2=valueMap.get("mode_triggerworkflowset");
if(list1.size()>0||list2.size()>0){
haveData=1;
}
}
jsonObject.put("haveData",haveData);
out.print(jsonObject.toString());
}else if("7".equals(type)){
FileUpload fu = new FileUpload(request,false);
String xmlfilepath="";
String filename = "data.zip";
RecordSet rs = new RecordSet();
FileManage fm = new FileManage();
int fileid = 0 ;
fileid = StringUtils.getIntValue(fu.uploadFiles("filename"),0);
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 = "读取文件失败!";//读取文件失败!
ProgressStatus.finish(sessionid,pageid);
}
}
xmlfilepath = GCONST.getRootPath()+"formmode"+File.separatorChar+"import"+File.separatorChar+filename ;
String zipfolderpath = FileUtils.unZip(xmlfilepath,StringUtils.getUnquieID());
XmlUtils xmlUtils = new XmlUtils();
String formDataXmlpath = zipfolderpath + File.separator + "dataSetForm.xml";
Element dataRoot = xmlUtils.parseXml(formDataXmlpath);
int haveData=0;
if(dataRoot != null){
FormDataXmlBean formDataXmlBean=new FormDataXmlBean();
formDataXmlBean.fromSetDocument(dataRoot);
Map<String, String> requestidMap = formDataXmlBean.getRequestidMap();
LogRecordService logRecordService=new LogRecordService();
for(String key : requestidMap.keySet()){
Map<String, String> map = logRecordService.getRecordMapByRequestid(key);
if (!map.isEmpty()){
String newTablename=map.get("tablename");
if(newTablename!=""){
rs.executeSql("select count(1) sum FROM "+newTablename);
while(rs.next()){
int sum=StringUtils.getIntValue(rs.getString("sum"),0);
if(sum>0){
haveData=1;
}
}
}
}
}
}
jsonObject.put("haveData",haveData);
out.print(jsonObject.toString());
}else if("8".equals(type)) {
String wsetids =StringUtils.null2String(request.getParameter("wsetids"));
String tsetids =StringUtils.null2String(request.getParameter("tsetids"));
String[] wsetidsAttr=wsetids.split(",");
String[] tsetidsAttr=tsetids.split(",");
Map<String,Map<String,String>> wvaluemap=new HashMap();
Map<String,Map<String,String>> tvaluemap=new HashMap();
for(int i=0;i<wsetidsAttr.length;i++){
String wsetid=wsetidsAttr[i];
Map<String,String> map=new HashMap();
List<Map<String,String>> wvalueList= new ArrayList();
String workflowid =StringUtils.null2String(request.getParameter("workflowid"+i));
String triggerMethod =StringUtils.null2String(request.getParameter("triggerMethod"+i)).split("_")[1];
String triggerNodeId =StringUtils.null2String(request.getParameter("triggerNodeId"+i));
String workflowExport =StringUtils.null2String(request.getParameter("workflowExport"+i));
map.put("workflowid",workflowid);
map.put("triggerMethod",triggerMethod);
map.put("triggerNodeId",triggerNodeId);
map.put("workflowExport",workflowExport);
wvaluemap.put(wsetid,map);
}
for(int i=0;i<tsetidsAttr.length;i++){
String tsetid=tsetidsAttr[i];
Map<String,String> map=new HashMap();
List<Map<String,Map<String,String>>> tvalueList= new ArrayList();
String workflowid =StringUtils.null2String(request.getParameter("tworkflowid"+i));
map.put("workflowid",workflowid);
tvaluemap.put(tsetid,map);
}
JSONObject json1 = JSONObject.fromObject(wvaluemap);
JSONObject json2 = JSONObject.fromObject(tvaluemap);
request.getSession().setAttribute("workToModeSet",json1);
request.getSession().setAttribute("modeTriggerWorkflow",json2);
out.print(jsonObject.toString());
}
%>