From 138d5f087e386c657d964e4e4c2b8ac65038e085 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期一, 01 二月 2021 14:47:06 +0800
Subject: [PATCH] 优化 考勤任务上报

---
 service-common/src/main/java/com/java110/common/smo/impl/ComplaintUserInnerServiceSMOImpl.java |   98 ++++++++++++++++++++++++++++--------------------
 1 files changed, 57 insertions(+), 41 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
index 3074b30..510297e 100644
--- 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
@@ -2,10 +2,10 @@
 
 
 import com.java110.core.base.smo.BaseServiceSMO;
-import com.java110.core.smo.common.IComplaintUserInnerServiceSMO;
-import com.java110.core.smo.common.IWorkflowInnerServiceSMO;
-import com.java110.core.smo.store.IComplaintInnerServiceSMO;
-import com.java110.core.smo.user.IUserInnerServiceSMO;
+import com.java110.intf.common.IComplaintUserInnerServiceSMO;
+import com.java110.intf.common.IWorkflowInnerServiceSMO;
+import com.java110.intf.store.IComplaintInnerServiceSMO;
+import com.java110.intf.user.IUserInnerServiceSMO;
 import com.java110.dto.PageDto;
 import com.java110.dto.auditMessage.AuditMessageDto;
 import com.java110.dto.complaint.ComplaintDto;
@@ -69,23 +69,8 @@
         Map<String, Object> variables = new HashMap<String, Object>();
         //variables.put("complaintDto", complaintDto);
         variables.put("startUserId", complaintDto.getCurrentUserId());
-        //寮�鍚祦绋�
-        //WorkflowDto.DEFAULT_PROCESS + workflowDto.getFlowId()
-        WorkflowDto workflowDto = new WorkflowDto();
-        workflowDto.setFlowType(WorkflowDto.FLOW_TYPE_COMPLAINT);
-        workflowDto.setCommunityId(complaintDto.getCommunityId());
-        List<WorkflowDto> workflowDtos = workflowInnerServiceSMOImpl.queryWorkflows(workflowDto);
 
-        Assert.listOnlyOne(workflowDtos, "鏈壘鍒� 鎶曡瘔寤鸿娴佺▼鎴栨壘鍒板鏉�");
-
-        WorkflowDto tmpWorkflowDto = workflowDtos.get(0);
-        if (StringUtil.isEmpty(tmpWorkflowDto.getProcessDefinitionKey())) {
-            throw new IllegalArgumentException("娴佺▼杩樻湭閮ㄧ讲");
-        }
-
-        String deployId = tmpWorkflowDto.getProcessDefinitionKey();
-
-        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(WorkflowDto.DEFAULT_PROCESS + tmpWorkflowDto.getFlowId(), complaintDto.getComplaintId(), variables);
+        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(getWorkflowDto(complaintDto.getCommunityId()), complaintDto.getComplaintId(), variables);
         //灏嗗緱鍒扮殑瀹炰緥娴佺▼id鍊艰祴缁欎箣鍓嶈缃殑鍙橀噺
         String processInstanceId = processInstance.getId();
         // System.out.println("娴佺▼寮�鍚垚鍔�.......瀹炰緥娴佺▼id:" + processInstanceId);
@@ -94,6 +79,23 @@
         //绗竴涓妭鐐硅嚜鍔ㄦ彁浜�
         //autoFinishFirstTask(complaintDto);
         return complaintDto;
+    }
+
+    private String getWorkflowDto(String communityId) {
+        //寮�鍚祦绋�
+        //WorkflowDto.DEFAULT_PROCESS + workflowDto.getFlowId()
+        WorkflowDto workflowDto = new WorkflowDto();
+        workflowDto.setFlowType(WorkflowDto.FLOW_TYPE_COMPLAINT);
+        workflowDto.setCommunityId(communityId);
+        List<WorkflowDto> workflowDtos = workflowInnerServiceSMOImpl.queryWorkflows(workflowDto);
+
+        Assert.listOnlyOne(workflowDtos, "鏈壘鍒� 鎶曡瘔寤鸿娴佺▼鎴栨壘鍒板鏉�");
+
+        WorkflowDto tmpWorkflowDto = workflowDtos.get(0);
+        if (StringUtil.isEmpty(tmpWorkflowDto.getProcessDefinitionKey())) {
+            throw new IllegalArgumentException("娴佺▼杩樻湭閮ㄧ讲");
+        }
+        return WorkflowDto.DEFAULT_PROCESS + tmpWorkflowDto.getFlowId();
     }
 
     /**
@@ -125,7 +127,7 @@
      */
     public long getUserTaskCount(@RequestBody AuditUser user) {
         TaskService taskService = processEngine.getTaskService();
-        TaskQuery query = taskService.createTaskQuery().processDefinitionKey("complaint");
+        TaskQuery query = taskService.createTaskQuery().processDefinitionKey(getWorkflowDto(user.getCommunityId()));
         query.taskAssignee(user.getUserId());
         return query.count();
     }
