From 5e56add00e129eb5f3d05c7c2c62f0b2516b1a62 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期五, 07 二月 2025 14:02:23 +0800
Subject: [PATCH] 首页省、市数量问题
---
business/src/main/java/com/ycl/task/FlowableTask.java | 104 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 65 insertions(+), 39 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..2e247ae 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,70 +43,94 @@
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) {
+ if (redTime != null && redTime !=0 && durationDay >= redTime) {
status = RED; // 濡傛灉瓒呰繃绾㈣壊鏃堕棿闃堝�硷紝鍒欑姸鎬佷负绾㈣壊
- } else if (yellowTime != null && durationDay >= yellowTime) {
+ } else if (yellowTime != null && yellowTime !=0 && durationDay >= yellowTime) {
status = YELLOW; // 鍚﹀垯锛屽鏋滆秴杩囬粍鑹叉椂闂撮槇鍊硷紝鍒欑姸鎬佷负榛勮壊
}
List<String> processInsIds = map.get(status);
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