Skip to content

Commit f8b8177

Browse files
committed
fix trySubmit
1 parent 48f0fd3 commit f8b8177

File tree

5 files changed

+217
-281
lines changed

5 files changed

+217
-281
lines changed

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

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,21 @@ public FlowRecordVerifyService(FlowRecordRepository flowRecordRepository,
4646
this.flowRecord = flowRecord;
4747
}
4848

49+
public FlowRecordVerifyService(FlowRecordRepository flowRecordRepository,
50+
FlowProcessRepository flowProcessRepository,
51+
FlowRecord flowRecord,
52+
FlowWork flowWork,
53+
IFlowOperator currentOperator) {
54+
this.flowRecordRepository = flowRecordRepository;
55+
this.flowProcessRepository = flowProcessRepository;
56+
this.currentOperator = currentOperator;
57+
this.flowRecord = flowRecord;
58+
this.flowWork = flowWork;
59+
}
4960

5061

5162
/**
52-
* 校验流程记录是否已提交状态
63+
* 校验流程记录是否已提交状态
5364
*/
5465
public void verifyFlowRecordSubmitState() {
5566
flowRecord.submitStateVerify();
@@ -59,13 +70,13 @@ public void verifyFlowRecordSubmitState() {
5970
* 校验流程是否当前操作者可操作的
6071
*/
6172
public void verifyFlowRecordCurrentOperator() {
62-
if(!currentOperator.isFlowManager()) {
73+
if (!currentOperator.isFlowManager()) {
6374
flowRecord.matcherOperator(currentOperator);
6475
}
6576
}
6677

6778
/**
68-
* 校验流程是否已审批
79+
* 校验流程是否已审批
6980
*/
7081
public void verifyFlowRecordNotDone() {
7182
if (flowRecord.isDone()) {
@@ -75,7 +86,7 @@ public void verifyFlowRecordNotDone() {
7586

7687

7788
/**
78-
* 校验流程是否已审批
89+
* 校验流程是否已审批
7990
*/
8091
public void verifyFlowRecordIsDone() {
8192
if (!flowRecord.isDone()) {
@@ -84,20 +95,19 @@ public void verifyFlowRecordIsDone() {
8495
}
8596

8697

87-
8898
/**
89-
* 校验流程是否未审批
99+
* 校验流程是否未审批
90100
*/
91101
public void verifyFlowRecordNotTodo() {
92102
if (flowRecord.isTodo()) {
93-
if(!flowRecord.isStartRecord()) {
103+
if (!flowRecord.isStartRecord()) {
94104
throw new IllegalArgumentException("flow record is todo");
95105
}
96106
}
97107
}
98108

99109
/**
100-
* 校验流程是未审批
110+
* 校验流程是未审批
101111
*/
102112
public void verifyFlowRecordIsTodo() {
103113
if (!flowRecord.isTodo()) {
@@ -106,7 +116,7 @@ public void verifyFlowRecordIsTodo() {
106116
}
107117

108118
/**
109-
* 校验流程是否已完成
119+
* 校验流程是否已完成
110120
*/
111121
public void verifyFlowRecordNotFinish() {
112122
if (flowRecord.isFinish()) {
@@ -115,7 +125,7 @@ public void verifyFlowRecordNotFinish() {
115125
}
116126

117127
/**
118-
* 校验流程节点是否可编辑
128+
* 校验流程节点是否可编辑
119129
*/
120130
public void verifyFlowNodeEditableState(boolean editable) {
121131
// 流程节点不可编辑时,不能保存
@@ -126,31 +136,32 @@ public void verifyFlowNodeEditableState(boolean editable) {
126136

127137

128138
/**
129-
* 校验转办人员不能是当前操作者
139+
* 校验转办人员不能是当前操作者
130140
*/
131141
public void verifyTargetOperatorIsNotCurrentOperator(IFlowOperator targetOperator) {
132-
if(currentOperator.getUserId() == targetOperator.getUserId()){
142+
if (currentOperator.getUserId() == targetOperator.getUserId()) {
133143
throw new IllegalArgumentException("current operator is target operator");
134144
}
135145
}
136146

137147

138-
139148
/**
140-
* 获取流程设计对象
149+
* 获取流程设计对象
141150
*/
142151
public void loadFlowWork() {
143-
FlowWork flowWork = flowProcessRepository.getFlowWorkByProcessId(flowRecord.getProcessId());
144-
if (flowWork == null) {
145-
throw new IllegalArgumentException("flow work not found");
152+
if(this.flowWork ==null) {
153+
FlowWork flowWork = flowProcessRepository.getFlowWorkByProcessId(flowRecord.getProcessId());
154+
if (flowWork == null) {
155+
throw new IllegalArgumentException("flow work not found");
156+
}
157+
flowWork.enableValidate();
158+
this.flowWork = flowWork;
146159
}
147-
flowWork.enableValidate();
148-
this.flowWork = flowWork;
149160
}
150161

151162

152163
/**
153-
* 获取流程节点对象
164+
* 获取流程节点对象
154165
*/
155166
public void loadFlowNode() {
156167
FlowNode flowNode = flowWork.getNodeByCode(flowRecord.getNodeCode());
@@ -161,11 +172,11 @@ public void loadFlowNode() {
161172
}
162173

163174
/**
164-
* 标记流程为已读状态
175+
* 标记流程为已读状态
165176
*/
166177
public void setFlowRecordRead() {
167178
if (currentOperator != null) {
168-
if(flowRecord.isOperator(currentOperator)) {
179+
if (flowRecord.isOperator(currentOperator)) {
169180
if (!flowRecord.isRead()) {
170181
flowRecord.read();
171182
flowRecordRepository.update(flowRecord);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class FlowService {
2222
private final FlowDetailService flowDetailService;
2323
private final FlowCustomEventService flowCustomEventService;
2424
private final FlowRecallService flowRecallService;
25-
private final FlowTrySubmitService flowTrySubmitService;
2625
private final FlowSaveService flowSaveService;
2726
private final FlowTransferService flowTransferService;
2827
private final FlowPostponedService flowPostponedService;
@@ -41,7 +40,6 @@ public FlowService(FlowWorkRepository flowWorkRepository,
4140
this.flowDetailService = new FlowDetailService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowOperatorRepository, flowProcessRepository);
4241
this.flowCustomEventService = new FlowCustomEventService(flowRecordRepository, flowProcessRepository);
4342
this.flowRecallService = new FlowRecallService(flowRecordRepository, flowProcessRepository);
44-
this.flowTrySubmitService = new FlowTrySubmitService(flowRecordRepository, flowBindDataRepository, flowOperatorRepository, flowProcessRepository, flowWorkRepository, flowBackupRepository);
4543
this.flowSaveService = new FlowSaveService(flowRecordRepository, flowBindDataRepository, flowProcessRepository);
4644
this.flowTransferService = new FlowTransferService(flowRecordRepository, flowBindDataRepository, flowProcessRepository);
4745
this.flowPostponedService = new FlowPostponedService(flowRecordRepository, flowProcessRepository);
@@ -183,7 +181,8 @@ public FlowResult startFlow(String workCode, IFlowOperator operator, IBindData b
183181
* @param opinion 审批意见
184182
*/
185183
public FlowSubmitResult trySubmitFlow(long recordId, IFlowOperator currentOperator, IBindData bindData, Opinion opinion) {
186-
return flowTrySubmitService.trySubmitFlow(recordId, currentOperator, bindData, opinion);
184+
FlowTrySubmitService flowTrySubmitService = new FlowTrySubmitService(currentOperator, bindData, opinion, flowServiceRepositoryHolder);
185+
return flowTrySubmitService.trySubmitFlow(recordId);
187186
}
188187

189188

@@ -196,7 +195,8 @@ public FlowSubmitResult trySubmitFlow(long recordId, IFlowOperator currentOperat
196195
* @param opinion 审批意见
197196
*/
198197
public FlowSubmitResult trySubmitFlow(String workCode, IFlowOperator currentOperator, IBindData bindData, Opinion opinion) {
199-
return flowTrySubmitService.trySubmitFlow(workCode, currentOperator, bindData, opinion);
198+
FlowTrySubmitService flowTrySubmitService = new FlowTrySubmitService(currentOperator, bindData, opinion, flowServiceRepositoryHolder);
199+
return flowTrySubmitService.trySubmitFlow(workCode);
200200
}
201201

202202

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.codingapi.springboot.flow.em.FlowSourceDirection;
99
import com.codingapi.springboot.flow.event.FlowApprovalEvent;
1010
import com.codingapi.springboot.flow.pojo.FlowResult;
11+
import com.codingapi.springboot.flow.pojo.FlowSubmitResult;
1112
import com.codingapi.springboot.flow.record.FlowBackup;
1213
import com.codingapi.springboot.flow.record.FlowProcess;
1314
import com.codingapi.springboot.flow.record.FlowRecord;
@@ -19,6 +20,7 @@
1920
import com.codingapi.springboot.flow.service.FlowServiceRepositoryHolder;
2021
import com.codingapi.springboot.flow.user.IFlowOperator;
2122
import com.codingapi.springboot.framework.event.EventPusher;
23+
import lombok.Getter;
2224
import org.springframework.transaction.annotation.Transactional;
2325

2426
import java.util.ArrayList;
@@ -34,14 +36,19 @@ public class FlowStartService {
3436
private final FlowServiceRepositoryHolder flowServiceRepositoryHolder;
3537

3638

39+
@Getter
3740
private FlowWork flowWork;
3841
private FlowNode flowNode;
3942
private FlowBackup flowBackup;
4043
private FlowProcess flowProcess;
4144
private BindDataSnapshot snapshot;
4245
private FlowNodeService flowNodeService;
4346

44-
public FlowStartService(String workCode, IFlowOperator operator, IBindData bindData, String advice, FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
47+
public FlowStartService(String workCode,
48+
IFlowOperator operator,
49+
IBindData bindData,
50+
String advice,
51+
FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
4552
this.workCode = workCode;
4653
this.operator = operator;
4754
this.bindData = bindData;
@@ -188,4 +195,42 @@ public FlowResult startFlow() {
188195
return new FlowResult(flowWork, records);
189196
}
190197

198+
199+
public FlowRecord tryStartFlow() {
200+
// 检测流程是否存在
201+
this.loadFlowWork();
202+
// 流程数据备份
203+
this.loadFlowBackup();
204+
205+
// 保存绑定数据
206+
snapshot = new BindDataSnapshot(bindData);
207+
// 保存流程
208+
flowProcess = new FlowProcess(flowBackup.getId(), operator);
209+
210+
// 构建流程节点服务
211+
this.buildFlowNodeService();
212+
213+
FlowRecord startRecord = null;
214+
215+
// 创建待办记录
216+
List<FlowRecord> records = flowNodeService.createRecord();
217+
if (records.isEmpty()) {
218+
throw new IllegalArgumentException("flow record not found");
219+
} else {
220+
for (FlowRecord record : records) {
221+
record.updateOpinion(opinion);
222+
startRecord = record;
223+
}
224+
}
225+
226+
// 检测流程是否结束
227+
if (flowNodeService.nextNodeIsOver()) {
228+
for (FlowRecord record : records) {
229+
record.submitRecord(operator, snapshot, opinion, FlowSourceDirection.PASS);
230+
record.finish();
231+
startRecord = record;
232+
}
233+
}
234+
return startRecord;
235+
}
191236
}

0 commit comments

Comments
 (0)