Skip to content

Commit 9ede252

Browse files
committed
update 2.9.29
1 parent a50655d commit 9ede252

File tree

12 files changed

+168
-27
lines changed

12 files changed

+168
-27
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.28</version>
18+
<version>2.9.29</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.28</version>
9+
<version>2.9.29</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.28</version>
8+
<version>2.9.29</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.28</version>
9+
<version>2.9.29</version>
1010
</parent>
1111

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

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/content/FlowSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
@Getter
2525
public class FlowSession {
2626

27-
// 当前的流程记录
27+
// 当前的流程记录(当前审批的流程)
2828
private final FlowRecord flowRecord;
2929
// 当前的流程设计器
3030
private final FlowWork flowWork;
3131
// 当前的流程节点
3232
private final FlowNode flowNode;
3333
// 流程的创建者
3434
private final IFlowOperator createOperator;
35-
// 当前的操作者
35+
// 当前的操作者(当前的操作者,非代办人)
3636
private final IFlowOperator currentOperator;
3737
// 流程绑定数据
3838
private final IBindData bindData;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ public boolean isTransfer() {
344344
return this.flowType == FlowType.TRANSFER;
345345
}
346346

347+
348+
/**
349+
* 拒绝状态
350+
*/
351+
public boolean isReject() {
352+
return this.opinion != null && this.opinion.isReject() && isDone();
353+
}
354+
347355
/**
348356
* 审批通过
349357
*/

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

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,44 @@ public void skipCirculate() {
101101
/**
102102
* 加载默认回退节点
103103
*/
104-
public void loadDefaultBackNode(long parentRecordId) {
105-
IFlowOperator flowOperator;
106-
// 拒绝时,默认返回上一个已办节点
107-
FlowRecord preRecord = flowRecordRepository.getFlowRecordById(parentRecordId);
108-
// 只寻找已办节点
109-
while (!preRecord.isDone()) {
110-
// 继续寻找上一个节点
111-
preRecord = flowRecordRepository.getFlowRecordById(preRecord.getPreId());
112-
}
113-
// 获取上一个节点的审批者,继续将审批者设置为当前审批者
114-
flowOperator = preRecord.getCurrentOperator();
115-
FlowNode nextNode = flowWork.getNodeByCode(preRecord.getNodeCode());
116-
if (nextNode == null) {
117-
throw new IllegalArgumentException("next node not found");
104+
public void loadDefaultBackNode(FlowRecord currentRecord) {
105+
List<FlowRecord> historyRecords =
106+
flowRecordRepository.findFlowRecordByProcessId(currentRecord.getProcessId())
107+
.stream()
108+
.sorted((o1, o2) -> (int) (o2.getId() - o1.getId()))
109+
.filter(record -> record.getId() < currentRecord.getId())
110+
.collect(Collectors.toList());
111+
112+
int index = 0;
113+
while (true) {
114+
if (index >= historyRecords.size()) {
115+
throw new IllegalArgumentException("back node not found");
116+
}
117+
FlowRecord record = historyRecords.get(index);
118+
if (record.isDone()) {
119+
// 是连续的回退节点时,则根据流程记录的状态来判断
120+
if(record.isReject()){
121+
boolean startRemove = false;
122+
for(FlowRecord historyRecord: historyRecords){
123+
if(startRemove){
124+
this.nextNode = flowWork.getNodeByCode(historyRecord.getNodeCode());
125+
this.nextOperator = historyRecord.getCurrentOperator();
126+
this.backOperator = historyRecord.getCurrentOperator();
127+
return;
128+
}
129+
if(historyRecord.getNodeCode().equals(currentRecord.getNodeCode())){
130+
startRemove = true;
131+
}
132+
}
133+
}else {
134+
this.nextNode = flowWork.getNodeByCode(record.getNodeCode());
135+
this.nextOperator = record.getCurrentOperator();
136+
this.backOperator = record.getCurrentOperator();
137+
return;
138+
}
139+
}
140+
index++;
118141
}
119-
this.nextNode = nextNode;
120-
this.nextOperator = flowOperator;
121-
this.backOperator = flowOperator;
122142
}
123143

124144

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private void loadNextNode(List<FlowRecord> historyRecords) {
194194
flowNodeService.loadNextPassNode(flowNode);
195195
// 审批拒绝返回上一节点
196196
} else if (flowDirectionService.isDefaultBackRecord()) {
197-
flowNodeService.loadDefaultBackNode(flowRecord.getPreId());
197+
flowNodeService.loadDefaultBackNode(flowRecord);
198198
} else {
199199
// 审批拒绝,并且自定了返回节点
200200
flowNodeService.loadCustomBackNode(flowNode, flowRecord.getPreId());

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

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.codingapi.springboot.flow.em.ApprovalType;
88
import com.codingapi.springboot.flow.flow.Leave;
99
import com.codingapi.springboot.flow.matcher.OperatorMatcher;
10+
import com.codingapi.springboot.flow.pojo.FlowDetail;
1011
import com.codingapi.springboot.flow.record.FlowRecord;
1112
import com.codingapi.springboot.flow.repository.*;
1213
import com.codingapi.springboot.flow.service.FlowService;
@@ -175,4 +176,116 @@ void flowWaitingTest() {
175176
assertTrue(records.stream().allMatch(FlowRecord::isFinish));
176177

177178
}
179+
180+
181+
/**
182+
* 部门拒绝再提交测试
183+
*/
184+
@Test
185+
void rejectTest() {
186+
PageRequest pageRequest = PageRequest.of(0, 1000);
187+
188+
User user = new User("张飞");
189+
userRepository.save(user);
190+
191+
User dept = new User("刘备");
192+
userRepository.save(dept);
193+
194+
User boss = new User("诸葛亮");
195+
userRepository.save(boss);
196+
197+
FlowWork flowWork = FlowWorkBuilder.builder(user)
198+
.title("请假流程")
199+
.nodes()
200+
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
201+
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
202+
.node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(boss.getUserId()))
203+
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
204+
.relations()
205+
.relation("部门领导审批", "start", "dept")
206+
.relation("总经理审批", "dept", "manager")
207+
.relation("结束节点", "manager", "over")
208+
.build();
209+
210+
flowWorkRepository.save(flowWork);
211+
212+
String workCode = flowWork.getCode();
213+
214+
Leave leave = new Leave("我要出去看看");
215+
leaveRepository.save(leave);
216+
217+
// 创建流程
218+
flowService.startFlow(workCode, user, leave, "发起流程");
219+
220+
// 查看我的待办
221+
List<FlowRecord> userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
222+
assertEquals(1, userTodos.size());
223+
224+
// 提交流程
225+
FlowRecord userTodo = userTodos.get(0);
226+
227+
// 查看流程详情
228+
FlowDetail flowDetail = flowService.detail(userTodo.getId());
229+
assertEquals("我要出去看看", ((Leave) flowDetail.getBindData()).getTitle());
230+
assertTrue(flowDetail.getFlowRecord().isUnRead());
231+
232+
233+
flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意"));
234+
235+
// 查看部门经理的待办
236+
List<FlowRecord> deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
237+
assertEquals(1, deptTodos.size());
238+
239+
// 提交部门经理的审批
240+
FlowRecord deptTodo = deptTodos.get(0);
241+
flowService.submitFlow(deptTodo.getId(), dept, leave, Opinion.pass("同意"));
242+
243+
// 查看老板审批
244+
List<FlowRecord> bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
245+
assertEquals(1, bossTodos.size());
246+
247+
// 老板审批不通过
248+
FlowRecord bossTodo = bossTodos.get(0);
249+
flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.reject("不同意"));
250+
251+
// 部门经理查看到流程
252+
deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
253+
assertEquals(1, deptTodos.size());
254+
255+
// 提交部门经理的审批
256+
deptTodo = deptTodos.get(0);
257+
flowService.submitFlow(deptTodo.getId(), dept, leave, Opinion.reject("不同意"));
258+
259+
// 查看用户的待办
260+
userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
261+
assertEquals(1, userTodos.size());
262+
263+
// 用户再次提交
264+
userTodo = userTodos.get(0);
265+
flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意"));
266+
267+
// 部门经理查看到流程
268+
deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
269+
assertEquals(1, deptTodos.size());
270+
271+
// 提交部门经理的审批
272+
deptTodo = deptTodos.get(0);
273+
flowService.submitFlow(deptTodo.getId(), dept, leave, Opinion.pass("同意"));
274+
275+
// 查看老板审批
276+
bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
277+
assertEquals(1, bossTodos.size());
278+
279+
// 老板审批通过
280+
bossTodo = bossTodos.get(0);
281+
flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.pass("同意"));
282+
283+
284+
List<FlowRecord> records = flowRecordRepository.findAll(pageRequest).getContent();
285+
assertEquals(7, records.size());
286+
287+
// 查看所有流程是否都已经结束
288+
assertTrue(records.stream().allMatch(FlowRecord::isFinish));
289+
290+
}
178291
}

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.28</version>
9+
<version>2.9.29</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.28</version>
8+
<version>2.9.29</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.28
2+
CodingApi SpringBoot-Starter 2.9.29
33
springboot version (${spring-boot.version})
44
------------------------------------------------------

0 commit comments

Comments
 (0)