| | |
| | | private ProjectInfoMapper projectInfoMapper; |
| | | @Autowired |
| | | private ProcessCodingMapper processCodingMapper; |
| | | |
| | | /** |
| | | * 赋码任务 |
| | | * 两个逻辑 改项目码、改节点颜色 |
| | |
| | | log.info("开始赋码"); |
| | | //当前正在运行的所有任务节点 |
| | | 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为taskId 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); |
| | | //提前准备接收数据的map 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(); |
| | | if (startTime == null) continue; |
| | | // long durationDay = (now.getTime() - startTime.getTime()) / (1000 * 60 * 60 * 24); |
| | | long durationDay = (now.getTime() - startTime.getTime()) / (1000 * 60); |
| | | String status = GREEN; // 默认状态为绿色 |
| | | if (redTime != null && durationDay >= redTime) { |
| | | status = RED; // 如果超过红色时间阈值,则状态为红色 |
| | | } else if (yellowTime != null && durationDay >= yellowTime) { |
| | | status = YELLOW; // 否则,如果超过黄色时间阈值,则状态为黄色 |
| | | } |
| | | List<String> processInsIds = map.get(status); |
| | | processInsIds.add(task.getProcessInstanceId()); |
| | | processCoding.setStatus(status); |
| | | list.add(processCoding); |
| | | } |
| | | //更新项目码 |
| | | map.forEach((key,value)-> updateProjectCoding(value, key)); |
| | | //更新节点状态 自定义的mybatis方法 |
| | | if(!CollectionUtils.isEmpty(list)) processCodingMapper.updateBatch(list); |
| | | startTaskMap = getStartTaskList(processCodingList); |
| | | } |
| | | //提前准备接收数据的map 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(); |
| | | if (startTime == null) continue; |
| | | // long durationDay = (now.getTime() - startTime.getTime()) / (1000 * 60 * 60 * 24); |
| | | long durationDay = (now.getTime() - startTime.getTime()) / (1000 * 60); |
| | | String status = GREEN; // 默认状态为绿色 |
| | | if (redTime != null && durationDay >= redTime) { |
| | | status = RED; // 如果超过红色时间阈值,则状态为红色 |
| | | } else if (yellowTime != null && durationDay >= yellowTime) { |
| | | status = YELLOW; // 否则,如果超过黄色时间阈值,则状态为黄色 |
| | | } |
| | | List<String> processInsIds = map.get(status); |
| | | processInsIds.add(task.getProcessInstanceId()); |
| | | processCoding.setStatus(status); |
| | | list.add(processCoding); |
| | | } |
| | | //更新项目码 |
| | | 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()); |
| | | //查出起始计时节点数据 注意正在进行的任务不会进入his表 结束了才会进入 所以需要查两张表 |
| | | //查出起始计时节点数据 |
| | | 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()); |