Commit 143645edacc0c6be5c5dc5fa71dc485903f8f5de

Authored by youxiw2000
1 parent 387d1c80

1

trash-workFlow/src/main/java/com/trash/workflow/service/impl/WorkflowServiceImpl.java
1 -package com.trash.workflow.service.impl;  
2 -  
3 -import java.text.SimpleDateFormat;  
4 -import java.util.Date;  
5 -import java.util.List;  
6 -import java.util.Map;  
7 -import java.util.stream.Collectors;  
8 -  
9 -import org.activiti.api.process.model.ProcessInstance;  
10 -import org.activiti.api.process.model.builders.ProcessPayloadBuilder;  
11 -import org.activiti.api.process.runtime.ProcessRuntime;  
12 -import org.activiti.api.task.runtime.TaskRuntime;  
13 -import org.activiti.engine.RuntimeService;  
14 -import org.activiti.engine.TaskService;  
15 -import org.activiti.engine.task.IdentityLink;  
16 -import org.activiti.engine.task.Task;  
17 -import org.apache.commons.collections4.map.HashedMap;  
18 -import org.springframework.beans.factory.annotation.Autowired;  
19 -import org.springframework.security.core.context.SecurityContextHolder;  
20 -import org.springframework.security.core.context.SecurityContextImpl;  
21 -import org.springframework.stereotype.Service;  
22 -import org.springframework.transaction.annotation.Transactional;  
23 -  
24 -import com.alibaba.fastjson.JSONArray;  
25 -import com.alibaba.fastjson.JSONObject;  
26 -import com.trash.activiti.domain.ActWorkflowFormData;  
27 -import com.trash.activiti.service.IActWorkflowFormDataService;  
28 -import com.trash.business.domain.ConstructionCredit;  
29 -import com.trash.business.domain.ConstructionSign;  
30 -import com.trash.business.domain.SupervisionThreestep;  
31 -import com.trash.business.service.IConstructionSignService;  
32 -import com.trash.business.service.ISupervisionThreestepService;  
33 -import com.trash.caseOffline.domain.CaseOffline;  
34 -import com.trash.casefile.domain.ViolationCaseFile;  
35 -import com.trash.casefile.domain.ViolationWarningInformation;  
36 -import com.trash.common.core.domain.entity.SysDictData;  
37 -import com.trash.common.core.domain.entity.SysUser;  
38 -import com.trash.common.core.redis.RedisCache;  
39 -import com.trash.common.utils.DateUtils;  
40 -import com.trash.common.utils.RemoteServerUtils;  
41 -import com.trash.common.utils.SecurityUtils;  
42 -import com.trash.common.utils.StringUtils;  
43 -import com.trash.common.utils.spring.SpringUtils;  
44 -import com.trash.framework.web.service.SysLoginService;  
45 -import com.trash.system.service.ISysDictTypeService;  
46 -import com.trash.system.service.ISysUserService;  
47 -import com.trash.workflow.domain.Workflow;  
48 -import com.trash.workflow.mapper.WorkflowMapper;  
49 -import com.trash.workflow.service.IWorkflowService;  
50 -  
51 -/**  
52 - * 请假Service业务层处理  
53 - *  
54 - * @author danny  
55 - * @date 2020-10-28  
56 - */  
57 -@Service  
58 -public class WorkflowServiceImpl implements IWorkflowService {  
59 -  
60 - @Autowired  
61 - private WorkflowMapper workflowMapper;  
62 - @Autowired  
63 - private ProcessRuntime processRuntime;  
64 - @Autowired  
65 - private ISysUserService sysUserService;  
66 - @Autowired  
67 - private TaskService taskService;  
68 -  
69 - @Autowired  
70 - private TaskRuntime taskRuntime;  
71 -  
72 - @Autowired  
73 - IConstructionSignService signService;  
74 -  
75 - @Autowired  
76 - com.trash.common.config.trashConfig trashConfig;  
77 -  
78 - @Autowired  
79 - SysLoginService loginService;  
80 -  
81 - String siteType[] = { "处理场所", "建筑垃圾资源化处置场", "盾构土环保处置场", "盾构土应急处理场所", "回填场" };  
82 -  
83 - String outArea = "株洲市,湘潭市,汨罗市,湘阴县";  
84 -  
85 - String tcdOutArea = "长沙县,望城区,浏阳市,宁乡市"; // 车企人外区  
86 -  
87 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
88 -  
89 - String inArea = "芙蓉区,天心区,开福区,雨花区";  
90 -  
91 - @Autowired  
92 - IActWorkflowFormDataService awfServer;  
93 -  
94 - @Autowired  
95 - RuntimeService runtimeService;  
96 -  
97 - @Autowired  
98 - ISupervisionThreestepService server;  
99 -  
100 - @Autowired  
101 - RedisCache redisCache;  
102 -  
103 - @Override  
104 - @Transactional  
105 - public int createWorkFlow(Map<String, Object> data) { // 第三方通用接收接口  
106 -  
107 - SysUser user = SecurityUtils.getLoginUser().getUser();  
108 -  
109 - String flowType = data.get("type").toString();  
110 -  
111 - Map map = (Map) data.get("data");  
112 -  
113 - String businessKey = flowType + ":" + map.get("id"); // 流程对应事务key  
114 - String title = map.get("title").toString();  
115 - String reason = map.get("reason").toString();  
116 - String startTime = map.get("startTime").toString();  
117 - String endTime = map.get("endTime").toString();  
118 - String areaCode = null;  
119 - int index = 0;  
120 - JSONArray areas = RemoteServerUtils.getAreas();  
121 - if (map.get("area") != null) {  
122 - areaCode = map.get("area").toString();  
123 -  
124 - if (flowType.equals("workflow_vehicle") || flowType.equals("workflow_company")  
125 - || flowType.equals("workflow_driver")) {  
126 - for (Object obj : areas) {  
127 - JSONObject jsonObject = (JSONObject) obj;  
128 - if (areaCode.equals(jsonObject.getString("code"))) {  
129 - if (tcdOutArea.contains(jsonObject.getString("name"))) {  
130 - index = 1;  
131 - }  
132 - break;  
133 - }  
134 - }  
135 - }else if (flowType.equals("workflow_earthsites")|| flowType.equals("workflow_earthsites_edit")) {  
136 - for (Object obj : areas) {  
137 - JSONObject jsonObject = (JSONObject) obj;  
138 - if (areaCode.equals(jsonObject.getString("code"))) {  
139 - if (inArea.contains(jsonObject.getString("name"))) {  
140 - index = 2;  
141 - }  
142 - if (tcdOutArea.contains(jsonObject.getString("name"))||jsonObject.getString("name").contains("湘江") ) {  
143 - index = 1;  
144 - }  
145 - break;  
146 - }  
147 - }  
148 - } else {  
149 - for (Object obj : areas) {  
150 - JSONObject jsonObject = (JSONObject) obj;  
151 - if (areaCode.equals(jsonObject.getString("code"))) {  
152 - if (outArea.contains(jsonObject.getString("name"))) {  
153 - index = 1;  
154 - }  
155 - break;  
156 - }  
157 - }  
158 - }  
159 - }  
160 -  
161 - ProcessInstance processInstance = null;  
162 - ActWorkflowFormData awf = null;  
163 -  
164 - try {  
165 -  
166 - processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(flowType)  
167 - .withName(title).withVariable("route", index).withBusinessKey(businessKey).build());  
168 -  
169 - if (areaCode != null) {  
170 - PorcThreeStepTask(processInstance, areaCode);  
171 - }  
172 -  
173 - if (flowType.equals("workflow_constructsite")) {  
174 -  
175 - ConstructionSign constructionSign = new ConstructionSign();  
176 -  
177 - constructionSign.setObjectId(map.get("id").toString());  
178 -  
179 - if (!user.getAvatar().contains("null")) {  
180 - constructionSign.setSign1(SecurityUtils.getLoginUser().getUser().getAvatar());  
181 - constructionSign.setSign1Time(new Date());  
182 - }  
183 -  
184 - signService.insertConstructionSign(constructionSign);  
185 -  
186 - }  
187 -  
188 - Workflow workflow = new Workflow();  
189 - workflow.setId(businessKey);  
190 - workflow.setTitle(title);  
191 - workflow.setReason(reason);  
192 - workflow.setStartTime(startTime);  
193 - workflow.setEndTime(endTime);  
194 - workflow.setType(map.get("type").toString());  
195 - workflow.setInstanceId(processInstance.getId());  
196 - workflow.setState("0");  
197 - workflow.setCreateTime(new Date());  
198 - workflow.setCreateBy(user.getUserName());  
199 - workflow.setCreateName(user.getUserName());  
200 -  
201 - awf = insertAwf(user, workflow);  
202 -  
203 - return workflowMapper.insertWorkflow(workflow);  
204 - } catch (Exception e) {  
205 -  
206 - if (processInstance != null)  
207 - processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));  
208 -  
209 - if (awf.getId() != null)  
210 - awfServer.deleteActWorkflowFormDataById(awf.getId());  
211 -  
212 - e.printStackTrace();  
213 - }  
214 -  
215 - return 0;  
216 - }  
217 -  
218 - private ActWorkflowFormData insertAwf(SysUser user, Workflow workflow) {  
219 -  
220 - if (user == null) {  
221 - user = new SysUser();  
222 - user.setUserName("长沙市建筑垃圾智慧监管平台");  
223 - }  
224 -  
225 - ActWorkflowFormData awf;  
226 - awf = new ActWorkflowFormData();  
227 - awf.setCreateBy(user.getUserName());  
228 - awf.setCreateName(user.getUserName());  
229 - awf.setCreateTime(new Date());  
230 - awf.setBusinessKey(workflow.getId());  
231 - awf.setControlId("CREATED");  
232 - awf.setControlName("发起人");  
233 - awf.setFormKey("CREATED");  
234 - awf.setTaskNodeName(user.getUserName() + "发起");  
235 - awf.setControlValue(workflow.getReason());  
236 -  
237 - awfServer.insertActWorkflowFormData(awf);  
238 - return awf;  
239 - }  
240 -  
241 - @Override  
242 - @Transactional  
243 - public int createLeaveWorkFlow(Workflow workflow, int index) {  
244 - ProcessInstance processInstance = null;  
245 -  
246 - ActWorkflowFormData awf = null;  
247 -  
248 - SysUser user = SecurityUtils.getLoginUser().getUser();  
249 -  
250 - try {  
251 -  
252 - processInstance = processRuntime.start(ProcessPayloadBuilder.start()  
253 - .withProcessDefinitionKey("workflow_leave").withName(workflow.getTitle())  
254 - .withBusinessKey(workflow.getId()).withVariable("route", index).build());  
255 -  
256 - Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();  
257 -  
258 - if (task != null) {  
259 -  
260 - task.setDescription(SecurityUtils.getLoginUser().getUser().getRoleIds().get(0));  
261 -  
262 - List<IdentityLink> list = taskService.getIdentityLinksForTask(task.getId());  
263 -  
264 - if (list.size() == 1) {  
265 - taskService.addCandidateUser(task.getId(), task.getDescription());  
266 - }  
267 -  
268 - taskService.saveTask(task);  
269 - }  
270 -  
271 - awf = insertAwf(user, workflow);  
272 -  
273 - workflow.setInstanceId(processInstance.getId());  
274 -  
275 - workflow.setCreateTime(new Date());  
276 - return workflowMapper.insertWorkflow(workflow);  
277 - } catch (Exception e) {  
278 -  
279 - if (awf.getId() != null)  
280 - awfServer.deleteActWorkflowFormDataById(awf.getId());  
281 - processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));  
282 -  
283 - e.printStackTrace();  
284 - }  
285 -  
286 - return 0;  
287 - }  
288 -  
289 - @Override  
290 - @Transactional  
291 - public int createDropPointWorkFlow(Map<String, String> droppoint) { // 三查  
292 - ProcessInstance processInstance = null;  
293 - ActWorkflowFormData awf = null;  
294 - try {  
295 - String name = "投放点审批:" + droppoint.get("name");  
296 -  
297 - processInstance = processRuntime  
298 - .start(ProcessPayloadBuilder.start().withProcessDefinitionKey("workflow_drop_point").withName(name)  
299 - .withBusinessKey("workflow_drop_point:" + droppoint.get("id")).build());  
300 -  
301 - PorcThreeStepTask(processInstance, droppoint.get("area"));  
302 -  
303 - Workflow workflow = new Workflow();  
304 - workflow.setId("workflow_drop_point:" + droppoint.get("id"));  
305 - workflow.setTitle(name);  
306 - workflow.setReason(droppoint.get("name") + "审批流程");  
307 - workflow.setStartTime(sdf.format(new Date()));  
308 - workflow.setEndTime(sdf.format(new Date()));  
309 - workflow.setType("投放点审批");  
310 - workflow.setInstanceId(processInstance.getId());  
311 - workflow.setState("0");  
312 - workflow.setCreateTime(new Date());  
313 -  
314 - SysUser user = SecurityUtils.getLoginUser().getUser();  
315 - awf = insertAwf(user, workflow);  
316 -  
317 - return workflowMapper.insertWorkflow(workflow);  
318 - } catch (Exception e) {  
319 - e.printStackTrace();  
320 - if (awf.getId() != null)  
321 - awfServer.deleteActWorkflowFormDataById(awf.getId());  
322 - processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));  
323 - }  
324 -  
325 - return 0;  
326 - }  
327 -  
328 - @Override  
329 - @Transactional  
330 - public int createThreeStepWorkFlow(SupervisionThreestep supervision) { // 三查  
331 - ProcessInstance processInstance = null;  
332 - ActWorkflowFormData awf = null;  
333 - try {  
334 - String name = "报工自查:" + supervision.getName();  
335 -  
336 - JSONArray areas = redisCache.getCacheObject("areas");  
337 -  
338 - int route = 0;  
339 -  
340 - if (areas == null) {  
341 - areas = RemoteServerUtils.getAreas();  
342 - redisCache.setCacheObject("areas", areas);  
343 - }  
344 -  
345 - for (Object obj : areas) {  
346 - JSONObject jsonObject = (JSONObject) obj;  
347 - if (supervision.getPlace().equals(jsonObject.getString("code"))) {  
348 - if (jsonObject.getString("name").contains("湘江新区")) {  
349 - route = 1;  
350 - }  
351 - break;  
352 - }  
353 - }  
354 -  
355 - processInstance = processRuntime.start(ProcessPayloadBuilder.start()  
356 - .withProcessDefinitionKey("workflow_threestep").withName(name).withVariable("route", route)  
357 - .withBusinessKey("workflow_threestep:" + supervision.getId()).build());  
358 -  
359 - PorcThreeStepTask(processInstance, supervision.getPlace());  
360 -  
361 - Workflow workflow = new Workflow();  
362 - workflow.setId("workflow_threestep:" + supervision.getId());  
363 - workflow.setTitle(name);  
364 - workflow.setReason("报工自查");  
365 - workflow.setStartTime(sdf.format(supervision.getSelfCheckTime()));  
366 - workflow.setEndTime(sdf.format(supervision.getSelfCheckTime()));  
367 - workflow.setType("报工审批");  
368 - workflow.setInstanceId(processInstance.getId());  
369 - workflow.setState("0");  
370 - workflow.setCreateTime(new Date());  
371 -  
372 - SysUser user = SecurityUtils.getLoginUser().getUser();  
373 - awf = insertAwf(user, workflow);  
374 -  
375 - return workflowMapper.insertWorkflow(workflow);  
376 - } catch (Exception e) {  
377 - e.printStackTrace();  
378 - if (awf.getId() != null)  
379 - awfServer.deleteActWorkflowFormDataById(awf.getId());  
380 - processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));  
381 - }  
382 -  
383 - return 0;  
384 - }  
385 -  
386 -// @Override  
387 -// @Transactional  
388 -// public int createCaseFileByTask(ViolationCaseFile caseFile, int index) { // 违规预警案卷  
389 -//  
390 -// if (StringUtils.isEmpty(RemoteServerUtils.remote)) {  
391 -// RemoteServerUtils.remote = trashConfig.getRemotePath();  
392 -// }  
393 -// loginService.loginByRemote(trashConfig.getToken());  
394 -//  
395 -// SysUser user = null;  
396 -//  
397 -// try {  
398 -// user = SecurityUtils.getLoginUser().getUser();  
399 -// } catch (Exception e) {  
400 -// // e.printStackTrace();  
401 -// }  
402 -//  
403 -// SecurityContextImpl securityContextImpl = new SecurityContextImpl();  
404 -//  
405 -// securityContextImpl.setAuthentication(SecurityContextHolder.getContext().getAuthentication());  
406 -// org.activiti.engine.runtime.ProcessInstance instance = null;  
407 -// String title = "案卷号:" + caseFile.getNumber();  
408 -// String flowType = "workflow_casefile";  
409 -//  
410 -// if (index > 0 && caseFile.getOwningRegion().contains("湘江新区")) {  
411 -// index += 3;  
412 -// }  
413 -// ActWorkflowFormData awf = null;  
414 -//  
415 -// try {  
416 -// Map map = new HashedMap<>();  
417 -//  
418 -// map.put("route", index);  
419 -// instance = runtimeService.createProcessInstanceBuilder().businessKey(flowType + ":" + caseFile.getId())  
420 -// .name(title).variable("route", index).processDefinitionKey(flowType).variables(map).start();  
421 -//  
422 -// // runtimeService.startProcessInstanceById(instance.getProcessDefinitionId(),map);  
423 -//  
424 -// if (index == 0) {  
425 -// Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();  
426 -//  
427 -// task.setAssignee(caseFile.getAbbreviation());  
428 -//  
429 -// task.setDescription(caseFile.getAbbreviation());  
430 -// taskService.saveTask(task);  
431 -// } else {  
432 -// updateProcessKafka(instance, caseFile.getOwningRegion(), trashConfig.getToken());  
433 -// }  
434 -//  
435 -// Workflow workflow = new Workflow();  
436 -// workflow.setId(flowType + ":" + caseFile.getId());  
437 -// workflow.setTitle(title);  
438 -// workflow.setReason("平台案卷");  
439 -// workflow.setStartTime(sdf.format(caseFile.getCreateTime()));  
440 -// workflow.setEndTime(sdf.format(caseFile.getCreateTime()));  
441 -// workflow.setType("违规案卷处置流程");  
442 -// workflow.setInstanceId(instance.getId());  
443 -// workflow.setState("0");  
444 -// workflow.setCreateTime(new Date());  
445 -//  
446 -// awf = insertAwf(user, workflow);  
447 -//  
448 -// return workflowMapper.insertWorkflow(workflow);  
449 -// } catch (Exception e) {  
450 -// if (awf.getId() != null)  
451 -// awfServer.deleteActWorkflowFormDataById(awf.getId());  
452 -// runtimeService.deleteProcessInstance(instance.getId(), "创建失败");  
453 -// throw new RuntimeException(e);  
454 -// }  
455 -//  
456 -// }  
457 -  
458 - @Override  
459 - @Transactional  
460 - public int createCaseFile(ViolationCaseFile caseFile, int index) { // 三查  
461 - ProcessInstance processInstance = null;  
462 - ActWorkflowFormData awf = null;  
463 - String title = "案卷号:" + caseFile.getNumber();  
464 - String flowType = "workflow_casefile";  
465 - try {  
466 - List<SysDictData> caseType = SpringUtils.getBean(ISysDictTypeService.class)  
467 - .selectDictDataByType("vio_casefile");  
468 -  
469 - for (SysDictData d : caseType) {  
470 - if (caseFile.getViolationType().equals(d.getDictValue())) {  
471 - if (d.getRemark() != null) {  
472 - index = 1;  
473 - }  
474 - break;  
475 - }  
476 - }  
477 -  
478 - if(index == 0){  
479 - if (tcdOutArea.indexOf(caseFile.getOwningRegion()) > -1) {  
480 - index = 2;  
481 - }  
482 -  
483 - if ("湘江新区".equals(caseFile.getOwningRegion())) {  
484 - index = 3;  
485 - }  
486 - }  
487 -  
488 -  
489 -  
490 -  
491 - processInstance = processRuntime  
492 - .start(ProcessPayloadBuilder.start().withProcessDefinitionKey(flowType).withName(title)  
493 - .withBusinessKey(flowType + ":" + caseFile.getId()).withVariable("route", index).build());  
494 -  
495 -  
496 - updateProcess(processInstance, caseFile.getOwningRegion());  
497 -  
498 -  
499 - Workflow workflow = new Workflow();  
500 - workflow.setId(flowType + ":" + caseFile.getId());  
501 - workflow.setTitle(title);  
502 - workflow.setReason("平台案卷");  
503 - workflow.setStartTime(sdf.format(caseFile.getCreateTime()));  
504 - workflow.setEndTime(sdf.format(caseFile.getCreateTime()));  
505 - workflow.setType("违规案卷处置流程");  
506 - workflow.setInstanceId(processInstance.getId());  
507 - workflow.setState("0");  
508 - workflow.setCreateTime(new Date());  
509 -  
510 - SysUser user = SecurityUtils.getLoginUser().getUser();  
511 - awf = insertAwf(user, workflow);  
512 - return workflowMapper.insertWorkflow(workflow);  
513 - } catch (Exception e) {  
514 - e.printStackTrace();  
515 - if (awf.getId() != null)  
516 - awfServer.deleteActWorkflowFormDataById(awf.getId());  
517 - processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));  
518 - throw new RuntimeException(e);  
519 - }  
520 - }  
521 -  
522 - @Override  
523 - @Transactional  
524 - public int createCaseFile1(ViolationWarningInformation caseFile, int index, int isAuto) { // 违规预警案卷  
525 - if (isAuto == 1) {  
526 - if (StringUtils.isEmpty(RemoteServerUtils.remote)) {  
527 - RemoteServerUtils.remote = trashConfig.getRemotePath();  
528 - }  
529 - loginService.loginByRemote(trashConfig.getToken());  
530 - }  
531 -  
532 - SysUser user = null;  
533 -  
534 - try {  
535 - user = SecurityUtils.getLoginUser().getUser();  
536 - } catch (Exception e) {  
537 - // e.printStackTrace();  
538 - }  
539 -  
540 - SecurityContextImpl securityContextImpl = new SecurityContextImpl();  
541 -  
542 - securityContextImpl.setAuthentication(SecurityContextHolder.getContext().getAuthentication());  
543 - org.activiti.engine.runtime.ProcessInstance instance = null;  
544 - String title = "案卷号:" + caseFile.getNumber();  
545 - String flowType = "violation_warning";  
546 -  
547 - if (index > 0 && caseFile.getOwningRegion().contains("湘江新区")) {  
548 - index += 3;  
549 - }  
550 - ActWorkflowFormData awf = null;  
551 -  
552 - try {  
553 - Map map = new HashedMap<>();  
554 -  
555 - map.put("route", index);  
556 - instance = runtimeService.createProcessInstanceBuilder().businessKey(flowType + ":" + caseFile.getId())  
557 - .name(title).variable("route", index).processDefinitionKey(flowType).variables(map).start();  
558 -  
559 - // runtimeService.startProcessInstanceById(instance.getProcessDefinitionId(),map);  
560 -  
561 - if (index == 0) {  
562 - Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();  
563 -  
564 - task.setAssignee(caseFile.getAbbreviation());  
565 - task.setDescription(caseFile.getAbbreviation());  
566 -  
567 - taskService.saveTask(task);  
568 - } else {  
569 - updateProcessKafka(instance, caseFile.getOwningRegion(), trashConfig.getToken());  
570 - }  
571 -  
572 - Workflow workflow = new Workflow();  
573 - workflow.setId(flowType + ":" + caseFile.getId());  
574 - workflow.setTitle(title);  
575 - workflow.setReason("违规预警信息");  
576 - workflow.setStartTime(sdf.format(caseFile.getCreateTime()));  
577 - workflow.setEndTime(sdf.format(caseFile.getCreateTime()));  
578 - workflow.setType("平台预警信息");  
579 - workflow.setInstanceId(instance.getId());  
580 - workflow.setState("0");  
581 - workflow.setCreateTime(new Date());  
582 -  
583 - awf = insertAwf(user, workflow);  
584 -  
585 - return workflowMapper.insertWorkflow(workflow);  
586 - } catch (Exception e) {  
587 - if (awf.getId() != null)  
588 - awfServer.deleteActWorkflowFormDataById(awf.getId());  
589 - runtimeService.deleteProcessInstance(instance.getId(), "创建失败");  
590 - throw new RuntimeException(e);  
591 - }  
592 -  
593 - }  
594 -  
595 - @Override  
596 - @Transactional  
597 - public int createCaseOffline(CaseOffline caseOffline) { // 三查  
598 - ProcessInstance processInstance = null;  
599 - ActWorkflowFormData awf = null;  
600 - try {  
601 -  
602 - String title = "案卷号:" + caseOffline.getNumber();  
603 - int index = 0;  
604 -  
605 - List<SysDictData> caseType = SpringUtils.getBean(ISysDictTypeService.class)  
606 - .selectDictDataByType("case_offline_type");  
607 -  
608 - for (SysDictData d : caseType) {  
609 - if (caseOffline.getType().equals(d.getDictValue())) {  
610 - if (d.getRemark() != null) {  
611 - index = 1;  
612 - }  
613 - break;  
614 - }  
615 - }  
616 -  
617 - if(index == 0){  
618 - JSONArray array = RemoteServerUtils.getAreas();  
619 - String placeName = "";  
620 - String placeCode = caseOffline.getPlace();  
621 -  
622 - for (Object obj : array) {  
623 - if (((JSONObject) (obj)).getString("code").equals(placeCode)) {  
624 - placeName = ((JSONObject) (obj)).getString("name");  
625 - if ("湘江新区".equals(placeName)) {  
626 - index = 3;  
627 - }  
628 -  
629 - break;  
630 - }  
631 - }  
632 -  
633 - if (tcdOutArea.indexOf(placeName) > -1) {  
634 - index = 2;  
635 - }  
636 - }  
637 -  
638 -  
639 - processInstance = processRuntime  
640 - .start(ProcessPayloadBuilder.start().withProcessDefinitionKey("workflow_caseoffline")  
641 - .withName(title).withBusinessKey("workflow_caseoffline:" + caseOffline.getId())  
642 - .withVariable("route", index).build());  
643 -  
644 - PorcThreeStepTask(processInstance, caseOffline.getPlace());  
645 -  
646 - Workflow workflow = new Workflow();  
647 - workflow.setId("workflow_caseoffline:" + caseOffline.getId());  
648 - workflow.setTitle(title);  
649 - workflow.setReason("案卷线下交办");  
650 - workflow.setStartTime(sdf.format(caseOffline.getCreateTime()));  
651 - workflow.setEndTime(sdf.format(caseOffline.getCreateTime()));  
652 - workflow.setType("交办案卷");  
653 - workflow.setInstanceId(processInstance.getId());  
654 - workflow.setState("0");  
655 - workflow.setCreateTime(new Date());  
656 -  
657 - SysUser user = null;  
658 -  
659 - try {  
660 - user = SecurityUtils.getLoginUser().getUser();  
661 - } catch (Exception e) {  
662 - // e.printStackTrace();  
663 - }  
664 -  
665 - awf = insertAwf(user, workflow);  
666 -  
667 - return workflowMapper.insertWorkflow(workflow);  
668 - } catch (Exception e) {  
669 - if (awf.getId() != null)  
670 - awfServer.deleteActWorkflowFormDataById(awf.getId());  
671 - e.printStackTrace();  
672 - processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));  
673 - }  
674 -  
675 - return 0;  
676 - }  
677 -  
678 - private void updateProcess(ProcessInstance processInstance, String owningRegion) {  
679 -  
680 - JSONArray array = RemoteServerUtils.getAreas();  
681 -  
682 - String placeCode = null;  
683 -  
684 - for (Object obj : array) {  
685 - if (((JSONObject) (obj)).getString("name").equals(owningRegion)) {  
686 -  
687 - placeCode = ((JSONObject) (obj)).getString("code");  
688 -  
689 - break;  
690 - }  
691 - }  
692 -  
693 - if (placeCode != null) {  
694 - PorcThreeStepTask(processInstance, placeCode);  
695 - }  
696 -  
697 - }  
698 -  
699 - public void PorcThreeStepTask(ProcessInstance processInstance, String areaCode) {  
700 - Map map = new HashedMap<>();  
701 -  
702 - map.put("type", "CSUserDepartmentType");  
703 -  
704 - Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();  
705 -  
706 - List<IdentityLink> list = taskService.getIdentityLinksForTask(task.getId());  
707 -  
708 - if (list.size() == 1) {  
709 - taskService.addCandidateUser(task.getId(), areaCode);  
710 - }  
711 -  
712 - task.setDescription(areaCode);  
713 -  
714 - taskService.saveTask(task);  
715 - }  
716 -  
717 - void updateProcessKafka(org.activiti.engine.runtime.ProcessInstance processInstance, String placeName,  
718 - String token) {  
719 - JSONArray array = RemoteServerUtils.getAreas(trashConfig.getToken());  
720 -  
721 - String placeCode = null;  
722 -  
723 - for (Object obj : array) {  
724 - if (((JSONObject) (obj)).getString("name").equals(placeName)) {  
725 -  
726 - placeCode = ((JSONObject) (obj)).getString("code");  
727 -  
728 - break;  
729 - }  
730 - }  
731 -  
732 - if (placeCode != null) {  
733 - Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();  
734 -  
735 - List<IdentityLink> list = taskService.getIdentityLinksForTask(task.getId());  
736 -  
737 - for (IdentityLink identityLink : list) {  
738 - // if(identityLink.getGroupId() != null)  
739 - // taskService.deleteGroupIdentityLink(task.getId(),  
740 - // identityLink.getGroupId(), identityLink.getType());  
741 - if (identityLink.getUserId() != null)  
742 - taskService.deleteUserIdentityLink(task.getId(), identityLink.getUserId(), identityLink.getType());  
743 - }  
744 -  
745 - taskService.addCandidateUser(task.getId(), placeCode);  
746 -  
747 - task.setDescription(placeCode);  
748 -  
749 - taskService.saveTask(task);  
750 - }  
751 - }  
752 -  
753 - /**  
754 - * 查询请假  
755 - *  
756 - * @param id  
757 - * 请假ID  
758 - * @return 请假  
759 - */  
760 - @Override  
761 - public Workflow selectWorkflowById(String id) {  
762 - return workflowMapper.selectWorkflowById(id);  
763 - }  
764 -  
765 - /**  
766 - * 查询请假列表  
767 - *  
768 - * @param Workflow  
769 - * 请假  
770 - * @return 请假  
771 - */  
772 - @Override  
773 - public List<Workflow> selectWorkflowList(Workflow Workflow) {  
774 - return workflowMapper.selectWorkflowListByWorkflowAndDeptId(Workflow,  
775 - SecurityUtils.getLoginUser().getUser().getDeptId());  
776 - }  
777 -  
778 - /**  
779 - * 查询请假列表带任务状态  
780 - *  
781 - * @param Workflow  
782 - * 请假  
783 - * @return 请假  
784 - */  
785 - @Override  
786 - public List<Workflow> selectWorkflowAndTaskNameList(Workflow Workflow) {  
787 - List<Workflow> Workflows = workflowMapper.selectWorkflowList(Workflow);  
788 - List<String> collect = Workflows.parallelStream().map(wl -> wl.getInstanceId()).collect(Collectors.toList());  
789 - if (collect != null && !collect.isEmpty()) {  
790 - List<Task> tasks = taskService.createTaskQuery().processInstanceIdIn(collect).list();  
791 - Workflows.forEach(wl -> {  
792 - Task task = tasks.parallelStream().filter(t -> t.getProcessInstanceId().equals(wl.getInstanceId()))  
793 - .findAny().orElse(null);  
794 - if (task != null) {  
795 - wl.setTaskName(task.getName());  
796 - }  
797 - });  
798 - }  
799 - return Workflows;  
800 - }  
801 -  
802 - /**  
803 - * 修改请假  
804 - *  
805 - * @param Workflow  
806 - * 请假  
807 - * @return 结果  
808 - */  
809 - @Override  
810 - public int updateWorkflow(Workflow Workflow) {  
811 - Workflow.setUpdateTime(DateUtils.getNowDate());  
812 - return workflowMapper.updateWorkflow(Workflow);  
813 - }  
814 -  
815 - /**  
816 - * 批量删除请假  
817 - *  
818 - * @param ids  
819 - * 需要删除的请假ID  
820 - * @return 结果  
821 - */  
822 - @Override  
823 - public int deleteWorkflowByIds(String[] ids) {  
824 - return workflowMapper.deleteWorkflowByIds(ids);  
825 - }  
826 -  
827 - /**  
828 - * 删除请假信息  
829 - *  
830 - * @param id  
831 - * 请假ID  
832 - * @return 结果  
833 - */  
834 - @Override  
835 - public int deleteWorkflowById(String id) {  
836 - return workflowMapper.deleteWorkflowById(id);  
837 - }  
838 -  
839 - @Override  
840 - public void deleteWorkflowByName(String name) {  
841 - workflowMapper.deleteWorkflowByName(name);  
842 - }  
843 -  
844 - @Override  
845 - public Workflow selectWorkflowByInstanceId(String instanceId) {  
846 -  
847 - return workflowMapper.selectWorkflowByInstanceId(instanceId);  
848 - }  
849 -  
850 -} 1 +package com.trash.workflow.service.impl;
  2 +
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.Date;
  5 +import java.util.List;
  6 +import java.util.Map;
  7 +import java.util.stream.Collectors;
  8 +
  9 +import org.activiti.api.process.model.ProcessInstance;
  10 +import org.activiti.api.process.model.builders.ProcessPayloadBuilder;
  11 +import org.activiti.api.process.runtime.ProcessRuntime;
  12 +import org.activiti.api.task.runtime.TaskRuntime;
  13 +import org.activiti.engine.RuntimeService;
  14 +import org.activiti.engine.TaskService;
  15 +import org.activiti.engine.task.IdentityLink;
  16 +import org.activiti.engine.task.Task;
  17 +import org.apache.commons.collections4.map.HashedMap;
  18 +import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.security.core.context.SecurityContextHolder;
  20 +import org.springframework.security.core.context.SecurityContextImpl;
  21 +import org.springframework.stereotype.Service;
  22 +import org.springframework.transaction.annotation.Transactional;
  23 +
  24 +import com.alibaba.fastjson.JSONArray;
  25 +import com.alibaba.fastjson.JSONObject;
  26 +import com.trash.activiti.domain.ActWorkflowFormData;
  27 +import com.trash.activiti.service.IActWorkflowFormDataService;
  28 +import com.trash.business.domain.ConstructionCredit;
  29 +import com.trash.business.domain.ConstructionSign;
  30 +import com.trash.business.domain.SupervisionThreestep;
  31 +import com.trash.business.service.IConstructionSignService;
  32 +import com.trash.business.service.ISupervisionThreestepService;
  33 +import com.trash.caseOffline.domain.CaseOffline;
  34 +import com.trash.casefile.domain.ViolationCaseFile;
  35 +import com.trash.casefile.domain.ViolationWarningInformation;
  36 +import com.trash.common.core.domain.entity.SysDictData;
  37 +import com.trash.common.core.domain.entity.SysUser;
  38 +import com.trash.common.core.redis.RedisCache;
  39 +import com.trash.common.utils.DateUtils;
  40 +import com.trash.common.utils.RemoteServerUtils;
  41 +import com.trash.common.utils.SecurityUtils;
  42 +import com.trash.common.utils.StringUtils;
  43 +import com.trash.common.utils.spring.SpringUtils;
  44 +import com.trash.framework.web.service.SysLoginService;
  45 +import com.trash.system.service.ISysDictTypeService;
  46 +import com.trash.system.service.ISysUserService;
  47 +import com.trash.workflow.domain.Workflow;
  48 +import com.trash.workflow.mapper.WorkflowMapper;
  49 +import com.trash.workflow.service.IWorkflowService;
  50 +
  51 +/**
  52 + * 请假Service业务层处理
  53 + *
  54 + * @author danny
  55 + * @date 2020-10-28
  56 + */
  57 +@Service
  58 +public class WorkflowServiceImpl implements IWorkflowService {
  59 +
  60 + @Autowired
  61 + private WorkflowMapper workflowMapper;
  62 + @Autowired
  63 + private ProcessRuntime processRuntime;
  64 + @Autowired
  65 + private ISysUserService sysUserService;
  66 + @Autowired
  67 + private TaskService taskService;
  68 +
  69 + @Autowired
  70 + private TaskRuntime taskRuntime;
  71 +
  72 + @Autowired
  73 + IConstructionSignService signService;
  74 +
  75 + @Autowired
  76 + com.trash.common.config.trashConfig trashConfig;
  77 +
  78 + @Autowired
  79 + SysLoginService loginService;
  80 +
  81 + String siteType[] = { "处理场所", "建筑垃圾资源化处置场", "盾构土环保处置场", "盾构土应急处理场所", "回填场" };
  82 +
  83 + String outArea = "株洲市,湘潭市,汨罗市,湘阴县";
  84 +
  85 + String tcdOutArea = "长沙县,望城区,浏阳市,宁乡市"; // 车企人外区
  86 +
  87 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  88 +
  89 + String inArea = "芙蓉区,天心区,开福区,雨花区,望城区";
  90 +
  91 + @Autowired
  92 + IActWorkflowFormDataService awfServer;
  93 +
  94 + @Autowired
  95 + RuntimeService runtimeService;
  96 +
  97 + @Autowired
  98 + ISupervisionThreestepService server;
  99 +
  100 + @Autowired
  101 + RedisCache redisCache;
  102 +
  103 + @Override
  104 + @Transactional
  105 + public int createWorkFlow(Map<String, Object> data) { // 第三方通用接收接口
  106 +
  107 + SysUser user = SecurityUtils.getLoginUser().getUser();
  108 +
  109 + String flowType = data.get("type").toString();
  110 +
  111 + Map map = (Map) data.get("data");
  112 +
  113 + String businessKey = flowType + ":" + map.get("id"); // 流程对应事务key
  114 + String title = map.get("title").toString();
  115 + String reason = map.get("reason").toString();
  116 + String startTime = map.get("startTime").toString();
  117 + String endTime = map.get("endTime").toString();
  118 + String areaCode = null;
  119 + int index = 0;
  120 + JSONArray areas = RemoteServerUtils.getAreas();
  121 + if (map.get("area") != null) {
  122 + areaCode = map.get("area").toString();
  123 +
  124 + if (flowType.equals("workflow_vehicle") || flowType.equals("workflow_company")
  125 + || flowType.equals("workflow_driver")) {
  126 + for (Object obj : areas) {
  127 + JSONObject jsonObject = (JSONObject) obj;
  128 + if (areaCode.equals(jsonObject.getString("code"))) {
  129 + if (tcdOutArea.contains(jsonObject.getString("name"))) {
  130 + index = 1;
  131 + }
  132 + break;
  133 + }
  134 + }
  135 + }else if (flowType.equals("workflow_earthsites")|| flowType.equals("workflow_earthsites_edit")) {
  136 + for (Object obj : areas) {
  137 + JSONObject jsonObject = (JSONObject) obj;
  138 + if (areaCode.equals(jsonObject.getString("code"))) {
  139 + if (inArea.contains(jsonObject.getString("name"))) {
  140 + index = 2;
  141 + }
  142 + if (tcdOutArea.contains(jsonObject.getString("name"))||jsonObject.getString("name").contains("湘江") ) {
  143 + index = 1;
  144 + }
  145 + break;
  146 + }
  147 + }
  148 + } else {
  149 + for (Object obj : areas) {
  150 + JSONObject jsonObject = (JSONObject) obj;
  151 + if (areaCode.equals(jsonObject.getString("code"))) {
  152 + if (outArea.contains(jsonObject.getString("name"))) {
  153 + index = 1;
  154 + }
  155 + break;
  156 + }
  157 + }
  158 + }
  159 + }
  160 +
  161 + ProcessInstance processInstance = null;
  162 + ActWorkflowFormData awf = null;
  163 +
  164 + try {
  165 +
  166 + processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(flowType)
  167 + .withName(title).withVariable("route", index).withBusinessKey(businessKey).build());
  168 +
  169 + if (areaCode != null) {
  170 + PorcThreeStepTask(processInstance, areaCode);
  171 + }
  172 +
  173 + if (flowType.equals("workflow_constructsite")) {
  174 +
  175 + ConstructionSign constructionSign = new ConstructionSign();
  176 +
  177 + constructionSign.setObjectId(map.get("id").toString());
  178 +
  179 + if (!user.getAvatar().contains("null")) {
  180 + constructionSign.setSign1(SecurityUtils.getLoginUser().getUser().getAvatar());
  181 + constructionSign.setSign1Time(new Date());
  182 + }
  183 +
  184 + signService.insertConstructionSign(constructionSign);
  185 +
  186 + }
  187 +
  188 + Workflow workflow = new Workflow();
  189 + workflow.setId(businessKey);
  190 + workflow.setTitle(title);
  191 + workflow.setReason(reason);
  192 + workflow.setStartTime(startTime);
  193 + workflow.setEndTime(endTime);
  194 + workflow.setType(map.get("type").toString());
  195 + workflow.setInstanceId(processInstance.getId());
  196 + workflow.setState("0");
  197 + workflow.setCreateTime(new Date());
  198 + workflow.setCreateBy(user.getUserName());
  199 + workflow.setCreateName(user.getUserName());
  200 +
  201 + awf = insertAwf(user, workflow);
  202 +
  203 + return workflowMapper.insertWorkflow(workflow);
  204 + } catch (Exception e) {
  205 +
  206 + if (processInstance != null)
  207 + processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));
  208 +
  209 + if (awf.getId() != null)
  210 + awfServer.deleteActWorkflowFormDataById(awf.getId());
  211 +
  212 + e.printStackTrace();
  213 + }
  214 +
  215 + return 0;
  216 + }
  217 +
  218 + private ActWorkflowFormData insertAwf(SysUser user, Workflow workflow) {
  219 +
  220 + if (user == null) {
  221 + user = new SysUser();
  222 + user.setUserName("长沙市建筑垃圾智慧监管平台");
  223 + }
  224 +
  225 + ActWorkflowFormData awf;
  226 + awf = new ActWorkflowFormData();
  227 + awf.setCreateBy(user.getUserName());
  228 + awf.setCreateName(user.getUserName());
  229 + awf.setCreateTime(new Date());
  230 + awf.setBusinessKey(workflow.getId());
  231 + awf.setControlId("CREATED");
  232 + awf.setControlName("发起人");
  233 + awf.setFormKey("CREATED");
  234 + awf.setTaskNodeName(user.getUserName() + "发起");
  235 + awf.setControlValue(workflow.getReason());
  236 +
  237 + awfServer.insertActWorkflowFormData(awf);
  238 + return awf;
  239 + }
  240 +
  241 + @Override
  242 + @Transactional
  243 + public int createLeaveWorkFlow(Workflow workflow, int index) {
  244 + ProcessInstance processInstance = null;
  245 +
  246 + ActWorkflowFormData awf = null;
  247 +
  248 + SysUser user = SecurityUtils.getLoginUser().getUser();
  249 +
  250 + try {
  251 +
  252 + processInstance = processRuntime.start(ProcessPayloadBuilder.start()
  253 + .withProcessDefinitionKey("workflow_leave").withName(workflow.getTitle())
  254 + .withBusinessKey(workflow.getId()).withVariable("route", index).build());
  255 +
  256 + Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  257 +
  258 + if (task != null) {
  259 +
  260 + task.setDescription(SecurityUtils.getLoginUser().getUser().getRoleIds().get(0));
  261 +
  262 + List<IdentityLink> list = taskService.getIdentityLinksForTask(task.getId());
  263 +
  264 + if (list.size() == 1) {
  265 + taskService.addCandidateUser(task.getId(), task.getDescription());
  266 + }
  267 +
  268 + taskService.saveTask(task);
  269 + }
  270 +
  271 + awf = insertAwf(user, workflow);
  272 +
  273 + workflow.setInstanceId(processInstance.getId());
  274 +
  275 + workflow.setCreateTime(new Date());
  276 + return workflowMapper.insertWorkflow(workflow);
  277 + } catch (Exception e) {
  278 +
  279 + if (awf.getId() != null)
  280 + awfServer.deleteActWorkflowFormDataById(awf.getId());
  281 + processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));
  282 +
  283 + e.printStackTrace();
  284 + }
  285 +
  286 + return 0;
  287 + }
  288 +
  289 + @Override
  290 + @Transactional
  291 + public int createDropPointWorkFlow(Map<String, String> droppoint) { // 三查
  292 + ProcessInstance processInstance = null;
  293 + ActWorkflowFormData awf = null;
  294 + try {
  295 + String name = "投放点审批:" + droppoint.get("name");
  296 +
  297 + processInstance = processRuntime
  298 + .start(ProcessPayloadBuilder.start().withProcessDefinitionKey("workflow_drop_point").withName(name)
  299 + .withBusinessKey("workflow_drop_point:" + droppoint.get("id")).build());
  300 +
  301 + PorcThreeStepTask(processInstance, droppoint.get("area"));
  302 +
  303 + Workflow workflow = new Workflow();
  304 + workflow.setId("workflow_drop_point:" + droppoint.get("id"));
  305 + workflow.setTitle(name);
  306 + workflow.setReason(droppoint.get("name") + "审批流程");
  307 + workflow.setStartTime(sdf.format(new Date()));
  308 + workflow.setEndTime(sdf.format(new Date()));
  309 + workflow.setType("投放点审批");
  310 + workflow.setInstanceId(processInstance.getId());
  311 + workflow.setState("0");
  312 + workflow.setCreateTime(new Date());
  313 +
  314 + SysUser user = SecurityUtils.getLoginUser().getUser();
  315 + awf = insertAwf(user, workflow);
  316 +
  317 + return workflowMapper.insertWorkflow(workflow);
  318 + } catch (Exception e) {
  319 + e.printStackTrace();
  320 + if (awf.getId() != null)
  321 + awfServer.deleteActWorkflowFormDataById(awf.getId());
  322 + processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));
  323 + }
  324 +
  325 + return 0;
  326 + }
  327 +
  328 + @Override
  329 + @Transactional
  330 + public int createThreeStepWorkFlow(SupervisionThreestep supervision) { // 三查
  331 + ProcessInstance processInstance = null;
  332 + ActWorkflowFormData awf = null;
  333 + try {
  334 + String name = "报工自查:" + supervision.getName();
  335 +
  336 + JSONArray areas = redisCache.getCacheObject("areas");
  337 +
  338 + int route = 0;
  339 +
  340 + if (areas == null) {
  341 + areas = RemoteServerUtils.getAreas();
  342 + redisCache.setCacheObject("areas", areas);
  343 + }
  344 +
  345 + for (Object obj : areas) {
  346 + JSONObject jsonObject = (JSONObject) obj;
  347 + if (supervision.getPlace().equals(jsonObject.getString("code"))) {
  348 + if (jsonObject.getString("name").contains("湘江新区")) {
  349 + route = 1;
  350 + }
  351 + break;
  352 + }
  353 + }
  354 +
  355 + processInstance = processRuntime.start(ProcessPayloadBuilder.start()
  356 + .withProcessDefinitionKey("workflow_threestep").withName(name).withVariable("route", route)
  357 + .withBusinessKey("workflow_threestep:" + supervision.getId()).build());
  358 +
  359 + PorcThreeStepTask(processInstance, supervision.getPlace());
  360 +
  361 + Workflow workflow = new Workflow();
  362 + workflow.setId("workflow_threestep:" + supervision.getId());
  363 + workflow.setTitle(name);
  364 + workflow.setReason("报工自查");
  365 + workflow.setStartTime(sdf.format(supervision.getSelfCheckTime()));
  366 + workflow.setEndTime(sdf.format(supervision.getSelfCheckTime()));
  367 + workflow.setType("报工审批");
  368 + workflow.setInstanceId(processInstance.getId());
  369 + workflow.setState("0");
  370 + workflow.setCreateTime(new Date());
  371 +
  372 + SysUser user = SecurityUtils.getLoginUser().getUser();
  373 + awf = insertAwf(user, workflow);
  374 +
  375 + return workflowMapper.insertWorkflow(workflow);
  376 + } catch (Exception e) {
  377 + e.printStackTrace();
  378 + if (awf.getId() != null)
  379 + awfServer.deleteActWorkflowFormDataById(awf.getId());
  380 + processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));
  381 + }
  382 +
  383 + return 0;
  384 + }
  385 +
  386 +// @Override
  387 +// @Transactional
  388 +// public int createCaseFileByTask(ViolationCaseFile caseFile, int index) { // 违规预警案卷
  389 +//
  390 +// if (StringUtils.isEmpty(RemoteServerUtils.remote)) {
  391 +// RemoteServerUtils.remote = trashConfig.getRemotePath();
  392 +// }
  393 +// loginService.loginByRemote(trashConfig.getToken());
  394 +//
  395 +// SysUser user = null;
  396 +//
  397 +// try {
  398 +// user = SecurityUtils.getLoginUser().getUser();
  399 +// } catch (Exception e) {
  400 +// // e.printStackTrace();
  401 +// }
  402 +//
  403 +// SecurityContextImpl securityContextImpl = new SecurityContextImpl();
  404 +//
  405 +// securityContextImpl.setAuthentication(SecurityContextHolder.getContext().getAuthentication());
  406 +// org.activiti.engine.runtime.ProcessInstance instance = null;
  407 +// String title = "案卷号:" + caseFile.getNumber();
  408 +// String flowType = "workflow_casefile";
  409 +//
  410 +// if (index > 0 && caseFile.getOwningRegion().contains("湘江新区")) {
  411 +// index += 3;
  412 +// }
  413 +// ActWorkflowFormData awf = null;
  414 +//
  415 +// try {
  416 +// Map map = new HashedMap<>();
  417 +//
  418 +// map.put("route", index);
  419 +// instance = runtimeService.createProcessInstanceBuilder().businessKey(flowType + ":" + caseFile.getId())
  420 +// .name(title).variable("route", index).processDefinitionKey(flowType).variables(map).start();
  421 +//
  422 +// // runtimeService.startProcessInstanceById(instance.getProcessDefinitionId(),map);
  423 +//
  424 +// if (index == 0) {
  425 +// Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();
  426 +//
  427 +// task.setAssignee(caseFile.getAbbreviation());
  428 +//
  429 +// task.setDescription(caseFile.getAbbreviation());
  430 +// taskService.saveTask(task);
  431 +// } else {
  432 +// updateProcessKafka(instance, caseFile.getOwningRegion(), trashConfig.getToken());
  433 +// }
  434 +//
  435 +// Workflow workflow = new Workflow();
  436 +// workflow.setId(flowType + ":" + caseFile.getId());
  437 +// workflow.setTitle(title);
  438 +// workflow.setReason("平台案卷");
  439 +// workflow.setStartTime(sdf.format(caseFile.getCreateTime()));
  440 +// workflow.setEndTime(sdf.format(caseFile.getCreateTime()));
  441 +// workflow.setType("违规案卷处置流程");
  442 +// workflow.setInstanceId(instance.getId());
  443 +// workflow.setState("0");
  444 +// workflow.setCreateTime(new Date());
  445 +//
  446 +// awf = insertAwf(user, workflow);
  447 +//
  448 +// return workflowMapper.insertWorkflow(workflow);
  449 +// } catch (Exception e) {
  450 +// if (awf.getId() != null)
  451 +// awfServer.deleteActWorkflowFormDataById(awf.getId());
  452 +// runtimeService.deleteProcessInstance(instance.getId(), "创建失败");
  453 +// throw new RuntimeException(e);
  454 +// }
  455 +//
  456 +// }
  457 +
  458 + @Override
  459 + @Transactional
  460 + public int createCaseFile(ViolationCaseFile caseFile, int index) { // 三查
  461 + ProcessInstance processInstance = null;
  462 + ActWorkflowFormData awf = null;
  463 + String title = "案卷号:" + caseFile.getNumber();
  464 + String flowType = "workflow_casefile";
  465 + try {
  466 + List<SysDictData> caseType = SpringUtils.getBean(ISysDictTypeService.class)
  467 + .selectDictDataByType("vio_casefile");
  468 +
  469 + for (SysDictData d : caseType) {
  470 + if (caseFile.getViolationType().equals(d.getDictValue())) {
  471 + if (d.getRemark() != null) {
  472 + index = 1;
  473 + }
  474 + break;
  475 + }
  476 + }
  477 +
  478 + if(index == 0){
  479 + if (tcdOutArea.indexOf(caseFile.getOwningRegion()) > -1) {
  480 + index = 2;
  481 + }
  482 +
  483 + if ("湘江新区".equals(caseFile.getOwningRegion())) {
  484 + index = 3;
  485 + }
  486 + }
  487 +
  488 +
  489 +
  490 +
  491 + processInstance = processRuntime
  492 + .start(ProcessPayloadBuilder.start().withProcessDefinitionKey(flowType).withName(title)
  493 + .withBusinessKey(flowType + ":" + caseFile.getId()).withVariable("route", index).build());
  494 +
  495 +
  496 + updateProcess(processInstance, caseFile.getOwningRegion());
  497 +
  498 +
  499 + Workflow workflow = new Workflow();
  500 + workflow.setId(flowType + ":" + caseFile.getId());
  501 + workflow.setTitle(title);
  502 + workflow.setReason("平台案卷");
  503 + workflow.setStartTime(sdf.format(caseFile.getCreateTime()));
  504 + workflow.setEndTime(sdf.format(caseFile.getCreateTime()));
  505 + workflow.setType("违规案卷处置流程");
  506 + workflow.setInstanceId(processInstance.getId());
  507 + workflow.setState("0");
  508 + workflow.setCreateTime(new Date());
  509 +
  510 + SysUser user = SecurityUtils.getLoginUser().getUser();
  511 + awf = insertAwf(user, workflow);
  512 + return workflowMapper.insertWorkflow(workflow);
  513 + } catch (Exception e) {
  514 + e.printStackTrace();
  515 + if (awf.getId() != null)
  516 + awfServer.deleteActWorkflowFormDataById(awf.getId());
  517 + processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));
  518 + throw new RuntimeException(e);
  519 + }
  520 + }
  521 +
  522 + @Override
  523 + @Transactional
  524 + public int createCaseFile1(ViolationWarningInformation caseFile, int index, int isAuto) { // 违规预警案卷
  525 + if (isAuto == 1) {
  526 + if (StringUtils.isEmpty(RemoteServerUtils.remote)) {
  527 + RemoteServerUtils.remote = trashConfig.getRemotePath();
  528 + }
  529 + loginService.loginByRemote(trashConfig.getToken());
  530 + }
  531 +
  532 + SysUser user = null;
  533 +
  534 + try {
  535 + user = SecurityUtils.getLoginUser().getUser();
  536 + } catch (Exception e) {
  537 + // e.printStackTrace();
  538 + }
  539 +
  540 + SecurityContextImpl securityContextImpl = new SecurityContextImpl();
  541 +
  542 + securityContextImpl.setAuthentication(SecurityContextHolder.getContext().getAuthentication());
  543 + org.activiti.engine.runtime.ProcessInstance instance = null;
  544 + String title = "案卷号:" + caseFile.getNumber();
  545 + String flowType = "violation_warning";
  546 +
  547 + if (index > 0 && caseFile.getOwningRegion().contains("湘江新区")) {
  548 + index += 3;
  549 + }
  550 + ActWorkflowFormData awf = null;
  551 +
  552 + try {
  553 + Map map = new HashedMap<>();
  554 +
  555 + map.put("route", index);
  556 + instance = runtimeService.createProcessInstanceBuilder().businessKey(flowType + ":" + caseFile.getId())
  557 + .name(title).variable("route", index).processDefinitionKey(flowType).variables(map).start();
  558 +
  559 + // runtimeService.startProcessInstanceById(instance.getProcessDefinitionId(),map);
  560 +
  561 + if (index == 0) {
  562 + Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();
  563 +
  564 + task.setAssignee(caseFile.getAbbreviation());
  565 + task.setDescription(caseFile.getAbbreviation());
  566 +
  567 + taskService.saveTask(task);
  568 + } else {
  569 + updateProcessKafka(instance, caseFile.getOwningRegion(), trashConfig.getToken());
  570 + }
  571 +
  572 + Workflow workflow = new Workflow();
  573 + workflow.setId(flowType + ":" + caseFile.getId());
  574 + workflow.setTitle(title);
  575 + workflow.setReason("违规预警信息");
  576 + workflow.setStartTime(sdf.format(caseFile.getCreateTime()));
  577 + workflow.setEndTime(sdf.format(caseFile.getCreateTime()));
  578 + workflow.setType("平台预警信息");
  579 + workflow.setInstanceId(instance.getId());
  580 + workflow.setState("0");
  581 + workflow.setCreateTime(new Date());
  582 +
  583 + awf = insertAwf(user, workflow);
  584 +
  585 + return workflowMapper.insertWorkflow(workflow);
  586 + } catch (Exception e) {
  587 + if (awf.getId() != null)
  588 + awfServer.deleteActWorkflowFormDataById(awf.getId());
  589 + runtimeService.deleteProcessInstance(instance.getId(), "创建失败");
  590 + throw new RuntimeException(e);
  591 + }
  592 +
  593 + }
  594 +
  595 + @Override
  596 + @Transactional
  597 + public int createCaseOffline(CaseOffline caseOffline) { // 三查
  598 + ProcessInstance processInstance = null;
  599 + ActWorkflowFormData awf = null;
  600 + try {
  601 +
  602 + String title = "案卷号:" + caseOffline.getNumber();
  603 + int index = 0;
  604 +
  605 + List<SysDictData> caseType = SpringUtils.getBean(ISysDictTypeService.class)
  606 + .selectDictDataByType("case_offline_type");
  607 +
  608 + for (SysDictData d : caseType) {
  609 + if (caseOffline.getType().equals(d.getDictValue())) {
  610 + if (d.getRemark() != null) {
  611 + index = 1;
  612 + }
  613 + break;
  614 + }
  615 + }
  616 +
  617 + if(index == 0){
  618 + JSONArray array = RemoteServerUtils.getAreas();
  619 + String placeName = "";
  620 + String placeCode = caseOffline.getPlace();
  621 +
  622 + for (Object obj : array) {
  623 + if (((JSONObject) (obj)).getString("code").equals(placeCode)) {
  624 + placeName = ((JSONObject) (obj)).getString("name");
  625 + if ("湘江新区".equals(placeName)) {
  626 + index = 3;
  627 + }
  628 +
  629 + break;
  630 + }
  631 + }
  632 +
  633 + if (tcdOutArea.indexOf(placeName) > -1) {
  634 + index = 2;
  635 + }
  636 + }
  637 +
  638 +
  639 + processInstance = processRuntime
  640 + .start(ProcessPayloadBuilder.start().withProcessDefinitionKey("workflow_caseoffline")
  641 + .withName(title).withBusinessKey("workflow_caseoffline:" + caseOffline.getId())
  642 + .withVariable("route", index).build());
  643 +
  644 + PorcThreeStepTask(processInstance, caseOffline.getPlace());
  645 +
  646 + Workflow workflow = new Workflow();
  647 + workflow.setId("workflow_caseoffline:" + caseOffline.getId());
  648 + workflow.setTitle(title);
  649 + workflow.setReason("案卷线下交办");
  650 + workflow.setStartTime(sdf.format(caseOffline.getCreateTime()));
  651 + workflow.setEndTime(sdf.format(caseOffline.getCreateTime()));
  652 + workflow.setType("交办案卷");
  653 + workflow.setInstanceId(processInstance.getId());
  654 + workflow.setState("0");
  655 + workflow.setCreateTime(new Date());
  656 +
  657 + SysUser user = null;
  658 +
  659 + try {
  660 + user = SecurityUtils.getLoginUser().getUser();
  661 + } catch (Exception e) {
  662 + // e.printStackTrace();
  663 + }
  664 +
  665 + awf = insertAwf(user, workflow);
  666 +
  667 + return workflowMapper.insertWorkflow(workflow);
  668 + } catch (Exception e) {
  669 + if (awf.getId() != null)
  670 + awfServer.deleteActWorkflowFormDataById(awf.getId());
  671 + e.printStackTrace();
  672 + processRuntime.delete(ProcessPayloadBuilder.delete(processInstance));
  673 + }
  674 +
  675 + return 0;
  676 + }
  677 +
  678 + private void updateProcess(ProcessInstance processInstance, String owningRegion) {
  679 +
  680 + JSONArray array = RemoteServerUtils.getAreas();
  681 +
  682 + String placeCode = null;
  683 +
  684 + for (Object obj : array) {
  685 + if (((JSONObject) (obj)).getString("name").equals(owningRegion)) {
  686 +
  687 + placeCode = ((JSONObject) (obj)).getString("code");
  688 +
  689 + break;
  690 + }
  691 + }
  692 +
  693 + if (placeCode != null) {
  694 + PorcThreeStepTask(processInstance, placeCode);
  695 + }
  696 +
  697 + }
  698 +
  699 + public void PorcThreeStepTask(ProcessInstance processInstance, String areaCode) {
  700 + Map map = new HashedMap<>();
  701 +
  702 + map.put("type", "CSUserDepartmentType");
  703 +
  704 + Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  705 +
  706 + List<IdentityLink> list = taskService.getIdentityLinksForTask(task.getId());
  707 +
  708 + if (list.size() == 1) {
  709 + taskService.addCandidateUser(task.getId(), areaCode);
  710 + }
  711 +
  712 + task.setDescription(areaCode);
  713 +
  714 + taskService.saveTask(task);
  715 + }
  716 +
  717 + void updateProcessKafka(org.activiti.engine.runtime.ProcessInstance processInstance, String placeName,
  718 + String token) {
  719 + JSONArray array = RemoteServerUtils.getAreas(trashConfig.getToken());
  720 +
  721 + String placeCode = null;
  722 +
  723 + for (Object obj : array) {
  724 + if (((JSONObject) (obj)).getString("name").equals(placeName)) {
  725 +
  726 + placeCode = ((JSONObject) (obj)).getString("code");
  727 +
  728 + break;
  729 + }
  730 + }
  731 +
  732 + if (placeCode != null) {
  733 + Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  734 +
  735 + List<IdentityLink> list = taskService.getIdentityLinksForTask(task.getId());
  736 +
  737 + for (IdentityLink identityLink : list) {
  738 + // if(identityLink.getGroupId() != null)
  739 + // taskService.deleteGroupIdentityLink(task.getId(),
  740 + // identityLink.getGroupId(), identityLink.getType());
  741 + if (identityLink.getUserId() != null)
  742 + taskService.deleteUserIdentityLink(task.getId(), identityLink.getUserId(), identityLink.getType());
  743 + }
  744 +
  745 + taskService.addCandidateUser(task.getId(), placeCode);
  746 +
  747 + task.setDescription(placeCode);
  748 +
  749 + taskService.saveTask(task);
  750 + }
  751 + }
  752 +
  753 + /**
  754 + * 查询请假
  755 + *
  756 + * @param id
  757 + * 请假ID
  758 + * @return 请假
  759 + */
  760 + @Override
  761 + public Workflow selectWorkflowById(String id) {
  762 + return workflowMapper.selectWorkflowById(id);
  763 + }
  764 +
  765 + /**
  766 + * 查询请假列表
  767 + *
  768 + * @param Workflow
  769 + * 请假
  770 + * @return 请假
  771 + */
  772 + @Override
  773 + public List<Workflow> selectWorkflowList(Workflow Workflow) {
  774 + return workflowMapper.selectWorkflowListByWorkflowAndDeptId(Workflow,
  775 + SecurityUtils.getLoginUser().getUser().getDeptId());
  776 + }
  777 +
  778 + /**
  779 + * 查询请假列表带任务状态
  780 + *
  781 + * @param Workflow
  782 + * 请假
  783 + * @return 请假
  784 + */
  785 + @Override
  786 + public List<Workflow> selectWorkflowAndTaskNameList(Workflow Workflow) {
  787 + List<Workflow> Workflows = workflowMapper.selectWorkflowList(Workflow);
  788 + List<String> collect = Workflows.parallelStream().map(wl -> wl.getInstanceId()).collect(Collectors.toList());
  789 + if (collect != null && !collect.isEmpty()) {
  790 + List<Task> tasks = taskService.createTaskQuery().processInstanceIdIn(collect).list();
  791 + Workflows.forEach(wl -> {
  792 + Task task = tasks.parallelStream().filter(t -> t.getProcessInstanceId().equals(wl.getInstanceId()))
  793 + .findAny().orElse(null);
  794 + if (task != null) {
  795 + wl.setTaskName(task.getName());
  796 + }
  797 + });
  798 + }
  799 + return Workflows;
  800 + }
  801 +
  802 + /**
  803 + * 修改请假
  804 + *
  805 + * @param Workflow
  806 + * 请假
  807 + * @return 结果
  808 + */
  809 + @Override
  810 + public int updateWorkflow(Workflow Workflow) {
  811 + Workflow.setUpdateTime(DateUtils.getNowDate());
  812 + return workflowMapper.updateWorkflow(Workflow);
  813 + }
  814 +
  815 + /**
  816 + * 批量删除请假
  817 + *
  818 + * @param ids
  819 + * 需要删除的请假ID
  820 + * @return 结果
  821 + */
  822 + @Override
  823 + public int deleteWorkflowByIds(String[] ids) {
  824 + return workflowMapper.deleteWorkflowByIds(ids);
  825 + }
  826 +
  827 + /**
  828 + * 删除请假信息
  829 + *
  830 + * @param id
  831 + * 请假ID
  832 + * @return 结果
  833 + */
  834 + @Override
  835 + public int deleteWorkflowById(String id) {
  836 + return workflowMapper.deleteWorkflowById(id);
  837 + }
  838 +
  839 + @Override
  840 + public void deleteWorkflowByName(String name) {
  841 + workflowMapper.deleteWorkflowByName(name);
  842 + }
  843 +
  844 + @Override
  845 + public Workflow selectWorkflowByInstanceId(String instanceId) {
  846 +
  847 + return workflowMapper.selectWorkflowByInstanceId(instanceId);
  848 + }
  849 +
  850 +}