Skip to content

Commit ef64d79

Browse files
committed
fix #119
1 parent b7474c9 commit ef64d79

File tree

10 files changed

+87
-39
lines changed

10 files changed

+87
-39
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.6</version>
18+
<version>2.10.7</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.6</version>
9+
<version>2.10.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>2.10.6</version>
8+
<version>2.10.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>2.10.6</version>
9+
<version>2.10.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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.ArrayList;
99
import java.util.List;
10+
import java.util.stream.Collectors;
1011

1112
@Getter
1213
public class FlowStepResult {
@@ -17,32 +18,34 @@ public FlowStepResult() {
1718
this.flowNodes = new ArrayList<>();
1819
}
1920

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));
21+
public void addFlowNode(FlowNode flowNode,boolean done,List<? extends IFlowOperator> operators) {
22+
this.flowNodes.add(new FlowStepNode(flowNode.getId(), flowNode.getCode(),flowNode.getName(),flowNode.getType(),done,operators));
2223
}
2324

2425

2526
public void print(){
27+
System.out.println("FlowStepResult:==========================>");
2628
for (FlowStepNode flowNode : flowNodes) {
27-
System.out.println("flowNode = " + flowNode.getName());
29+
System.out.println("flowNode = " + flowNode.getName()+",done = " + flowNode.isDone() + ",type = " + flowNode.getType()+" operators = " + flowNode.getOperators().stream().map(IFlowOperator::getUserId).collect(Collectors.toList()));
2830
}
2931
}
3032

31-
3233
@Getter
3334
public static class FlowStepNode{
3435
private final String id;
3536
private final String code;
3637
private final String name;
3738
private final NodeType type;
39+
private final boolean done;
3840
private final List<? extends IFlowOperator> operators;
3941

40-
public FlowStepNode(String id, String code, String name, NodeType type,List<? extends IFlowOperator> operators) {
42+
public FlowStepNode(String id, String code, String name, NodeType type,boolean done,List<? extends IFlowOperator> operators) {
4143
this.id = id;
4244
this.code = code;
4345
this.name = name;
4446
this.type = type;
4547
this.operators = operators;
48+
this.done = done;
4649
}
4750
}
4851
}

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public FlowService(FlowWorkRepository flowWorkRepository,
4040
FlowBackupRepository flowBackupRepository) {
4141
this.flowServiceRepositoryHolder = new FlowServiceRepositoryHolder(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowOperatorRepository, flowProcessRepository, flowBackupRepository);
4242
this.flowDetailService = new FlowDetailService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowOperatorRepository, flowProcessRepository);
43-
this.flowCustomEventService = new FlowCustomEventService(flowWorkRepository,flowRecordRepository, flowProcessRepository);
44-
this.flowRecallService = new FlowRecallService(flowWorkRepository,flowRecordRepository, flowProcessRepository);
45-
this.flowRemoveService = new FlowRemoveService(flowWorkRepository,flowRecordRepository, flowProcessRepository);
46-
this.flowSaveService = new FlowSaveService(flowWorkRepository,flowRecordRepository, flowBindDataRepository, flowProcessRepository);
47-
this.flowTransferService = new FlowTransferService(flowWorkRepository,flowRecordRepository, flowBindDataRepository, flowProcessRepository);
48-
this.flowPostponedService = new FlowPostponedService(flowWorkRepository,flowRecordRepository, flowProcessRepository);
49-
this.flowUrgeService = new FlowUrgeService(flowWorkRepository,flowRecordRepository, flowProcessRepository);
43+
this.flowCustomEventService = new FlowCustomEventService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
44+
this.flowRecallService = new FlowRecallService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
45+
this.flowRemoveService = new FlowRemoveService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
46+
this.flowSaveService = new FlowSaveService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowProcessRepository);
47+
this.flowTransferService = new FlowTransferService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowProcessRepository);
48+
this.flowPostponedService = new FlowPostponedService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
49+
this.flowUrgeService = new FlowUrgeService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
5050
}
5151

