Skip to content

Commit d78830d

Browse files
committed
fix flow bug
1 parent bb754dd commit d78830d

File tree

13 files changed

+470
-76
lines changed

13 files changed

+470
-76
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.10.10</version>
18+
<version>2.10.11</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.10</version>
9+
<version>2.10.11</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.10</version>
8+
<version>2.10.11</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.10</version>
9+
<version>2.10.11</version>
1010
</parent>
1111

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

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public void loadFlowSourceDirection() {
4848
}
4949
}
5050

51+
5152
/**
5253
* 重新加载审批方向
5354
* 根据会签结果判断是否需要重新设置审批方向
@@ -84,38 +85,12 @@ public boolean hasCurrentFlowNodeIsDone() {
8485
return historyRecords.stream().filter(item -> !item.isTransfer()).allMatch(FlowRecord::isDone);
8586
}
8687

87-
88-
/**
89-
* 检测当前流程是否已经完成
90-
* 即流程已经进行到了最终节点且审批意见为同意
91-
*/
92-
public boolean hasCurrentFlowIsFinish() {
93-
if (flowSourceDirection == FlowSourceDirection.PASS && flowNode.isOverNode()) {
94-
return true;
95-
}
96-
return false;
97-
}
98-
99-
100-
/**
101-
* 判断当前流程是否为默认的驳回流程
102-
*/
103-
public boolean isDefaultBackRecord() {
104-
return flowSourceDirection == FlowSourceDirection.REJECT && !flowWork.hasBackRelation();
105-
}
106-
10788
/**
10889
* 判断当前流程是否为通过流程
10990
*/
11091
public boolean isPassRecord() {
11192
return flowSourceDirection == FlowSourceDirection.PASS;
11293
}
11394

114-
/**
115-
* 判断当前流程是否为自定义的驳回流程
116-
*/
117-
public boolean isCustomBackRecord() {
118-
return flowSourceDirection == FlowSourceDirection.REJECT && flowWork.hasBackRelation();
119-
}
12095

12196
}

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,6 @@ public void loadDefaultBackNode(FlowRecord currentRecord) {
146146
}
147147

148148

149-
/**
150-
* 加载自定义回退节点
151-
*/
152-
public void loadCustomBackNode(FlowNode flowNode, long parentRecordId) {
153-
FlowNode nextNode = this.matcherNextNode(flowNode, true);
154-
if (nextNode == null) {
155-
throw new IllegalArgumentException("next node not found");
156-
}
157-
IFlowOperator flowOperator = currentOperator;
158-
if (nextNode.isAnyOperatorMatcher()) {
159-
// 如果是任意人员操作时则需要指定为当时审批人员为当前审批人员
160-
FlowRecord preFlowRecord = flowRecordRepository.getFlowRecordById(parentRecordId);
161-
while (preFlowRecord.isTransfer() || !preFlowRecord.getNodeCode().equals(nextNode.getCode())) {
162-
preFlowRecord = flowRecordRepository.getFlowRecordById(preFlowRecord.getPreId());
163-
}
164-
flowOperator = preFlowRecord.getCurrentOperator();
165-
}
166-
this.nextNode = nextNode;
167-
this.nextOperator = flowOperator;
168-
this.backOperator = null;
169-
}
170-
171149

