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 | 92 +++++++++++++++++++++++++++++++--------------- 1 files changed, 62 insertions(+), 30 deletions(-) diff --git a/business/src/main/java/com/ycl/task/FlowableTask.java b/business/src/main/java/com/ycl/task/FlowableTask.java index 971be1f..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,12 +112,16 @@ 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("缁撴潫璧嬬爜"); } -- Gitblit v1.8.0