Skip to content

Commit b9569fc

Browse files
committed
fix trySubmit
1 parent f8b8177 commit b9569fc

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/pojo/FlowResult.java

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codingapi.springboot.flow.domain.FlowWork;
44
import com.codingapi.springboot.flow.record.FlowRecord;
5+
import com.codingapi.springboot.flow.user.IFlowOperator;
56
import lombok.Getter;
67

78
import java.util.ArrayList;
@@ -23,4 +24,14 @@ public FlowResult(FlowWork flowWork,FlowRecord flowRecord) {
2324
this.records = new ArrayList<>();
2425
this.records.add(flowRecord);
2526
}
27+
28+
/**
29+
* 匹配操作者的记录
30+
* @param operator 操作者
31+
* @return 记录
32+
*/
33+
public List<FlowRecord> matchRecordByOperator(IFlowOperator operator){
34+
return records.stream().filter(record -> record.isOperator(operator)).toList();
35+
}
36+
2637
}

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

+32
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,33 @@ private void pushEvent(FlowRecord flowRecord, int eventState) {
218218
), true);
219219
}
220220

221+
222+
/**
223+
* 提交流程 根据流程的是否跳过相同审批人来判断是否需要继续提交
224+
* @return 流程结果
225+
*/
221226
public FlowResult submitFlow() {
227+
FlowResult flowResult = this.submitCurrentFlow();
228+
if (this.isSkipIfSameApprover()) {
229+
List<FlowRecord> flowRecords = flowResult.matchRecordByOperator(currentOperator);
230+
FlowResult result = flowResult;
231+
if (!flowRecords.isEmpty()) {
232+
for (FlowRecord flowRecord : flowRecords) {
233+
FlowSubmitService flowSubmitService = new FlowSubmitService(flowRecord.getId(), currentOperator, bindData, opinion, flowServiceRepositoryHolder);
234+
result = flowSubmitService.submitCurrentFlow();
235+
}
236+
}
237+
return result;
238+
} else {
239+
return flowResult;
240+
}
241+
}
242+
243+
/**
244+
* 提交当前流程
245+
* @return 流程结果
246+
*/
247+
private FlowResult submitCurrentFlow() {
222248
// 加载流程信息
223249
this.loadFlow(false);
224250

@@ -340,4 +366,10 @@ public FlowSubmitResult trySubmitFlow() {
340366
List<? extends IFlowOperator> operators = flowNodeService.loadNextNodeOperators();
341367
return new FlowSubmitResult(flowWork, nextNode, operators);
342368
}
369+
370+
371+
// 是否跳过相同审批人
372+
public boolean isSkipIfSameApprover() {
373+
return flowWork.isSkipIfSameApprover();
374+
}
343375
}

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

+78
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,84 @@ void entrustTest() {
131131

132132

133133

134+
/**
135+
* 自己审批时直接通过
136+
*/
137+
@Test
138+
void sameUserFlow() {
139+
PageRequest pageRequest = PageRequest.of(0, 1000);
140+
141+
User user = new User("张飞");
142+
userRepository.save(user);
143+
144+
User dept = new User("刘备");
145+
userRepository.save(dept);
146+
147+
User boss = new User("诸葛亮");
148+
userRepository.save(boss);
149+
150+
FlowWork flowWork = FlowWorkBuilder.builder(user)
151+
.title("请假流程")
152+
.skipIfSameApprover(true)
153+
.nodes()
154+
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
155+
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
156+
.node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
157+
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
158+
.relations()
159+
.relation("部门领导审批", "start", "dept")
160+
.relation("总经理审批", "dept", "manager")
161+
.relation("结束节点", "manager", "over")
162+
.build();
163+
164+
flowWorkRepository.save(flowWork);
165+
166+
String workCode = flowWork.getCode();
167+
168+
Leave leave = new Leave("我要出去看看");
169+
leaveRepository.save(leave);
170+
171+
// 创建流程
172+
flowService.startFlow(workCode, user, leave, "发起流程");
173+
174+
// 查看我的待办
175+
List<FlowRecord> userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
176+
assertEquals(1, userTodos.size());
177+
178+
// 提交流程
179+
FlowRecord userTodo = userTodos.get(0);
180+
assertEquals(0, userTodo.getTimeoutTime());
181+
182+
flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意"));
183+
184+
// 查看刘备经理的待办
185+
List<FlowRecord> deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
186+
assertEquals(1, deptTodos.size());
187+
188+
// 提交委托dept部门经理的审批
189+
FlowRecord deptTodo = deptTodos.get(0);
190+
flowService.submitFlow(deptTodo.getId(), dept, leave, Opinion.pass("同意"));
191+
192+
// 查看所有流程
193+
List<FlowRecord> records = flowRecordRepository.findAll(pageRequest).getContent();
194+
assertEquals(3, records.size());
195+
196+
userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
197+
assertEquals(0, userTodos.size());
198+
199+
records = flowRecordRepository.findAll(pageRequest).getContent();
200+
assertEquals(3, records.size());
201+
// 查看所有流程是否都已经结束
202+
assertTrue(records.stream().allMatch(FlowRecord::isFinish));
203+
204+
List<BindDataSnapshot> snapshots = flowBindDataRepository.findAll();
205+
assertEquals(4, snapshots.size());
206+
207+
}
208+
209+
210+
211+
134212
/**
135213
* 同意再拒绝
136214
*/

0 commit comments

Comments
 (0)