Skip to content

Commit 7a4e902

Browse files
committed
update end node sync record data
1 parent a763dcc commit 7a4e902

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

flow-engine-framework/src/main/java/com/codingapi/flow/action/actions/PassAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public void run(FlowSession flowSession) {
127127
});
128128
}
129129
}
130-
131130
RepositoryHolderContext.getInstance().saveRecords(recordList);
132131

133132
flowEvents.forEach(EventPusher::push);

flow-engine-framework/src/main/java/com/codingapi/flow/node/nodes/EndNode.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
import com.codingapi.flow.utils.RandomUtils;
1414
import com.codingapi.springboot.framework.event.EventPusher;
1515

16+
import java.util.ArrayList;
17+
import java.util.HashMap;
1618
import java.util.List;
1719
import java.util.Map;
20+
import java.util.concurrent.Executors;
21+
import java.util.concurrent.ScheduledExecutorService;
1822

1923
/**
2024
* 结束节点
@@ -24,6 +28,8 @@ public class EndNode extends BaseFlowNode implements IDisplayNode {
2428
public static final String NODE_TYPE = NodeType.END.name();
2529
public static final String DEFAULT_NAME = "结束节点";
2630

31+
private final ScheduledExecutorService threadPools = Executors.newScheduledThreadPool(1);
32+
2733
@Override
2834
public String getType() {
2935
return NODE_TYPE;
@@ -47,17 +53,30 @@ public void fillNewRecord(FlowSession session, FlowRecord flowRecord) {
4753
IFlowAction currentAction = session.getCurrentAction();
4854
// 标记当前流程结束
4955
FlowRecord latestRecord = session.getCurrentRecord();
56+
5057
// 添加历史记录到记录中
5158
List<FlowRecord> historyRecords = RepositoryHolderContext.getInstance().findProcessRecords(latestRecord.getProcessId());
59+
60+
// 同步当前处理的FlowRecord的数据
61+
List<FlowRecord> recordList = new ArrayList<>();
62+
for (FlowRecord historyRecord:historyRecords){
63+
if(historyRecord.getId()== latestRecord.getId()){
64+
recordList.add(latestRecord);
65+
}else {
66+
recordList.add(historyRecord);
67+
}
68+
}
69+
5270
// 设置状态为完成
53-
historyRecords.forEach(item -> {
71+
recordList.forEach(item -> {
5472
item.finish(currentAction instanceof PassAction);
5573
});
56-
RepositoryHolderContext.getInstance().saveRecords(historyRecords);
74+
RepositoryHolderContext.getInstance().saveRecords(recordList);
5775
// 流程是否正常结束
5876
EventPusher.push(new FlowRecordFinishEvent(latestRecord));
5977
}
6078

79+
6180
@Override
6281
public boolean handle(FlowSession session) {
6382
return false;
@@ -75,6 +94,46 @@ public static EndNode formMap(Map<String, Object> map) {
7594
return BaseFlowNode.fromMap(map, EndNode.class);
7695
}
7796

97+
98+
private static class RecordMergeHelper {
99+
100+
private final List<FlowRecord> currentRecords;
101+
private final List<FlowRecord> historyRecords;
102+
103+
private final Map<Long,FlowRecord> currentRecordCache;
104+
105+
private final List<FlowRecord> recordList;
106+
107+
public RecordMergeHelper(List<FlowRecord> historyRecords, List<FlowRecord> currentRecords) {
108+
this.historyRecords = historyRecords;
109+
this.currentRecords = currentRecords;
110+
this.currentRecordCache = new HashMap<>();
111+
this.recordList = new ArrayList<>();
112+
this.initCurrentRecordCache();
113+
}
114+
115+
private void initCurrentRecordCache(){
116+
for (FlowRecord currentRecord:this.currentRecords){
117+
this.currentRecordCache.put(currentRecord.getId(),currentRecord);
118+
}
119+
}
120+
121+
public List<FlowRecord> getUpdateRecordList() {
122+
for(FlowRecord historyRecord:historyRecords){
123+
FlowRecord currentRecord = this.currentRecordCache.get(historyRecord.getId());
124+
if(currentRecord!=null){
125+
this.recordList.add(currentRecord);
126+
}else {
127+
this.recordList.add(historyRecord);
128+
}
129+
}
130+
return this.recordList;
131+
}
132+
133+
134+
135+
}
136+
78137
public static Builder builder() {
79138
return new Builder();
80139
}

0 commit comments

Comments
 (0)