diff --git a/backend/src/main/java/com/designhub/service/TaskService.java b/backend/src/main/java/com/designhub/service/TaskService.java index b8c12b2..de89556 100644 --- a/backend/src/main/java/com/designhub/service/TaskService.java +++ b/backend/src/main/java/com/designhub/service/TaskService.java @@ -5019,6 +5019,88 @@ public class TaskService { node3.setStatus("waiting"); } timeline.add(node3); + + // 4. 如果是流水线任务,添加每个节点的详细进度 + boolean isPipeline = task.getIsPipeline() != null && task.getIsPipeline() == 1; + if (isPipeline && ("in_progress".equals(status) || "completed".equals(status))) { + // 查询所有子任务,按 group_no 分组 + java.util.List taskItems = taskItemMapper.selectList( + new LambdaQueryWrapper() + .eq(TaskItem::getTaskId, task.getId()) + .orderByAsc(TaskItem::getGroupNo) + .orderByAsc(TaskItem::getSortOrder) + ); + + // 按 group_no 分组统计 + java.util.Map> groupedItems = taskItems.stream() + .collect(java.util.stream.Collectors.groupingBy( + item -> item.getGroupNo() != null ? item.getGroupNo() : 1 + )); + + // 为每个节点创建时间线项 + java.util.List sortedGroupNos = groupedItems.keySet().stream() + .sorted() + .collect(java.util.stream.Collectors.toList()); + + for (Integer groupNo : sortedGroupNos) { + java.util.List groupItems = groupedItems.get(groupNo); + if (groupItems == null || groupItems.isEmpty()) continue; + + // 统计该节点的完成情况 + int totalItems = groupItems.size(); + int completedItems = 0; + int inProgressItems = 0; + int pendingApprovalItems = 0; + TaskItem firstItem = groupItems.get(0); + String receiverName = null; + java.time.LocalDateTime completeTime = null; + + for (TaskItem item : groupItems) { + if ("completed".equals(item.getStatus())) { + completedItems++; + if (completeTime == null || (item.getCompleteTime() != null && item.getCompleteTime().isAfter(completeTime))) { + completeTime = item.getCompleteTime(); + } + } else if ("in_progress".equals(item.getStatus())) { + inProgressItems++; + } else if ("pending_approval".equals(item.getStatus())) { + pendingApprovalItems++; + } + if (receiverName == null && item.getReceiverName() != null) { + receiverName = item.getReceiverName(); + } + } + + // 创建节点时间线 + com.designhub.vo.TaskFlowStatusVO.FlowTimelineNode pipelineNode = new com.designhub.vo.TaskFlowStatusVO.FlowTimelineNode(); + pipelineNode.setNodeName("节点" + groupNo + "执行"); + + if (completedItems == totalItems) { + // 所有子任务都完成 + pipelineNode.setStatus("completed"); + pipelineNode.setTime(completeTime); + pipelineNode.setComment("已完成 " + completedItems + "/" + totalItems + " 项"); + } else if (completedItems > 0 || inProgressItems > 0) { + // 有进行中的子任务 + pipelineNode.setStatus("pending"); + pipelineNode.setComment("进行中 " + (completedItems + inProgressItems) + "/" + totalItems + " 项"); + } else if (pendingApprovalItems > 0) { + // 等待审批 + pipelineNode.setStatus("pending"); + pipelineNode.setComment("待审批 " + pendingApprovalItems + " 项"); + } else { + // 等待中 + pipelineNode.setStatus("waiting"); + pipelineNode.setComment("等待前置节点完成"); + } + + if (receiverName != null) { + pipelineNode.setOperatorName(receiverName); + } + + timeline.add(pipelineNode); + } + } } return timeline;