Skip to content

Commit a11dceb

Browse files
committed
merge flow record
1 parent 78dc0fd commit a11dceb

File tree

20 files changed

+112
-29
lines changed

20 files changed

+112
-29
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.36</version>
18+
<version>2.10.0</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.36</version>
9+
<version>2.10.0</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.36</version>
8+
<version>2.10.0</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.36</version>
9+
<version>2.10.0</version>
1010
</parent>
1111

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

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/build/FlowWorkBuilder.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,43 +73,47 @@ public FlowWork build() {
7373

7474
public class Nodes {
7575

76-
public Nodes node(String id, String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, TitleGenerator titleGenerator, ErrTrigger errTrigger, boolean editable, List<FlowButton> buttons) {
77-
FlowNode node = new FlowNode(id, name, code, view, NodeType.parser(code), approvalType, titleGenerator, operatorMatcher, timeout, errTrigger, editable, buttons);
76+
public Nodes node(String id, String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, TitleGenerator titleGenerator, ErrTrigger errTrigger, boolean editable, boolean mergeable, List<FlowButton> buttons) {
77+
FlowNode node = new FlowNode(id, name, code, view, NodeType.parser(code), approvalType, titleGenerator, operatorMatcher, timeout, errTrigger, editable,mergeable, buttons);
7878
work.addNode(node);
7979
return this;
8080
}
8181

8282
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, boolean editable) {
83-
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, timeout, TitleGenerator.defaultTitleGenerator(), null, editable, null);
83+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, timeout, TitleGenerator.defaultTitleGenerator(), null, editable,false, null);
8484
}
8585

86-
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, boolean editable, List<FlowButton> buttons) {
87-
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, timeout, TitleGenerator.defaultTitleGenerator(), null, editable, buttons);
86+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, boolean editable,boolean mergeable) {
87+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, timeout, TitleGenerator.defaultTitleGenerator(), null, editable,mergeable, null);
88+
}
89+
90+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, boolean editable,boolean mergeable, List<FlowButton> buttons) {
91+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, timeout, TitleGenerator.defaultTitleGenerator(), null, editable,mergeable, buttons);
8892
}
8993

9094

91-
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, boolean editable) {
92-
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), null, editable, null);
95+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, boolean editable,boolean mergeable) {
96+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), null, editable,mergeable, null);
9397
}
9498

95-
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, boolean editable, List<FlowButton> buttons) {
96-
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), null, editable, buttons);
99+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, boolean editable,boolean mergeable, List<FlowButton> buttons) {
100+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), null, editable,mergeable, buttons);
97101
}
98102

99103
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, List<FlowButton> buttons) {
100-
return node(name, code, view, approvalType, operatorMatcher, true, buttons);
104+
return node(name, code, view, approvalType, operatorMatcher, true,false, buttons);
101105
}
102106

103107
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher) {
104-
return node(name, code, view, approvalType, operatorMatcher, true, null);
108+
return node(name, code, view, approvalType, operatorMatcher, true,false, null);
105109
}
106110

107-
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, ErrTrigger errTrigger, boolean editable, List<FlowButton> buttons) {
108-
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), errTrigger, editable, buttons);
111+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, ErrTrigger errTrigger, boolean editable,boolean mergeable, List<FlowButton> buttons) {
112+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), errTrigger, editable,mergeable, buttons);
109113
}
110114

111-
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, ErrTrigger errTrigger, boolean editable) {
112-
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), errTrigger, editable, null);
115+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, ErrTrigger errTrigger, boolean editable,boolean mergeable) {
116+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), errTrigger, editable,mergeable, null);
113117
}
114118

