Skip to content

Commit a9ffb2b

Browse files
xlorneclaude
andcommitted
refactor(024982): processNodes 数据返回修复
完成 024982 计划的代码实施 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0adc6a6 commit a9ffb2b

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

flow-engine-framework/src/main/java/com/codingapi/flow/pojo/response/ProcessNode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ public boolean equals(Object target) {
115115

116116
@Override
117117
public int hashCode() {
118-
return Objects.hash(nodeId, nodeName, nodeType, state, operators);
118+
return Objects.hash(nodeId);
119+
}
120+
121+
public void addOperator(FlowOperatorBody operator) {
122+
this.operators.add(operator);
119123
}
120124

121125
/**

flow-engine-framework/src/main/java/com/codingapi/flow/service/impl/FlowProcessNodeService.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import lombok.Getter;
2424

2525
import java.util.ArrayList;
26+
import java.util.LinkedHashMap;
2627
import java.util.List;
28+
import java.util.Map;
2729

2830
/**
2931
* 流程节点记录服务
@@ -90,11 +92,9 @@ public List<ProcessNode> processNodes() {
9092
backupId = this.flowRecord.getWorkRuntimeId();
9193
// 如果当前记录已结束,则不查询后续流程
9294
if (this.flowRecord.isDone()) {
93-
List<FlowRecord> historyRecords = flowRecordService.findFlowRecordByProcessId(this.flowRecord.getProcessId());
94-
for (FlowRecord historyRecord : historyRecords) {
95-
ProcessNode processNode = new ProcessNode(historyRecord, this.workflow);
96-
nodeList.add(processNode);
97-
}
95+
List<FlowRecord> allRecords = flowRecordService.findFlowRecordByProcessId(this.flowRecord.getProcessId());
96+
List<FlowRecord> doneRecords = allRecords.stream().filter(FlowRecord::isDone).toList();
97+
nodeList.addAll(buildHistoryNodes(doneRecords));
9898
if (this.flowRecord.isFinish()) {
9999
nodeList.add(ProcessNode.createEndNode(this.workflow));
100100
} else {
@@ -104,10 +104,7 @@ public List<ProcessNode> processNodes() {
104104
} else {
105105
// 查询历史记录
106106
List<FlowRecord> historyRecords = flowRecordService.findFlowRecordBeforeRecords(flowRecord.getProcessId(), flowRecord.getId());
107-
for (FlowRecord historyRecord : historyRecords) {
108-
ProcessNode processNode = new ProcessNode(historyRecord, this.workflow);
109-
nodeList.add(processNode);
110-
}
107+
nodeList.addAll(buildHistoryNodes(historyRecords));
111108
}
112109
}
113110

@@ -116,6 +113,19 @@ public List<ProcessNode> processNodes() {
116113
return this.nodeList;
117114
}
118115

116+
private List<ProcessNode> buildHistoryNodes(List<FlowRecord> records) {
117+
Map<String, ProcessNode> nodeMap = new LinkedHashMap<>();
118+
for (FlowRecord record : records) {
119+
ProcessNode existing = nodeMap.get(record.getNodeId());
120+
if (existing != null) {
121+
existing.addOperator(new ProcessNode.FlowOperatorBody(record));
122+
} else {
123+
nodeMap.put(record.getNodeId(), new ProcessNode(record, this.workflow));
124+
}
125+
}
126+
return new ArrayList<>(nodeMap.values());
127+
}
128+
119129

120130
private void loadNextNode(long backupId) {
121131

0 commit comments

Comments
 (0)