Skip to content

Commit a50655d

Browse files
committed
update 2.9.28
1 parent b89edde commit a50655d

File tree

17 files changed

+201
-19
lines changed

17 files changed

+201
-19
lines changed

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.9.27</version>
18+
<version>2.9.28</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.9.27</version>
9+
<version>2.9.28</version>
1010
</parent>
1111

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

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.9.27</version>
8+
<version>2.9.28</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.9.27</version>
9+
<version>2.9.28</version>
1010
</parent>
1111

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ public FlowRecord createRecord(long workId,
217217
String title,
218218
IFlowOperator createOperator,
219219
IFlowOperator currentOperator,
220-
BindDataSnapshot snapshot) {
220+
BindDataSnapshot snapshot,
221+
boolean isWaiting) {
221222

222223
// 当前操作者存在委托人时,才需要寻找委托人
223224
IFlowOperator flowOperator = currentOperator;
@@ -239,7 +240,7 @@ public FlowRecord createRecord(long workId,
239240
record.setPreId(preId);
240241
record.setTitle(title);
241242
record.setTimeoutTime(this.loadTimeoutTime());
242-
record.setFlowType(FlowType.TODO);
243+
record.setFlowType(isWaiting?FlowType.WAITING:FlowType.TODO);
243244
record.setErrMessage(null);
244245
record.setSnapshotId(snapshot.getId());
245246
return record;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class Opinion {
3333
public static final int RESULT_REJECT = 3;
3434
// 审批结果 抄送
3535
public static final int RESULT_CIRCULATE = 4;
36+
// 审批结果 等待
37+
public static final int RESULT_WAITING = 5;
38+
3639

3740
/**
3841
* 审批意见
@@ -88,6 +91,10 @@ public static Opinion transfer(String advice) {
8891
return new Opinion(advice, RESULT_TRANSFER, TYPE_DEFAULT);
8992
}
9093

94+
public static Opinion waiting(String advice) {
95+
return new Opinion(advice, RESULT_WAITING, TYPE_DEFAULT);
96+
}
97+
9198
public static Opinion unSignAutoSuccess() {
9299
return new Opinion("非会签自动审批", RESULT_PASS, TYPE_AUTO);
93100
}
@@ -104,6 +111,10 @@ public boolean isSuccess() {
104111
return result == RESULT_PASS;
105112
}
106113

114+
public boolean isWaiting() {
115+
return result == RESULT_WAITING;
116+
}
117+
107118
public boolean isReject() {
108119
return result == RESULT_REJECT;
109120
}

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowType.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public enum FlowType {
2020
/**
2121
* 转办
2222
*/
23-
TRANSFER;
23+
TRANSFER,
24+
/**
25+
* 等待执行
26+
*/
27+
WAITING;
2428

2529

2630
public static FlowType parser(String type){

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ public boolean isFinish() {
321321
return this.flowStatus == FlowStatus.FINISH;
322322
}
323323

324+
/**
325+
* 是否等待
326+
*/
327+
public boolean isWaiting() {
328+
return this.flowType == FlowType.WAITING;
329+
}
330+
324331
/**
325332
* 是否是待办
326333
*/

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ public void bindHistoryRecords(List<FlowRecord> historyRecords) {
4040
* 解析当前的审批方向
4141
*/
4242
public void loadFlowSourceDirection() {
43-
if (opinion.isSuccess()) {
43+
if (opinion.isSuccess() || opinion.isWaiting()) {
4444
flowSourceDirection = FlowSourceDirection.PASS;
4545
}
4646
if (opinion.isReject()) {
4747
flowSourceDirection = FlowSourceDirection.REJECT;
4848
}
4949
}
5050

51-
5251
/**
5352
* 重新加载审批方向
5453
* 根据会签结果判断是否需要重新设置审批方向

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private List<FlowRecord> createNextRecord() {
264264
String recordTitle = nextNode.generateTitle(flowSession);
265265
recordList = new ArrayList<>();
266266
for (IFlowOperator operator : operators) {
267-
FlowRecord record = nextNode.createRecord(workId, flowWork.getCode(), processId, preId, recordTitle, createOperator, operator, snapshot);
267+
FlowRecord record = nextNode.createRecord(workId, flowWork.getCode(), processId, preId, recordTitle, createOperator, operator, snapshot, opinion.isWaiting());
268268
recordList.add(record);
269269
}
270270
}
@@ -294,7 +294,7 @@ private List<FlowRecord> errMatcher(FlowNode currentNode, IFlowOperator currentO
294294
for (IFlowOperator operator : operators) {
295295
FlowSession content = new FlowSession(flowRecord, flowWork, currentNode, createOperator, operator, snapshot.toBindData(), opinion, historyRecords);
296296
String recordTitle = currentNode.generateTitle(content);
297-
FlowRecord record = currentNode.createRecord(flowWork.getId(), flowWork.getCode(), processId, preId, recordTitle, createOperator, operator, snapshot);
297+
FlowRecord record = currentNode.createRecord(flowWork.getId(), flowWork.getCode(), processId, preId, recordTitle, createOperator, operator, snapshot, opinion.isWaiting());
298298
recordList.add(record);
299299
}
300300
return recordList;
@@ -312,7 +312,7 @@ private List<FlowRecord> errMatcher(FlowNode currentNode, IFlowOperator currentO
312312
if (!matcherOperators.isEmpty()) {
313313
for (IFlowOperator matcherOperator : matcherOperators) {
314314
String recordTitle = node.generateTitle(content);
315-
FlowRecord record = node.createRecord(flowWork.getId(), flowWork.getCode(), processId, preId, recordTitle, createOperator, matcherOperator, snapshot);
315+
FlowRecord record = node.createRecord(flowWork.getId(), flowWork.getCode(), processId, preId, recordTitle, createOperator, matcherOperator, snapshot, opinion.isWaiting());
316316
recordList.add(record);
317317
}
318318
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ public FlowResult submitFlow(long recordId, IFlowOperator currentOperator, IBind
228228
return flowSubmitService.submitFlow();
229229
}
230230

231+
/**
232+
* 唤醒流程
233+
* @param processId 流程实例id
234+
* @param currentOperator 当前操作者
235+
*/
236+
public void notifyFlow(String processId,IFlowOperator currentOperator) {
237+
FlowNotifyService flowNotifyService = new FlowNotifyService(processId, currentOperator, flowServiceRepositoryHolder);
238+
flowNotifyService.notifyFlow();
239+
}
231240

232241
/**
233242
* 自定义事件
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.codingapi.springboot.flow.service.impl;
2+
3+
import com.codingapi.springboot.flow.bind.BindDataSnapshot;
4+
import com.codingapi.springboot.flow.domain.FlowWork;
5+
import com.codingapi.springboot.flow.em.FlowType;
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.FlowProcessRepository;
10+
import com.codingapi.springboot.flow.repository.FlowRecordRepository;
11+
import com.codingapi.springboot.flow.repository.FlowWorkRepository;
12+
import com.codingapi.springboot.flow.service.FlowServiceRepositoryHolder;
13+
import com.codingapi.springboot.flow.user.IFlowOperator;
14+
import com.codingapi.springboot.framework.event.EventPusher;
15+
import org.springframework.transaction.annotation.Transactional;
16+
17+
import java.util.List;
18+
import java.util.stream.Collectors;
19+
20+
@Transactional
21+
public class FlowNotifyService {
22+
23+
private final String processId;
24+
private final IFlowOperator currentOperator;
25+
private final FlowRecordRepository flowRecordRepository;
26+
private final FlowBindDataRepository flowBindDataRepository;
27+
private final FlowWorkRepository flowWorkRepository;
28+
private final FlowProcessRepository flowProcessRepository;
29+
30+
31+
public FlowNotifyService(String processId, IFlowOperator currentOperator, FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
32+
this.processId = processId;
33+
this.currentOperator = currentOperator;
34+
this.flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository();
35+
this.flowBindDataRepository = flowServiceRepositoryHolder.getFlowBindDataRepository();
36+
this.flowWorkRepository = flowServiceRepositoryHolder.getFlowWorkRepository();
37+
this.flowProcessRepository = flowServiceRepositoryHolder.getFlowProcessRepository();
38+
}
39+
40+
41+
/**
42+
* 获取流程设计对象
43+
*/
44+
public FlowWork loadFlowWork(FlowRecord flowRecord) {
45+
FlowWork flowWork = flowProcessRepository.getFlowWorkByProcessId(flowRecord.getProcessId());
46+
if (flowWork == null) {
47+
flowWork = flowWorkRepository.getFlowWorkByCode(flowRecord.getWorkCode());
48+
}
49+
if (flowWork == null) {
50+
throw new IllegalArgumentException("flow work not found");
51+
}
52+
flowWork.enableValidate();
53+
54+
return flowWork;
55+
}
56+
57+
/**
58+
* 流程通知
59+
*/
60+
public void notifyFlow() {
61+
List<FlowRecord> flowRecords = flowRecordRepository.findFlowRecordByProcessId(processId);
62+
List<FlowRecord> waitingRecords = flowRecords.stream().filter(FlowRecord::isWaiting).collect(Collectors.toList());
63+
for (FlowRecord flowRecord : waitingRecords) {
64+
if (flowRecord.isOperator(currentOperator)) {
65+
flowRecord.setFlowType(FlowType.TODO);
66+
flowRecordRepository.update(flowRecord);
67+
68+
BindDataSnapshot snapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId());
69+
70+
FlowWork flowWork = this.loadFlowWork(flowRecord);
71+
72+
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_TODO,
73+
flowRecord,
74+
flowRecord.getCurrentOperator(),
75+
flowWork,
76+
snapshot.toBindData()
77+
), true);
78+
}
79+
}
80+
}
81+
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private void updateFinishFlowRecord() {
209209
}
210210

211211
// 保存流程记录
212-
private void saveFlowRecords(List<FlowRecord> flowRecords) {
212+
private void saveNextFlowRecords(List<FlowRecord> flowRecords) {
213213
flowServiceRepositoryHolder.getFlowRecordRepository().save(flowRecords);
214214
}
215215

@@ -313,15 +313,17 @@ private FlowResult submitCurrentFlow() {
313313
}
314314

315315
// 保存流程记录
316-
this.saveFlowRecords(nextRecords);
316+
this.saveNextFlowRecords(nextRecords);
317317

318318
// 推送审批事件消息
319319
int eventState = flowSourceDirection == FlowSourceDirection.PASS ? FlowApprovalEvent.STATE_PASS : FlowApprovalEvent.STATE_REJECT;
320320
this.pushEvent(flowRecord, eventState);
321321

322322
// 推送待办事件消息
323323
for (FlowRecord record : nextRecords) {
324-
this.pushEvent(record, FlowApprovalEvent.STATE_TODO);
324+
if(record.isTodo()) {
325+
this.pushEvent(record, FlowApprovalEvent.STATE_TODO);
326+
}
325327
}
326328

327329
return new FlowResult(flowWork, nextRecords);

springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowTest2.java

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class FlowTest2 {
3030
private final FlowService flowService = new FlowService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, userRepository,flowProcessRepository,flowBackupRepository);
3131

3232
/**
33-
* flow test
33+
* 转办测试
3434
*/
3535
@Test
3636
void flowTest() {
@@ -107,4 +107,72 @@ void flowTest() {
107107
assertTrue(records.stream().allMatch(FlowRecord::isFinish));
108108

109109
}
110+
111+
112+
/**
113+
* 流程等待测试
114+
*/
115+
@Test
116+
void flowWaitingTest() {
117+
PageRequest pageRequest = PageRequest.of(0, 1000);
118+
User lorne = new User("lorne");
119+
userRepository.save(lorne);
120+
121+
User boss = new User("boss");
122+
userRepository.save(boss);
123+
124+
FlowWork flowWork = FlowWorkBuilder.builder(lorne)
125+
.title("请假流程")
126+
.nodes()
127+
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
128+
.node("老板审批", "boss", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(boss.getUserId()))
129+
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
130+
.relations()
131+
.relation("老板审批", "start", "boss")
132+
.relation("结束节点", "boss", "over")
133+
.build();
134+
135+
flowWorkRepository.save(flowWork);
136+
137+
String workCode = flowWork.getCode();
138+
139+
Leave leave = new Leave("我想要出去看看");
140+
leaveRepository.save(leave);
141+
142+
// 创建流程
143+
flowService.startFlow(workCode, lorne, leave, "发起流程");
144+
145+
// 查看我的待办
146+
List<FlowRecord> userTodos = flowRecordRepository.findTodoByOperatorId(lorne.getUserId(), pageRequest).getContent();
147+
assertEquals(1, userTodos.size());
148+
149+
String processId = userTodos.get(0).getProcessId();
150+
151+
FlowRecord userTodo = userTodos.get(0);
152+
flowService.submitFlow(userTodo.getId(), lorne, leave, Opinion.waiting("自己先提交"));
153+
154+
// 查看boss的待办
155+
List<FlowRecord> bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
156+
assertEquals(0, bossTodos.size());
157+
158+
// 通知流程
159+
flowService.notifyFlow(processId,boss);
160+
161+
// 查看boss的待办
162+
bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
163+
assertEquals(1, bossTodos.size());
164+
165+
FlowRecord bossTodo = bossTodos.get(0);
166+
flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.pass("领导审批通过"));
167+
168+
bossTodos = flowRecordRepository.findTodoByOperatorId(lorne.getUserId(), pageRequest).getContent();
169+
assertEquals(0, bossTodos.size());
170+
171+
List<FlowRecord> records = flowRecordRepository.findAll(pageRequest).getContent();
172+
assertEquals(2, records.size());
173+
174+
// 查看所有流程是否都已经结束
175+
assertTrue(records.stream().allMatch(FlowRecord::isFinish));
176+
177+
}
110178
}

springboot-starter-security/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.9.27</version>
9+
<version>2.9.28</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security</artifactId>

springboot-starter/pom.xml

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
------------------------------------------------------
2-
CodingApi SpringBoot-Starter 2.9.27
2+
CodingApi SpringBoot-Starter 2.9.28
33
springboot version (${spring-boot.version})
44
------------------------------------------------------

0 commit comments

Comments
 (0)