5252
/**
@@ -189,6 +189,18 @@ public FlowSubmitResult trySubmitFlow(long recordId, IFlowOperator currentOperat
189189
}
190190

191191

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

@@ -230,10 +242,11 @@ public FlowResult submitFlow(long recordId, IFlowOperator currentOperator, IBind
230242

231243
/**
232244
* 唤醒流程
233-
* @param processId 流程实例id
245+
*
246+
* @param processId 流程实例id
234247
* @param currentOperator 当前操作者
235248
*/
236-
public void notifyFlow(String processId,IFlowOperator currentOperator) {
249+
public void notifyFlow(String processId, IFlowOperator currentOperator) {
237250
FlowNotifyService flowNotifyService = new FlowNotifyService(processId, currentOperator, flowServiceRepositoryHolder);
238251
flowNotifyService.notifyFlow();
239252
}
@@ -263,7 +276,6 @@ public void recall(long recordId, IFlowOperator currentOperator) {
263276
}
264277

265278

266-
267279
/**
268280
* 删除流程
269281
*

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

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,77 @@
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;
20+
import java.util.stream.Collectors;
1821

1922
public class FlowStepService {
2023
private final FlowWork flowWork;
24+
private final long recordId;
25+
private final List<FlowRecord> flowRecords;
2126

2227
private final IFlowOperator currentOperator;
2328
private final IBindData bindData;
2429
private final FlowServiceRepositoryHolder flowServiceRepositoryHolder;
2530

2631
private FlowNodeService flowNodeService;
2732
private FlowNode flowNode;
33+
private FlowRecord currentFlowRecord;
2834

29-
public FlowStepService(String workCode, IFlowOperator currentOperator, IBindData bindData, FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
35+
public FlowStepService(long recordId,String workCode, IFlowOperator currentOperator, IBindData bindData, FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
36+
this.recordId = recordId;
3037
this.currentOperator = currentOperator;
3138
this.bindData = bindData;
3239
this.flowServiceRepositoryHolder = flowServiceRepositoryHolder;
33-
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(workCode);
40+
if(this.recordId>0) {
41+
this.currentFlowRecord = flowServiceRepositoryHolder.getFlowRecordRepository().getFlowRecordById(recordId);
42+
this.flowRecords = flowServiceRepositoryHolder.getFlowRecordRepository().findFlowRecordByProcessId(currentFlowRecord.getProcessId()).stream().sorted(Comparator.comparingLong(FlowRecord::getId)).collect(Collectors.toList());
43+
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(currentFlowRecord.getWorkCode());
44+
}else {
45+
this.currentFlowRecord = null;
46+
this.flowRecords = new ArrayList<>();
47+
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(workCode);
48+
}
3449
}
3550

3651

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

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

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

5483
FlowOperatorRepository flowOperatorRepository = flowServiceRepositoryHolder.getFlowOperatorRepository();
5584
FlowRecordRepository flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository();
56-
85+
List<FlowRecord> historyRecords = new ArrayList<>();
5786
BindDataSnapshot snapshot = new BindDataSnapshot(bindData);
5887
flowNodeService = new FlowNodeService(flowOperatorRepository,
5988
flowRecordRepository,
@@ -67,15 +96,19 @@ public FlowStepResult getFlowStep() {
6796
processId,
6897
preId);
6998

70-
flowNodeService.setNextNode(start);
99+
flowNodeService.setNextNode(this.flowNode);
71100

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

75105
do {
76106
flowNodeService.loadNextPassNode(this.flowNode);
77107
this.flowNode = flowNodeService.getNextNode();
78-
flowStepResult.addFlowNode(this.flowNode, this.flowNodeService.loadNextNodeOperators());
108+
109+
boolean isFinish = currentFlowRecord != null && currentFlowRecord.isFinish();
110+
111+
flowStepResult.addFlowNode(this.flowNode,isFinish, this.flowNodeService.loadNextNodeOperators());
79112
} while (!flowNode.isOverNode());
80113

81114
return flowStepResult;

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

0 commit comments

Comments
 (0)