172150
/**
173151
* 获取下一个节点

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,8 @@ private void loadNextNode(List<FlowRecord> historyRecords) {
192192
// 审批通过并进入下一节点
193193
if (flowDirectionService.isPassRecord()) {
194194
flowNodeService.loadNextPassNode(flowNode);
195-
// 审批拒绝返回上一节点
196-
} else if (flowDirectionService.isDefaultBackRecord()) {
195+
} else {
197196
flowNodeService.loadDefaultBackNode(flowRecord);
198-
} else {
199-
// 审批拒绝,并且自定了返回节点
200-
flowNodeService.loadCustomBackNode(flowNode, flowRecord.getPreId());
201197
}
202198
this.nextNode = flowNodeService.getNextNode();
203199
}
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
package com.codingapi.springboot.flow.test;
2+
3+
import com.codingapi.springboot.flow.bind.BindDataSnapshot;
4+
import com.codingapi.springboot.flow.build.FlowWorkBuilder;
5+
import com.codingapi.springboot.flow.domain.FlowWork;
6+
import com.codingapi.springboot.flow.domain.Opinion;
7+
import com.codingapi.springboot.flow.em.ApprovalType;
8+
import com.codingapi.springboot.flow.flow.Leave;
9+
import com.codingapi.springboot.flow.matcher.OperatorMatcher;
10+
import com.codingapi.springboot.flow.pojo.FlowResult;
11+
import com.codingapi.springboot.flow.record.FlowRecord;
12+
import com.codingapi.springboot.flow.repository.*;
13+
import com.codingapi.springboot.flow.service.FlowService;
14+
import com.codingapi.springboot.flow.trigger.OutTrigger;
15+
import com.codingapi.springboot.flow.user.User;
16+
import org.junit.jupiter.api.Test;
17+
import org.springframework.data.domain.PageRequest;
18+
19+
import java.util.List;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
24+
public class FlowRejectTest {
25+
26+
private final UserRepository userRepository = new UserRepository();
27+
private final FlowWorkRepository flowWorkRepository = new FlowWorkRepositoryImpl();
28+
private final FlowRecordRepositoryImpl flowRecordRepository = new FlowRecordRepositoryImpl();
29+
private final FlowBindDataRepositoryImpl flowBindDataRepository = new FlowBindDataRepositoryImpl();
30+
private final LeaveRepository leaveRepository = new LeaveRepository();
31+
private final FlowBackupRepository flowBackupRepository = new FlowBackupRepositoryImpl();
32+
private final FlowProcessRepository flowProcessRepository = new FlowProcessRepositoryImpl(flowBackupRepository, userRepository);
33+
private final FlowService flowService = new FlowService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, userRepository, flowProcessRepository, flowBackupRepository);
34+
35+
/**
36+
* 驳回测试
37+
*/
38+
@Test
39+
void reject1() {
40+
PageRequest pageRequest = PageRequest.of(0, 1000);
41+
42+
User lorne = new User("lorne");
43+
userRepository.save(lorne);
44+
45+
User user = new User("张飞");
46+
userRepository.save(user);
47+
48+
User dept = new User("刘备");
49+
userRepository.save(dept);
50+
51+
User boss = new User("诸葛亮");
52+
userRepository.save(boss);
53+
54+
FlowWork flowWork = FlowWorkBuilder.builder(user)
55+
.title("请假流程")
56+
.nodes()
57+
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
58+
.node("部门领导审批", "dept", "default", ApprovalType.SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId(),lorne.getUserId()))
59+
.node("总经理审批", "manager", "default", ApprovalType.SIGN, OperatorMatcher.specifyOperatorMatcher(boss.getUserId()))
60+
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
61+
.relations()
62+
.relation("部门领导审批", "start", "dept")
63+
.relation("总经理审批", "dept", "manager")
64+
.relation("总经理审批", "dept", "start",new OutTrigger(" def run(content) {\n" +
65+
" return false;\n" +
66+
" }"),1,true)
67+
.relation("结束节点", "manager", "over")
68+
.build();
69+
70+
flowWorkRepository.save(flowWork);
71+
72+
String workCode = flowWork.getCode();
73+
74+
Leave leave = new Leave("我要出去看看");
75+
leaveRepository.save(leave);
76+
77+
// 创建流程
78+
flowService.startFlow(workCode, user, leave, "发起流程");
79+
80+
// 查看我的待办
81+
List<FlowRecord> userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
82+
assertEquals(1, userTodos.size());
83+
84+
// 提交流程
85+
FlowRecord userTodo = userTodos.get(0);
86+
assertEquals(0, userTodo.getTimeoutTime());
87+
88+
flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意").specify(lorne.getUserId()));
89+
90+
// 查看刘备经理的待办
91+
List<FlowRecord> deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
92+
assertEquals(0, deptTodos.size());
93+
94+
List<FlowRecord> lorneTodos = flowRecordRepository.findTodoByOperatorId(lorne.getUserId(), pageRequest).getContent();
95+
assertEquals(1, lorneTodos.size());
96+
97+
// 提交委托lorne部门经理的审批
98+
FlowRecord lorneTodo = lorneTodos.get(0);
99+
flowService.submitFlow(lorneTodo.getId(), lorne, leave, Opinion.pass("同意"));
100+
101+
// 查看总经理的待办
102+
List<FlowRecord> bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
103+
assertEquals(1, bossTodos.size());
104+
105+
// 提交总经理的审批
106+
FlowRecord bossTodo = bossTodos.get(0);
107+
FlowResult flowResult = flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.reject("不同意"));
108+
System.out.println(flowResult.getRecords());
109+
110+
deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
111+
assertEquals(0, deptTodos.size());
112+
113+
lorneTodos = flowRecordRepository.findTodoByOperatorId(lorne.getUserId(), pageRequest).getContent();
114+
assertEquals(1, lorneTodos.size());
115+
116+
lorneTodo = lorneTodos.get(0);
117+
flowService.submitFlow(lorneTodo.getId(), lorne, leave, Opinion.pass("同意"));
118+
119+
bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
120+
assertEquals(1, bossTodos.size());
121+
122+
bossTodo = bossTodos.get(0);
123+
flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.pass("同意"));
124+
125+
// 查看所有流程
126+
List<FlowRecord> records = flowRecordRepository.findAll(pageRequest).getContent();
127+
assertEquals(5, records.size());
128+
129+
records = flowRecordRepository.findAll(pageRequest).getContent();
130+
assertEquals(5, records.size());
131+
// 查看所有流程是否都已经结束
132+
assertTrue(records.stream().allMatch(FlowRecord::isFinish));
133+
134+
List<BindDataSnapshot> snapshots = flowBindDataRepository.findAll();
135+
assertEquals(6, snapshots.size());
136+
137+
}
138+
139+
140+
141+
/**
142+
* 驳回测试
143+
*/
144+
@Test
145+
void reject2() {
146+
PageRequest pageRequest = PageRequest.of(0, 1000);
147+
148+
User lorne = new User("lorne");
149+
userRepository.save(lorne);
150+
151+
User user = new User("张飞");
152+
userRepository.save(user);
153+
154+
User dept = new User("刘备");
155+
userRepository.save(dept);
156+
157+
User boss = new User("诸葛亮");
158+
userRepository.save(boss);
159+
160+
FlowWork flowWork = FlowWorkBuilder.builder(user)
161+
.title("请假流程")
162+
.nodes()
163+
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
164+
.node("部门领导审批", "dept", "default", ApprovalType.SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId(),lorne.getUserId()))
165+
.node("总经理审批", "manager", "default", ApprovalType.SIGN, OperatorMatcher.specifyOperatorMatcher(boss.getUserId()))
166+
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
167+
.relations()
168+
.relation("部门领导审批", "start", "dept")
169+
.relation("总经理审批", "dept", "manager")
170+
.relation("结束节点", "manager", "over")
171+
.build();
172+
173+
flowWorkRepository.save(flowWork);
174+
175+
String workCode = flowWork.getCode();
176+
177+
Leave leave = new Leave("我要出去看看");
178+
leaveRepository.save(leave);
179+
180+
// 创建流程
181+
flowService.startFlow(workCode, user, leave, "发起流程");
182+
183+
// 查看我的待办
184+
List<FlowRecord> userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
185+
assertEquals(1, userTodos.size());
186+
187+
// 提交流程
188+
FlowRecord userTodo = userTodos.get(0);
189+
assertEquals(0, userTodo.getTimeoutTime());
190+
191+
flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意").specify(lorne.getUserId()));
192+
193+
// 查看刘备经理的待办
194+
List<FlowRecord> deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
195+
assertEquals(0, deptTodos.size());
196+
197+
List<FlowRecord> lorneTodos = flowRecordRepository.findTodoByOperatorId(lorne.getUserId(), pageRequest).getContent();
198+
assertEquals(1, lorneTodos.size());
199+
200+
// 提交委托lorne部门经理的审批
201+
FlowRecord lorneTodo = lorneTodos.get(0);
202+
flowService.submitFlow(lorneTodo.getId(), lorne, leave, Opinion.pass("同意"));
203+
204+
// 查看总经理的待办
205+
List<FlowRecord> bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
206+
assertEquals(1, bossTodos.size());
207+
208+
// 提交总经理的审批
209+
FlowRecord bossTodo = bossTodos.get(0);
210+
FlowResult flowResult = flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.reject("不同意"));
211+
System.out.println(flowResult.getRecords());
212+
213+
deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
214+
assertEquals(0, deptTodos.size());
215+
216+
lorneTodos = flowRecordRepository.findTodoByOperatorId(lorne.getUserId(), pageRequest).getContent();
217+
assertEquals(1, lorneTodos.size());
218+
219+
lorneTodo = lorneTodos.get(0);
220+
flowService.submitFlow(lorneTodo.getId(), lorne, leave, Opinion.pass("同意"));
221+
222+
bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
223+
assertEquals(1, bossTodos.size());
224+
225+
bossTodo = bossTodos.get(0);
226+
flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.pass("同意"));
227+
228+
// 查看所有流程
229+
List<FlowRecord> records = flowRecordRepository.findAll(pageRequest).getContent();
230+
assertEquals(5, records.size());
231+
232+
records = flowRecordRepository.findAll(pageRequest).getContent();
233+
assertEquals(5, records.size());
234+
// 查看所有流程是否都已经结束
235+
assertTrue(records.stream().allMatch(FlowRecord::isFinish));
236+
237+
List<BindDataSnapshot> snapshots = flowBindDataRepository.findAll();
238+
assertEquals(6, snapshots.size());
239+
240+
}
241+
242+
}

0 commit comments

Comments
 (0)