Преглед на файлове

流程数量效率优化

dzx преди 6 месеца
родител
ревизия
d928b50505
променени са 1 файла, в които са добавени 34 реда и са изтрити 17 реда
  1. 34 17
      src/main/java/com/xjrsoft/module/organization/controller/UserController.java

+ 34 - 17
src/main/java/com/xjrsoft/module/organization/controller/UserController.java

@@ -55,9 +55,12 @@ import com.xjrsoft.module.teacher.entity.BaseTeacherRegular;
 import com.xjrsoft.module.teacher.entity.XjrUser;
 import com.xjrsoft.module.workflow.constant.WorkflowConstant;
 import com.xjrsoft.module.workflow.entity.WorkflowCirculated;
+import com.xjrsoft.module.workflow.entity.WorkflowExtra;
+import com.xjrsoft.module.workflow.entity.WorkflowFormRelation;
 import com.xjrsoft.module.workflow.entity.WorkflowSchema;
 import com.xjrsoft.module.workflow.service.IWorkflowCirculatedService;
 import com.xjrsoft.module.workflow.service.IWorkflowExecuteService;
+import com.xjrsoft.module.workflow.service.IWorkflowExtraService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
@@ -72,6 +75,7 @@ import javax.validation.Valid;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
@@ -120,6 +124,8 @@ public class UserController {
     private final IWorkflowCirculatedService circulatedService;
     private final IBaseNewStudentService baseNewStudentService;
 
+    private final IWorkflowExtraService workflowExtraService;
+
     @GetMapping(value = "/list")
     @ApiOperation(value = "用户列表(不分页)")
     @XjrLog(value = "用户列表(不分页)")
@@ -417,24 +423,35 @@ public class UserController {
         PendingCountDto pendingCountDto = new PendingCountDto();
         pendingCountDto.setWfPendingCount(workflowExecuteService.pendingCount());
 
-        HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery()
-                .variableValueEquals(WorkflowConstant.PROCESS_START_USER_ID_KEY, StpUtil.getLoginIdAsLong())
-                .variableValueEquals(WorkflowConstant.PROCESS_ISRECYCLE_FLAG_KEY, WorkflowIsRecycleType.NO.getCode());
-        List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.orderByProcessInstanceStartTime().desc().list();
-
-        //获取到所有流程id
-        int myApplicationCount = 0;
-        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
-            Long countByProcessId = workflowExecuteService.getCountByProcessId(historicProcessInstance.getId());
-            if (countByProcessId == 0L) {
-                continue;
+        List<WorkflowExtra> extraList = workflowExtraService.list(
+                new MPJLambdaWrapper<WorkflowExtra>()
+                        .select(WorkflowExtra::getId)
+                        .select(WorkflowExtra.class, x -> VoToColumnUtil.fieldsToColumns(WorkflowExtra.class).contains(x.getProperty()))
+                        .innerJoin(WorkflowFormRelation.class, WorkflowFormRelation::getProcessId, WorkflowExtra::getProcessId)
+                        .eq(WorkflowFormRelation::getCurrentState, HistoricProcessInstance.STATE_ACTIVE)
+                        .eq(WorkflowExtra::getStartUserId, StpUtil.getLoginIdAsLong())
+                        .isNull(WorkflowFormRelation::getEndTime)
+        );
+        Set<String> processIdSet = extraList.stream().map(WorkflowExtra::getProcessId).collect(Collectors.toSet());
 
-            }
-            if (!ObjectUtil.isNotNull(historicProcessInstance.getEndTime())) {
-                myApplicationCount++;
-            }
-        }
-        pendingCountDto.setMyApplicationCount(myApplicationCount);
+//        HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery()
+//                .variableValueEquals(WorkflowConstant.PROCESS_START_USER_ID_KEY, StpUtil.getLoginIdAsLong())
+//                .variableValueEquals(WorkflowConstant.PROCESS_ISRECYCLE_FLAG_KEY, WorkflowIsRecycleType.NO.getCode());
+//        List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.orderByProcessInstanceStartTime().desc().list();
+//
+//        //获取到所有流程id
+//        int myApplicationCount = 0;
+//        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
+//            Long countByProcessId = workflowExecuteService.getCountByProcessId(historicProcessInstance.getId());
+//            if (countByProcessId == 0L) {
+//                continue;
+//
+//            }
+//            if (!ObjectUtil.isNotNull(historicProcessInstance.getEndTime())) {
+//                myApplicationCount++;
+//            }
+//        }
+        pendingCountDto.setMyApplicationCount(processIdSet.size());
 
         long circulatedCount = circulatedService.count(
                 MPJWrappers.<WorkflowCirculated>lambdaJoin()