Skip to content

Commit ecaab81

Browse files
committed
fix bug
1 parent 7fa8b5a commit ecaab81

File tree

4 files changed

+153
-78
lines changed

4 files changed

+153
-78
lines changed

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/domain/Opinion.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ public static Opinion unSignAutoSuccess() {
7171
public boolean isSuccess() {
7272
return result == RESULT_PASS;
7373
}
74+
75+
public boolean isReject() {
76+
return result == RESULT_REJECT;
77+
}
7478
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package com.codingapi.springboot.flow.service;
2+
3+
import com.codingapi.springboot.flow.bind.BindDataSnapshot;
4+
import com.codingapi.springboot.flow.bind.IBindData;
5+
import com.codingapi.springboot.flow.domain.FlowNode;
6+
import com.codingapi.springboot.flow.domain.FlowWork;
7+
import com.codingapi.springboot.flow.domain.Opinion;
8+
import com.codingapi.springboot.flow.em.FlowSourceDirection;
9+
import com.codingapi.springboot.flow.record.FlowRecord;
10+
import com.codingapi.springboot.flow.repository.FlowBindDataRepository;
11+
import com.codingapi.springboot.flow.repository.FlowOperatorRepository;
12+
import lombok.Getter;
13+
14+
import java.util.List;
15+
16+
class FlowNodeService {
17+
18+
19+
private final FlowOperatorRepository flowOperatorRepository;
20+
private final FlowBindDataRepository flowBindDataRepository;
21+
22+
private final FlowRecordService2 flowRecordService2;
23+
24+
private final FlowRecord flowRecord;
25+
private final FlowWork flowWork;
26+
private final FlowNode flowNode;
27+
private final IBindData bindData;
28+
private final Opinion opinion;
29+
30+
// load Object
31+
@Getter
32+
private FlowSourceDirection flowSourceDirection;
33+
@Getter
34+
private List<FlowRecord> childrenRecords;
35+
@Getter
36+
private BindDataSnapshot snapshot;
37+
38+
public FlowNodeService(FlowOperatorRepository flowOperatorRepository,
39+
FlowBindDataRepository flowBindDataRepository,
40+
FlowRecordService2 flowRecordService2,
41+
IBindData bindData,
42+
Opinion opinion) {
43+
44+
this.flowOperatorRepository = flowOperatorRepository;
45+
this.flowBindDataRepository = flowBindDataRepository;
46+
47+
this.flowRecordService2 = flowRecordService2;
48+
this.bindData = bindData;
49+
this.opinion = opinion;
50+
51+
this.flowRecord = flowRecordService2.getFlowRecord();
52+
this.flowWork = flowRecordService2.getFlowWork();
53+
this.flowNode = flowRecordService2.getFlowNode();
54+
55+
}
56+
57+
58+
public void loadFlowSourceDirection(){
59+
if(opinion.isSuccess()){
60+
flowSourceDirection = FlowSourceDirection.PASS;
61+
}
62+
if(opinion.isReject()){
63+
flowSourceDirection = FlowSourceDirection.REJECT;
64+
}
65+
}
66+
67+
68+
/**
69+
* 保存流程表单数据
70+
*/
71+
public void updateSnapshot() {
72+
BindDataSnapshot snapshot = new BindDataSnapshot(flowRecord.getSnapshotId(), bindData);
73+
flowBindDataRepository.update(snapshot);
74+
}
75+
76+
77+
78+
public void loadSnapshot(){
79+
// 保存绑定数据
80+
if (flowNode.isEditable()) {
81+
snapshot = new BindDataSnapshot(bindData);
82+
flowBindDataRepository.save(snapshot);
83+
} else {
84+
snapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId());
85+
}
86+
}
87+
88+
89+
/**
90+
* 更新流程记录
91+
*/
92+
public void updateFlowRecord() {
93+
flowRecord.setOpinion(opinion);
94+
flowRecordService2.flowRecordRepository.update(flowRecord);
95+
}
96+
97+
98+
public void loadChildrenRecords(){
99+
childrenRecords = flowRecordService2.flowRecordRepository.findFlowRecordByPreId(flowRecord.getId());
100+
}
101+
102+
103+
public void verifyChildrenRecordsIsEmpty(){
104+
if (!childrenRecords.isEmpty()) {
105+
throw new IllegalArgumentException("flow node is done");
106+
}
107+
}
108+
109+
110+
public void verifyFlowSourceDirection() {
111+
if(flowSourceDirection==null){
112+
throw new IllegalArgumentException("flow source direction is null");
113+
}
114+
if(flowNode.isStartNode() && flowSourceDirection == FlowSourceDirection.REJECT){
115+
throw new IllegalArgumentException("flow node is start node");
116+
}
117+
}
118+
}

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowRecordService2.java

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.codingapi.springboot.flow.service;
22

