Skip to content

Commit 59bece7

Browse files
committed
fix #144
1 parent 949ecbd commit 59bece7

File tree

14 files changed

+329
-8
lines changed

14 files changed

+329
-8
lines changed

event.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
事件: URGE 当前审批人
2727
* 延期流程
2828
事件: 未发送事件
29+
* 停止流程
30+
事件: STOP 当前审批人
2931

3032
---------------------
3133
自定义事件:是前端自己触法的逻辑

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<groupId>com.codingapi.springboot</groupId>
1717
<artifactId>springboot-parent</artifactId>
18-
<version>2.10.13</version>
18+
<version>2.10.14</version>
1919

2020
<url>https://github.com/codingapi/springboot-framewrok</url>
2121
<name>springboot-parent</name>

springboot-starter-data-authorization/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>2.10.13</version>
9+
<version>2.10.14</version>
1010
</parent>
1111

1212
<name>springboot-starter-data-authorization</name>

springboot-starter-data-fast/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>2.10.13</version>
8+
<version>2.10.14</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-flow/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>2.10.13</version>
9+
<version>2.10.14</version>
1010
</parent>
1111

1212
<name>springboot-starter-flow</name>

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class Opinion {
3535
public static final int RESULT_CIRCULATE = 4;
3636
// 审批结果 等待
3737
public static final int RESULT_WAITING = 5;
38+
// 审批结果 停止
39+
public static final int RESULT_STOP = 6;
3840

3941

4042
/**
@@ -83,6 +85,10 @@ public static Opinion pass(String advice) {
8385
return new Opinion(advice, RESULT_PASS, TYPE_DEFAULT);
8486
}
8587

88+
public static Opinion stop() {
89+
return new Opinion("", RESULT_STOP, TYPE_DEFAULT);
90+
}
91+
8692
public static Opinion reject(String advice) {
8793
return new Opinion(advice, RESULT_REJECT, TYPE_DEFAULT);
8894
}
@@ -114,7 +120,7 @@ public boolean isSuccess() {
114120
public boolean isWaiting() {
115121
return result == RESULT_WAITING;
116122
}
117-
123+
118124
public boolean isReject() {
119125
return result == RESULT_REJECT;
120126
}

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class FlowApprovalEvent implements ISyncEvent {
4242
public static final int STATE_BACK = 12;
4343
// 作废
4444
public static final int STATE_VOIDED = 13;
45+
// 停止
46+
public static final int STATE_STOP = 14;
4547

4648

4749
private final int state;

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowRecord.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ public void circulate() {
247247
this.opinion = Opinion.circulate();
248248
}
249249

250+
251+
/**
252+
* 停止流程
253+
*/
254+
public void stop(){
255+
this.flowSourceDirection = FlowSourceDirection.PASS;
256+
this.flowType = FlowType.DONE;
257+
this.updateTime = System.currentTimeMillis();
258+
this.opinion = Opinion.stop();
259+
}
260+
250261
/**
251262
* 转交流程
252263
*/

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,15 @@ public void voided(String processId, IFlowOperator currentOperator) {
314314
public void back(String processId, String backNodeCode, IFlowOperator currentOperator) {
315315
flowBackService.back(processId, backNodeCode, currentOperator);
316316
}
317+
318+
/**
319+
* 停止流程
320+
*
321+
* @param recordId 流程记录id
322+
* @param currentOperator 当前操作者
323+
*/
324+
public void stop(long recordId, IFlowOperator currentOperator) {
325+
FlowStopService flowSubmitService = new FlowStopService(recordId, currentOperator, flowServiceRepositoryHolder);
326+
flowSubmitService.stop();
327+
}
317328
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.codingapi.springboot.flow.service.impl;
2+
3+
import com.codingapi.springboot.flow.bind.BindDataSnapshot;
4+
import com.codingapi.springboot.flow.domain.FlowNode;
5+
import com.codingapi.springboot.flow.domain.FlowWork;
6+
import com.codingapi.springboot.flow.event.FlowApprovalEvent;
7+
import com.codingapi.springboot.flow.record.FlowRecord;
8+
import com.codingapi.springboot.flow.repository.FlowBindDataRepository;
9+
import com.codingapi.springboot.flow.repository.FlowRecordRepository;
10+
import com.codingapi.springboot.flow.service.FlowRecordVerifyService;
11+
import com.codingapi.springboot.flow.service.FlowServiceRepositoryHolder;
12+
import com.codingapi.springboot.flow.user.IFlowOperator;
13+
import com.codingapi.springboot.framework.event.EventPusher;
14+
import org.springframework.transaction.annotation.Transactional;
15+
16+
import java.util.List;
17+
18+
@Transactional
19+
public class FlowStopService {
20+
21+
22+
private final IFlowOperator currentOperator;
23+
private final FlowRecordVerifyService flowRecordVerifyService;
24+
private final FlowRecordRepository flowRecordRepository;
25+
private final FlowBindDataRepository flowBindDataRepository ;
26+
27+
private FlowRecord flowRecord;
28+
private FlowWork flowWork;
29+
private FlowNode flowNode;
30+
private BindDataSnapshot snapshot;
31+
32+
33+
34+
public FlowStopService(long recordId,
35+
IFlowOperator currentOperator,
36+
FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
37+
this.currentOperator = currentOperator;
38+
this.flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository();
39+
this.flowBindDataRepository = flowServiceRepositoryHolder.getFlowBindDataRepository();
40+
this.flowRecordVerifyService = new FlowRecordVerifyService(
41+
flowServiceRepositoryHolder.getFlowWorkRepository(),
42+
flowServiceRepositoryHolder.getFlowRecordRepository(),
43+
flowServiceRepositoryHolder.getFlowProcessRepository(),
44+
recordId,
45+
currentOperator);
46+
}
47+
48+
49+
// 加载流程
50+
private void loadFlow() {
51+
// 验证流程的提交状态
52+
flowRecordVerifyService.verifyFlowRecordSubmitState();
53+
// 验证当前操作者
54+
flowRecordVerifyService.verifyFlowRecordCurrentOperator();
55+
56+
// 加载流程设计
57+
flowRecordVerifyService.loadFlowWork();
58+
// 加载流程节点
59+
flowRecordVerifyService.loadFlowNode();
60+
// 验证没有子流程
61+
flowRecordVerifyService.verifyChildrenRecordsIsEmpty();
62+
63+
this.flowRecord = flowRecordVerifyService.getFlowRecord();
64+
this.flowNode = flowRecordVerifyService.getFlowNode();
65+
this.flowWork = flowRecordVerifyService.getFlowWork();
66+
this.snapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId());
67+
}
68+
69+
70+
71+
/**
72+
* 提交流程
73+
**/
74+
public void stop() {
75+
// 加载流程信息
76+
this.loadFlow();
77+
78+
// 停止流程
79+
flowRecord.stop();
80+
flowRecordRepository.update(flowRecord);
81+
82+
List<FlowRecord> todoRecords = flowRecordRepository.findFlowRecordByProcessId(flowRecord.getProcessId());
83+
for (FlowRecord record : todoRecords) {
84+
if (record.isTodo()) {
85+
record.stop();
86+
flowRecordRepository.update(record);
87+
}
88+
}
89+
90+
flowRecordRepository.finishFlowRecordByProcessId(flowRecord.getProcessId());
91+
92+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_STOP,
93+
flowRecord,
94+
flowRecord.getCurrentOperator(),
95+
flowWork,
96+
snapshot.toBindData()
97+
), true);
98+
99+
}
100+
101+
102+
}

0 commit comments

Comments
 (0)