signDataPushAction.java
16.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
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
package com.cntytz;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.file.ImageFileManager;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;
import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
*
* @author XuBin
* @date 2020/4/15
*/
public class signDataPushAction extends BaseBean implements Action {
Log logger = LogFactory.getLog(signDataPushAction.class);
/**
* 执行器
*
* @param requestInfo
* @return
*/
@Override
public String execute(RequestInfo requestInfo) {
JSONObject json = new JSONObject();
Boolean isNewWorkFolw=true;
writeLog("===================================start 1 2 3 =================================================");
RequestManager manager = requestInfo.getRequestManager();
String requestid = requestInfo.getRequestid();
writeLog("get the ====== requrstId=", requestInfo + "====requestid" + requestid);
String workflowid = requestInfo.getWorkflowid();
String tableName = getTableName(workflowid);
writeLog("get the ====== workflowid=", workflowid + "get the tableName===" + tableName);
RecordSet rsInfo = new RecordSet();
RecordSet rsInfo1 = new RecordSet();
RecordSet rsInfo2 = new RecordSet();
RecordSet rsInfo3 = new RecordSet();
RecordSet rsInfo4 = new RecordSet();
RecordSet rsInfo7 = new RecordSet();
RecordSet rsInfo8 = new RecordSet();
String mainID = "";
String sql;
//获取申请信息
sql = "select * from " + tableName + " where requestid = " + requestid + "";
writeLog("get the ====== sql=", sql);
rsInfo.execute(sql);
rsInfo.next();
mainID= rsInfo.getString("id");
//判断申请是 重新申请还是新流程发起
sql = "select * from workflow_requestlog where REQUESTID = "+requestid+"";
rsInfo8.execute(sql);
rsInfo8.next();
List<List<Object>> requestLogList= rsInfo8.getArray();
writeLog("the requestlog list is list={}",JSONObject.toJSONString(requestLogList));
if(requestLogList.size()>1){
//重新发起流程
isNewWorkFolw = false;
}
//获取申请人信息
sql = "select h.LOGINID as loginName,c.SUBCOMPANYNAME as companyName,h.mobile as phone from hrmresource as h left join hrmsubcompany as c on h.subcompanyid1 = c.id where h.id =" + rsInfo.getString("sqr") + "";
writeLog("get the ====== sql=", sql);
rsInfo1.execute(sql);
rsInfo1.next();
//申请人账户
String loginName = rsInfo1.getString("loginName");
//申请人公司
String companyName = rsInfo1.getString("companyName");
//申请人手机号
String mobile = rsInfo1.getString("mobile");
//获取项目经理
sql = "select h.LOGINID as loginName , h.LASTNAME as name from hrmresource as h where id =" + rsInfo.getString("xmjl1") + "";
writeLog("get the ====== sql=", sql);
rsInfo2.execute(sql);
rsInfo2.next();
//项目经理名称
String pmName = rsInfo2.getString("name");
//项目经理登录账户
String pmLoginName = rsInfo2.getString("loginName");
//获取材料科审核人
sql = "select h.LOGINID as loginName , h.LASTNAME as name from hrmresource as h where id =" + rsInfo.getString("clkshr1") + "";
writeLog("get the ====== sql=", sql);
rsInfo3.execute(sql);
rsInfo3.next();
//材料科审核人名称
String clName = rsInfo3.getString("name");
//材料科审核人登录账户
String clLoginName = rsInfo3.getString("loginName");
//获取所选项目部名称
sql = "select d.DEPARTMENTNAME as departName from hrmdepartment as d where id = " + rsInfo.getString("xmmc") + "";
writeLog("get the ====== sql=", sql);
rsInfo4.execute(sql);
rsInfo4.next();
//项目部名称
String departName = rsInfo4.getString("departName");
writeLog("get the departName====== departName=", departName);
//获取用印盖章文件 list
List<Object> fileList = new ArrayList();
String yywj = rsInfo.getString("yywj");
writeLog("111111111111111111111111111111111111111111111111111111111111111111111111111111");
String[] yywjList = yywj.split(",");
writeLog("yywjListyywjListyywjListyywjList", yywjList);
for (int i = 0; i < yywjList.length; i++) {
Map<String, Object> fileMap = new HashMap<>(16);
RecordSet rsInfo5 = new RecordSet();
sql = "select imagefile.IMAGEFILENAME as fileName,imagefile.FILEREALPATH as filepath,imagefile.IMAGEFILEID as imageFileId from docimagefile left join imagefile on docimagefile.IMAGEFILEID = imagefile.IMAGEFILEID where docimagefile.DOCID =" + yywjList[i] + "";
writeLog("=========fileListsqlsqlqslqsqlsql========", sql);
rsInfo5.execute(sql);
rsInfo5.next();
String fileName = rsInfo5.getString("fileName");
String initialFileId = rsInfo5.getString("filepath");
String imageFileId = rsInfo5.getString("imageFileId");
//换成主建id
fileMap.put("initialFileId", imageFileId);
String newFilePath = getNewFilePath(imageFileId);
//原有的docid
fileMap.put("initialDocId", yywjList[i]);
fileMap.put("fileId", imageFileId+fileName.substring(fileName.lastIndexOf(".")));
fileMap.put("fileName", fileName);
fileMap.put("initialImageFileId", mainID);
fileList.add(fileMap);
}
writeLog("=========fileListfileListfileListfileList========", JSONObject.toJSONString(fileList));
//其他附件
List<Object> attachmentList = new ArrayList();
String qtfj = rsInfo.getString("qfj");
writeLog("2222222222222222222222222222222222222222222222222222222222222222");
String[] qtfjList = qtfj.split(",");
for (int i = 0; i < qtfjList.length; i++) {
if (qtfjList[i] ==null || qtfjList[i].length() ==0 ){
}else{
Map<String, Object> fileMap = new HashMap<>(16);
RecordSet rsInfo6 = new RecordSet();
sql = "select imagefile.IMAGEFILENAME as fileName,imagefile.FILEREALPATH as filepath ,imagefile.IMAGEFILEID as imageFileId,imagefile.IMAGEFILEID as imageFileId from docimagefile left join imagefile on docimagefile.IMAGEFILEID = imagefile.IMAGEFILEID where docimagefile.DOCID =" + qtfjList[i] + "";
writeLog("=========qtfjListqtfjListqtfjListqtfjList========", sql);
rsInfo6.execute(sql);
rsInfo6.next();
String fileName = rsInfo6.getString("fileName");
String initialFileId = rsInfo6.getString("filepath");
String imageFileId = rsInfo6.getString("imageFileId");
String newFilePath = getNewFilePath(imageFileId);
//原有的docid
fileMap.put("initialDocId", qtfjList[i]);
fileMap.put("fileId", imageFileId+fileName.substring(fileName.lastIndexOf(".")));
fileMap.put("fileName", fileName);
attachmentList.add(fileMap);
}
}
writeLog("=========qtfjListqtfjListqtfjList========", JSONObject.toJSONString(attachmentList));
//获取材料明细数据
//formtable_main_38 formtable_main_38_dt1
String tableDt1 = tableName+"_dt1";
sql = "select dt1.* from "+tableDt1+" as dt1 left join "+tableName+" as fm on dt1.mainid = fm.id where fm.id = " + rsInfo.getString("id") + "";
// sql = "select dt1.* from formtable_main_38_dt1 as dt1 left join formtable_main_38 as fm on dt1.mainid = fm.id where fm.id = " + rsInfo.getString("id") + "";
writeLog("get the userFileSql====== sql=", sql);
rsInfo7.execute(sql);
rsInfo7.next();
List<List<Object>> materialInfoList = rsInfo7.getArray();
String[] columnName = rsInfo7.getColumnName();
writeLog("=========materialInfoListmaterialInfoList========", JSONObject.toJSONString(materialInfoList));
writeLog("=========columnNamecolumnName========", JSONObject.toJSONString(columnName));
UseSealApplySubmitRequest useSealApplySubmitRequest = new UseSealApplySubmitRequest();
//发票类型
useSealApplySubmitRequest.setInvoiceType(rsInfo.getString("fplx"));
writeLog("get the departName====== fplx=", departName);
//税率
useSealApplySubmitRequest.setTaxRate(rsInfo.getString("sl"));
//任务ID
useSealApplySubmitRequest.setRequestId(requestid);
//用印申请
useSealApplySubmitRequest.setContractType(1);
//ecology用印流程的workFlowId
useSealApplySubmitRequest.setWorkFlowId(workflowid);
//泛微中对应的流程业务表
useSealApplySubmitRequest.setEcologyTable(tableName);
//项目经理
useSealApplySubmitRequest.setPmName(pmName);
writeLog("get the departName====== pmName1=", departName);
//项目经理登录账户
useSealApplySubmitRequest.setPmName(pmLoginName);
writeLog("get the departName====== pmName2");
//供应商登录账户
useSealApplySubmitRequest.setSupplierUserLoginName(rsInfo.getString("gysdlzh"));
writeLog("get the departName====== pmName3");
//申请时间
useSealApplySubmitRequest.setApplyTime(new Date());
writeLog("get the departName====== pmName4");
//申请人名称
useSealApplySubmitRequest.setApplyUserName(loginName);
writeLog("get the departName====== pmName5");
//申请人所在公司
useSealApplySubmitRequest.setApplyUserCompanyName(companyName);
writeLog("get the departName====== pmName6");
//申请人所在部门
useSealApplySubmitRequest.setApplyUserDeptName(rsInfo.getString("szbm"));
//联系电话
useSealApplySubmitRequest.setApplyUserTel(rsInfo.getString(mobile));
//项目名称
useSealApplySubmitRequest.setProjectName(departName);
//工程名称
useSealApplySubmitRequest.setProgramName(rsInfo.getString("gczwmc"));
//申请主题
useSealApplySubmitRequest.setApplySubject(rsInfo.getString("sqzt"));
//用印类型
useSealApplySubmitRequest.setUseSealType(rsInfo.getString("yylx"));
//备注
useSealApplySubmitRequest.setRemarks(rsInfo.getString("yywz").replace(" ",""));
//供应商id
useSealApplySubmitRequest.setSupplierId(rsInfo.getString("gyssj"));
//结算方式
useSealApplySubmitRequest.setPaymentMethod(rsInfo.getString("jsfs")==""?"无":rsInfo.getString("jsfs").replace(" ",""));
//原始未盖章的文件id
useSealApplySubmitRequest.setInitialFileId(rsInfo.getString("yywj"));
//计征方式
int jzfs = Integer.valueOf(rsInfo.getString("jzfs"))+1;
useSealApplySubmitRequest.setLevyType(String.valueOf(jzfs));
//材料大类
useSealApplySubmitRequest.setMaterialType(rsInfo.getString("cldl"));
//项目涉及的财务组织
useSealApplySubmitRequest.setProjectFinancialOrg(rsInfo.getString("sjcwzz"));
//材料审核人名称
useSealApplySubmitRequest.setMaterialUserName(clName);
//是否新流程
useSealApplySubmitRequest.setNewWorkFolw(isNewWorkFolw);
//是否未立项 1是 2不是
useSealApplySubmitRequest.setProjectApproval(rsInfo.getString("wlxgc"));
//是否加盖法人代表章 1是 2不是
useSealApplySubmitRequest.setLegalSeal(rsInfo.getString("jgfrdbz"));
writeLog("get the departName====== clName=", departName);
//材料审核人登录名称
useSealApplySubmitRequest.setMaterialLoginName(clLoginName);
this.writeLog("get the departName====== clLoginName=", clLoginName);
json.put("useSealApplySubmitRequest", JSONObject.toJSONString(useSealApplySubmitRequest));
json.put("attachmentList", attachmentList);
json.put("fileList", fileList);
json.put("materialInfoList", materialInfoList);
writeLog("json =============json " + JSONObject.toJSONString(json));
String url = "https://ty.cntytz.com/uasSign/ecology/startWorkFlow";
writeLog("json =============url " + url);
JSONObject jsonObject = HttpUtils.doPost(url, json);
return SUCCESS;
}
/**
* 得到表名
* @param wfid
* @return
*/
public static String getTableName (String wfid){
String sql = "select a.tablename from workflow_bill a,workflow_base b where a.id=b.formid and b.id=" + wfid;
RecordSet rs = new RecordSet();
rs.execute(sql);
rs.next();
return rs.getString(1);
}
/**
* 创建新文件路径 根据文件的imageFileid
* @param imageFileId
* @return
*/
public String getNewFilePath(String imageFileId){
//获取文件
try {
ImageFileManager imageFileManager = new ImageFileManager();
imageFileManager.getImageFileInfoById(Util.getIntValue(imageFileId));
InputStream inputStream = imageFileManager.getInputStream();
String filename = imageFileManager.getImageFileName();
//编码后文件名称
filename = new String(filename.getBytes(StandardCharsets.UTF_8));
writeLog("save file =========",filename);
String targetFilePath = saveAsFile(filename, inputStream,imageFileId);
writeLog(" ========= ========= ========= ========= ========= ========= =========",filename);
return targetFilePath;
} catch (Exception e) {
writeLog("get the new filePath fail error={}",e.getMessage());
return null;
}
}
/**
* 保存文件
* @param filename
* @param in
* @return
*/
private String saveAsFile(String filename, InputStream in,String imageFileId) throws UnknownHostException {
String targetFilePath ="/share/ecologyfile/newfile/filesystem/sign/" + imageFileId+filename.substring(filename.lastIndexOf("."));
writeLog("-=====targetFilePath====",targetFilePath);
// String targetFilePath = GCONST.getRootPath() + "weaverjn" + File.separator + "tempfile" + File.separator + filename;
writeLog("the linux file path is targetFilePath={}",targetFilePath);
File file1 = new File(targetFilePath);
File parent = file1.getParentFile();
if (!parent.exists()) {
boolean bool = parent.mkdirs();
if (!bool) {
System.err.println("创建目标文件夹 tempfile 失败");
return targetFilePath;
// return false;
}
}
if (file1.exists()) {
return targetFilePath;
// return true;
}
int index;
byte[] bytes = new byte[1024];
try {
FileOutputStream downloadFile = new FileOutputStream(targetFilePath);
while ((index = in.read(bytes)) != -1) {
downloadFile.write(bytes, 0, index);
downloadFile.flush();
}
downloadFile.close();
in.close();
return targetFilePath;
// return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return targetFilePath;
// return false;
}
/**
* 根据网络接口获取IP地址
* @param ethNum 网络接口名,Linux下是eth0
* @return
*/
private String getIpByEthNum(String ethNum) {
try {
Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip;
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
if (ethNum.equals(netInterface.getName())) {
Enumeration addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
ip = (InetAddress) addresses.nextElement();
if (ip != null && ip instanceof Inet4Address) {
return ip.getHostAddress();
}
}
}
}
} catch (SocketException e) {
logger.error(e.getMessage(), e);
}
return "获取服务器IP错误";
}
}