Skip to content

Commit 7c78374

Browse files
committed
add flow
1 parent 0927b71 commit 7c78374

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2337
-0
lines changed

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
<module>springboot-starter</module>
254254
<module>springboot-starter-security</module>
255255
<module>springboot-starter-data-fast</module>
256+
<module>springboot-starter-flow</module>
256257
</modules>
257258
</profile>
258259

@@ -264,6 +265,7 @@
264265
<module>springboot-starter</module>
265266
<module>springboot-starter-security</module>
266267
<module>springboot-starter-data-fast</module>
268+
<module>springboot-starter-flow</module>
267269
</modules>
268270

269271
<build>
@@ -313,6 +315,7 @@
313315
<module>springboot-starter</module>
314316
<module>springboot-starter-security</module>
315317
<module>springboot-starter-data-fast</module>
318+
<module>springboot-starter-flow</module>
316319
</modules>
317320

318321

springboot-starter-flow/pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<artifactId>springboot-parent</artifactId>
8+
<groupId>com.codingapi.springboot</groupId>
9+
<version>3.2.6</version>
10+
</parent>
11+
12+
<name>springboot-starter-flow</name>
13+
<description>springboot-starter-flow project for Spring Boot</description>
14+
<artifactId>springboot-starter-flow</artifactId>
15+
16+
<properties>
17+
<java.version>17</java.version>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.codingapi.springboot</groupId>
23+
<artifactId>springboot-starter</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.apache.groovy</groupId>
28+
<artifactId>groovy</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.apache.groovy</groupId>
33+
<artifactId>groovy-json</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.apache.groovy</groupId>
38+
<artifactId>groovy-xml</artifactId>
39+
</dependency>
40+
41+
</dependencies>
42+
43+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.codingapi.springboot.flow;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
5+
@Configuration
6+
public class FlowConfiguration {
7+
8+
9+
10+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.codingapi.springboot.flow.builder;
2+
3+
import com.codingapi.springboot.flow.creator.DefaultTitleCreator;
4+
import com.codingapi.springboot.flow.domain.FlowNode;
5+
import com.codingapi.springboot.flow.em.FlowType;
6+
import com.codingapi.springboot.flow.em.NodeType;
7+
import com.codingapi.springboot.flow.matcher.IOperatorMatcher;
8+
import com.codingapi.springboot.flow.operator.IFlowOperator;
9+
import com.codingapi.springboot.flow.trigger.IErrTrigger;
10+
import com.codingapi.springboot.flow.trigger.IOutTrigger;
11+
import com.codingapi.springboot.flow.trigger.OverOutTrigger;
12+
import lombok.AllArgsConstructor;
13+
14+
public class FlowNodeFactory {
15+
16+
@AllArgsConstructor
17+
public static class Builder {
18+
private IFlowOperator createUser;
19+
20+
public FlowNode startNode(String name, IOperatorMatcher operatorMatcher, IOutTrigger outTrigger) {
21+
return startNode(name, FlowNode.VIEW_DEFAULT, operatorMatcher, outTrigger);
22+
}
23+
24+
25+
public FlowNode startNode(String name, String view, IOperatorMatcher operatorMatcher, IOutTrigger outTrigger) {
26+
FlowNode flowNode = new FlowNode();
27+
flowNode.setName(name);
28+
flowNode.setType(NodeType.START);
29+
flowNode.setCode(FlowNode.CODE_START);
30+
flowNode.setView(view);
31+
flowNode.setTitleCreator(new DefaultTitleCreator());
32+
flowNode.setFlowType(FlowType.NOT_SIGN);
33+
flowNode.setCreateTime(System.currentTimeMillis());
34+
flowNode.setUpdateTime(System.currentTimeMillis());
35+
flowNode.setCreateUser(createUser);
36+
flowNode.setOutOperatorMatcher(operatorMatcher);
37+
flowNode.setOutTrigger(outTrigger);
38+
return flowNode;
39+
}
40+
41+
public FlowNode overNode(String name) {
42+
FlowNode flowNode = new FlowNode();
43+
flowNode.setName(name);
44+
flowNode.setType(NodeType.OVER);
45+
flowNode.setCode(FlowNode.CODE_OVER);
46+
flowNode.setView(FlowNode.VIEW_DEFAULT);
47+
flowNode.setOutTrigger(new OverOutTrigger());
48+
flowNode.setTitleCreator(new DefaultTitleCreator());
49+
flowNode.setFlowType(FlowType.NOT_SIGN);
50+
flowNode.setCreateTime(System.currentTimeMillis());
51+
flowNode.setUpdateTime(System.currentTimeMillis());
52+
flowNode.setCreateUser(createUser);
53+
return flowNode;
54+
}
55+
56+
public FlowNode node(String name,
57+
String code,
58+
String view,
59+
FlowType flowType,
60+
IOutTrigger outTrigger,
61+
IOperatorMatcher outOperatorMatcher) {
62+
return node(name, code, view, flowType, outTrigger, outOperatorMatcher, null, null);
63+
}
64+
65+
66+
public FlowNode node(String name,
67+
String code,
68+
FlowType flowType,
69+
IOutTrigger outTrigger,
70+
IOperatorMatcher outOperatorMatcher) {
71+
return node(name, code, FlowNode.VIEW_DEFAULT, flowType, outTrigger, outOperatorMatcher, null, null);
72+
}
73+
74+
public FlowNode node(String name,
75+
String code,
76+
String view,
77+
FlowType flowType,
78+
IOutTrigger outTrigger,
79+
IOperatorMatcher outOperatorMatcher,
80+
IErrTrigger errTrigger,
81+
IOperatorMatcher errOperatorMatcher) {
82+
FlowNode flowNode = new FlowNode();
83+
flowNode.setName(name);
84+
flowNode.setType(NodeType.APPROVAL);
85+
flowNode.setCode(code);
86+
flowNode.setView(view);
87+
flowNode.setTitleCreator(new DefaultTitleCreator());
88+
flowNode.setFlowType(flowType);
89+
flowNode.setCreateTime(System.currentTimeMillis());
90+
flowNode.setUpdateTime(System.currentTimeMillis());
91+
flowNode.setCreateUser(createUser);
92+
93+
flowNode.setOutTrigger(outTrigger);
94+
flowNode.setOutOperatorMatcher(outOperatorMatcher);
95+
96+
flowNode.setErrTrigger(errTrigger);
97+
flowNode.setErrOperatorMatcher(errOperatorMatcher);
98+
99+
return flowNode;
100+
}
101+
102+
}
103+
104+
public static Builder Builder(IFlowOperator createUser) {
105+
return new Builder(createUser);
106+
}
107+
108+
109+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package com.codingapi.springboot.flow.builder;
2+
3+
import com.codingapi.springboot.flow.context.FlowRepositoryContext;
4+
import com.codingapi.springboot.flow.domain.FlowNode;
5+
import com.codingapi.springboot.flow.domain.FlowWork;
6+
import com.codingapi.springboot.flow.operator.IFlowOperator;
7+
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
12+
public class FlowWorkBuilder {
13+
14+
private final FlowWork flowWork = new FlowWork();
15+
16+
private FlowWorkBuilder(IFlowOperator createOperator) {
17+
flowWork.setEnable(true);
18+
flowWork.setLock(false);
19+
flowWork.setCreateUser(createOperator);
20+
flowWork.setCreateTime(System.currentTimeMillis());
21+
}
22+
23+
public static FlowWorkBuilder Builder(IFlowOperator createOperator) {
24+
return new FlowWorkBuilder(createOperator);
25+
}
26+
27+
public FlowWorkBuilder title(String title) {
28+
flowWork.setTitle(title);
29+
return this;
30+
}
31+
32+
public FlowWorkBuilder description(String description) {
33+
flowWork.setDescription(description);
34+
return this;
35+
}
36+
37+
public FlowNodeBuilder nodes() {
38+
return new FlowNodeBuilder();
39+
}
40+
41+
public FlowWorkBuilder schema(String schema) {
42+
flowWork.setSchema(schema);
43+
return this;
44+
}
45+
46+
public FlowWorkBuilder enable(boolean enable) {
47+
flowWork.setEnable(enable);
48+
return this;
49+
}
50+
51+
public FlowWorkBuilder lock(boolean lock) {
52+
flowWork.setLock(lock);
53+
return this;
54+
}
55+
56+
public FlowWork build() {
57+
flowWork.setUpdateTime(System.currentTimeMillis());
58+
return flowWork;
59+
}
60+
61+
public class Relations{
62+
private final List<FlowNode> list;
63+
64+
private Relations(List<FlowNode> list) {
65+
this.list = list;
66+
}
67+
68+
public Relations relation(String... codes) {
69+
relationNodes(codes);
70+
return this;
71+
}
72+
73+
public FlowWork build() {
74+
FlowNode flowNode = getFlowNodeByCode(FlowNode.CODE_START);
75+
if(flowNode==null){
76+
throw new RuntimeException("start node not found");
77+
}
78+
list.add(flowNode);
79+
FlowRepositoryContext.getInstance().save(flowWork);
80+
list.forEach(FlowRepositoryContext.getInstance()::save);
81+
flowWork.setNodes(list);
82+
return flowWork;
83+
}
84+
85+
private FlowNode getFlowNodeByCode(String code) {
86+
for (FlowNode flowNode : list) {
87+
if (flowNode.getCode().equals(code)) {
88+
return flowNode;
89+
}
90+
}
91+
return null;
92+
}
93+
94+
private void relationNodes(String[] codes) {
95+
int length = codes.length;
96+
if (length >= 2) {
97+
String first = codes[0];
98+
FlowNode firstNode = getFlowNodeByCode(first);
99+
if (firstNode == null) {
100+
throw new RuntimeException(first+" not found node");
101+
}
102+
String next = codes[1];
103+
FlowNode nexNode = getFlowNodeByCode(next);
104+
if (nexNode == null) {
105+
throw new RuntimeException(next+" not found node");
106+
}
107+
nexNode.setParentCode(first);
108+
firstNode.addNextNode(nexNode);
109+
relationNodes(Arrays.copyOfRange(codes, 1, length));
110+
}
111+
}
112+
}
113+
114+
115+
public class FlowNodeBuilder {
116+
117+
private final List<FlowNode> list = new ArrayList<>();
118+
119+
private FlowNodeBuilder() {
120+
}
121+
122+
public FlowNodeBuilder node(FlowNode flowNode) {
123+
flowNode.setFlowWork(flowWork);
124+
list.add(flowNode);
125+
return this;
126+
}
127+
128+
public Relations relations() {
129+
return new Relations(list);
130+
}
131+
132+
133+
}
134+
135+
136+
}

0 commit comments

Comments
 (0)