Skip to content

Commit 8624a28

Browse files
authored
Merge pull request #118 from codingapi/dev
Dev
2 parents f6f9d91 + e982904 commit 8624a28

File tree

29 files changed

+333
-33
lines changed

29 files changed

+333
-33
lines changed

example/example-app/example-app-cmd-domain/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-app</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-app/example-app-cmd-meta/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-app</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-app/example-app-query/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-app</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-example</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212
<packaging>pom</packaging>

example/example-domain/example-domain-leave/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-domain</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-domain/example-domain-user/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-domain</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-domain/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-example</artifactId>
8-
<version>3.4.4</version>
8+
<version>3.4.6</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

example/example-infra/example-infra-flow/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>example-infra</artifactId>
8-
<version>3.4.4</version>
8+
<version>3.4.6</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

example/example-infra/example-infra-jpa/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>example-infra</artifactId>
8-
<version>3.4.4</version>
8+
<version>3.4.6</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

example/example-infra/example-infra-security/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>example-infra</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-infra/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-example</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212
<packaging>pom</packaging>

example/example-interface/pom.xml

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

1212
<artifactId>example-interface</artifactId>

example/example-server/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-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.4.4</version>
8+
<version>3.4.6</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</parent>
2020

2121
<artifactId>springboot-example</artifactId>
22-
<version>3.4.4</version>
22+
<version>3.4.6</version>
2323

2424
<name>springboot-example</name>
2525
<description>springboot-example project for Spring Boot</description>

