ProcessController.java
18.0 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
package com.skua.modules.app.process;
import com.alibaba.fastjson.JSONObject;
import com.skua.core.api.ISysBaseAPI;
import com.skua.common.system.listener.ProcessHandleService;
import com.skua.common.system.listener.ProcessService;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.constant.CommonConstant;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.audit.entity.FAuditDoing;
import com.skua.modules.audit.entity.FAuditHistory;
import com.skua.modules.audit.service.IFAuditDoingService;
import com.skua.modules.audit.service.IFAuditHistoryService;
import com.skua.modules.process.entity.FProcessCfg;
import com.skua.modules.process.entity.FProcessNode;
import com.skua.modules.process.entity.FProcessNodeApprover;
import com.skua.modules.process.service.IFProcessCfgService;
import com.skua.modules.process.service.IFProcessNodeApproverService;
import com.skua.modules.process.service.IFProcessNodePercfgService;
import com.skua.modules.process.service.IFProcessNodeService;
import com.skua.modules.system.entity.CustomDictVO;
import com.skua.modules.system.entity.SysCustomField;
import com.skua.modules.system.entity.SysCustomTable;
import com.skua.modules.system.service.ICustomDictService;
import com.skua.modules.system.service.ISysCustomFieldService;
import com.skua.modules.system.service.ISysCustomTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.lang.reflect.Field;
import java.util.*;
/**
* 待办APP接口
* @author
*/
@Slf4j
@Api(tags="待办APP接口")
@RestController
@RequestMapping("/v1/app/process")
public class ProcessController {
@Autowired
private ISysBaseAPI iSysBaseAPI;
@Autowired
private IFAuditDoingService fAuditDoingService;
@Autowired
private IFProcessNodePercfgService fProcessNodePercfgService;
@Autowired
private IFProcessNodeService fProcessNodeService;
@Autowired
private IFProcessCfgService fProcessCfgService;
@Autowired
private IFProcessNodeApproverService fProcessNodeApproverService;
@Autowired
private ISysCustomTableService sysCustomTableService;
@Autowired
private IFAuditHistoryService fAuditHistoryService;
@Autowired
private ISysCustomFieldService sysCustomFieldService;
@Autowired
private ICustomDictService customDictService;
@AutoLog(value = "获取人员待办事项")
@ApiOperation(value="获取人员待办事项", notes="获取人员待办事项")
@GetMapping(value = "/getToDoByUser")
public Result<Map<String,Object>> getToDoByUser(@RequestParam(name="userId") String userId) {
Result<Map<String,Object>> result = new Result<Map<String,Object>>();
Map<String,Object> resMap = new HashMap<>();
String rId = null;
List<Map<String,Object>> proList = new ArrayList<>();
List<Map<String,Object>> resList = new ArrayList<>();
StringBuffer sql = new StringBuffer("select * from view_audit_doing where approver in (''");
//获取人员ID
sql.append(",'"+userId+"'");
//获取角色ID
List<String> roleCodes = iSysBaseAPI.getRolesByUserId(userId);
for (int i = 0; i < roleCodes.size(); i++) {
String roleCode = roleCodes.get(i);
String roleId = iSysBaseAPI.getRoleIdByCode(roleCode);
sql.append(",'"+roleId+"'");
}
//获取部门ID
List<String> deptIds = iSysBaseAPI.getDeptIdsByUserId(userId);
for (int j = 0; j < deptIds.size(); j++) {
String deptId = deptIds.get(j);
sql.append(",'"+deptId+"'");
}
sql.append(") and node_value != '-1' ");
sql.append(" and (report_id like 'equip%' or report_id like 'medica%' or report_id like 'document%') ");
sql.append(" order by audit_time desc");
List<Map<String,Object>> list = fAuditDoingService.getToBySql(sql.toString());
if(list!=null){
rId = list.get(0).get("report_id").toString();
proList = getAllByReportId(rId);
for (int i = 0; i < list.size(); i++) {
String reportId = list.get(i).get("report_id").toString();
String nodeId = list.get(i).get("node_id").toString();
String dataId = list.get(i).get("report_content_id").toString();
String nodeValue = list.get(i).get("node_value").toString();
String toDoTime = list.get(i).get("audit_time").toString();
String processId = list.get(i).get("process_id").toString();
Map<String,Object> map = new HashMap<>();
SysCustomTable sysCustomTable = sysCustomTableService.getOneByTable(reportId);
if(sysCustomTable!=null){
map.put("toDoName","待办事项-"+sysCustomTable.getTableDescribe());
}else{
map.put("toDoName","待办事项-"+toDoTime.substring(0,10));
}
map.put("reportId",reportId);
map.put("nodeId",nodeId);
map.put("dataId",dataId);
map.put("processId",processId);
map.put("toDoTime", toDoTime);
map.put("nodeValue",nodeValue);
resList.add(i,map);
}
}
resMap.put("data",resList);
resMap.put("process",proList);
result.setResult(resMap);
return result;
}
private List<Map<String,Object>> getAllByReportId(String tableName) {
List<Map<String,Object>> allList = new ArrayList<>();
try {
String reportId = getCustomTableIdByTableName(tableName);
if(reportId!=null){
FProcessCfg fProcessCfg = fProcessCfgService.getByReportId(reportId);
String processCfgId = fProcessCfg.getId();
List<FProcessNode> nodeList = fProcessNodeService.getListByProcessId(processCfgId);
if(nodeList.size() > 0){
for (int i = 1; i < nodeList.size(); i++) {
Map<String,Object> map = new HashMap();
String nodeId = nodeList.get(i).getId();
map.put("id",nodeId);
map.put("nodeName",nodeList.get(i).getNodeName());
map.put("nodeValue",nodeList.get(i).getNodeValue());
map.put("monitorClass",nodeList.get(i).getMonitorClass());
map.put("proId",nodeList.get(i).getProId());
map.put("proVer",nodeList.get(i).getProVer());
List<FProcessNodeApprover> approverList = fProcessNodeApproverService.getByNodeId(nodeId);
if(approverList.size() > 0){
map.put("approver",approverList.get(0));
}else{
FProcessNodeApprover approver = new FProcessNodeApprover();
approver.setNodeId(nodeId);
map.put("approver",approver);
}
allList.add(map);
}
Map<String,Object> bjMap = new HashMap();
String nodeId_bj = nodeList.get(0).getId();
bjMap.put("id",nodeId_bj);
bjMap.put("nodeName",nodeList.get(0).getNodeName());
bjMap.put("nodeValue",nodeList.get(0).getNodeValue());
bjMap.put("monitorClass",nodeList.get(0).getMonitorClass());
bjMap.put("proId",nodeList.get(0).getProId());
bjMap.put("proVer",nodeList.get(0).getProVer());
List<FProcessNodeApprover> lastApproverList = fProcessNodeApproverService.getByNodeId(nodeId_bj);
if(lastApproverList.size() > 0){
bjMap.put("approver",lastApproverList.get(0));
}else{
FProcessNodeApprover approver = new FProcessNodeApprover();
approver.setNodeId(nodeId_bj);
bjMap.put("approver",approver);
}
allList.add(bjMap);
}else{
//发起-节点
FProcessNode nodeStart = new FProcessNode();
nodeStart.setNodeName("发起");
nodeStart.setNodeValue(0);
nodeStart.setProId(processCfgId);
fProcessNodeService.save(nodeStart);
//办结-节点
FProcessNode nodeEnd = new FProcessNode();
nodeEnd.setNodeName("办结");
nodeEnd.setNodeValue(-1);
nodeEnd.setProId(processCfgId);
fProcessNodeService.save(nodeEnd);
List<FProcessNode> list = fProcessNodeService.getListByProcessId(processCfgId);
for (int i = 0; i < list.size(); i++) {
Map<String,Object> map = new HashMap();
FProcessNodeApprover approver = new FProcessNodeApprover();
map.put("id",list.get(i).getId());
map.put("nodeName",list.get(i).getNodeName());
map.put("nodeValue",list.get(i).getNodeValue());
map.put("monitorClass",list.get(i).getMonitorClass());
map.put("proId",list.get(i).getProId());
map.put("proVer",list.get(i).getProVer());
approver.setNodeId(list.get(i).getId());
map.put("approver",approver);
allList.add(map);
}
}
}
return allList;
} catch (Exception e) {
return new ArrayList<>();
}
}
private String getCustomTableIdByTableName(String tableName) {
SysCustomTable sysCustomTable = sysCustomTableService.getOneByTable(tableName);
if(sysCustomTable==null){
return null;
}else{
return sysCustomTable.getId();
}
}
@AutoLog(value = "APP审批流程")
@ApiOperation(value="APP审批流程", notes="APP审批流程")
@PutMapping(value = "/spAudit")
public Result<FAuditDoing> saveAudit(@RequestBody JSONObject jsonObject) {
String reportId = jsonObject.getString("reportId");//库表管理中的ID
String processId = jsonObject.getString("processId");//流程ID
String dataId = jsonObject.getString("dataId");//数据ID
String userId = jsonObject.getString("userId");//用户ID
String nodeValue = jsonObject.getString("nodeValue");//节点值
String approveRecord = jsonObject.getString("approveRecord");
Result<FAuditDoing> result = new Result<FAuditDoing>();
FAuditDoing fAuditDoing = fAuditDoingService.getBeanByAllId(reportId,processId,dataId);
if(fAuditDoing!=null){//修改节点值
fAuditDoing.setNodeValue(nodeValue);
fAuditDoing.setOpeId(userId);
fAuditDoing.setReprotAttr(approveRecord);
boolean ok = fAuditDoingService.updateById(fAuditDoing);
if(ok){
FAuditHistory fAuditHistory = new FAuditHistory();
fAuditHistory.setReportId(reportId);
fAuditHistory.setProcessId(processId);
fAuditHistory.setReportContentId(dataId);
fAuditHistory.setOpeId(userId);
fAuditHistory.setNodeValue(nodeValue);
fAuditHistory.setReprotAttr(approveRecord);
fAuditHistoryService.save(fAuditHistory);
}
}else{
FAuditDoing audit = new FAuditDoing();
audit.setReportId(reportId);
audit.setProcessId(processId);
audit.setReportContentId(dataId);
audit.setOpeId(userId);
audit.setNodeValue(nodeValue);
audit.setReprotAttr(approveRecord);
boolean ok = fAuditDoingService.save(audit);
if(ok){
FAuditHistory fAuditHistory = new FAuditHistory();
fAuditHistory.setReportId(reportId);
fAuditHistory.setProcessId(processId);
fAuditHistory.setReportContentId(dataId);
fAuditHistory.setOpeId(userId);
fAuditHistory.setNodeValue(nodeValue);
fAuditHistory.setReprotAttr(approveRecord);
fAuditHistoryService.save(fAuditHistory);
}
}
FProcessNode fProcessNode = fProcessNodeService.getByProIdAndNodeValue(processId,nodeValue);
if(fProcessNode.getMonitorClass()!=null){
ProcessHandleService createPlanService = (ProcessHandleService)SpringContextUtils.getBean(fProcessNode.getMonitorClass());
boolean flag = createPlanService.doService(dataId);
if(!flag){ System.out.print("监听类执行:"+flag);}
}
result.setSuccess(true);
return result;
}
@AutoLog(value = "待办事项详情")
@ApiOperation(value="待办事项详情", notes="待办事项详情")
@PutMapping(value = "/getInfo")
public Result<List<Map<String,Object>>> getInfo(@RequestBody JSONObject jsonObject) throws IllegalAccessException {
Result<List<Map<String,Object>>> result = new Result<List<Map<String,Object>>>();
String reportId = jsonObject.getString("report_id");
String nodeId = jsonObject.getString("node_id");
String dataId = jsonObject.getString("report_content_id");
Map<String,Object> resMap = new HashMap<>();
List<Map<String,Object>> resList = new ArrayList<>();
SysCustomTable sysCustomTable=new SysCustomTable();
sysCustomTable.setTableName(reportId);
List<SysCustomField> headList = sysCustomFieldService.queryDictField(sysCustomTable);
//定义字典map集合
Map<String,Map<String,String>> dictMap=new HashMap<String,Map<String,String>>();
for(SysCustomField field:headList) {
String fieldType=field.getFieldType();//获取字段类型
String dictType=field.getDictType();
if(fieldType.equals(CommonConstant.COMMON_DICT_TYPE)) {
//普通字典
List<CustomDictVO> dictList=customDictService.queryDictItemsByCode(dictType);
Map<String,String> dictItemMap=new HashMap<String,String>();
for(int j=0;j<dictList.size();j++) {
dictItemMap.put(dictList.get(j).getDictCode(), dictList.get(j).getDictName());
}
dictMap.put(field.getEntityFieldCode(), dictItemMap);
}else if(fieldType.equals(CommonConstant.BUSINESS_DICT_TYPE)) {
if(dictType.equals("chicePerson")) {
List<Map<String,Object>> userList=iSysBaseAPI.queryUserList();
Map<String,String> dictItemMap=new HashMap<String,String>();
for(int j=0;j<userList.size();j++) {
dictItemMap.put(userList.get(j).get("userId").toString(), userList.get(j).get("userName").toString());
}
dictMap.put(field.getEntityFieldCode(), dictItemMap);
}
}
}
List<Map<String,Object>> list = fProcessNodePercfgService.getByNodeId(nodeId,reportId);
ProcessService processService = (ProcessService) SpringContextUtils.getBean(ConvertUtils.camelName(reportId+"_service_impl"));
Object obj = processService.getInfoById(dataId);
Map<String,Object> map = getObjectToMap(obj);
for (int i = 0; i < list.size(); i++) {
Map<String,Object> entity = list.get(i);
String entityFieldCode = list.get(i).get("entity_field_code").toString();
String fieldType = list.get(i).get("field_type").toString();
String checkRule = list.get(i).get("check_rule").toString();
entity.put("dictType",mapToList(dictMap.get(entityFieldCode)));
entity.put("key",entityFieldCode);
entity.put("value",map.get(entityFieldCode));
entity.put("fieldType",fieldType);
entity.put("checkRule",checkRule);
resList.add(entity);
}
result.setResult(resList);
return result;
}
private List<Map<String,String>> mapToList(Map<String, String> entity) {
List<Map<String,String>> list = new ArrayList<>();
if(entity!=null){
for (String key : entity.keySet()) {
Map<String, String> map = new HashMap<>();
map.put("key",key);
map.put("value",entity.get(key));
list.add(map);
}
}
return list;
}
//Object转Map
public static Map<String, Object> getObjectToMap(Object obj) throws IllegalAccessException {
Map<String, Object> map = new LinkedHashMap<String, Object>();
Class<?> clazz = obj.getClass();
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
String fieldName = field.getName();
Object value = field.get(obj);
if (value == null) {
value = "";
}
map.put(fieldName, value);
}
return map;
}
@AutoLog(value = "上传待办填报详情")
@ApiOperation(value="上传待办填报详情", notes="上传待办填报详情")
@PutMapping(value = "/saveInfo")
public Result<List<Map<String,Object>>> saveInfo(@RequestBody JSONObject jsonObject){
Result<List<Map<String,Object>>> result = new Result<List<Map<String,Object>>>();
String reportId = jsonObject.getString("report_id");
ProcessService processService = (ProcessService) SpringContextUtils.getBean(ConvertUtils.camelName(reportId+"_service_impl"));
boolean ok = processService.saveInfo(jsonObject);
if(ok){
result.setSuccess(true);
}else{
result.error500("上传失败");
}
return result;
}
}