@@ -137,7 +139,7 @@
      */
     public List<ComplaintDto> getUserTasks(@RequestBody AuditUser user) {
         TaskService taskService = processEngine.getTaskService();
-        TaskQuery query = taskService.createTaskQuery().processDefinitionKey("complaint");
+        TaskQuery query = taskService.createTaskQuery().processDefinitionKey(getWorkflowDto(user.getCommunityId()));
         ;
         query.taskAssignee(user.getUserId());
         query.orderByTaskCreateTime().desc();
@@ -191,8 +193,9 @@
 //                .taskAssignee(user.getUserId());
 
         HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
-                .processDefinitionKey("complaint")
-                .taskAssignee(user.getUserId());
+                .processDefinitionKey(getWorkflowDto(user.getCommunityId()))
+                .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())) {
@@ -200,6 +203,7 @@
         }
 
         Query query = historicTaskInstanceQuery;
+
         return query.count();
     }
 
@@ -212,8 +216,9 @@
         HistoryService historyService = processEngine.getHistoryService();
 
         HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
-                .processDefinitionKey("complaint")
-                .taskAssignee(user.getUserId());
+                .processDefinitionKey(getWorkflowDto(user.getCommunityId()))
+                .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())) {
@@ -258,6 +263,8 @@
         Map<String, Object> variables = new HashMap<String, Object>();
         variables.put("auditCode", complaintDto.getAuditCode());
         variables.put("currentUserId", complaintDto.getCurrentUserId());
+        variables.put("flag", "1200".equals(complaintDto.getAuditCode()) ? "false" : "true");
+        variables.put("startUserId", complaintDto.getStartUserId());
         //taskService.setAssignee(complaintDto.getTaskId(),complaintDto.getCurrentUserId());
         //taskService.addCandidateUser(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
         //taskService.claim(complaintDto.getTaskId(), complaintDto.getCurrentUserId());
@@ -300,28 +307,37 @@
     public ComplaintDto getTaskCurrentUser(@RequestBody ComplaintDto complaintDto) {
 
         TaskService taskService = processEngine.getTaskService();
-        Task task = taskService.createTaskQuery().processInstanceBusinessKey(complaintDto.getComplaintId()).singleResult();
+        List<Task> tasks = taskService.createTaskQuery().processInstanceBusinessKey(complaintDto.getComplaintId()).list();
 
-        if (task == null) {
+        if (tasks == null || tasks.size() == 0) {
             complaintDto.setCurrentUserId("");
             complaintDto.setCurrentUserName("");
             complaintDto.setCurrentUserTel("");
             return complaintDto;
         }
-
-        String userId = task.getAssignee();
-        List<UserDto> users = userInnerServiceSMOImpl.getUserInfo(new String[]{userId});
-
-        if (users == null || users.size() == 0) {
-            complaintDto.setCurrentUserId("");
-            complaintDto.setCurrentUserName("");
-            complaintDto.setCurrentUserTel("");
-            return complaintDto;
+        String userIds = "";
+        String userNames = "";
+        String userTels = "";
+        String taskIds = "";
+        for (Task task : tasks) {
+            String userId = task.getAssignee();
+            taskIds += (task.getId() + "/");
+            List<UserDto> users = userInnerServiceSMOImpl.getUserInfo(new String[]{userId});
+            if (users == null || users.size() == 0) {
+                continue;
+            }
+            userIds += (userId + "/");
+            userNames += (users.get(0).getName() + "/");
+            userTels += (users.get(0).getTel() + "/");
         }
-
-        complaintDto.setCurrentUserId(userId);
-        complaintDto.setCurrentUserName(users.get(0).getName());
-        complaintDto.setCurrentUserTel(users.get(0).getTel());
+        userIds = userIds.endsWith("/") ? userIds.substring(0, userIds.length() - 1) : userIds;
+        userNames = userNames.endsWith("/") ? userNames.substring(0, userNames.length() - 1) : userNames;
+        userTels = userTels.endsWith("/") ? userTels.substring(0, userTels.length() - 1) : userTels;
+        taskIds = taskIds.endsWith("/") ? taskIds.substring(0, taskIds.length() - 1) : taskIds;
+        complaintDto.setCurrentUserId(userIds);
+        complaintDto.setCurrentUserName(userNames);
+        complaintDto.setCurrentUserTel(userTels);
+        complaintDto.setTaskId(taskIds);
         return complaintDto;
 
     }

--
Gitblit v1.8.0