2323import lombok .Getter ;
2424
2525import java .util .ArrayList ;
26+ import java .util .LinkedHashMap ;
2627import 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