From 96a893bcc673085f7d6fe3bc5ca7dc34e7ca1db2 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期三, 12 二月 2025 17:44:25 +0800
Subject: [PATCH] flowable模块中的FlowTaskService及controller移动到business模块,完成任务和驳回任务添加日志
---
business/src/main/java/com/ycl/task/FlowableTask.java | 114 +++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 74 insertions(+), 40 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..ecc8ed0 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,102 @@
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;
- }
- //鍒ゆ柇鏄惁瓒呮椂
- Date startTime = startTaskMap.get(processCoding.getStartTaskId());
- Integer yellowTime = processCoding.getYellowTime();
- Integer redTime = processCoding.getRedTime();
+ 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 redTime = getTime(processCoding.getRedTime());
+ Long yellowTime = getTime(processCoding.getYellowTime());
+ Long overtime = getTime(processCoding.getOvertime());
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; // 鍚﹀垯锛屽鏋滆秴杩囬粍鑹叉椂闂撮槇鍊硷紝鍒欑姸鎬佷负榛勮壊
}
+ //澶勭悊鍔炵悊鏈熼檺
+ String overtimeStatus = NORMAL;
+ if (overtime != null && overtime !=0 && durationDay >= overtime) {
+ overtimeStatus = OVERTIME; // 濡傛灉瓒呰繃鍔炵悊鏈熼檺
+ }
+ else if (overtime != null && overtime != 0 && durationDay >= (overtime - 12 * 60 * 60)) {
+ overtimeStatus = WILLOVERTIME; // 濡傛灉涓存湡(鍥哄畾瓒呮椂鍓�12灏忔椂涓轰复鏈�)
+ }
+// else if (overtime != null && overtime != 0 && durationDay >= (overtime - 60)) {
+// overtimeStatus = WILLOVERTIME; // 濡傛灉涓存湡(鍥哄畾瓒呮椂鍓�12灏忔椂涓轰复鏈�)
+// }
List<String> processInsIds = map.get(status);
processInsIds.add(task.getProcessInstanceId());
+
processCoding.setStatus(status);
+ processCoding.setOvertimeStatus(overtimeStatus);
list.add(processCoding);
+ } catch (Exception e) {
+ 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 Long getTime(String timeStr) {
+ Long time = null;
+ if (StringUtils.isNotBlank(timeStr)) {
+ String[] timeArr = timeStr.split("-");
+ // 瑙f瀽澶╂暟鍜屽皬鏃舵暟
+ int days = Integer.parseInt(timeArr[0]);
+ int hours = 0;
+ if (timeArr.length > 1) {
+ hours = Integer.parseInt(timeArr[1]);
+ }
+ time = (days * 24L + hours) * 3600L;
+// //鍒�-绉�
+// time= (days * 60L) + hours;
+ }
+ return time;
}
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