From e0d938f54896e9247aeeccd3a7fe43cc9fadbfd6 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期二, 21 一月 2025 04:48:18 +0800
Subject: [PATCH] 查询任务时,处理表达式

---
 business/src/main/java/com/ycl/task/FlowableTask.java |  100 +++++++++++++++++++++++++++++++------------------
 1 files changed, 63 insertions(+), 37 deletions(-)

diff --git a/business/src/main/java/com/ycl/task/FlowableTask.java b/business/src/main/java/com/ycl/task/FlowableTask.java
index 5842b3b..e7ddff2 100644
--- a/business/src/main/java/com/ycl/task/FlowableTask.java
+++ b/business/src/main/java/com/ycl/task/FlowableTask.java
@@ -11,6 +11,7 @@
 import com.ycl.mapper.ProjectProcessMapper;
 import com.ycl.service.ProcessCodingService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.flowable.task.api.Task;
 import org.flowable.task.api.TaskInfo;
 import org.flowable.task.api.history.HistoricTaskInstance;
@@ -33,6 +34,7 @@
     private ProjectInfoMapper projectInfoMapper;
     @Autowired
     private ProcessCodingMapper processCodingMapper;
+
     /**
      * 璧嬬爜浠诲姟
      * 涓や釜閫昏緫 鏀归」鐩爜銆佹敼鑺傜偣棰滆壊
@@ -41,39 +43,65 @@
         log.info("寮�濮嬭祴鐮�");
         //褰撳墠姝e湪杩愯鐨勬墍鏈変换鍔¤妭鐐�
         List<Task> taskList = taskService.createTaskQuery().list();
-        if(CollectionUtils.isEmpty(taskList)) return;
+        if (CollectionUtils.isEmpty(taskList)) return;
         List<String> taskIds = taskList.stream().map(TaskInfo::getId).collect(Collectors.toList());
         //闇�瑕佺洃鎺х殑璧嬬爜浠诲姟
-        List<ProcessCoding> processCodingList = processCodingMapper.selectList(new QueryWrapper<ProcessCoding>().in("task_id",taskIds));
+        List<ProcessCoding> processCodingList = processCodingMapper.selectList(new QueryWrapper<ProcessCoding>().in("task_id", taskIds));
+        Map<String, ProcessCoding> taskMap = new HashMap<>();
+        Map<String, Date> startTaskMap = new HashMap<>();
         if (!CollectionUtils.isEmpty(processCodingList)) {
             //key涓簍askId value涓烘湰浣撳璞�
-            Map<String, ProcessCoding> taskMap = processCodingList.stream().collect(Collectors.toMap(ProcessCoding::getTaskId, Function.identity()));
+            taskMap = processCodingList.stream().collect(Collectors.toMap(ProcessCoding::getTaskId, Function.identity()));
             //鎷垮埌寮�濮嬭鏃剁殑鑺傜偣闆嗗悎 key:taskId value:寮�濮嬫椂闂�
-            Map<String, Date> startTaskMap = getStartTaskList(processCodingList);
-            //鎻愬墠鍑嗗鎺ユ敹鏁版嵁鐨刴ap key:娴佺▼瀹炰緥id value:闇�瑕佹敼鍙樼殑棰滆壊
-            Map<String, List<String>> map = new HashMap<>();
-            List<ProcessCoding> list = new ArrayList<>();
-            map.put(GREEN, new ArrayList<>());
-            map.put(RED, new ArrayList<>());
-            map.put(YELLOW, new ArrayList<>());
-            Date now = new Date();
-            //閬嶅巻鎵�鏈変唬鍔炵殑鑺傜偣
-            for (Task task : taskList) {
-                String taskId = task.getId();
-                ProcessCoding processCoding = taskMap.get(taskId);
-                if (processCoding == null) {
-                    //涓嶉渶瑕佺洃鎺х殑浠诲姟鑺傜偣鐩存帴鏀逛负缁胯壊
-                    List<String> processInsIds = map.get(GREEN);
-                    processInsIds.add(task.getProcessInstanceId());
-                    continue;
+            startTaskMap = getStartTaskList(processCodingList);
+        }
+        //鎻愬墠鍑嗗鎺ユ敹鏁版嵁鐨刴ap key:娴佺▼瀹炰緥id value:闇�瑕佹敼鍙樼殑棰滆壊
+        Map<String, List<String>> map = new HashMap<>();
+        List<ProcessCoding> list = new ArrayList<>();
+        map.put(GREEN, new ArrayList<>());
+        map.put(RED, new ArrayList<>());
+        map.put(YELLOW, new ArrayList<>());
+        Date now = new Date();
+        //閬嶅巻鎵�鏈変唬鍔炵殑鑺傜偣
+        for (Task task : taskList) {
+            String taskId = task.getId();
+            ProcessCoding processCoding = taskMap.get(taskId);
+            if (processCoding == null) {
+                //涓嶉渶瑕佺洃鎺х殑浠诲姟鑺傜偣鐩存帴鏀逛负缁胯壊
+                List<String> processInsIds = map.get(GREEN);
+                processInsIds.add(task.getProcessInstanceId());
+                continue;
+            }
+            //鍒ゆ柇鏄惁瓒呮椂
+            Date startTime = startTaskMap.get(processCoding.getStartTaskId());
+            try {
+                Long yellowTime = null;
+                Long redTime = null;
+                String yellowTimeStr = processCoding.getYellowTime();
+                if (StringUtils.isNotBlank(yellowTimeStr)) {
+                    String[] yellowTimeArr = yellowTimeStr.split("-");
+                    // 瑙f瀽澶╂暟鍜屽皬鏃舵暟
+                    int days = Integer.parseInt(yellowTimeArr[0]);
+                    int hours = 0;
+                    // 鍏煎涔嬪墠閰嶇疆鐨勬暣鏁板ぉ
+                    if (yellowTimeArr.length > 1) {
+                        hours = Integer.parseInt(yellowTimeArr[1]);
+                    }
+                    yellowTime = (days * 24L + hours) * 3600L;
                 }
-                //鍒ゆ柇鏄惁瓒呮椂
-                Date startTime = startTaskMap.get(processCoding.getStartTaskId());
-                Integer yellowTime = processCoding.getYellowTime();
-                Integer redTime = processCoding.getRedTime();
+                String redTimeStr = processCoding.getRedTime();
+                if (StringUtils.isNotBlank(redTimeStr)) {
+                    String[] redTimeArr = redTimeStr.split("-");
+                    // 瑙f瀽澶╂暟鍜屽皬鏃舵暟
+                    int days = Integer.parseInt(redTimeArr[0]);
+                    int hours = 0;
+                    if (redTimeArr.length > 1) {
+                        hours = Integer.parseInt(redTimeArr[1]);
+                    }
+                    redTime = (days * 24L + hours) * 3600L;
+                }
                 if (startTime == null) continue;
-//                long durationDay = (now.getTime() - startTime.getTime()) / (1000 * 60 * 60 * 24);
-                long durationDay = (now.getTime() - startTime.getTime()) / (1000 * 60);
+                long durationDay = (now.getTime() - startTime.getTime()) / 1000;
                 String status = GREEN; // 榛樿鐘舵�佷负缁胯壊
                 if (redTime != null && durationDay >= redTime) {
                     status = RED; // 濡傛灉瓒呰繃绾㈣壊鏃堕棿闃堝�硷紝鍒欑姸鎬佷负绾㈣壊
@@ -84,27 +112,25 @@
                 processInsIds.add(task.getProcessInstanceId());
                 processCoding.setStatus(status);
                 list.add(processCoding);
+            } catch (Exception e) {
+                e.printStackTrace();
+                log.error(e.getMessage(),"璧嬬爜鏃堕棿鏍煎紡鏈夎");
             }
-            //鏇存柊椤圭洰鐮�
-            map.forEach((key,value)-> updateProjectCoding(value, key));
-            //鏇存柊鑺傜偣鐘舵�� 鑷畾涔夌殑mybatis鏂规硶
-            if(!CollectionUtils.isEmpty(list)) processCodingMapper.updateBatch(list);
         }
+        //鏇存柊椤圭洰鐮�
+        map.forEach((key, value) -> updateProjectCoding(value, key));
+        //鏇存柊鑺傜偣鐘舵�� 鑷畾涔夌殑mybatis鏂规硶
+        if (!CollectionUtils.isEmpty(list)) processCodingMapper.updateBatch(list);
+
         log.info("缁撴潫璧嬬爜");
     }
 
     private Map<String, Date> getStartTaskList(List<ProcessCoding> processCodingList) {
         //鏌ュ嚭浠诲姟璁℃椂璧峰鑺傜偣闆嗗悎
         List<String> startTaskIds = processCodingList.stream().map(ProcessCoding::getStartTaskId).collect(Collectors.toList());
-        //鏌ュ嚭璧峰璁℃椂鑺傜偣鏁版嵁 娉ㄦ剰姝e湪杩涜鐨勪换鍔′笉浼氳繘鍏is琛� 缁撴潫浜嗘墠浼氳繘鍏� 鎵�浠ラ渶瑕佹煡涓ゅ紶琛�
+        //鏌ュ嚭璧峰璁℃椂鑺傜偣鏁版嵁
         Map<String, Date> startDateMap = new HashMap<>();
-        List<Task> startTasks = taskService.createTaskQuery().taskIds(startTaskIds).list();
         List<HistoricTaskInstance> hisStartTasks = historyService.createHistoricTaskInstanceQuery().taskIds(startTaskIds).list();
-        if (!CollectionUtils.isEmpty(startTasks)) {
-            startTasks.forEach(task -> {
-                startDateMap.put(task.getId(), task.getCreateTime());
-            });
-        }
         if (!CollectionUtils.isEmpty(hisStartTasks)) {
             hisStartTasks.forEach(hisTask -> {
                 startDateMap.put(hisTask.getId(), hisTask.getStartTime());

--
Gitblit v1.8.0