Skip to content

Commit 0a5fd5b

Browse files
committed
add buttons
1 parent 0d7d978 commit 0a5fd5b

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.codingapi.springboot.flow.build;
22

3+
import com.codingapi.springboot.flow.domain.FlowButton;
34
import com.codingapi.springboot.flow.domain.FlowNode;
45
import com.codingapi.springboot.flow.domain.FlowRelation;
56
import com.codingapi.springboot.flow.domain.FlowWork;
@@ -12,6 +13,8 @@
1213
import com.codingapi.springboot.flow.user.IFlowOperator;
1314
import com.codingapi.springboot.framework.utils.RandomGenerator;
1415

16+
import java.util.List;
17+
1518
/**
1619
* 流程工作构建器
1720
*/
@@ -65,25 +68,43 @@ public FlowWork build() {
6568

6669
public class Nodes {
6770

68-
public Nodes node(String id,String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, TitleGenerator titleGenerator, ErrTrigger errTrigger, boolean editable) {
69-
FlowNode node = new FlowNode(id, name, code, view, NodeType.parser(code), approvalType, titleGenerator, operatorMatcher, timeout, errTrigger, editable);
71+
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) {
72+
FlowNode node = new FlowNode(id, name, code, view, NodeType.parser(code), approvalType, titleGenerator, operatorMatcher, timeout, errTrigger, editable, buttons);
7073
work.addNode(node);
7174
return this;
7275
}
7376

74-
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher,long timeout, boolean editable) {
75-
return node(RandomGenerator.generateUUID(),name, code, view, approvalType, operatorMatcher, timeout, TitleGenerator.defaultTitleGenerator(), null, editable);
77+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, boolean editable) {
78+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, timeout, TitleGenerator.defaultTitleGenerator(), null, editable, null);
79+
}
80+
81+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, long timeout, boolean editable, List<FlowButton> buttons) {
82+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, timeout, TitleGenerator.defaultTitleGenerator(), null, editable, buttons);
7683
}
84+
85+
7786
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, boolean editable) {
78-
return node(RandomGenerator.generateUUID(),name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), null, editable);
87+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), null, editable, null);
88+
}
89+
90+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, boolean editable, List<FlowButton> buttons) {
91+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), null, editable, buttons);
92+
}
93+
94+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, List<FlowButton> buttons) {
95+
return node(name, code, view, approvalType, operatorMatcher, true, buttons);
7996
}
8097

8198
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher) {
82-
return node(name, code, view, approvalType, operatorMatcher, true);
99+
return node(name, code, view, approvalType, operatorMatcher, true, null);
100+
}
101+
102+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, ErrTrigger errTrigger, boolean editable, List<FlowButton> buttons) {
103+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), errTrigger, editable, buttons);
83104
}
84105

85-
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, ErrTrigger errTrigger, boolean editable) {
86-
return node(RandomGenerator.generateUUID(),name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), errTrigger, editable);
106+
public Nodes node(String name, String code, String view, ApprovalType approvalType, OperatorMatcher operatorMatcher, ErrTrigger errTrigger, boolean editable) {
107+
return node(RandomGenerator.generateUUID(), name, code, view, approvalType, operatorMatcher, 0, TitleGenerator.defaultTitleGenerator(), errTrigger, editable, null);
87108
}
88109

89110

