Просмотр исходного кода

数据面板,流程详情统计倒序排序

dzx 8 месяцев назад
Родитель
Сommit
e24790dbfb

+ 43 - 79
src/main/java/com/xjrsoft/module/databoard/controller/DatadetailController.java

@@ -35,6 +35,7 @@ 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.IWorkflowExtraService;
+import com.xjrsoft.module.workflow.service.IWorkflowFormRelationService;
 import com.xjrsoft.module.workflow.utils.WorkFlowUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -71,7 +72,7 @@ import java.util.stream.Collectors;
 public class DatadetailController {
 
     private final HistoryService historyService;
-    private final IWorkflowExtraService extraService;
+    private final IWorkflowFormRelationService relationService;
     private final ITeacherbaseManagerService teacherService;
     private final IBaseStudentService studentService;
     private final IWfSubscriptionService subscriptionService;
@@ -82,90 +83,49 @@ public class DatadetailController {
     @SaCheckPermission("datadetail:detail")
     @XjrLog(value = "流程统计详情", saveResponseData = true)
     public RT<ProcessStatisticsDetailVo> processStatistics(@Valid StatisticsDetailDto dto) {
-        HistoricProcessInstanceQuery instanceQuery = historyService.createHistoricProcessInstanceQuery();
-        if (dto.getUserId() != null) {
-            instanceQuery.variableValueEquals(WorkflowConstant.PROCESS_START_USER_ID_KEY, dto.getUserId());
-        }
-        LocalDateTime startTime = null;
-        LocalDateTime endTime = null;
-        if (dto.getStartDate() != null) {
-            startTime = dto.getStartDate().atStartOfDay();
-        }
-        if (dto.getEndDate() != null) {
-            endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
-        }
-        if (!ObjectUtil.isNull(dto.getStartDate())) {
-            instanceQuery.startedAfter(WorkFlowUtil.getStartOfDay(dto.getStartDate()));
-        }
-        if (!ObjectUtil.isNull(dto.getEndDate())) {
-            instanceQuery.startedBefore(WorkFlowUtil.getEndOfDay(dto.getEndDate()));
+        ProcessStatisticsDetailVo result = new ProcessStatisticsDetailVo();
+        String sql = "SELECT DISTINCT t1.id,t2.schema_name,t1.start_time,t1.end_time,t1.current_state FROM xjr_workflow_form_relation t1" +
+                " INNER JOIN xjr_workflow_extra t2 ON t1.process_id = t2.process_id" +
+                " WHERE 1 = 1";
+        if (dto.getStartDate() != null && dto.getEndDate() != null) {
+            sql += " and DATE_FORMAT(t1.start_time, '%Y-%m-%d') BETWEEN '" + dto.getStartDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "'"
+                + " and '" + dto.getEndDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "'";
+        }
+        List<Map<String, Object>> dataList = SqlRunnerAdapter.db().selectList(sql);
+        result.setAllCount(dataList.stream().count());
+        Long uncompleteCount = 0L;
+        Long completeCount = 0L;
+
+        for (Map<String, Object> objectMap : dataList) {
+            String currentState = objectMap.get("current_state").toString();
+            if(HistoricProcessInstance.STATE_ACTIVE.equals(currentState)){
+                uncompleteCount ++;
+            }else{
+                completeCount ++;
+            }
         }
+        result.setCompleteCount(completeCount);
+        result.setUncompleteCount(uncompleteCount);
 
-        List<WorkflowExtra> workflowExtras = extraService.list(
-                new MPJLambdaWrapper<WorkflowExtra>()
-                        .between((startTime != null && endTime != null), WorkflowExtra::getLaunchTime, startTime, endTime)
-                        .select(WorkflowExtra::getId)
-                        .select(WorkflowExtra.class, x -> VoToColumnUtil.fieldsToColumns(WorkflowExtra.class).contains(x.getProperty()))
-                        .leftJoin(WorkflowSchema.class, WorkflowSchema::getId, WorkflowExtra::getSchemaId)
-                        .leftJoin(DictionaryDetail.class, DictionaryDetail::getId, WorkflowSchema::getCategory)
-        );
+        Set<String> itemSet = dataList.stream().map(x -> x.get("schema_name").toString()).collect(Collectors.toSet());
 
+        Map<String, Long> finishedMap = dataList.stream()
+                .filter(x -> !HistoricProcessInstance.STATE_ACTIVE.equals(x.get("current_state").toString()))
+                .collect(Collectors.groupingBy(x -> x.get("schema_name").toString(), Collectors.counting()));
+        Map<String, Long> unfinishedMap = dataList.stream()
+                .filter(x -> HistoricProcessInstance.STATE_ACTIVE.equals(x.get("current_state").toString()))
+                .collect(Collectors.groupingBy(x -> x.get("schema_name").toString(), Collectors.counting()));
 
-        ProcessStatisticsDetailVo result = new ProcessStatisticsDetailVo();
-        List<HistoricProcessInstance> list = instanceQuery.list();
-        List<WorkflowExtra> allCountList = new ArrayList<>();
-        for (HistoricProcessInstance historicProcessInstance : list) {
-            workflowExtras.stream()
-                    .filter(e -> e.getProcessId().equals(historicProcessInstance.getId()))
-                    .max(Comparator.comparing(WorkflowExtra::getStartTime))
-                    .ifPresent(e -> {
-                        allCountList.add(e);
-                    });
-        }
-        result.setAllCount(Long.parseLong(allCountList.size() + ""));
-
-        List<HistoricProcessInstance> finished = historyService.createHistoricProcessInstanceQuery().finished().list();
-        List<WorkflowExtra> completeCountList = new ArrayList<>();
-        for (HistoricProcessInstance historicProcessInstance : finished) {
-            workflowExtras.stream()
-                    .filter(e -> e.getProcessId().equals(historicProcessInstance.getId()) && e.getEndTime() != null)
-                    .max(Comparator.comparing(WorkflowExtra::getStartTime))
-                    .ifPresent(e -> {
-                        completeCountList.add(e);
-                    });
-        }
-        result.setCompleteCount(Long.parseLong(completeCountList.size() + ""));
-
-        List<HistoricProcessInstance> unfinished = historyService.createHistoricProcessInstanceQuery().unfinished().list();
-        List<WorkflowExtra> uncompleteCountList = new ArrayList<>();
-        for (HistoricProcessInstance historicProcessInstance : unfinished) {
-            workflowExtras.stream()
-                    .filter(e -> e.getProcessId().equals(historicProcessInstance.getId()))
-                    .max(Comparator.comparing(WorkflowExtra::getStartTime))
-                    .ifPresent(e -> {
-                        uncompleteCountList.add(e);
-                    });
-        }
-        result.setUncompleteCount(Long.parseLong(uncompleteCountList.size() + ""));
-
-        Map<String, Long> finishedMap = completeCountList.stream()
-                .collect(Collectors.groupingBy(WorkflowExtra::getSchemaName, Collectors.counting()));
-        Map<String, Long> unfinishedMap = uncompleteCountList.stream()
-                .collect(Collectors.groupingBy(WorkflowExtra::getSchemaName, Collectors.counting()));
-
-        Set<String> itemSet = new HashSet<>();
-        itemSet.addAll(finishedMap.keySet());
-        itemSet.addAll(unfinishedMap.keySet());
-        List<DistributionVo> distributionList = new ArrayList();
+        List<DistributionVo> distributionList = new ArrayList<>();
         for (String item : itemSet) {
-            Long uncompleteCount = unfinishedMap.get(item) == null ? 0L : unfinishedMap.get(item);
-            Long completeCount = finishedMap.get(item) == null ? 0L : finishedMap.get(item);
+            Long unfinishedCount = unfinishedMap.get(item) == null ? 0L : unfinishedMap.get(item);
+            Long finishedCount = finishedMap.get(item) == null ? 0L : finishedMap.get(item);
             distributionList.add(
                     new DistributionVo() {{
                         setItem(item);
-                        setCompleteCount(completeCount);
-                        setUncompleteCount(uncompleteCount);
-                        setAllCount(completeCount + uncompleteCount);
+                        setCompleteCount(finishedCount);
+                        setUncompleteCount(unfinishedCount);
+                        setAllCount(unfinishedCount + finishedCount);
                     }}
             );
         }
@@ -174,8 +134,12 @@ public class DatadetailController {
         List<DurationVo> durationList = new ArrayList<>();
 
         List<Long> secondList = new ArrayList<>();
-        completeCountList.stream().filter(el -> el.getEndTime() != null && el.getStartTime() != null).forEach(el -> {
-            Duration diff = Duration.between(el.getStartTime(), el.getEndTime());
+        List<Map<String, Object>> completeCountList = dataList.stream()
+                .filter(x -> HistoricProcessInstance.STATE_COMPLETED.equals(x.get("current_state").toString()))
+                .collect(Collectors.toList());
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        completeCountList.stream().forEach(el -> {
+            Duration diff = Duration.between(LocalDateTime.parse(el.get("start_time").toString(), formatter), LocalDateTime.parse(el.get("end_time").toString(), formatter));
             secondList.add(diff.getSeconds());
         });
 

+ 1 - 1
src/main/resources/application.yml

@@ -5,7 +5,7 @@ server:
 spring:
   # 环 io境 dev|pre|prod
   profiles:
-    active: dev
+    active: pre
   # jackson时间格式化
   jackson:
     time-zone: GMT+8

+ 1 - 1
src/main/resources/mapper/student/PbVXsxxsfytbMapper.xml

@@ -65,7 +65,7 @@
         GROUP BY t2.name
     </select>
     <select id="getClassQfPage" parameterType="com.xjrsoft.module.student.dto.PbVXsxxsfytbStatDto" resultType="com.xjrsoft.module.student.vo.ClassQfPageVo">
-        SELECT t1.id, t1.name AS grade_name,t2.name AS class_name,t3.name AS teacher_name,
+        SELECT t1.id, t1.name AS class_name,t2.name AS grade_name,t3.name AS teacher_name,
         (
         SELECT SUM(qfje) FROM pb_v_xsxxsfytb a1
         INNER JOIN xjr_user a2 ON a1.studentcode = a2.credential_number

+ 1 - 1
src/test/java/com/xjrsoft/module/job/JianyuekbScheduleTaskTest.java

@@ -285,7 +285,7 @@ class JianyuekbScheduleTaskTest {
         Map<String, String> classroomMap = dataMap.get(tableName);
 
         Set<String> techerIds = dataUtil.insertCourseTableEntiy(scheduleInfo, classroomMap, courseMap, semesterMap,
-                teacherMap, classMap, courseReceiveMsgId, startDate, endDate);
+                teacherMap, classMap, String.valueOf(courseReceiveMsgId), startDate, endDate);
         sendMsg(techerIds, courseReceiveMsgId);
         dataUtil.insertClassTime(scheduleInfo);
     }

+ 1 - 1
src/test/java/com/xjrsoft/module/job/JianyuekbScheduleTaskTest2.java

@@ -282,7 +282,7 @@ class JianyuekbScheduleTaskTest2 {
         tableName = "base_classroom";
         Map<String, String> classroomMap = dataMap.get(tableName);
 
-        Set<String> techerIds = dataUtil.insertCourseTableEntiy(scheduleInfo, classroomMap, courseMap, semesterMap, teacherMap, classMap, courseReceiveMsgId, null, null);
+        Set<String> techerIds = dataUtil.insertCourseTableEntiy(scheduleInfo, classroomMap, courseMap, semesterMap, teacherMap, classMap, String.valueOf(courseReceiveMsgId), null, null);
         sendMsg(techerIds, courseReceiveMsgId);
         dataUtil.insertClassTime(scheduleInfo);
     }

+ 2 - 0
src/test/java/com/xjrsoft/xjrsoftboot/Test2.java

@@ -55,5 +55,7 @@ public class Test2 {
         LocalDateTime birthday = LocalDateTime.parse(dateStr, formatter);
         System.out.println(birthday);
 
+
+
     }
 }