Skip to content

Commit cad0f32

Browse files
authored
Merge pull request #31 from codingapi/dev
Dev
2 parents 3d4bfa1 + 63c7c67 commit cad0f32

50 files changed

Lines changed: 1787 additions & 92 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

flow-engine-framework/src/main/java/com/codingapi/flow/context/RepositoryHolderContext.java

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
import com.codingapi.flow.gateway.FlowOperatorGateway;
66
import com.codingapi.flow.operator.IFlowOperator;
77
import com.codingapi.flow.record.FlowRecord;
8+
import com.codingapi.flow.record.FlowTodoRecord;
9+
import com.codingapi.flow.record.FlowTodoMerge;
810
import com.codingapi.flow.repository.*;
911
import com.codingapi.flow.service.FlowService;
1012
import com.codingapi.flow.service.impl.FlowActionService;
1113
import com.codingapi.flow.service.impl.FlowDelayTriggerService;
1214
import com.codingapi.flow.session.FlowSession;
1315
import lombok.Getter;
1416

17+
import java.util.ArrayList;
1518
import java.util.List;
1619

1720
public class RepositoryHolderContext {
@@ -29,6 +32,10 @@ private RepositoryHolderContext() {
2932
@Getter
3033
private FlowRecordRepository flowRecordRepository;
3134
@Getter
35+
private FlowTodoRecordRepository flowTodoRecordRepository;
36+
@Getter
37+
private FlowTodoMergeRepository flowTodoMergeRepository;
38+
@Getter
3239
private FlowOperatorGateway flowOperatorGateway;
3340
@Getter
3441
private ParallelBranchRepository parallelBranchRepository;
@@ -45,6 +52,8 @@ public boolean isRegistered() {
4552
&& delayTaskRepository != null
4653
&& workflowBackupRepository != null
4754
&& flowRecordRepository != null
55+
&& flowTodoRecordRepository != null
56+
&& flowTodoMergeRepository != null
4857
&& flowOperatorGateway != null
4958
&& workflowRepository != null
5059
&& urgeIntervalRepository != null;
@@ -60,13 +69,17 @@ public void verify() {
6069
public void register(WorkflowRepository workflowRepository,
6170
WorkflowBackupRepository workflowBackupRepository,
6271
FlowRecordRepository flowRecordRepository,
72+
FlowTodoRecordRepository flowTodoRecordRepository,
73+
FlowTodoMergeRepository flowTodoMergeRepository,
6374
FlowOperatorGateway flowOperatorGateway,
6475
ParallelBranchRepository parallelBranchRepository,
6576
DelayTaskRepository delayTaskRepository,
6677
UrgeIntervalRepository urgeIntervalRepository) {
6778
this.workflowRepository = workflowRepository;
6879
this.workflowBackupRepository = workflowBackupRepository;
6980
this.flowRecordRepository = flowRecordRepository;
81+
this.flowTodoRecordRepository = flowTodoRecordRepository;
82+
this.flowTodoMergeRepository = flowTodoMergeRepository;
7083
this.flowOperatorGateway = flowOperatorGateway;
7184
this.parallelBranchRepository = parallelBranchRepository;
7285
this.delayTaskRepository = delayTaskRepository;
@@ -97,10 +110,7 @@ public FlowDelayTriggerService createDelayTriggerService(DelayTask task) {
97110
*/
98111
public FlowActionService createFlowActionService(FlowSession flowSession) {
99112
this.verify();
100-
return new FlowActionService(flowSession.toActionRequest(),
101-
flowOperatorGateway,
102-
flowRecordRepository,
103-
workflowBackupRepository);
113+
return new FlowActionService(flowSession.toActionRequest());
104114
}
105115

106116

@@ -114,6 +124,8 @@ public FlowService createFlowService() {
114124
return new FlowService(workflowRepository,
115125
flowOperatorGateway,
116126
flowRecordRepository,
127+
flowTodoRecordRepository,
128+
flowTodoMergeRepository,
117129
workflowBackupRepository,
118130
parallelBranchRepository,
119131
delayTaskRepository,
@@ -142,12 +154,15 @@ public void deleteDelayTask(DelayTask delayTask) {
142154
delayTaskRepository.delete(delayTask);
143155
}
144156

157+
145158
public void saveRecords(List<FlowRecord> flowRecords) {
146-
flowRecordRepository.saveAll(flowRecords);
159+
FlowRecordRepositoryService flowRecordRepositoryService = new FlowRecordRepositoryService(flowRecords);
160+
flowRecordRepositoryService.saveAll();
147161
}
148162

149163
public void saveRecord(FlowRecord flowRecord) {
150-
flowRecordRepository.save(flowRecord);
164+
FlowRecordRepositoryService flowRecordRepositoryService = new FlowRecordRepositoryService(flowRecord);
165+
flowRecordRepositoryService.saveAll();
151166
}
152167

153168
public List<FlowRecord> findCurrentNodeRecords(long fromId, String nodeId) {
@@ -179,4 +194,109 @@ public List<DelayTask> findDelayTasks() {
179194
}
180195

181196

197+
private static class FlowRecordRepositoryService {
198+
199+
private final List<FlowRecord> flowRecords;
200+
private final FlowTodoRecordRepository flowTodoRecordRepository;
201+
private final FlowTodoMergeRepository flowTodoMergeRepository;
202+
private final FlowRecordRepository flowRecordRepository;
203+
204+
205+
public FlowRecordRepositoryService(List<FlowRecord> flowRecords) {
206+
this.flowTodoRecordRepository = RepositoryHolderContext.getInstance().getFlowTodoRecordRepository();
207+
this.flowTodoMergeRepository = RepositoryHolderContext.getInstance().getFlowTodoMergeRepository();
208+
this.flowRecordRepository = RepositoryHolderContext.getInstance().getFlowRecordRepository();
209+
this.flowRecords = flowRecords;
210+
}
211+
212+
public FlowRecordRepositoryService(FlowRecord flowRecord) {
213+
this.flowTodoRecordRepository = RepositoryHolderContext.getInstance().getFlowTodoRecordRepository();
214+
this.flowTodoMergeRepository = RepositoryHolderContext.getInstance().getFlowTodoMergeRepository();
215+
this.flowRecordRepository = RepositoryHolderContext.getInstance().getFlowRecordRepository();
216+
this.flowRecords = new ArrayList<>();
217+
this.flowRecords.add(flowRecord);
218+
}
219+
220+
221+
private void saveTodoMargeRecords() {
222+
List<FlowTodoRecord> flowTodoRecords = new ArrayList<>();
223+
for (FlowRecord flowRecord : flowRecords) {
224+
if (flowRecord.isTodo()) {
225+
FlowTodoRecord todoMargeRecord = null;
226+
if (flowRecord.isMergeable()) {
227+
todoMargeRecord = flowTodoRecordRepository.getByMergeKey(flowRecord.getMergeKey());
228+
if (todoMargeRecord == null) {
229+
todoMargeRecord = new FlowTodoRecord(flowRecord);
230+
} else {
231+
todoMargeRecord.update(flowRecord);
232+
todoMargeRecord.addMargeCount();
233+
}
234+
} else {
235+
todoMargeRecord = new FlowTodoRecord(flowRecord);
236+
}
237+
flowTodoRecords.add(todoMargeRecord);
238+
}
239+
}
240+
if (!flowTodoRecords.isEmpty()) {
241+
flowTodoRecordRepository.saveAll(flowTodoRecords);
242+
}
243+
244+
if (!flowTodoRecords.isEmpty()) {
245+
List<FlowTodoMerge> relationList = new ArrayList<>();
246+
for (FlowTodoRecord margeRecord : flowTodoRecords) {
247+
if(margeRecord.isMergeable()) {
248+
relationList.add(new FlowTodoMerge(margeRecord));
249+
}
250+
}
251+
flowTodoMergeRepository.saveAll(relationList);
252+
}
253+
}
254+
255+
private void saveRecords() {
256+
if (!flowRecords.isEmpty()) {
257+
flowRecordRepository.saveAll(flowRecords);
258+
}
259+
}
260+
261+
262+
private void removeTodoMargeRecords() {
263+
for (FlowRecord flowRecord : flowRecords) {
264+
if (flowRecord.isDone()) {
265+
if (flowRecord.isMergeable()) {
266+
FlowTodoRecord todoMargeRecord = flowTodoRecordRepository.getByMergeKey(flowRecord.getMergeKey());
267+
if(todoMargeRecord!=null) {
268+
List<FlowTodoMerge> margeRelations = flowTodoMergeRepository.findByTodoId(todoMargeRecord.getId());
269+
if(margeRelations!=null && !margeRelations.isEmpty()) {
270+
for (FlowTodoMerge margeRelation : margeRelations) {
271+
if (margeRelation.isRecord(flowRecord.getId())) {
272+
flowTodoMergeRepository.remove(margeRelation);
273+
todoMargeRecord.divMargeCount();
274+
if (todoMargeRecord.hasMargeCount()) {
275+
flowTodoRecordRepository.save(todoMargeRecord);
276+
} else {
277+
flowTodoRecordRepository.remove(todoMargeRecord);
278+
}
279+
}
280+
}
281+
}
282+
}
283+
} else {
284+
FlowTodoRecord todoMargeRecord = flowTodoRecordRepository.getByMergeKey(flowRecord.getMergeKey());
285+
if (todoMargeRecord != null) {
286+
flowTodoRecordRepository.remove(todoMargeRecord);
287+
}
288+
}
289+
}
290+
}
291+
}
292+
293+
public void saveAll() {
294+
this.saveRecords();
295+
this.saveTodoMargeRecords();
296+
this.removeTodoMargeRecords();
297+
}
298+
299+
300+
}
301+
182302
}

flow-engine-framework/src/main/java/com/codingapi/flow/pojo/body/FlowAdviceBody.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import java.util.List;
1010

11+
/**
12+
* 流程审批意见
13+
*/
1114
@Data
1215
@NoArgsConstructor
1316
public class FlowAdviceBody {
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package com.codingapi.flow.pojo.response;
2+
3+
import com.codingapi.flow.action.IFlowAction;
4+
import com.codingapi.flow.form.FormMeta;
5+
import lombok.Data;
6+
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
/**
11+
* 流程详情
12+
*/
13+
@Data
14+
public class FlowContent {
15+
16+
/**
17+
* 流程记录编号
18+
*/
19+
private long recordId;
20+
/**
21+
* 流程编号
22+
*/
23+
private String workflowCode;
24+
/**
25+
* 流程视图
26+
*/
27+
private String view;
28+
29+
/**
30+
* 表单元数据
31+
*/
32+
private FormMeta form;
33+
/**
34+
* 流程记录
35+
*/
36+
private List<Body> todos;
37+
38+
/**
39+
* 流程按钮
40+
*/
41+
private List<IFlowAction> actions;
42+
43+
/**
44+
* 是否可合并
45+
*/
46+
private boolean mergeable;
47+
48+
/**
49+
* 发起者id
50+
*/
51+
private long createOperatorId;
52+
53+
/**
54+
* 历史记录
55+
*/
56+
private List<History> histories;
57+
58+
/**
59+
* 下一审批
60+
*/
61+
private List<NextNode> nextNodes;
62+
63+
/**
64+
* 流程图
65+
*/
66+
@Data
67+
public static class NextNode{
68+
/**
69+
* 节点名称
70+
*/
71+
private String nodeId;
72+
/**
73+
* 节点名称
74+
*/
75+
private String nodeName;
76+
/**
77+
* 节点类型
78+
*/
79+
private String nodeType;
80+
}
81+
82+
@Data
83+
public static class History{
84+
/**
85+
* 流程编号
86+
*/
87+
private long recordId;
88+
/**
89+
* 流程标题
90+
*/
91+
private String title;
92+
93+
/**
94+
* 审批意见
95+
*/
96+
private String advice;
97+
98+
/**
99+
* 签名key
100+
*/
101+
private String signKey;
102+
103+
/**
104+
* 节点名称
105+
*/
106+
private String nodeName;
107+
108+
/**
109+
* 节点id
110+
*/
111+
private String nodeId;
112+
/**
113+
* 节点类型
114+
*/
115+
private String nodeType;
116+
117+
/**
118+
* 更新时间
119+
*/
120+
private long updateTime;
121+
122+
/**
123+
* 当前审批人Id
124+
*/
125+
private long currentOperatorId;
126+
127+
/**
128+
* 当前审批人名称
129+
*/
130+
private String currentOperatorName;
131+
}
132+
133+
@Data
134+
public static class Body {
135+
/**
136+
* 流程记录编号
137+
*/
138+
private long recordId;
139+
/**
140+
* 流程标题
141+
*/
142+
private String title;
143+
/**
144+
* 表单数据
145+
*/
146+
private Map<String, Object> data;
147+
148+
/**
149+
* 节点状态 | 待办、已办
150+
*/
151+
private int recordState;
152+
/**
153+
* 流程状态 | 运行中、已完成、异常、删除
154+
*/
155+
private int flowState;
156+
}
157+
}

0 commit comments

Comments
 (0)