WorkflowToModeSetOperation.jsp
20 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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<%@page import="net.sf.json.JSONObject"%>
<%@page import="weaver.formmode.browser.FormModeBrowserUtil"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="com.weaver.formmodel.util.StringHelper"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="weaver.workflow.action.WorkflowActionManager"%>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="WorkflowComInfo" class="weaver.workflow.workflow.WorkflowComInfo" scope="page" />
<%
if(!HrmUserVarify.checkUserRight("ModeSetting:All", user)){
response.sendRedirect("/notice/noright.jsp");
return;
}
String operation = Util.null2String(request.getParameter("operation"));
if (operation.equals("getBaseField")){
String wfformid = Util.null2String(request.getParameter("wfformid"));
String formtype = Util.null2String(request.getParameter("formtype"));
String basedfield = Util.null2String(request.getParameter("basedfield"));
boolean ischangeformtype = Util.null2String(request.getParameter("type")).equals("true");
StringBuffer basedfieldhtml = new StringBuffer();
String tablename = "";
rs.executeSql("select tablename from workflow_bill where id = '"+wfformid+"'");
if(rs.next()){
tablename = Util.null2String(rs.getString("tablename"));
}
String tempdetailtable = tablename+"_dt"+formtype.replace("detail","");
String sql = "select id,fieldname,fieldlabel,fielddbtype,fieldhtmltype,type,viewtype,detailtable from workflow_billfield where billid = '" +
wfformid + "' order by viewtype asc,detailtable asc,id asc";
rs.executeSql(sql);
boolean basedfieldexists = false;
basedfieldhtml.append("<select class=InputStyle id='basedfield' name='basedfield' onChange=\"checkinput('basedfield','basedfieldspan');initSbSelectorStyle();\">") ;
basedfieldhtml.append("<option value=''></option>");
while(!"".equals(wfformid)&&rs.next()){
String fieldid = Util.null2String(rs.getString("id"));
String fieldname = Util.null2String(rs.getString("fieldname"));
String fieldlabel = Util.null2String(rs.getString("fieldlabel"));
String fielddbtype = Util.null2String(rs.getString("fielddbtype"));
String fieldhtmltype = Util.null2String(rs.getString("fieldhtmltype"));
String type = Util.null2String(rs.getString("type"));
String viewtype = Util.null2String(rs.getString("viewtype"));
String detailtable = Util.null2String(rs.getString("detailtable"));
String labelname = SystemEnv.getHtmlLabelName(Util.getIntValue(fieldlabel),user.getLanguage());
if("3".equals(fieldhtmltype) && "256".equals(type)){
labelname += "("+fieldname+",varchar(1000))";
}else if("3".equals(fieldhtmltype) && "257".equals(type)){
labelname += "("+fieldname+",varchar(4000))";
}else{
labelname += "("+fieldname+","+fielddbtype+")";
}
if(viewtype.equals("1")){
if(tempdetailtable.equals(detailtable)) {
int modedetailno = Util.getIntValue(detailtable.replace(tablename+"_dt", ""));
labelname = SystemEnv.getHtmlLabelName(17463,user.getLanguage())+modedetailno +"_"+ labelname;
} else {
continue;
}
}
if(formtype.equals("maintable") && !"0".equals(viewtype)) {
continue;
}
//整数或者多选browser框可以作为依据字段
if(("1".equals(fieldhtmltype)&&"2".equals(type))||FormModeBrowserUtil.isMultiBrowser(fieldhtmltype, type)){
basedfieldhtml.append("<option value='"+fieldid+"'");
if(!"1".equals(fieldhtmltype)){
basedfieldhtml.append(" ismultibrowser='true' ");
}
if(!ischangeformtype && fieldid.equals(basedfield)){
basedfieldhtml.append(" selected ");
basedfieldexists = true;
}
basedfieldhtml.append(">"+labelname+"</option>");
}
}
basedfieldhtml.append("</select>");
basedfieldhtml.append("<span id=basedfieldspan>");
if(!basedfieldexists){
basedfieldhtml.append("<IMG src='/images/BacoError_wev8.gif' align=absMiddle>");
}
basedfieldhtml.append("</span>");
JSONObject obj = new JSONObject();
response.resetBuffer();
response.setContentType("text/html;charset=UTF-8");
obj.put("basedfieldhtml",basedfieldhtml.toString());
response.getWriter().write(obj.toString());
return;
}
char separator = Util.getSeparator() ;
String sql = "";
int workflowid = Util.getIntValue(request.getParameter("workflowid"),0);
int modeid = Util.getIntValue(request.getParameter("modeid"),0);
int id = Util.getIntValue(request.getParameter("id"),0);
int modecreater = Util.getIntValue(request.getParameter("modecreater"),0);
int modecreaterfieldid = Util.getIntValue(request.getParameter("modecreaterfieldid"),0);
int detailno = Util.getIntValue(request.getParameter("detailno"),0);
int triggerMethod = Util.getIntValue(request.getParameter("triggerMethod"),1); //触发方式:节点触发,出口触发
int triggerMethodOld = Util.getIntValue(request.getParameter("triggerMethodOld"), 1);
int resetdataid = Util.getIntValue(request.getParameter("resetdataid"),0);
int ishistoricaluser = Util.getIntValue(request.getParameter("ishistoricaluser"),0);
int triggerNodeId = 0;
int triggerNodeIdOld = 0;
int triggerType = 0;
int workflowExport = 0;
int workflowExportOld = 0;
if (triggerMethod == 1) { //节点触发
triggerNodeId = Util.getIntValue(request.getParameter("triggerNodeId"),0);
triggerNodeIdOld = Util.getIntValue(request.getParameter("triggerNodeIdOld"),0);
triggerType = Util.getIntValue(request.getParameter("triggerType"),0);
} else if (triggerMethod == 2) { //出口触发
workflowExport = Util.getIntValue(request.getParameter("workflowExport"),0); //触发出口
workflowExportOld = Util.getIntValue(request.getParameter("workflowExportOld"),0); //触发出口
}
int isenable = Util.getIntValue(request.getParameter("isenable"),0);
String formtype = Util.null2String(request.getParameter("formtype"),"maintable");
int tempid = id;
String isnode = "1";
String type = "2";
int initworkflowid = Util.getIntValue(request.getParameter("initworkflowid"),0);
int initmodeid = Util.getIntValue(request.getParameter("initmodeid"),0);
int actionid = Util.getIntValue(request.getParameter("actionid"),0);
int actionorder = 0;
String maintableopttype = Util.null2String(request.getParameter("maintableopttype"),"1");
String maintableupdatecondition = Util.null2String(request.getParameter("maintableupdatecondition")).trim();
String maintablewherecondition = Util.null2String(request.getParameter("maintablewherecondition")).trim();
String workflowtomodename = Util.null2String(request.getParameter("workflowtomodename")).trim();
String __multilangpre_workflowtomodename = Util.null2String(request.getParameter("__multilangpre_workflowtomodename")).trim();
if(!StringHelper.isEmpty(__multilangpre_workflowtomodename)) {
workflowtomodename = __multilangpre_workflowtomodename;
}
if (!"4".equals(maintableopttype)) { //如果不是插入并更新,则清除掉条件
maintablewherecondition = "";
}
if("1".equals(maintableopttype) || "4".equals(maintableopttype)){//如果是插入或者是插入并更新,则清空更新条件
maintableupdatecondition = "";
}else{
maintableupdatecondition = maintableupdatecondition.replaceAll("<br>",""+'\n').replaceAll("\'","\''");
}
String basedfield = Util.null2String(request.getParameter("basedfield"));
//如果不是批量插入操作,则清空生成多条数据字段信息
if(!"3".equals(maintableopttype)){
basedfield = "";
}
boolean needDeleteAction = false;
//1、触发发方式改变;2、触发节点改变;3、触发出口改变
if(triggerMethod != triggerMethodOld || (triggerMethod == 1 && triggerNodeId != triggerNodeIdOld) || (triggerMethod == 2 && workflowExport != workflowExportOld)){
needDeleteAction = true;
}
String actionname = "WorkflowToMode";
WorkflowActionManager workflowActionManager = new WorkflowActionManager();
//先删除数据再重新保存
if (operation.equals("save")) {
String customervalue = "action.WorkflowToMode";//通过action,使流程的数据转为卡片数据
if(modecreater!=3){
modecreaterfieldid = 0;
}
if(id>0){//编辑
sql = "select a.workflowid,a.formtype from mode_workflowtomodeset a where id="+id;//修改前先判断是否修改了流程类型和触发表单--如果修改,则需要清空触发条件
rs.executeSql(sql);
if(rs.next()){
int old_workflowid = rs.getInt("workflowid");
String old_formtype = rs.getString("formtype");
if(old_workflowid!=workflowid||!old_formtype.equals(formtype)){
String objdbname = "workflowtomodeid";
sql = "delete from mode_expressions where "+objdbname+"="+id;
rs.executeSql(sql);
sql = "delete from mode_expressionbase where "+objdbname+"="+id;
rs.executeSql(sql);
sql = "update mode_workflowtomodeset set conditiontype=null,conditionsql=null,conditiontext=null where id="+id;
rs.executeSql(sql);
}
}
//修改数据
sql = "update mode_workflowtomodeset set workflowtomodename = '"+workflowtomodename+"', isenable = "+isenable+",modeid = "+modeid+",workflowid = "+workflowid+",modecreater = "+modecreater
+",modecreaterfieldid = "+modecreaterfieldid+",triggerMethod="+triggerMethod+",triggerNodeId = "+triggerNodeId+",triggerType = "+triggerType+",workflowExport="+workflowExport+",formtype='"
+formtype+"',maintableopttype='"+maintableopttype+"',maintableupdatecondition='"+maintableupdatecondition+"',maintablewherecondition='"+maintablewherecondition+"',basedfield='"+basedfield+"',resetdataid='"+resetdataid+"',ishistoricaluser='"+ishistoricaluser+"' where id = " + id;
rs.executeSql(sql);
//删除已经设置好的明细数据
sql = "delete from mode_workflowtomodesetdetail where mainid = " + id;
rs.executeSql(sql);
for(int i=0;i<=detailno;i++){
String wffieldidvalues[] = request.getParameterValues("wffieldid"+i);
String modefieldidvalues[] = request.getParameterValues("modefieldid"+i);
if(wffieldidvalues!=null && modefieldidvalues!=null){
for(int j=0;j<wffieldidvalues.length;j++){
int wffieldidvalue = Util.getIntValue((String)wffieldidvalues[j],0);
int modefieldidvalue = Util.getIntValue((String)modefieldidvalues[j],0);
String defaultValue = Util.null2String(request.getParameter("defaultValue_"+i+"_"+j));
sql = "insert into mode_workflowtomodesetdetail (mainid,modefieldid,wffieldid,defaultValue) values ("+id+","+modefieldidvalue+","+wffieldidvalue+",'"+defaultValue+"')";
rs.executeSql(sql);
}
}
}
//删除已经设置好的明细表操作方式
sql ="delete from mode_workflowtomodesetopt where mainid = " + id;
rs.executeSql(sql);
if(formtype.indexOf("detail")==-1){
for(int i=1;i<=detailno;i++){
String detailtablename = Util.null2String(request.getParameter("detailtablename"+i));
String detailtableopttype =Util.null2String(request.getParameter("detailtableopttype"+i));
String detailtableupdatecondition = Util.null2String(request.getParameter("detailtableupdatecondition"+i));
String detailtablewherecondition = Util.null2String(request.getParameter("detailtablewherecondition"+i));
detailtableupdatecondition = Util.fromScreen(detailtableupdatecondition,user.getLanguage());
//如果主数据中不是插入并更新,清除掉条件数据
if (!"4".equals(maintableopttype)) {
detailtablewherecondition = "";
}
if("1".equals(maintableopttype)){//如果主表是插入操作,则子表操作条件清空
detailtableopttype = "";
detailtableupdatecondition = "";
}
if(!"3".equals(detailtableopttype)&&!"4".equals(detailtableopttype)){//如果不是更新操作则更新条件清空
detailtableupdatecondition = "";
}
sql = "insert into mode_workflowtomodesetopt (mainid,detailtablename,opttype,updatecondition,wherecondition) values "
+"("+id+",'"+detailtablename+"','"+detailtableopttype+"','"+detailtableupdatecondition+"','"+detailtablewherecondition+"')";
rs.executeSql(sql);
}
}
/*if(actionid>0){
WorkflowActionManager workflowActionManager = new WorkflowActionManager();
workflowActionManager.doDeleteWsAction(actionid);
} */
//检查修改前的action情况
rs.executeSql(" select isold from mode_workflowtomodeset where id = "+id);
int isold = 0;
if(rs.next()) {
isold = Util.getIntValue(rs.getString("isold"),0);
}
if(isold == 0) { //新接口, 一个流程转数据配置与流程转数据接口一一对应。
boolean hasaction = rs.executeSql("select actionorder from workflowactionset where id = "+actionid);
if(!rs.next()) {
actionid = 0;
actionorder = 0;
} else {
actionorder = Util.getIntValue(rs.getString("actionorder"),0);
}
if(needDeleteAction){
workflowActionManager.doDeleteWsAction(actionid);
actionid = 0;
}
workflowActionManager.setActionid(actionid);
workflowActionManager.setWorkflowid(workflowid);
workflowActionManager.setNodeid(triggerNodeId);
workflowActionManager.setNodelinkid(workflowExport);
workflowActionManager.setIspreoperator(triggerType);
workflowActionManager.setActionname(workflowtomodename);
workflowActionManager.setInterfaceid(actionname);
workflowActionManager.setActionorder(actionorder);
workflowActionManager.setInterfacetype(3);
workflowActionManager.setIsused(isenable);//是否启用
actionid = workflowActionManager.doSaveWsAction();
} else { //老接口,同一位置触发的流程转数据配置对应一个流程转数据接口
//判断修改后接口情况, 如果修改后的位置存在启用的老接口,直接用这个接口,如果不存在需要新建一个
sql = " select a.actionid, b.actionorder from mode_workflowtomodeset a,workflowactionset b where a.actionid=b.id and a.isold = '1' and a.isenable = '1' and b.isused = '1' ";
if(triggerNodeId > 0){
sql += " and a.triggernodeid="+triggerNodeId+" and a.triggertype="+triggerType;
}else{
sql += " and a.workflowexport="+workflowExport;
}
int tmpactionid = 0;
int tmpactionorder = 0;
int tmpactionorder1 = 0;
rs.executeSql(sql);
while(rs.next()) {
tmpactionorder1 = Util.getIntValue(rs.getString("actionorder"),0);
if(tmpactionorder1<=tmpactionorder1 || tmpactionorder == 0){
tmpactionid = Util.getIntValue(rs.getString("actionid"),0);
tmpactionorder = tmpactionorder1;
}
}
//检查原接口情况
int oldTriggerNodeId=0,oldTriggerType=0,oldWorkflowExport=0;
sql = " select triggerNodeId,triggerType,workflowExport from mode_workflowtomodeset where id ="+id;
rs.executeSql(sql);
if(rs.next()){
oldTriggerNodeId = Util.getIntValue(rs.getString("triggerNodeId"),0);
oldTriggerType = Util.getIntValue(rs.getString("oldTriggerType"),0);
oldWorkflowExport = Util.getIntValue(rs.getString("oldWorkflowExport"),0);
}
sql = " select id from mode_workflowtomodeset where isold = '1' and isenable = '1' and id <> "+id;
if(oldTriggerNodeId > 0){
sql += " and triggernodeid="+oldTriggerNodeId+" and triggertype="+oldTriggerType;
}else{
sql += " and workflowexport="+oldWorkflowExport;
}
rs.executeSql(sql);
if(rs.next()) { //不能移动原接口
actionid = tmpactionid;
actionorder = tmpactionorder;
} else { //可以移动接口
//检查action是否存在
rs.executeSql(" select actionorder from workflowactionset where id ="+actionid);
if(rs.next()) {
actionorder = Util.getIntValue(rs.getString("actionorder"),0);
} else {
actionid = 0;
actionorder = 0;
}
}
if(tmpactionid > 0) {
workflowActionManager.setIsused(1);//启用
actionid = tmpactionid;
actionorder = tmpactionorder;
} else {
workflowActionManager.setIsused(isenable);//是否启用
}
workflowActionManager.setActionid(actionid);
workflowActionManager.setWorkflowid(workflowid);
workflowActionManager.setNodeid(triggerNodeId);
workflowActionManager.setActionorder(actionorder);
workflowActionManager.setNodelinkid(workflowExport);
workflowActionManager.setIspreoperator(triggerType);
workflowActionManager.setActionname(actionname+"_old");
workflowActionManager.setInterfaceid(actionname);
workflowActionManager.setInterfacetype(3);
actionid = workflowActionManager.doSaveWsAction();
}
//更新修改后位置流程转数据配置中actionid
sql = "update mode_workflowtomodeset set actionid = " + actionid;
if(isold == 0) {
sql+=" where id = " + id;
} else {//老接口,需要更新所有老接口
sql +=" where isold = '1' and workflowid = "+workflowid;
if(triggerNodeId > 0){
sql += " and triggernodeid="+triggerNodeId+" and triggertype="+triggerType;
}else{
sql += " and workflowexport="+workflowExport;
}
}
rs.executeSql(sql);
} else {//新建
workflowActionManager.setActionid(0);//新建
workflowActionManager.setWorkflowid(workflowid);
workflowActionManager.setNodeid(triggerNodeId);
workflowActionManager.setActionorder(0);
workflowActionManager.setNodelinkid(workflowExport);
workflowActionManager.setIspreoperator(triggerType);
workflowActionManager.setActionname(workflowtomodename);
workflowActionManager.setInterfaceid(actionname);
workflowActionManager.setInterfacetype(3);
workflowActionManager.setIsused(0);//新建未启用
actionid = workflowActionManager.doSaveWsAction();
//插入主表数据
sql = "insert into mode_workflowtomodeset(workflowtomodename,modeid,workflowid,modecreater,modecreaterfieldid,triggerMethod,triggerNodeId,triggerType,workflowExport,isenable,formtype,actionid,resetdataid,ishistoricaluser)"
+" values ('"+workflowtomodename+"',"+modeid+","+workflowid+","+modecreater+","+modecreaterfieldid+","+triggerMethod+","+triggerNodeId+","+triggerType+","+workflowExport+","+isenable+",'"+formtype+"',"+actionid+",'"+resetdataid+"','"+ishistoricaluser+"')";
rs.executeSql(sql);
//查询id
sql = "select max(id) id from mode_workflowtomodeset where modeid = " + modeid + " and workflowid = " + workflowid + " and modecreater = " + modecreater + " and modecreaterfieldid = " +modecreaterfieldid;
rs.executeSql(sql);
while(rs.next()){
id = rs.getInt("id");
}
//新建的时候,如果明细和主表用的为同一个表单,则初始化字段的对应关系
int modeformid = 0;
int wfformid = 0;
wfformid = Util.getIntValue(WorkflowComInfo.getFormId(String.valueOf(workflowid)));
sql = "select modename,formid from modeinfo where id = " + modeid;
rs.executeSql(sql);
while(rs.next()){
modeformid = rs.getInt("formid");
}
if(wfformid==modeformid&&wfformid!=0){
sql = "insert into mode_workflowtomodesetdetail (mainid,modefieldid,wffieldid) select " + id + ",id,id from workflow_billfield where billid = " + wfformid;
rs.executeSql(sql);
}
}
response.sendRedirect("/formmode/interfaces/WorkflowToModeSet.jsp?initworkflowid="+initworkflowid+"&initmodeid="+initmodeid+"&id="+id);
}else if (operation.equals("del")) {
//删除主表数据
sql = "delete from mode_workflowtomodeset where id = " + id;
rs.executeSql(sql);
//删除明细表更新条件
sql = "delete from mode_workflowtomodesetopt where mainid = " + id;
rs.executeSql(sql);
//删除明细表数据
sql = "delete from mode_workflowtomodesetdetail where mainid = " + id;
rs.executeSql(sql);
if(actionid>0){
workflowActionManager.doDeleteWsAction(actionid);
}
response.sendRedirect("/formmode/interfaces/WorkflowToModeList.jsp?workflowid="+initworkflowid+"&modeid="+initmodeid);
}
%>