pom.xml

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

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>3.4.4</version>
15+
<version>3.4.6</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<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
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-parent</artifactId>
9-
<version>3.4.4</version>
9+
<version>3.4.6</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>3.4.4</version>
8+
<version>3.4.6</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>3.4.4</version>
9+
<version>3.4.6</version>
1010
</parent>
1111

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

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
@AllArgsConstructor
1818
public class FlowRelation {
1919

20+
public static final int DEFAULT_ORDER = -100;
21+
2022
/**
2123
* 关系id
2224
*/
@@ -38,7 +40,7 @@ public class FlowRelation {
3840
private FlowNode target;
3941

4042
/**
41-
* 排序
43+
* 排序 (顺序越大的排序越靠前)
4244
*/
4345
private int order;
4446

@@ -145,12 +147,12 @@ public void verify() {
145147
throw new RuntimeException("outTrigger is null");
146148
}
147149

148-
if(source.getCode().equals(target.getCode())){
150+
if (source.getCode().equals(target.getCode())) {
149151
throw new RuntimeException("source node code is equals target node code");
150152
}
151153

152-
if(back){
153-
if(source.getType() != NodeType.APPROVAL){
154+
if (back) {
155+
if (source.getType() != NodeType.APPROVAL) {
154156
throw new RuntimeException("source node type is not approval");
155157
}
156158
}

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.codingapi.springboot.flow.record.FlowRecord;
1414
import com.codingapi.springboot.flow.repository.FlowOperatorRepository;
1515
import com.codingapi.springboot.flow.repository.FlowRecordRepository;
16+
import com.codingapi.springboot.flow.trigger.OutTrigger;
1617
import com.codingapi.springboot.flow.user.IFlowOperator;
1718
import com.codingapi.springboot.framework.event.EventPusher;
1819
import lombok.Getter;
@@ -113,7 +114,7 @@ public void loadDefaultBackNode(FlowRecord currentRecord) {
113114
throw new IllegalArgumentException("back node not found");
114115
}
115116
FlowRecord record = historyRecords.get(index);
116-
if (record.isDone()) {
117+
if (record.isDone() && record.getId()== currentRecord.getPreId()) {
117118
// 是连续的回退节点时,则根据流程记录的状态来判断
118119
if(record.isReject()){
119120
boolean startRemove = false;
@@ -172,7 +173,28 @@ public void loadCustomBackNode(FlowNode flowNode, long parentRecordId) {
172173
* @return 下一个节点
173174
*/
174175
private FlowNode matcherNextNode(FlowNode flowNode, boolean back) {
175-
List<FlowRelation> relations = flowWork.getRelations().stream()
176+
List<FlowRelation> currentRelations = new ArrayList<>(flowWork.getRelations());
177+
if(back){
178+
String preCode = FlowNode.CODE_START;
179+
if(flowRecord.getPreId()!=0){
180+
FlowRecord preRecord = flowRecordRepository.getFlowRecordById(flowRecord.getPreId());
181+
if(preRecord!=null){
182+
preCode = preRecord.getNodeCode();
183+
while (preCode.equals(flowRecord.getNodeCode())){
184+
preRecord = flowRecordRepository.getFlowRecordById(preRecord.getPreId());
185+
if(preRecord==null){
186+
break;
187+
}
188+
preCode = preRecord.getNodeCode();
189+
}
190+
}
191+
}
192+
FlowRelation backRelation = new FlowRelation("defaultId",
193+
"默认回退关系", flowNode, flowWork.getNodeByCode(preCode), OutTrigger.defaultOutTrigger(), FlowRelation.DEFAULT_ORDER, true);
194+
currentRelations.add(backRelation);
195+
}
196+
197+
List<FlowRelation> relations = currentRelations.stream()
176198
.filter(relation -> relation.sourceMatcher(flowNode.getCode()))
177199
.filter(relation -> relation.isBack() == back)
178200
.sorted((o1, o2) -> (o2.getOrder() - o1.getOrder()))
@@ -313,7 +335,7 @@ private List<FlowRecord> errMatcher(FlowNode currentNode, IFlowOperator currentO
313335
List<Long> operatorIds = ((OperatorResult) errorResult).getOperatorIds();
314336
List<? extends IFlowOperator> operators = flowOperatorRepository.findByIds(operatorIds);
315337
for (IFlowOperator operator : operators) {
316-
FlowSession content = new FlowSession(flowRecord, flowWork, currentNode, createOperator, operator, snapshot.toBindData(), opinion, historyRecords);
338+
FlowSession content = new FlowSession(flowRecord, flowWork, currentNode, createOperator, nextOperator, snapshot.toBindData(), opinion, historyRecords);
317339
String recordTitle = currentNode.generateTitle(content);
318340
FlowRecord record = currentNode.createRecord(flowWork.getId(), flowWork.getCode(), processId, preId, recordTitle, createOperator, operator, snapshot, opinion.isWaiting());
319341
recordList.add(record);

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
@@ -281,7 +281,7 @@ private FlowResult submitCurrentFlow() {
281281
if (flowNode.isUnSign()) {
282282
for (FlowRecord record : historyRecords) {
283283
if (record.isTodo() && record.getId() != flowRecord.getId()) {
284-
record.autoPass(currentOperator, snapshot);
284+
record.autoPass(record.getCurrentOperator(), snapshot);
285285
FlowRecordRepository flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository();
286286
flowRecordRepository.update(record);
287287
}

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,84 @@ void errorMatcherNodeTest(){
209209
List<BindDataSnapshot> snapshots = flowBindDataRepository.findAll();
210210
assertEquals(3, snapshots.size());
211211
}
212+
213+
214+
/**
215+
* 相同人审批通过,指定人员审批时遇到异常,走异常节点配置
216+
*/
217+
@Test
218+
void sameUserFlow() {
219+
PageRequest pageRequest = PageRequest.of(0, 1000);
220+
221+
User user = new User("张飞");
222+
userRepository.save(user);
223+
224+
User dept = new User("刘备");
225+
userRepository.save(dept);
226+
227+
User boss = new User("诸葛亮");
228+
userRepository.save(boss);
229+
230+
FlowWork flowWork = FlowWorkBuilder.builder(user)
231+
.title("请假流程")
232+
.skipIfSameApprover(true)
233+
.nodes()
234+
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
235+
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(user.getUserId()))
236+
.node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()), new ErrTrigger("" +
237+
"def run(content){" +
238+
" return content.createOperatorErrTrigger(" + dept.getUserId() + ")" +
239+
"}"+
240+
""),true, false)
241+
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
242+
.relations()
243+
.relation("部门领导审批", "start", "dept")
244+
.relation("总经理审批", "dept", "manager")
245+
.relation("结束节点", "manager", "over")
246+
.build();
247+
248+
flowWorkRepository.save(flowWork);
249+
250+
String workCode = flowWork.getCode();
251+
252+
Leave leave = new Leave("我要出去看看");
253+
leaveRepository.save(leave);
254+
255+
// 创建流程
256+
flowService.startFlow(workCode, user, leave, "发起流程");
257+
258+
// 查看我的待办
259+
List<FlowRecord> userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
260+
assertEquals(1, userTodos.size());
261+
262+
// 提交流程
263+
FlowRecord userTodo = userTodos.get(0);
264+
assertEquals(0, userTodo.getTimeoutTime());
265+
266+
flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意").specify(user.getUserId()));
267+
268+
// 查看刘备经理的待办
269+
List<FlowRecord> deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
270+
assertEquals(1, deptTodos.size());
271+
272+
// 提交委托dept部门经理的审批
273+
FlowRecord deptTodo = deptTodos.get(0);
274+
flowService.submitFlow(deptTodo.getId(), dept, leave, Opinion.pass("同意"));
275+
276+
// 查看所有流程
277+
List<FlowRecord> records = flowRecordRepository.findAll(pageRequest).getContent();
278+
assertEquals(3, records.size());
279+
280+
userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
281+
assertEquals(0, userTodos.size());
282+
283+
records = flowRecordRepository.findAll(pageRequest).getContent();
284+
assertEquals(3, records.size());
285+
// 查看所有流程是否都已经结束
286+
assertTrue(records.stream().allMatch(FlowRecord::isFinish));
287+
288+
List<BindDataSnapshot> snapshots = flowBindDataRepository.findAll();
289+
assertEquals(4, snapshots.size());
290+
291+
}
212292
}

0 commit comments

Comments
 (0)