feat: 增强任务节点查询-展示流水线子任务的详细节点进度

- 为流水线任务添加每个节点的执行状态展示
- 显示节点完成情况(如 已完成 1/1 项)
- 显示接单人信息
- 支持待审批、进行中、等待中等状态
This commit is contained in:
Your Name 2026-01-30 11:08:48 +08:00
parent 11b94b8438
commit 72f23a782a

View File

@ -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<TaskItem> taskItems = taskItemMapper.selectList(
new LambdaQueryWrapper<TaskItem>()
.eq(TaskItem::getTaskId, task.getId())
.orderByAsc(TaskItem::getGroupNo)
.orderByAsc(TaskItem::getSortOrder)
);
// 按 group_no 分组统计
java.util.Map<Integer, java.util.List<TaskItem>> groupedItems = taskItems.stream()
.collect(java.util.stream.Collectors.groupingBy(
item -> item.getGroupNo() != null ? item.getGroupNo() : 1
));
// 为每个节点创建时间线项
java.util.List<Integer> sortedGroupNos = groupedItems.keySet().stream()
.sorted()
.collect(java.util.stream.Collectors.toList());
for (Integer groupNo : sortedGroupNos) {
java.util.List<TaskItem> 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;