From 05683f2b2bdbdbe21cf17ad523c21ab338bd1c54 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 19 七月 2022 21:49:55 +0800
Subject: [PATCH] 优化添加设备 功能

---
 service-common/src/main/java/com/java110/common/smo/impl/ComplaintUserInnerServiceSMOImpl.java |   50 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/service-common/src/main/java/com/java110/common/smo/impl/ComplaintUserInnerServiceSMOImpl.java b/service-common/src/main/java/com/java110/common/smo/impl/ComplaintUserInnerServiceSMOImpl.java
old mode 100644
new mode 100755
index 4a3d6d9..f18bbba
--- a/service-common/src/main/java/com/java110/common/smo/impl/ComplaintUserInnerServiceSMOImpl.java
+++ b/service-common/src/main/java/com/java110/common/smo/impl/ComplaintUserInnerServiceSMOImpl.java
@@ -12,6 +12,7 @@
 import com.java110.dto.user.UserDto;
 import com.java110.dto.workflow.WorkflowDto;
 import com.java110.entity.audit.AuditUser;
+import com.java110.utils.cache.MappingCache;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.StringUtil;
 import org.activiti.engine.HistoryService;
@@ -27,6 +28,8 @@
 import org.activiti.engine.task.Comment;
 import org.activiti.engine.task.Task;
 import org.activiti.engine.task.TaskQuery;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
@@ -40,6 +43,9 @@
 @RestController
 public class ComplaintUserInnerServiceSMOImpl extends BaseServiceSMO implements IComplaintUserInnerServiceSMO {
 
+
+    private final static Logger logger = LoggerFactory.getLogger(ComplaintUserInnerServiceSMOImpl.class);
+
     @Autowired
     private ProcessEngine processEngine;
 
@@ -48,6 +54,9 @@
 
     @Autowired
     private TaskService taskService;
+
+    @Autowired
+    private HistoryService historyService;
 
     @Autowired
     private IComplaintInnerServiceSMO complaintInnerServiceSMOImpl;
@@ -69,8 +78,13 @@
         Map<String, Object> variables = new HashMap<String, Object>();
         //variables.put("complaintDto", complaintDto);
         variables.put("startUserId", complaintDto.getCurrentUserId());
+        String key = getWorkflowDto(complaintDto.getCommunityId());
 
-        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(complaintDto.getCommunityId()), complaintDto.getComplaintId(), variables);
+        if(StringUtil.isEmpty(key)){
+            return null;
+        }
+
+        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key, complaintDto.getComplaintId(), variables);
         //灏嗗緱鍒扮殑瀹炰緥娴佺▼id鍊艰祴缁欎箣鍓嶈缃殑鍙橀噺
         String processInstanceId = processInstance.getId();
         // System.out.println("娴佺▼寮�鍚垚鍔�.......瀹炰緥娴佺▼id:" + processInstanceId);
@@ -89,11 +103,13 @@
         workflowDto.setCommunityId(communityId);
         List<WorkflowDto> workflowDtos = workflowInnerServiceSMOImpl.queryWorkflows(workflowDto);
 
-        Assert.listOnlyOne(workflowDtos, "鏈壘鍒� 鎶曡瘔寤鸿娴佺▼鎴栨壘鍒板鏉�");
+        if(workflowDtos == null || workflowDtos.size() < 1){
+            return "";
+        }
 
         WorkflowDto tmpWorkflowDto = workflowDtos.get(0);
         if (StringUtil.isEmpty(tmpWorkflowDto.getProcessDefinitionKey())) {
-            throw new IllegalArgumentException("娴佺▼杩樻湭閮ㄧ讲");
+            return "";
         }
         return WorkflowDto.DEFAULT_PROCESS + tmpWorkflowDto.getFlowId();
     }
@@ -194,7 +210,8 @@
 
         HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
                 .processDefinitionKey(getWorkflowDto(user.getCommunityId()))
-                .taskAssignee(user.getUserId());
+                .taskAssignee(user.getUserId())
+                .finished();
         if (!StringUtil.isEmpty(user.getAuditLink()) && "START".equals(user.getAuditLink())) {
             historicTaskInstanceQuery.taskName("complaint");
         } else if (!StringUtil.isEmpty(user.getAuditLink()) && "AUDIT".equals(user.getAuditLink())) {
@@ -202,6 +219,7 @@
         }
 
         Query query = historicTaskInstanceQuery;
+
         return query.count();
     }
 
@@ -215,7 +233,8 @@
 
         HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
                 .processDefinitionKey(getWorkflowDto(user.getCommunityId()))
-                .taskAssignee(user.getUserId());
+                .taskAssignee(user.getUserId())
+                .finished();
         if (!StringUtil.isEmpty(user.getAuditLink()) && "START".equals(user.getAuditLink())) {
             historicTaskInstanceQuery.taskName("complaint");
         } else if (!StringUtil.isEmpty(user.getAuditLink()) && "AUDIT".equals(user.getAuditLink())) {
@@ -296,6 +315,27 @@
     }
 
     /**
+     * 鍒犻櫎鎸囧畾浠诲姟
+     */
+    public boolean deleteTask(@RequestBody ComplaintDto complaintDto){
+        String taskId = complaintDto.getTaskId();
+
+        Task task = taskService.createTaskQuery().taskId(complaintDto.getTaskId()).singleResult();
+        String processInstanceId = task.getProcessInstanceId();
+        ProcessInstance pi = runtimeService.createProcessInstanceQuery()
+                .processInstanceId(processInstanceId)
+                .singleResult();
+        logger.info("鍒犻櫎id涓猴細{}锛屾姇璇夊缓璁换鍔�");
+        if (null != pi) {
+            //璇ユ祦绋嬪疄渚嬫湭缁撴潫鐨�
+            runtimeService.deleteProcessInstance(processInstanceId, "鍒犻櫎浠诲姟");
+        }
+        historyService.deleteHistoricProcessInstance(processInstanceId);
+        return true;
+    }
+
+
+    /**
      * 鑾峰彇浠诲姟褰撳墠澶勭悊浜�
      *
      * @param complaintDto

--
Gitblit v1.8.0