Skip to content

Commit 535cf7f

Browse files
committed
add copy
1 parent 96f3a5c commit 535cf7f

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.codingapi.springboot.flow.build.SchemaReader;
44
import com.codingapi.springboot.flow.serializable.FlowWorkSerializable;
55
import com.codingapi.springboot.flow.user.IFlowOperator;
6+
import com.codingapi.springboot.flow.utils.IDGenerator;
67
import lombok.AllArgsConstructor;
78
import lombok.Getter;
89
import lombok.Setter;
@@ -88,6 +89,35 @@ public FlowWork(IFlowOperator createUser) {
8889
this.postponedMax = 1;
8990
}
9091

92+
93+
/**
94+
* 流程设计复制
95+
* @return FlowWork 流程设计
96+
*/
97+
public FlowWork copy(){
98+
if(!StringUtils.hasLength(schema)){
99+
throw new IllegalArgumentException("schema is empty");
100+
}
101+
String schema = this.getSchema();
102+
for(FlowNode flowNode:this.getNodes()){
103+
String newId = IDGenerator.generate();
104+
schema = schema.replaceAll(flowNode.getId(),newId);
105+
}
106+
107+
for(FlowRelation relation:this.getRelations()){
108+
String newId = IDGenerator.generate();
109+
schema = schema.replaceAll(relation.getId(),newId);
110+
}
111+
112+
FlowWork flowWork = new FlowWork(this.createUser);
113+
flowWork.setDescription(this.getDescription());
114+
flowWork.setTitle(this.getTitle());
115+
flowWork.setPostponedMax(this.getPostponedMax());
116+
flowWork.schema(schema);
117+
return flowWork;
118+
}
119+
120+
91121
public FlowWork(String title, String description, int postponedMax, IFlowOperator createUser) {
92122
this.title = title;
93123
this.description = description;

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package com.codingapi.springboot.flow.test;
22

33
import com.codingapi.springboot.flow.build.FlowWorkBuilder;
4+
import com.codingapi.springboot.flow.domain.FlowNode;
45
import com.codingapi.springboot.flow.domain.FlowWork;
56
import com.codingapi.springboot.flow.user.User;
67
import org.junit.jupiter.api.Test;
78

89
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
911

1012
public class ScriptBuildTest {
1113

1214

1315
@Test
14-
void build() {
16+
void copy() {
1517
User user = new User("张三");
1618
String script = "{\"nodes\":[{\"id\":\"e7699cab-e20b-4606-af66-fb8d782fd0f8\",\"type\":\"start-node\",\"x\":1005,\"y\":153,\"properties\":{\"name\":\"开始节点\",\"code\":\"start\",\"type\":\"START\",\"view\":\"default\",\"operatorMatcher\":\"def run(content) {return [content.getCreateOperator().getUserId()];}\",\"editable\":true,\"titleGenerator\":\"def run(content){ return content.getCreateOperator().getName() + '-' + content.getFlowWork().getTitle() + '-' + content.getFlowNode().getName();}\",\"errTrigger\":\"\",\"approvalType\":\"UN_SIGN\",\"timeout\":0,\"id\":\"e7699cab-e20b-4606-af66-fb8d782fd0f8\",\"width\":200,\"height\":45,\"operatorMatcherType\":\"creator\",\"titleGeneratorType\":\"default\",\"errTriggerType\":\"custom\"}},{\"id\":\"0d6638e9-0f98-45de-a5ad-8d55702158f7\",\"type\":\"node-node\",\"x\":722,\"y\":392,\"properties\":{\"name\":\"部门审批\",\"code\":\"dept\",\"type\":\"APPROVAL\",\"view\":\"default\",\"operatorMatcher\":\"def run(content) {return [content.getCurrentOperator().getUserId()];}\",\"editable\":true,\"titleGenerator\":\"def run(content){ return content.getCreateOperator().getName() + '-' + content.getFlowWork().getTitle() + '-' + content.getFlowNode().getName();}\",\"errTrigger\":\"\",\"approvalType\":\"SIGN\",\"timeout\":0,\"id\":\"0d6638e9-0f98-45de-a5ad-8d55702158f7\",\"width\":200,\"height\":45}},{\"id\":\"c4f8dd1b-53f2-4a87-8f57-9828b79fc4d0\",\"type\":\"over-node\",\"x\":918,\"y\":773,\"properties\":{\"name\":\"结束节点\",\"code\":\"over\",\"type\":\"OVER\",\"view\":\"default\",\"operatorMatcher\":\"def run(content) {return [content.getCurrentOperator().getUserId()];}\",\"editable\":true,\"titleGenerator\":\"def run(content){ return content.getCreateOperator().getName() + '-' + content.getFlowWork().getTitle() + '-' + content.getFlowNode().getName();}\",\"errTrigger\":\"\",\"approvalType\":\"UN_SIGN\",\"timeout\":0,\"id\":\"c4f8dd1b-53f2-4a87-8f57-9828b79fc4d0\",\"width\":200,\"height\":45}},{\"id\":\"ed654f48-c94c-4fdd-9b14-91f6295ae17a\",\"type\":\"node-node\",\"x\":1227,\"y\":530,\"properties\":{\"name\":\"老板审批\",\"code\":\"boss\",\"type\":\"APPROVAL\",\"view\":\"default\",\"operatorMatcher\":\"def run(content) {return [content.getCurrentOperator().getUserId()];}\",\"editable\":true,\"titleGenerator\":\"def run(content){ return content.getCreateOperator().getName() + '-' + content.getFlowWork().getTitle() + '-' + content.getFlowNode().getName();}\",\"errTrigger\":\"\",\"approvalType\":\"SIGN\",\"timeout\":0,\"id\":\"ed654f48-c94c-4fdd-9b14-91f6295ae17a\",\"width\":200,\"height\":45}}],\"edges\":[{\"id\":\"6854a4ef-89cf-48d3-9aa7-af1e5b87e93c\",\"type\":\"bezier\",\"properties\":{\"outTrigger\":\"def run(content) {return true;}\",\"order\":2,\"back\":false},\"sourceNodeId\":\"e7699cab-e20b-4606-af66-fb8d782fd0f8\",\"targetNodeId\":\"0d6638e9-0f98-45de-a5ad-8d55702158f7\",\"startPoint\":{\"x\":1005,\"y\":175.5},\"endPoint\":{\"x\":722,\"y\":369.5},\"pointsList\":[{\"x\":1005,\"y\":175.5},{\"x\":1005,\"y\":275.5},{\"x\":722,\"y\":269.5},{\"x\":722,\"y\":369.5}]},{\"id\":\"7c2c01fc-ded1-46e7-baf7-9fa664898d74\",\"type\":\"bezier\",\"properties\":{\"outTrigger\":\"def run(content) {return true;}\",\"order\":1,\"back\":false},\"sourceNodeId\":\"0d6638e9-0f98-45de-a5ad-8d55702158f7\",\"targetNodeId\":\"c4f8dd1b-53f2-4a87-8f57-9828b79fc4d0\",\"startPoint\":{\"x\":722,\"y\":414.5},\"endPoint\":{\"x\":918,\"y\":750.5},\"pointsList\":[{\"x\":722,\"y\":414.5},{\"x\":722,\"y\":514.5},{\"x\":918,\"y\":650.5},{\"x\":918,\"y\":750.5}]},{\"id\":\"67ee0fe7-b88c-4fde-be82-e23276f567e6\",\"type\":\"bezier\",\"properties\":{\"outTrigger\":\"def run(content) {return true;}\",\"order\":1,\"back\":false},\"sourceNodeId\":\"e7699cab-e20b-4606-af66-fb8d782fd0f8\",\"targetNodeId\":\"ed654f48-c94c-4fdd-9b14-91f6295ae17a\",\"startPoint\":{\"x\":1005,\"y\":175.5},\"endPoint\":{\"x\":1227,\"y\":507.5},\"pointsList\":[{\"x\":1005,\"y\":175.5},{\"x\":1005,\"y\":275.5},{\"x\":1227,\"y\":407.5},{\"x\":1227,\"y\":507.5}]},{\"id\":\"9c6f3b0c-03f5-46eb-be39-c79528a824dc\",\"type\":\"bezier\",\"properties\":{\"outTrigger\":\"def run(content) {return true;}\",\"order\":1,\"back\":false},\"sourceNodeId\":\"ed654f48-c94c-4fdd-9b14-91f6295ae17a\",\"targetNodeId\":\"c4f8dd1b-53f2-4a87-8f57-9828b79fc4d0\",\"startPoint\":{\"x\":1227,\"y\":552.5},\"endPoint\":{\"x\":918,\"y\":750.5},\"pointsList\":[{\"x\":1227,\"y\":552.5},{\"x\":1227,\"y\":652.5},{\"x\":918,\"y\":650.5},{\"x\":918,\"y\":750.5}]}]}";
1719
FlowWork flowWork = FlowWorkBuilder.builder(user)
@@ -21,5 +23,21 @@ void build() {
2123
assertEquals("请假流程", flowWork.getTitle());
2224
assertEquals(4, flowWork.getNodes().size());
2325
assertEquals(4, flowWork.getRelations().size());
26+
27+
28+
FlowNode startNode = flowWork.getStartNode();
29+
30+
FlowWork copyWork = flowWork.copy();
31+
32+
assertEquals("请假流程", copyWork.getTitle());
33+
assertEquals(4, copyWork.getNodes().size());
34+
assertEquals(4, copyWork.getRelations().size());
35+
36+
copyWork.verify();
37+
38+
FlowNode startNode2 = copyWork.getNodeByCode("start");
39+
assertNotEquals(startNode.getId(), startNode2.getId());
40+
41+
2442
}
2543
}

0 commit comments

Comments
 (0)