Skip to content

Commit adcd6b8

Browse files
committed
update flow
1 parent 7bf1a12 commit adcd6b8

File tree

58 files changed

+2555
-745
lines changed

Some content is hidden

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

58 files changed

+2555
-745
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>2.9.6</version>
15+
<version>2.9.7</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>

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.6</version>
8+
<version>2.9.7</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicSQLBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public String getHQL() {
4545
Sort sort = request.getSort();
4646
if (sort.isSorted()) {
4747
hql.append(" ORDER BY ");
48-
List<Sort.Order> orders = sort.toList();
48+
List<Sort.Order> orders = sort.collect(Collectors.toList());
4949
for (int i = 0; i < orders.size(); i++) {
5050
Sort.Order order = orders.get(i);
5151
hql.append(order.getProperty()).append(" ").append(order.getDirection().name());

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.6</version>
9+
<version>2.9.7</version>
1010
</parent>
1111

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

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/bind/IBindData.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ public interface IBindData {
1515
default String toJsonSnapshot() {
1616
return JSONObject.toJSONString(this);
1717
}
18+
19+
20+
/**
21+
* 获取类名称
22+
* @return 类名称
23+
*/
24+
default String getClazzName() {
25+
return this.getClass().getName();
26+
}
1827
}

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/content/FlowSession.java

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
import com.codingapi.springboot.flow.domain.Opinion;
77
import com.codingapi.springboot.flow.error.NodeResult;
88
import com.codingapi.springboot.flow.error.OperatorResult;
9+
import com.codingapi.springboot.flow.pojo.FlowResult;
10+
import com.codingapi.springboot.flow.pojo.FlowSubmitResult;
911
import com.codingapi.springboot.flow.record.FlowRecord;
12+
import com.codingapi.springboot.flow.result.MessageResult;
13+
import com.codingapi.springboot.flow.service.FlowService;
1014
import com.codingapi.springboot.flow.user.IFlowOperator;
1115
import lombok.Getter;
1216

@@ -18,16 +22,34 @@
1822
@Getter
1923
public class FlowSession {
2024

25+
// 当前的流程记录
26+
private final FlowRecord flowRecord;
27+
// 当前的流程设计器
2128
private final FlowWork flowWork;
29+
// 当前的流程节点
2230
private final FlowNode flowNode;
31+
// 流程的创建者
2332
private final IFlowOperator createOperator;
33+
// 当前的操作者
2434
private final IFlowOperator currentOperator;
35+
// 流程绑定数据
2536
private final IBindData bindData;
37+
// 流程审批意见
2638
private final Opinion opinion;
39+
// 当前节点的审批记录
2740
private final List<FlowRecord> historyRecords;
41+
// bean提供者
2842
private final FlowSessionBeanProvider provider;
2943

30-
public FlowSession(FlowWork flowWork, FlowNode flowNode, IFlowOperator createOperator, IFlowOperator currentOperator, IBindData bindData, Opinion opinion, List<FlowRecord> historyRecords) {
44+
public FlowSession(FlowRecord flowRecord,
45+
FlowWork flowWork,
46+
FlowNode flowNode,
47+
IFlowOperator createOperator,
48+
IFlowOperator currentOperator,
49+
IBindData bindData,
50+
Opinion opinion,
51+
List<FlowRecord> historyRecords) {
52+
this.flowRecord = flowRecord;
3153
this.flowWork = flowWork;
3254
this.flowNode = flowNode;
3355
this.createOperator = createOperator;
@@ -73,5 +95,124 @@ public OperatorResult createOperatorErrTrigger(long... operatorIds) {
7395
return new OperatorResult(operatorIds);
7496
}
7597

98+
/**
99+
* 创建流程提醒
100+
*
101+
* @param title 提醒标题
102+
* @return 提醒对象
103+
*/
104+
public MessageResult createMessageResult(String title, String resultState) {
105+
return MessageResult.create(title, resultState);
106+
}
107+
108+
109+
/**
110+
* 创建流程提醒
111+
*
112+
* @param title 提醒标题
113+
* @return 提醒对象
114+
*/
115+
public MessageResult createMessageResult(String title) {
116+
return MessageResult.create(title);
117+
}
118+
119+
/**
120+
* 创建流程提醒
121+
*
122+
* @param title 提醒标题
123+
* @param closeable 是否可关闭流程
124+
* @return 提醒对象
125+
*/
126+
public MessageResult createMessageResult(String title, String resultState, boolean closeable) {
127+
return MessageResult.create(title, resultState, closeable);
128+
}
129+
130+
131+
/**
132+
* 创建流程提醒
133+
*
134+
* @param title 提醒标题
135+
* @param items 提醒内容
136+
* @param closeable 是否可关闭流程
137+
* @return 提醒对象
138+
*/
139+
public MessageResult createMessageResult(String title, String resultState, List<MessageResult.Message> items, boolean closeable) {
140+
return MessageResult.create(title, resultState, items, closeable);
141+
}
142+
143+
/**
144+
* 提交流程
145+
*/
146+
public MessageResult submitFlow() {
147+
if (flowRecord == null) {
148+
throw new IllegalArgumentException("flow record is null");
149+
}
150+
FlowService flowService = loadFlowService();
151+
FlowResult result = flowService.submitFlow(flowRecord.getId(), currentOperator, bindData, Opinion.pass(opinion.getAdvice()));
152+
return MessageResult.create(result);
153+
}
76154

155+
/**
156+
* 驳回流程
157+
*/
158+
public MessageResult rejectFlow() {
159+
if (flowRecord == null) {
160+
throw new IllegalArgumentException("flow record is null");
161+
}
162+
FlowService flowService = loadFlowService();
163+
FlowResult result = flowService.submitFlow(flowRecord.getId(), currentOperator, bindData, Opinion.reject(opinion.getAdvice()));
164+
return MessageResult.create(result);
165+
}
166+
167+
168+
/**
169+
* 预提交流程
170+
*/
171+
public MessageResult trySubmitFlow() {
172+
if (flowRecord == null) {
173+
throw new IllegalArgumentException("flow record is null");
174+
}
175+
FlowService flowService = loadFlowService();
176+
FlowSubmitResult result = flowService.trySubmitFlow(flowRecord.getId(), currentOperator, bindData, Opinion.pass(opinion.getAdvice()));
177+
return MessageResult.create(result);
178+
}
179+
180+
/**
181+
* 保存流程
182+
*/
183+
public void saveFlow() {
184+
if (flowRecord == null) {
185+
throw new IllegalArgumentException("flow record is null");
186+
}
187+
FlowService flowService = loadFlowService();
188+
flowService.save(flowRecord.getId(), currentOperator, bindData, opinion.getAdvice());
189+
}
190+
191+
192+
/**
193+
* 催办流程
194+
*/
195+
public void urgeFlow() {
196+
if (flowRecord == null) {
197+
throw new IllegalArgumentException("flow record is null");
198+
}
199+
FlowService flowService = loadFlowService();
200+
flowService.urge(flowRecord.getId(), currentOperator);
201+
}
202+
203+
/**
204+
* 撤回流程
205+
*/
206+
public void recallFlow() {
207+
if (flowRecord == null) {
208+
throw new IllegalArgumentException("flow record is null");
209+
}
210+
FlowService flowService = loadFlowService();
211+
flowService.recall(flowRecord.getId(), currentOperator);
212+
}
213+
214+
215+
private FlowService loadFlowService() {
216+
return (FlowService) getBean("flowService");
217+
}
77218
}

0 commit comments

Comments
 (0)