3-
import com.codingapi.springboot.flow.bind.BindDataSnapshot;
4-
import com.codingapi.springboot.flow.bind.IBindData;
53
import com.codingapi.springboot.flow.domain.FlowNode;
64
import com.codingapi.springboot.flow.domain.FlowWork;
7-
import com.codingapi.springboot.flow.domain.Opinion;
85
import com.codingapi.springboot.flow.record.FlowRecord;
96
import com.codingapi.springboot.flow.repository.FlowBindDataRepository;
107
import com.codingapi.springboot.flow.repository.FlowProcessRepository;
@@ -17,15 +14,15 @@
1714
*/
1815
class FlowRecordService2 {
1916

17+
// constructor params
2018
private final long recordId;
2119
private final IFlowOperator currentOperator;
22-
private IBindData bindData;
23-
private Opinion opinion;
2420

25-
private final FlowRecordRepository flowRecordRepository;
26-
private final FlowProcessRepository flowProcessRepository;
27-
private final FlowBindDataRepository flowBindDataRepository;
21+
// register repository
22+
final FlowRecordRepository flowRecordRepository;
23+
final FlowProcessRepository flowProcessRepository;
2824

25+
// load Object
2926
@Getter
3027
private FlowWork flowWork;
3128
@Getter
@@ -35,25 +32,15 @@ class FlowRecordService2 {
3532

3633
public FlowRecordService2(FlowRecordRepository flowRecordRepository,
3734
FlowProcessRepository flowProcessRepository,
38-
FlowBindDataRepository flowBindDataRepository,
39-
4035
long recordId,
4136
IFlowOperator currentOperator) {
4237
this.flowRecordRepository = flowRecordRepository;
4338
this.flowProcessRepository = flowProcessRepository;
44-
this.flowBindDataRepository = flowBindDataRepository;
4539

4640
this.currentOperator = currentOperator;
4741
this.recordId = recordId;
4842
}
4943

50-
public void bindBindData(IBindData bindData){
51-
this.bindData = bindData;
52-
}
53-
54-
public void bindOpinion(Opinion opinion){
55-
this.opinion = opinion;
56-
}
5744

5845

5946
/**
@@ -185,31 +172,6 @@ public void loadFlowNode() {
185172
this.flowNode = flowNode;
186173
}
187174

188-
189-
/**
190-
* 保存流程表单数据
191-
*/
192-
public void saveSnapshot() {
193-
if(bindData==null){
194-
throw new IllegalArgumentException("bind data is null");
195-
}
196-
BindDataSnapshot snapshot = new BindDataSnapshot(flowRecord.getSnapshotId(), bindData);
197-
flowBindDataRepository.update(snapshot);
198-
}
199-
200-
201-
/**
202-
* 更新流程记录
203-
*/
204-
public void updateFlowRecord() {
205-
if(opinion==null){
206-
throw new IllegalArgumentException("opinion is null");
207-
}
208-
flowRecord.setOpinion(opinion);
209-
flowRecordRepository.update(flowRecord);
210-
}
211-
212-
213175
/**
214176
* 标记流程为已读状态
215177
*/

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public FlowDetail detail(long recordId) {
5151
* @param time 延期时间
5252
*/
5353
public void postponed(long recordId, IFlowOperator currentOperator, long time) {
54-
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository, flowProcessRepository, flowBindDataRepository,
54+
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository,
55+
flowProcessRepository,
5556
recordId,currentOperator);
5657

5758
flowRecordService2.loadFlowRecord();
@@ -75,7 +76,8 @@ public void postponed(long recordId, IFlowOperator currentOperator, long time) {
7576
* @param currentOperator 当前操作者
7677
*/
7778
public void urge(long recordId, IFlowOperator currentOperator) {
78-
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository, flowProcessRepository, flowBindDataRepository,
79+
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository,
80+
flowProcessRepository,
7981
recordId,currentOperator);
8082
flowRecordService2.loadFlowRecord();
8183
flowRecordService2.loadFlowWork();
@@ -103,7 +105,8 @@ public void urge(long recordId, IFlowOperator currentOperator) {
103105
*/
104106
public FlowDetail detail(long recordId, IFlowOperator currentOperator) {
105107

106-
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository, flowProcessRepository, flowBindDataRepository,
108+
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository,
109+
flowProcessRepository,
107110
recordId,currentOperator);
108111

109112
flowRecordService2.loadFlowRecord();
@@ -159,7 +162,8 @@ public void interfere(long recordId, IFlowOperator currentOperator, IBindData bi
159162
*/
160163
public void transfer(long recordId, IFlowOperator currentOperator, IFlowOperator targetOperator, IBindData bindData, String advice) {
161164

162-
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository, flowProcessRepository, flowBindDataRepository,
165+
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository,
166+
flowProcessRepository,
163167
recordId,currentOperator);
164168

165169
flowRecordService2.loadFlowRecord();
@@ -227,19 +231,19 @@ public void transfer(long recordId, IFlowOperator currentOperator, IFlowOperator
227231
* @param advice 审批意见
228232
*/
229233
public void save(long recordId, IFlowOperator currentOperator, IBindData bindData, String advice) {
230-
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository, flowProcessRepository, flowBindDataRepository,
234+
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository,
235+
flowProcessRepository,
231236
recordId,currentOperator);
232-
flowRecordService2.bindBindData(bindData);
233-
flowRecordService2.bindOpinion(Opinion.save(advice));
234-
235237
flowRecordService2.loadFlowRecord();
236238
flowRecordService2.verifyFlowRecordSubmitState();
237239
flowRecordService2.verifyFlowRecordCurrentOperator();
238240
flowRecordService2.loadFlowWork();
239241
flowRecordService2.loadFlowNode();
240242
flowRecordService2.verifyFlowNodeEditableState(false);
241-
flowRecordService2.saveSnapshot();
242-
flowRecordService2.updateFlowRecord();
243+
244+
FlowNodeService flowNodeService = new FlowNodeService(flowOperatorRepository,flowBindDataRepository,flowRecordService2,bindData,Opinion.save(advice));
245+
flowNodeService.updateSnapshot();
246+
flowNodeService.updateFlowRecord();
243247

244248
}
245249

@@ -313,13 +317,9 @@ public void startFlow(long workId, IFlowOperator operator, IBindData bindData, S
313317
*/
314318
public void submitFlow(long recordId, IFlowOperator currentOperator, IBindData bindData, Opinion opinion) {
315319

316-
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository, flowProcessRepository, flowBindDataRepository,
320+
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository, flowProcessRepository,
317321
recordId,currentOperator);
318322

319-
flowRecordService2.bindBindData(bindData);
320-
flowRecordService2.bindOpinion(opinion);
321-
322-
323323
flowRecordService2.loadFlowRecord();
324324
flowRecordService2.verifyFlowRecordSubmitState();
325325
flowRecordService2.verifyFlowRecordCurrentOperator();
@@ -330,32 +330,22 @@ public void submitFlow(long recordId, IFlowOperator currentOperator, IBindData b
330330
FlowNode flowNode = flowRecordService2.getFlowNode();
331331
FlowWork flowWork = flowRecordService2.getFlowWork();
332332

333-
// 根据审批意见判断流程是否进入下一节点
334-
FlowSourceDirection flowSourceDirection = opinion.isSuccess()? FlowSourceDirection.PASS: FlowSourceDirection.REJECT;
333+
FlowNodeService flowNodeService = new FlowNodeService(flowOperatorRepository,flowBindDataRepository,flowRecordService2,bindData,opinion);
335334

336-
if(flowNode.isStartNode() && flowSourceDirection == FlowSourceDirection.REJECT){
337-
throw new IllegalArgumentException("flow node is start node");
338-
}
335+
flowNodeService.loadFlowSourceDirection();
336+
flowNodeService.verifyFlowSourceDirection();
339337

340338

341-
// 下一流程的流程记录
342-
List<FlowRecord> childrenRecords = flowRecordRepository.findFlowRecordByPreId(recordId);
343-
// 不能存在后续的子流程
344-
if (!childrenRecords.isEmpty()) {
345-
throw new IllegalArgumentException("flow node is done");
346-
}
339+
flowNodeService.loadChildrenRecords();
340+
flowNodeService.verifyChildrenRecordsIsEmpty();
347341

348342
// 获取创建者
349343
IFlowOperator createOperator = flowOperatorRepository.getFlowOperatorById(flowRecord.getCreateOperatorId());
350344

351-
BindDataSnapshot snapshot = null;
352-
// 保存绑定数据
353-
if (flowNode.isEditable()) {
354-
snapshot = new BindDataSnapshot(bindData);
355-
flowBindDataRepository.save(snapshot);
356-
} else {
357-
snapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId());
358-
}
345+
flowNodeService.loadSnapshot();
346+
347+
BindDataSnapshot snapshot = flowNodeService.getSnapshot();
348+
FlowSourceDirection flowSourceDirection = flowNodeService.getFlowSourceDirection();
359349

360350
// 提交流程
361351
flowRecord.submitRecord(currentOperator, snapshot, opinion, flowSourceDirection);
@@ -495,7 +485,8 @@ private void createNexRecordList(FlowRecordService flowRecordService,long preId,
495485
* @param currentOperator 当前操作者
496486
*/
497487
public void recall(long recordId, IFlowOperator currentOperator) {
498-
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository, flowProcessRepository, flowBindDataRepository,
488+
FlowRecordService2 flowRecordService2 = new FlowRecordService2(flowRecordRepository,
489+
flowProcessRepository,
499490
recordId,currentOperator);
500491

501492
flowRecordService2.loadFlowRecord();

0 commit comments

Comments
 (0)