@@ -102,13 +123,13 @@ public FlowWork build() {
102123
public class Relations {
103124

104125
public Relations relation(String name, String source, String target) {
105-
return relation(name,source,target,OutTrigger.defaultOutTrigger(),1,false);
126+
return relation(name, source, target, OutTrigger.defaultOutTrigger(), 1, false);
106127
}
107128

108-
public Relations relation(String name, String source, String target, OutTrigger outTrigger,int order, boolean back) {
129+
public Relations relation(String name, String source, String target, OutTrigger outTrigger, int order, boolean back) {
109130
FlowNode from = work.getNodeByCode(source);
110131
FlowNode to = work.getNodeByCode(target);
111-
FlowRelation relation = new FlowRelation(RandomGenerator.generateUUID(), name, from, to, outTrigger,order, back);
132+
FlowRelation relation = new FlowRelation(RandomGenerator.generateUUID(), name, from, to, outTrigger, order, back);
112133
work.addRelation(relation);
113134
return this;
114135
}

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.alibaba.fastjson.JSONArray;
44
import com.alibaba.fastjson.JSONObject;
5+
import com.codingapi.springboot.flow.domain.FlowButton;
56
import com.codingapi.springboot.flow.domain.FlowNode;
67
import com.codingapi.springboot.flow.domain.FlowRelation;
78
import com.codingapi.springboot.flow.em.ApprovalType;
@@ -37,7 +38,7 @@ public SchemaReader(String schema) {
3738
}
3839

3940

40-
private void loadNodes(){
41+
private void loadNodes() {
4142
JSONArray nodes = data.getJSONArray("nodes");
4243
for (int i = 0; i < nodes.size(); i++) {
4344
JSONObject node = nodes.getJSONObject(i);
@@ -53,39 +54,43 @@ private void loadNodes(){
5354
int timeout = properties.getIntValue("timeout");
5455
String errTrigger = properties.getString("errTrigger");
5556
String id = properties.getString("id");
56-
FlowNode flowNode = new FlowNode(id,name,code,view, NodeType.parser(type),ApprovalType.parser(approvalType),new TitleGenerator(titleGenerator),
57-
new OperatorMatcher(operatorMatcher),timeout, StringUtils.hasLength(errTrigger)?new ErrTrigger(errTrigger):null,editable);
57+
List<FlowButton> buttons = null;
58+
if(properties.containsKey("buttons")){
59+
buttons = properties.getJSONArray("buttons").toJavaList(FlowButton.class);
60+
}
61+
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);
5863
flowNodes.add(flowNode);
5964
}
6065
}
6166

62-
private FlowNode getFlowNodeById(String id){
63-
for(FlowNode flowNode:flowNodes){
64-
if(flowNode.getId().equals(id)){
67+
private FlowNode getFlowNodeById(String id) {
68+
for (FlowNode flowNode : flowNodes) {
69+
if (flowNode.getId().equals(id)) {
6570
return flowNode;
6671
}
6772
}
6873
return null;
6974
}
7075

71-
private void loadEdges(){
76+
private void loadEdges() {
7277
JSONArray edges = data.getJSONArray("edges");
73-
for(int i=0;i<edges.size();i++){
78+
for (int i = 0; i < edges.size(); i++) {
7479
JSONObject edge = edges.getJSONObject(i);
7580
String id = edge.getString("id");
7681
String sourceNodeId = edge.getString("sourceNodeId");
7782
String targetNodeId = edge.getString("targetNodeId");
7883

7984
JSONObject properties = edge.getJSONObject("properties");
80-
String name = properties.containsKey("name")?properties.getString("name"):null;
81-
String outTrigger = properties.containsKey("outTrigger")?properties.getString("outTrigger"):OutTrigger.defaultOutTrigger().getScript();
82-
boolean back = properties.containsKey("back")?properties.getBoolean("back"):false;
83-
int order = properties.containsKey("order")?properties.getIntValue("order"):1;
85+
String name = properties.containsKey("name") ? properties.getString("name") : null;
86+
String outTrigger = properties.containsKey("outTrigger") ? properties.getString("outTrigger") : OutTrigger.defaultOutTrigger().getScript();
87+
boolean back = properties.containsKey("back") ? properties.getBoolean("back") : false;
88+
int order = properties.containsKey("order") ? properties.getIntValue("order") : 1;
8489

8590
FlowNode source = getFlowNodeById(sourceNodeId);
8691
FlowNode target = getFlowNodeById(targetNodeId);
8792

88-
FlowRelation relation = new FlowRelation(id,name,source,target,new OutTrigger(outTrigger),order,back);
93+
FlowRelation relation = new FlowRelation(id, name, source, target, new OutTrigger(outTrigger), order, back);
8994
flowRelations.add(relation);
9095
}
9196
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public FlowNode(String id,
153153
OperatorMatcher operatorMatcher,
154154
long timeout,
155155
ErrTrigger errTrigger,
156-
boolean editable) {
156+
boolean editable,
157+
List<FlowButton> buttons) {
157158
this.id = id;
158159
this.code = code;
159160
this.name = name;
@@ -167,6 +168,7 @@ public FlowNode(String id,
167168
this.errTrigger = errTrigger;
168169
this.timeout = timeout;
169170
this.editable = editable;
171+
this.buttons = buttons;
170172
}
171173

172174

0 commit comments

Comments
 (0)