Skip to content

Commit 1d0fc95

Browse files
authored
Merge pull request #120 from codingapi/dev
fix #119
2 parents 8624a28 + 4aa2a14 commit 1d0fc95

File tree

28 files changed

+109
-49
lines changed

28 files changed

+109
-49
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.6</version>
9+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowCmd.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public String getUserName() {
3232
@Getter
3333
public static class FlowStep{
3434
private String workCode;
35+
private long recordId;
3536
private JSONObject formData;
3637

3738
@SneakyThrows
@@ -43,6 +44,10 @@ public IBindData getBindData() {
4344
public String getUserName() {
4445
return TokenContext.current().getUsername();
4546
}
47+
48+
public boolean hasRecordId() {
49+
return recordId > 0;
50+
}
4651
}
4752

4853
@Setter

example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public FlowResult startFlow(FlowCmd.StartFlow request) {
2626

2727
public FlowStepResult getFlowStep(FlowCmd.FlowStep request) {
2828
IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName());
29-
return flowService.getFlowStep(request.getWorkCode(), request.getBindData(), current);
29+
if(request.hasRecordId()) {
30+
return flowService.getFlowStep(request.getRecordId(), request.getBindData(), current);
31+
}else {
32+
return flowService.getFlowStep(request.getWorkCode(), request.getBindData(), current);
33+
}
3034
}
3135

3236

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.6</version>
9+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</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.6</version>
8+
<version>3.4.7</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.6</version>
8+
<version>3.4.7</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.6</version>
8+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</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.6</version>
8+
<version>3.4.7</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.6</version>
22+
<version>3.4.7</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.6</version>
15+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</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.6</version>
8+
<version>3.4.7</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.6</version>
9+
<version>3.4.7</version>
1010
</parent>
1111

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

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,34 @@ public FlowStepResult() {
1717
this.flowNodes = new ArrayList<>();
1818
}
1919

20-
public void addFlowNode(FlowNode flowNode,List<? extends IFlowOperator> operators) {
21-
this.flowNodes.add(new FlowStepNode(flowNode.getId(), flowNode.getCode(),flowNode.getName(),flowNode.getType(),operators));
20+
public void addFlowNode(FlowNode flowNode,boolean done,List<? extends IFlowOperator> operators) {
21+
this.flowNodes.add(new FlowStepNode(flowNode.getId(), flowNode.getCode(),flowNode.getName(),flowNode.getType(),done,operators));
2222
}
2323

2424

2525
public void print(){
26+
System.out.println("FlowStepResult:==========================>");
2627
for (FlowStepNode flowNode : flowNodes) {
27-
System.out.println("flowNode = " + flowNode.getName());
28+
System.out.println("flowNode = " + flowNode.getName()+",done = " + flowNode.isDone() + ",type = " + flowNode.getType()+" operators = " + flowNode.getOperators().stream().map(IFlowOperator::getUserId).toList());
2829
}
2930
}
3031

31-
3232
@Getter
3333
public static class FlowStepNode{
3434
private final String id;
3535
private final String code;
3636
private final String name;
3737
private final NodeType type;
38+
private final boolean done;
3839
private final List<? extends IFlowOperator> operators;
3940

40-
public FlowStepNode(String id, String code, String name, NodeType type,List<? extends IFlowOperator> operators) {
41+
public FlowStepNode(String id, String code, String name, NodeType type,boolean done,List<? extends IFlowOperator> operators) {
4142
this.id = id;
4243
this.code = code;
4344
this.name = name;
4445
this.type = type;
4546
this.operators = operators;
47+
this.done = done;
4648
}
4749
}
4850
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ public FlowSubmitResult trySubmitFlow(long recordId, IFlowOperator currentOperat
188188
return flowTrySubmitService.trySubmitFlow(recordId);
189189
}
190190

191+
/**
192+
* 获取流程执行节点
193+
*
194+
* @param recordId
195+
* @param currentOperator
196+
* @return
197+
*/
198+
public FlowStepResult getFlowStep(long recordId, IBindData bindData, IFlowOperator currentOperator) {
199+
FlowStepService flowStepService = new FlowStepService(recordId,null, currentOperator, bindData, flowServiceRepositoryHolder);
200+
return flowStepService.getFlowStep();
201+
}
202+
191203
/**
192204
* 获取流程执行节点
193205
*
@@ -196,7 +208,7 @@ public FlowSubmitResult trySubmitFlow(long recordId, IFlowOperator currentOperat
196208
* @return
197209
*/
198210
public FlowStepResult getFlowStep(String workCode, IBindData bindData, IFlowOperator currentOperator) {
199-
FlowStepService flowStepService = new FlowStepService(workCode, currentOperator, bindData, flowServiceRepositoryHolder);
211+
FlowStepService flowStepService = new FlowStepService(0,workCode, currentOperator, bindData, flowServiceRepositoryHolder);
200212
return flowStepService.getFlowStep();
201213
}
202214

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

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,76 @@
1212
import com.codingapi.springboot.flow.service.FlowNodeService;
1313
import com.codingapi.springboot.flow.service.FlowServiceRepositoryHolder;
1414
import com.codingapi.springboot.flow.user.IFlowOperator;
15+
import com.codingapi.springboot.framework.utils.RandomGenerator;
1516

1617
import java.util.ArrayList;
18+
import java.util.Comparator;
1719
import java.util.List;
1820

1921
public class FlowStepService {
2022
private final FlowWork flowWork;
23+
private final long recordId;
24+
private final List<FlowRecord> flowRecords;
2125

2226
private final IFlowOperator currentOperator;
2327
private final IBindData bindData;
2428
private final FlowServiceRepositoryHolder flowServiceRepositoryHolder;
2529

2630
private FlowNodeService flowNodeService;
2731
private FlowNode flowNode;
32+
private FlowRecord currentFlowRecord;
2833

29-
public FlowStepService(String workCode, IFlowOperator currentOperator, IBindData bindData, FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
34+
public FlowStepService(long recordId,String workCode, IFlowOperator currentOperator, IBindData bindData, FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
35+
this.recordId = recordId;
3036
this.currentOperator = currentOperator;
3137
this.bindData = bindData;
3238
this.flowServiceRepositoryHolder = flowServiceRepositoryHolder;
33-
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(workCode);
39+
if(this.recordId>0) {
40+
this.currentFlowRecord = flowServiceRepositoryHolder.getFlowRecordRepository().getFlowRecordById(recordId);
41+
this.flowRecords = flowServiceRepositoryHolder.getFlowRecordRepository().findFlowRecordByProcessId(currentFlowRecord.getProcessId()).stream().sorted(Comparator.comparingLong(FlowRecord::getId)).toList();
42+
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(currentFlowRecord.getWorkCode());
43+
}else {
44+
this.currentFlowRecord = null;
45+
this.flowRecords = new ArrayList<>();
46+
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(workCode);
47+
}
3448
}
3549

3650

3751
public FlowStepResult getFlowStep() {
3852
FlowStepResult flowStepResult = new FlowStepResult();
39-
// 获取开始节点
40-
FlowNode start = flowWork.getStartNode();
41-
if (start == null) {
42-
throw new IllegalArgumentException("start node not found");
43-
}
4453

45-
this.flowNode = start;
4654
// 设置开始流程的上一个流程id
4755
long preId = 0;
56+
if(currentFlowRecord==null) {
57+
// 获取开始节点
58+
FlowNode start = flowWork.getStartNode();
59+
if (start == null) {
60+
throw new IllegalArgumentException("start node not found");
61+
}
62+
preId = 0;
63+
this.flowNode = start;
64+
}else {
65+
for(FlowRecord flowRecord : flowRecords) {
66+
FlowNode flowNode = this.flowWork.getNodeByCode(flowRecord.getNodeCode());
67+
List<IFlowOperator> operators = new ArrayList<>();
68+
if(flowRecord.getCurrentOperator()!=null) {
69+
operators.add(flowRecord.getCurrentOperator());
70+
}
71+
boolean isDone =flowRecord.isDone() || flowRecord.getOpinion().isCirculate();
72+
flowStepResult.addFlowNode(flowNode,isDone, operators);
73+
}
74+
FlowRecord lastRecord = this.flowRecords.get(this.flowRecords.size()-1);
75+
this.flowNode = this.flowWork.getNodeByCode(lastRecord.getNodeCode());
76+
preId = lastRecord.getId();
77+
}
4878

4979
// 创建流程id
50-
String processId = "flow_" + System.currentTimeMillis();
51-
52-
List<FlowRecord> historyRecords = new ArrayList<>();
80+
String processId = "flow_" + RandomGenerator.generateUUID();
5381

5482
FlowOperatorRepository flowOperatorRepository = flowServiceRepositoryHolder.getFlowOperatorRepository();
5583
FlowRecordRepository flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository();
56-
84+
List<FlowRecord> historyRecords = new ArrayList<>();
5785
BindDataSnapshot snapshot = new BindDataSnapshot(bindData);
5886
flowNodeService = new FlowNodeService(flowOperatorRepository,
5987
flowRecordRepository,
@@ -67,16 +95,19 @@ public FlowStepResult getFlowStep() {
6795
processId,
6896
preId);
6997

70-
flowNodeService.setNextNode(start);
98+
flowNodeService.setNextNode(this.flowNode);
7199

72-
this.flowNode = start;
73-
flowStepResult.addFlowNode(this.flowNode, this.flowNodeService.loadNextNodeOperators());
100+
if(currentFlowRecord==null) {
101+
flowStepResult.addFlowNode(this.flowNode, false, this.flowNodeService.loadNextNodeOperators());
102+
}
74103

75104
do {
76105
flowNodeService.loadNextPassNode(this.flowNode);
77106
this.flowNode = flowNodeService.getNextNode();
78107

79-
flowStepResult.addFlowNode(this.flowNode, this.flowNodeService.loadNextNodeOperators());
108+
boolean isFinish = currentFlowRecord != null && currentFlowRecord.isFinish();
109+
110+
flowStepResult.addFlowNode(this.flowNode,isFinish, this.flowNodeService.loadNextNodeOperators());
80111
} while (!flowNode.isOverNode());
81112

82113
return flowStepResult;

0 commit comments

Comments
 (0)