115119

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/build/SchemaReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ private void loadNodes() {
4848
String titleGenerator = properties.getString("titleGenerator");
4949
String name = properties.getString("name");
5050
boolean editable = properties.getBoolean("editable");
51+
boolean mergeable = properties.getBoolean("mergeable");
5152
String view = properties.getString("view");
5253
String type = properties.getString("type");
5354
String approvalType = properties.getString("approvalType");
@@ -59,7 +60,7 @@ private void loadNodes() {
5960
buttons = properties.getJSONArray("buttons").toJavaList(FlowButton.class);
6061
}
6162
FlowNode flowNode = new FlowNode(id, name, code, view, NodeType.parser(type), ApprovalType.parser(approvalType), new TitleGenerator(titleGenerator),
62-
new OperatorMatcher(operatorMatcher), timeout, StringUtils.hasLength(errTrigger) ? new ErrTrigger(errTrigger) : null, editable, buttons);
63+
new OperatorMatcher(operatorMatcher), timeout, StringUtils.hasLength(errTrigger) ? new ErrTrigger(errTrigger) : null, editable,mergeable, buttons);
6364
flowNodes.add(flowNode);
6465
}
6566
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ public class FlowNode {
7878
*/
7979
private boolean editable;
8080

81+
/**
82+
* 是否合并记录
83+
* <p>
84+
* 如果为true,则表示该节点可以合并记录
85+
*/
86+
private boolean mergeable;
87+
88+
8189
/**
8290
* 创建时间
8391
*/
@@ -148,6 +156,7 @@ public FlowNodeSerializable toSerializable() {
148156
this.approvalType,
149157
this.operatorMatcher.getScript(),
150158
this.editable,
159+
this.mergeable,
151160
this.createTime,
152161
this.updateTime,
153162
this.timeout,
@@ -168,6 +177,7 @@ public FlowNode(String id,
168177
long timeout,
169178
ErrTrigger errTrigger,
170179
boolean editable,
180+
boolean mergeable,
171181
List<FlowButton> buttons) {
172182
this.id = id;
173183
this.code = code;
@@ -182,6 +192,7 @@ public FlowNode(String id,
182192
this.errTrigger = errTrigger;
183193
this.timeout = timeout;
184194
this.editable = editable;
195+
this.mergeable = mergeable;
185196
this.buttons = buttons;
186197
}
187198

@@ -229,6 +240,7 @@ public FlowRecord createRecord(long workId,
229240
FlowRecord record = new FlowRecord();
230241
record.setProcessId(processId);
231242
record.setNodeCode(this.code);
243+
record.setMergeable(this.mergeable);
232244
record.setCreateTime(System.currentTimeMillis());
233245
record.setWorkId(workId);
234246
record.setWorkCode(workCode);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.codingapi.springboot.flow.domain.FlowNode;
66
import com.codingapi.springboot.flow.domain.FlowWork;
77
import com.codingapi.springboot.flow.domain.Opinion;
8+
import com.codingapi.springboot.flow.record.FlowMerge;
89
import com.codingapi.springboot.flow.record.FlowRecord;
910
import com.codingapi.springboot.flow.user.IFlowOperator;
1011
import lombok.Getter;
@@ -64,15 +65,22 @@ public class FlowDetail {
6465
*/
6566
private final boolean canHandle;
6667

68+
/**
69+
* 合并记录
70+
*/
71+
private final List<FlowMerge> mergeRecords;
72+
6773

6874
public FlowDetail(FlowRecord flowRecord,
75+
List<FlowMerge> mergeRecords,
6976
BindDataSnapshot snapshot,
7077
FlowWork flowWork,
7178
List<FlowRecord> historyRecords,
7279
List<? extends IFlowOperator> operators,
7380
boolean canHandle) {
7481
this.operators = operators;
7582
this.flowRecord = flowRecord;
83+
this.mergeRecords = mergeRecords;
7684
this.flowWork = flowWork;
7785
this.bindData = snapshot.toBindData();
7886
this.historyRecords = historyRecords;
@@ -92,6 +100,7 @@ public FlowDetail(FlowWork flowWork,
92100
this.operators = operators;
93101
this.flowCreateTime = 0;
94102
this.flowRecord = null;
103+
this.mergeRecords = null;
95104
this.historyRecords = null;
96105
this.bindData = null;
97106
this.opinions = null;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.codingapi.springboot.flow.record;
2+
3+
import com.codingapi.springboot.flow.bind.IBindData;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
7+
@Getter
8+
@AllArgsConstructor
9+
public class FlowMerge {
10+
11+
private final FlowRecord flowRecord;
12+
private final IBindData bindData;
13+
14+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public class FlowRecord {
4949
*/
5050
private String nodeCode;
5151

52+
53+
/**
54+
* 是否可合并
55+
*/
56+
private boolean mergeable;
57+
5258
/**
5359
* 流程标题
5460
*/
@@ -402,6 +408,7 @@ public FlowRecord copy() {
402408
record.setWorkCode(this.workCode);
403409
record.setProcessId(this.processId);
404410
record.setNodeCode(this.nodeCode);
411+
record.setMergeable(this.mergeable);
405412
record.setTitle(this.title);
406413
record.setCurrentOperator(this.currentOperator);
407414
record.setFlowType(this.flowType);

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/repository/FlowRecordRepository.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public interface FlowRecordRepository {
4848
*/
4949
List<FlowRecord> findFlowRecordByProcessId(String processId);
5050

51+
/**
52+
* 获取合并的流程记录
53+
* @param workCode 流程编码
54+
* @param nodeCode 节点编码
55+
* @param currentOperatorId 当前操作者ID
56+
* @return List of FlowRecord
57+
*/
58+
List<FlowRecord> findMergeFlowRecordById(String workCode,String nodeCode,long currentOperatorId);
59+
5160

5261
/**
5362
* 查询所有未完成的流程记录

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/serializable/FlowNodeSerializable.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public class FlowNodeSerializable implements Serializable {
6969
*/
7070
private boolean editable;
7171

72+
/**
73+
* 是否可合并审批
74+
*/
75+
private boolean mergeable;
76+
7277
/**
7378
* 创建时间
7479
*/
@@ -95,6 +100,6 @@ public class FlowNodeSerializable implements Serializable {
95100

96101
public FlowNode toFlowNode() {
97102
return new FlowNode(id, code, name, new TitleGenerator(titleGenerator), type, view, approvalType,
98-
new OperatorMatcher(operatorMatcher), editable, createTime, updateTime, timeout, errTrigger == null ? null : new ErrTrigger(errTrigger),buttons);
103+
new OperatorMatcher(operatorMatcher), editable, mergeable, createTime, updateTime, timeout, errTrigger == null ? null : new ErrTrigger(errTrigger), buttons);
99104
}
100105
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.codingapi.springboot.flow.domain.FlowNode;
66
import com.codingapi.springboot.flow.domain.FlowWork;
77
import com.codingapi.springboot.flow.pojo.FlowDetail;
8+
import com.codingapi.springboot.flow.record.FlowMerge;
89
import com.codingapi.springboot.flow.record.FlowRecord;
910
import com.codingapi.springboot.flow.repository.*;
1011
import com.codingapi.springboot.flow.service.FlowRecordVerifyService;
@@ -46,6 +47,16 @@ public FlowDetail detail(long recordId, IFlowOperator currentOperator) {
4647
FlowRecord flowRecord = flowRecordVerifyService.getFlowRecord();
4748
FlowWork flowWork = flowRecordVerifyService.getFlowWork();
4849

50+
List<FlowMerge> mergeRecords = null;
51+
if(flowRecord.isTodo() && flowRecord.isMergeable()){
52+
List<FlowRecord> flowRecords = flowRecordRepository.findMergeFlowRecordById(flowRecord.getWorkCode(),flowRecord.getNodeCode(),currentOperator.getUserId());
53+
if(!flowRecords.isEmpty()){
54+
mergeRecords = flowRecords.stream().map(record->{
55+
BindDataSnapshot bindDataSnapshot = flowBindDataRepository.getBindDataSnapshotById(record.getSnapshotId());
56+
return new FlowMerge(record,bindDataSnapshot.toBindData());
57+
}).collect(Collectors.toList());
58+
}
59+
}
4960

5061
BindDataSnapshot snapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId());
5162
List<FlowRecord> flowRecords =
@@ -64,7 +75,7 @@ public FlowDetail detail(long recordId, IFlowOperator currentOperator) {
6475
}
6576
}
6677

67-
return new FlowDetail(flowRecord, snapshot, flowWork, flowRecords, operators, currentOperator != null && flowRecord.isTodo() && flowRecord.isOperator(currentOperator));
78+
return new FlowDetail(flowRecord,mergeRecords, snapshot, flowWork, flowRecords, operators, currentOperator != null && flowRecord.isTodo() && flowRecord.isOperator(currentOperator));
6879
}
6980

7081

springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowRecordRepositoryImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ public List<FlowRecord> findFlowRecordByPreId(long preId) {
4343
return cache.stream().filter(record -> record.getPreId() == preId).collect(Collectors.toList());
4444
}
4545

46+
@Override
47+
public List<FlowRecord> findMergeFlowRecordById(String workCode, String nodeCode, long operatorId) {
48+
return cache.stream()
49+
.filter(record -> record.isTodo() && record.getCurrentOperator().getUserId() == operatorId
50+
&& record.getWorkCode().equals(workCode)
51+
&& record.getNodeCode().equals(nodeCode)
52+
&& record.isMergeable()
53+
)
54+
.collect(Collectors.toList());
55+
}
56+
4657
@Override
4758
public List<FlowRecord> findFlowRecordByProcessId(String processId) {
4859
return cache.stream().filter(record -> record.getProcessId().equals(processId))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void errorMatcherOperatorTest(){
5353
.title("请假流程")
5454
.nodes()
5555
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
56-
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, new OperatorMatcher("def run(content){return []}"), new ErrTrigger("def run(content){return content.createOperatorErrTrigger("+dept.getId()+")}"), true)
56+
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, new OperatorMatcher("def run(content){return []}"), new ErrTrigger("def run(content){return content.createOperatorErrTrigger("+dept.getId()+")}"), true,false)
5757
.node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(boss.getUserId()))
5858
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
5959
.relations()
@@ -145,7 +145,7 @@ void errorMatcherNodeTest(){
145145
.title("请假流程")
146146
.nodes()
147147
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
148-
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, new OperatorMatcher("def run(content){return []}"), new ErrTrigger("def run(content){return content.createNodeErrTrigger('manager')}"), true)
148+
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, new OperatorMatcher("def run(content){return []}"), new ErrTrigger("def run(content){return content.createNodeErrTrigger('manager')}"), true,false)
149149
.node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(boss.getUserId()))
150150
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
151151
.relations()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void saveDisableTest() {
388388
.title("请假流程")
389389
.nodes()
390390
.node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
391-
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()), false)
391+
.node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()), false,false)
392392
.node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(boss.getUserId()))
393393
.node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
394394
.relations()

0 commit comments

Comments
 (0)