odocCommonAjax.jsp
20.3 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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.general.Util"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.PrintWriter"%>
<%@ page import="com.alibaba.fastjson.JSONObject"%>
<%@ page import="weaver.docs.docs.DocManager" %>
<%@ page import="weaver.docs.docs.DocDbServer" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="weaver.docs.docs.DocImageManager" %>
<%@ page import="weaver.file.ImageFileManager" %>
<jsp:useBean id="TexttoPDFManager" class="weaver.workflow.request.TexttoPDFManager" scope="page" />
<jsp:useBean id="DocCheckInOutUtil" class="weaver.docs.docs.DocCheckInOutUtil" scope="page"/>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs2" class="weaver.conn.RecordSet" scope="page"/>
<%@ page import="weaver.hrm.User" %>
<%@ page import="com.engine.workflow.util.CommonUtil" %>
<%@ page import="weaver.workflow.workflow.WorkflowComInfo" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="weaver.common.StringUtil" %>
<%
User user = CommonUtil.getUserByRequest(request, response);
if(user == null){
return;
}
String action = Util.null2String(request.getParameter("action"));
if("getData".equals(action)){
int workflowid = Util.getIntValue(request.getParameter("workflowid"),-1);
int selectValue = Util.getIntValue(request.getParameter("selectValue"),-1);
int requestid = Util.getIntValue(request.getParameter("requestid"),-1);
//int formId=Util.getIntValue(workflowComInfo.getFormId(""+workflowId),0);
//String isBill=Util.null2String(workflowComInfo.getIsBill(""+workflowId));
String strFields="";
String flowCat=""+selectValue; //取得流程中“显示目录”字段ID
int seccategoryid = -1;
int editmouldCount = 0;
int showmouldCount = 0;
int editMouldId = -1;
int showMouldId = -1;
com.api.odoc.service.RequestDocService requestDocService = new com.api.odoc.service.RequestDocService();
if(workflowid > 0 ){
rs.execute(" select flowdocfield,flowdoccatfield,defaultview from workflow_createdoc where workflowid = " + workflowid);
int docfieldid = 0;
int flowdoccategoryFieldid = 0;
String flowdoccategoryFieldname = "";
String docCategory = "";
if(rs.next()){
docfieldid = rs.getInt("flowdocfield");
flowdoccategoryFieldid = rs.getInt("flowdoccatfield");
docCategory = rs.getString("defaultView");
}
if(flowdoccategoryFieldid > 0 && selectValue >= 0){
WorkflowComInfo workflowComInfo = new WorkflowComInfo();
int isBill = Util.getIntValue(workflowComInfo.getIsBill(workflowid + ""));
String docCategoryTemp = requestDocService.getSecCategoryBySelectValue(user,flowdoccategoryFieldid,selectValue,requestid,1);
if(docCategoryTemp.length() > 0) docCategory = docCategoryTemp;
// rs.execute("select * from workflow_selectitem where fieldid = " + flowdoccategoryFieldid + " and selectvalue=" + selectValue);
// if(rs.next()){
// docCategory = rs.getString("docCategory");
// }
}
//获取编辑模板
rs.executeQuery("SELECT mouldid FROM workflow_mould a,docmouldfile b WHERE a.mouldid = b.id AND a.mouldtype IN (3, 4) AND workflowId = ? AND a.selectvalue=? order by (case isdefault when '1' then 0 else 1 end) ",workflowid,selectValue);
if(rs.next()){
editmouldCount = rs.getCounts();
editMouldId = rs.getInt("mouldid");
}else{
//获取默认编辑模板
rs.executeQuery("SELECT mouldid FROM workflow_mould a,docmouldfile b WHERE a.mouldid = b.id AND a.mouldtype IN (3, 4) AND workflowId = ? AND a.selectvalue=-1 order by (case isdefault when '1' then 0 else 1 end) ",workflowid);
if(rs.next()){
editMouldId = rs.getInt("mouldid");
}
}
//获取显示模板
rs.executeQuery("SELECT mouldid FROM workflow_mould a,docmould b WHERE a.mouldid = b.id AND a.mouldtype IN (0, 1) AND a.workflowId = ? and a.selectvalue=? order by (case isdefault when '1' then 0 else 1 end)",workflowid,selectValue);
if(rs.next()){
showmouldCount = rs.getCounts();
showMouldId = rs.getInt("mouldid");
}else{
//获取默认显示模板
rs.executeQuery("SELECT mouldid FROM workflow_mould a,docmould b WHERE a.mouldid = b.id AND a.mouldtype IN (0, 1) AND a.workflowId = ? and a.selectvalue=-1 order by (case isdefault when '1' then 0 else 1 end) ",workflowid);
if(rs.next()){
showMouldId = rs.getInt("mouldid");
}
}
//切分目录,只获取最后一级目录ID
ArrayList TempAyyay=Util.TokenizerString(""+docCategory.replace("||",","),",");
seccategoryid = Util.getIntValue(Util.null2String(TempAyyay.get(TempAyyay.size() - 1)));
}
JSONObject object = requestDocService.getDocMouldInfo(workflowid,selectValue);
//JSONObject object = new JSONObject();
object.put("seccategoryid",seccategoryid);
object.put("editmouldCount",editmouldCount);
object.put("showmouldCount",showmouldCount);
object.put("editMouldId",editMouldId);
object.put("showMouldId",showMouldId);
PrintWriter writer = response.getWriter();
writer.print(object);
return;
}
else if("updateDocToPdf".equals(action))
{
JSONObject object = new JSONObject();
PrintWriter writer = response.getWriter();
boolean success = false;
try
{
String fromFlowDocsubmit=Util.null2String(request.getParameter("fromFlowDocsubmit"));
boolean isSavePDF;
int docId = Util.getIntValue(request.getParameter("docid"),-1);
int workflowid = Util.getIntValue(request.getParameter("workflowid"),-1);
int requestid = Util.getIntValue(request.getParameter("requestid"),-1);
int nodeid = Util.getIntValue(request.getParameter("nodeid"),-1);
Map texttoPDFMap=TexttoPDFManager.getTexttoPDFMap(requestid, workflowid, nodeid,docId,fromFlowDocsubmit.equals("1"));
isSavePDF="1".equals((String)texttoPDFMap.get("isSavePDF"))?true:false;
String pdffieldid = Util.null2String((String)texttoPDFMap.get("pdffieldid"));
List attachmentList=(List)texttoPDFMap.get("attachmentList");
rs.writeLog("=====pdffieldid:"+pdffieldid+"=====docId:"+docId+"===workflowid:"+workflowid+"===requestid:"+requestid+"===nodeid:"+nodeid+"===isSavePDF:"+isSavePDF);
if(isSavePDF)
{
com.api.odoc.util.RequestIdUtil reUtil = new com.api.odoc.util.RequestIdUtil();
String pdfFieldName = reUtil.getFieldNameByRequeetIdAndFieldId(requestid+"",pdffieldid);
String billType = reUtil.getFormBillByRequestId(requestid+"");
int formId = reUtil.getFormIdByRequestId(requestid+"");
String tableName = reUtil.getFormNameByFormIdAndBillType(formId,billType);
rs.writeLog("=====pdfFieldName:"+pdfFieldName+"=====formId:"+formId+"===tableName:"+tableName);
//获取此流程有无pdf转换记录
int pdfdocid = 0;
rs.executeQuery("select pdfdocid from workflow_texttopdf where requestid = ?",requestid);
if(rs.next())
{
pdfdocid = Util.getIntValue(rs.getString(1),-1);
}
//获取正文名称,把pdf更新为正文同名
String docSubject = "";
rs.executeQuery("select docsubject from docdetail where id = ?",docId);
if(rs.next())
{
docSubject = rs.getString(1);
}
// 当前日期
String currentDate = TimeUtil.getCurrentDateString();
// 当前时间
String currentTime = TimeUtil.getOnlyCurrentTimeString();
//复制pdf正文,作为转换后pdf文件,并。
DocManager dm = new DocManager();
dm.resetParameter();
dm.setId(docId);
dm.getDocInfoById();
int newPdfId = dm.copyDoc();
String pdfimagefileid = "";
rs.executeQuery("select imagefileid from docimagefile where docid = ? and versionid = (select max(versionid) from docimagefile where docid = ? )",newPdfId,newPdfId);
if(rs.next())
{
pdfimagefileid = rs.getString(1);
}
rs.writeLog("=====docId:"+docId+"=====newPdfId:"+newPdfId+"===docSubject:"+docSubject+"===pdfdocid:"+pdfdocid+"===pdfimagefileid:"+pdfimagefileid);
String pdfsavesecid = "";
String pdfdocstatus = "";
String filetopdffile = "";
rs.executeQuery("select pdfsavesecid,pdfdocstatus,filetopdffile from workflow_texttopdfconfig WHERE workflowid = ? and topdfnodeid = ?",workflowid,nodeid);
if(rs.next())
{
pdfsavesecid = rs.getString("pdfsavesecid");
pdfdocstatus = rs.getString("pdfdocstatus");
filetopdffile = rs.getString("filetopdffile");
}
//开启了流程附件存为pdf副本附件
int todocid = 0;
if(pdfdocid>0)
todocid = pdfdocid;
//把老的附件先干掉,再转
rs2.executeUpdate("delete from docimagefile where docid = ? and isextfile = ?",todocid,1);
if("1".equals(filetopdffile))
{
String sql_fieldname = "";
if ("1".equals(billType)) {
sql_fieldname = "select * from workflow_billfield b where b.fieldhtmltype=6 and b.billid="
+ formId;
} else {
sql_fieldname = "select * from workflow_formfield f, workflow_formdict d where f.fieldid=d.id and d.fieldhtmltype=6 and f.formid="
+ formId;
}
rs.execute(sql_fieldname);
ArrayList extraFileList = new ArrayList();
while (rs.next()) {
String tmp_fieldName = Util.null2String(rs.getString("fieldname"));
if (!tmp_fieldName.trim().equals("") && !"null".equalsIgnoreCase(tmp_fieldName)) {
extraFileList.add(tmp_fieldName);
}
}
int fieldCount = extraFileList.size();
if (fieldCount > 0) {
rs.execute("select * from " + tableName + " where requestid=" + requestid);
if (rs.next()) {
for (int i = 0; i < fieldCount; i++) {
String tmp_fieldName = (String) extraFileList.get(i);
String fieldValue = Util.null2String(rs.getString(tmp_fieldName));
if ("".equals(fieldValue.trim()) || "null".equalsIgnoreCase(fieldValue)) {
continue;
}
List docIdOfAttachmentList = Util.TokenizerString(fieldValue, ",");
for (int cx = 0; cx < docIdOfAttachmentList.size(); cx++) {
int tmp_docIdOfAttachment = 0;
try {
tmp_docIdOfAttachment = Util
.getIntValue((String) docIdOfAttachmentList.get(cx), 0);
int maxId = 0;
rs2.executeSql(
"select max(a.id) as maxid from DocDetail a where a.doceditionid>0 and exists(select 1 from DocDetail where doceditionid=a.doceditionid and id="
+ tmp_docIdOfAttachment + ") ");
if (rs2.next()) {
maxId = Util.getIntValue(rs2.getString("maxid"), 0);
}
if (maxId > tmp_docIdOfAttachment) {
tmp_docIdOfAttachment = maxId;
}
else
todocid = newPdfId;
if (todocid == tmp_docIdOfAttachment) {
continue;
}
rs2.writeLog("========tmp_docIdOfAttachment:"+tmp_docIdOfAttachment);
DocImageManager imgManger = new DocImageManager() ;
int imageFileId=0;
String imageFileName=null;
String docFileType=null;
String tmptsql ="select * from docimagefile where docid="+tmp_docIdOfAttachment+" and isextfile='1' and imagefileid not in(select imagefileid from docimagefile where docid="+todocid+") and versionid in(select max(VERSIONID) from docimagefile where docid="+tmp_docIdOfAttachment+" group by id) order by id asc";
rs2.executeSql(tmptsql);
while(rs2.next()){
imageFileId=Util.getIntValue(rs2.getString("imageFileId"),0);
imageFileName=Util.null2String(rs2.getString("imageFileName"));
docFileType=Util.null2String(rs2.getString("docFileType"));
imageFileId = ImageFileManager.copyImageFile(imageFileId);
imgManger.resetParameter() ;
imgManger.setDocid(todocid) ;
imgManger.setImagefileid(imageFileId) ;
imgManger.setImagefilename(imageFileName) ;
imgManger.setDocfiletype(docFileType) ;
imgManger.setIsextfile("1");
imgManger.setHasUsedTemplet(Util.null2String(rs2.getString("hasUsedTemplet")));
imgManger.AddDocImageInfo() ;
rs2.executeSql("update imagefile set imagefileused=imagefileused+1 where imagefileid="+imageFileId);
}
} catch (Exception e) {
rs2.writeLog("DocDetail maxid=", e);
}
}
}
}
}
}
success = rs.executeUpdate("update docdetail set seccategory = ?, docstatus = ? where id = ? ",pdfsavesecid,pdfdocstatus,newPdfId);
//判断有无转换记录,若有则更新记录,若无则新增记录且更新新复制的pdf文档docid为原文档docid,并删除docdetail.
if(pdfdocid>0)
{
rs.executeUpdate("update docimagefile set docid = ? where docid = ?",pdfdocid,newPdfId);
rs.executeUpdate("update docimagefile set imagefilename = ? where docid = ? and (isextfile is null or isextfile = '' or isextfile = 0) ",docSubject+".pdf",pdfdocid);
rs.executeUpdate("update imagefile set imagefilename = ? where imagefileid in (select imagefileid from docimagefile where docid = ?)",docSubject+".pdf",pdfdocid);
success = rs.executeUpdate("update docdetail set seccategory = ?, docstatus = ?,docsubject = ? where id = ? ",pdfsavesecid,pdfdocstatus,docSubject,pdfdocid);
if(success)
rs.executeUpdate("delete from docdetail where id = ? ",newPdfId);
newPdfId = pdfdocid;
String texttopdfsql = "update workflow_texttopdf set pdfimagefileid = ?,transformDate = ?,transformTime = ? where requestid = ? and pdfdocid = ?";
rs.executeUpdate(texttopdfsql,pdfimagefileid,currentDate,currentTime,requestid,newPdfId);
}else
{
String texttopdfsql = "insert into workflow_texttopdf(requestid,docid,pdfdocid,pdfimagefileid,transformDate,transformTime) values(?,?,?,?,?,?)";
rs.executeUpdate(texttopdfsql,requestid,docId,newPdfId,pdfimagefileid,currentDate,currentTime);
}
rs.writeLog("======update "+tableName+" set "+pdfFieldName+" = "+newPdfId+" where requestid = "+requestid);
rs.executeUpdate("update "+tableName+" set "+pdfFieldName+" = ? where requestid = ?",newPdfId+"",requestid);
object.put("fieldValue",newPdfId);
object.put("fieldId",pdffieldid);
object.put("PdfName",docSubject);
}
}catch (Exception e)
{
success = false;
e.printStackTrace();
}
object.put("success",success);
writer.print(object);
}
else if("setUrlParams".equals(action)) {
Map readOnlyMap = request.getParameterMap();
String UrlParam = "";
//遍历map中的键
Iterator<Map.Entry<String, String[]>> entries = readOnlyMap.entrySet().iterator();
JSONObject paramMap = new JSONObject();
while (entries.hasNext()) {
Map.Entry<String, String[]> entry = entries.next();
if(entry.getKey() != null && !entry.getKey().equals("")){
String requestValue = "";
if(entry.getValue().length==1){
requestValue = entry.getValue()[0];
} else {
String[] values = entry.getValue();
for(int i=0; i<values.length; i++){
requestValue = values[i] + ",";
}
requestValue = requestValue.substring(0, requestValue.length()-1);
}
if(!UrlParam.equals("")) UrlParam += "&";
UrlParam += entry.getKey() + "=" + requestValue;
String url = requestValue.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
String urlStr = URLEncoder.encode(url, "UTF-8");
paramMap.put(entry.getKey(),urlStr);
}
}
String uuid = UUID.randomUUID().toString();
boolean retFalg = rs.executeUpdate("insert into odoc_urlparam (uuid,urlparams) values (?,?)",uuid,paramMap.toString());
JSONObject object = new JSONObject();
object.put("uuid",uuid);
object.put("success",retFalg);
PrintWriter writer = response.getWriter();
writer.print(object);
} else if("saveGinatureCount".equals(action)) {
int requestid = Util.getIntValue(Util.null2String(request.getParameter("requestid")));
int singCount = Util.getIntValue(Util.null2String(request.getParameter("singCount")));
int nodeid = -1;
rs.executeQuery(" select currentnodeid from workflow_requestbase where requestid = ?",requestid);
if(rs.next()){
nodeid = rs.getInt("currentnodeid");
}
rs.executeUpdate("delete from odoc_ofd_sign where requestid = ? and nodeid = ?",requestid,nodeid);
boolean retFalg = rs.executeUpdate("insert into odoc_ofd_sign (requestid,nodeid,signCount) values (?,?,?)",requestid,nodeid,singCount);
JSONObject object = new JSONObject();
object.put("success",retFalg);
PrintWriter writer = response.getWriter();
writer.print(object);
} else if("getGinatureCount".equals(action)) {
int requestid = Util.getIntValue(Util.null2String(request.getParameter("requestid")));
int nodeid = Util.getIntValue(Util.null2String(request.getParameter("nodeid")));
int singCount = -1;
rs.executeQuery(" select signCount from odoc_ofd_sign where requestid = ? and nodeid = ?",requestid,nodeid);
if(rs.next()){
singCount = rs.getInt("singCount");
}
JSONObject object = new JSONObject();
object.put("success",true);
object.put("singCount",singCount);
PrintWriter writer = response.getWriter();
writer.print(object);
}else if("updateAttachFile".equals(action))
{
try
{
String fileIds=Util.null2String(request.getParameter("fileIds"));
String time=Util.null2String(request.getParameter("time"));
int docId = Util.getIntValue(request.getParameter("docid"),-1);
if(docId>0)
{
String isExistedImageFileIds = "";
rs.executeQuery("select imagefileid from docimagefile where docid = ? and isextfile = ?",docId,1);
while(rs.next())
{
isExistedImageFileIds += rs.getInt("imagefileid")+",";
}
if(!"".equals(isExistedImageFileIds))
{
isExistedImageFileIds = isExistedImageFileIds.substring(0,isExistedImageFileIds.length()-1);
}
//未操作的附件
List<String> existFileList = new ArrayList<String>();
//新增的附件
List<String> addFileList = new ArrayList<String>();
String delids = "";
String existfiles = "";
String newaddfiles = "";
for (String fileid : fileIds.split(","))
{
boolean hasFile = false;
for(String existFile : isExistedImageFileIds.split(","))
{
if(fileid.equals(existFile))
{
hasFile = true;
}
}
if(hasFile)
{
existFileList.add(fileid);
existfiles+= fileid +",";
}else
{
addFileList.add(fileid);
newaddfiles+= fileid +",";
}
}
if(!"".equals(existfiles))
{
//先删
existfiles = existfiles.substring(0,existfiles.length()-1);
if(StringUtil.isNotNull(existfiles)){
rs.executeUpdate("delete from docimagefile where docid = ? and imagefileid not in (" + existfiles+") and isextfile = ?",docId,1);
}
}else
{
//如果没有存在的文件,那就全删
rs.executeUpdate("delete from docimagefile where docid = ? and isextfile = ?",docId,1);
}
//再加
com.api.doc.detail.service.DocAccService accService = new com.api.doc.detail.service.DocAccService();
for(int i = 0 ; i < addFileList.size(); i++)
{
String addfile = addFileList.get(i);
int flag = accService.buildRelForDoc(Util.getIntValue(addfile, 0), docId);
}
int num = 0;
rs.executeQuery("select count(id) num from docimagefile where docid = ? and isextfile = ?",docId,1);
if(rs.next())
{
num = rs.getInt("num");
}
rs.executeUpdate("update docdetail set accessorycount = ? where id = ? ",num,docId);
rs.writeLog("===exist:"+existfiles+"=====add:"+newaddfiles+"===time:"+time+"====num:"+num);
}
}catch (Exception e)
{
e.printStackTrace();
}
} else if("getNewImagefileId".equals(action)) {
int docid = Util.getIntValue(Util.null2String(request.getParameter("docid")));
int imagefileid = -1;
rs.executeQuery(" select docimagefile.imagefileid from docimagefile inner join imagefile on docimagefile.imagefileid = imagefile.imagefileid where docimagefile.docid=? and (docimagefile.isextfile is null or docimagefile.isextfile <> '1') order by docimagefile.imagefileid desc", docid);
if(rs.next()){
imagefileid = rs.getInt("imagefileid");
}
JSONObject object = new JSONObject();
object.put("success",true);
object.put("imageFileId",imagefileid);
PrintWriter writer = response.getWriter();
writer.print(object);
} else if("saveIsignature2015Count".equals(action)) {
JSONObject object = new JSONObject();
PrintWriter writer = response.getWriter();
String requestId=Util.null2String(request.getParameter("requestId"));
String nodeId=Util.null2String(request.getParameter("nodeId"));
String userId=Util.null2String(request.getParameter("userId"));
String loginType=Util.null2String(request.getParameter("loginType"));
String signNum=Util.null2String(request.getParameter("signNum"));
try
{
DocCheckInOutUtil.saveIsignatureFun(requestId,nodeId,userId,loginType,signNum);
object.put("success",true);
}catch (Exception e)
{
object.put("success",false);
e.printStackTrace();
}
writer.print(object);
}
%>