Skip to content

Commit 913a130

Browse files
committed
add processNodes api
1 parent 8e3f994 commit 913a130

27 files changed

Lines changed: 784 additions & 254 deletions

File tree

flow-engine-framework/src/main/java/com/codingapi/flow/pojo/request/FlowCreateRequest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public class FlowCreateRequest {
3131
*/
3232
private long operatorId;
3333

34+
/**
35+
* 父流程id
36+
*/
37+
private long parentRecordId;
38+
39+
3440
public FlowActionRequest toActionRequest(long recordId) {
3541
FlowActionRequest flowActionRequest = new FlowActionRequest();
3642
flowActionRequest.setFormData(this.getFormData());
@@ -56,4 +62,7 @@ public void verify() {
5662
}
5763
}
5864

65+
public boolean isSubProcess() {
66+
return this.parentRecordId!=0;
67+
}
5968
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.codingapi.flow.pojo.request;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
6+
/**
7+
* 流程详情请求
8+
*/
9+
@Data
10+
@NoArgsConstructor
11+
public class FlowDetailRequest {
12+
/**
13+
* 详情id,可以是workId或者是recordId
14+
*/
15+
private String id;
16+
/**
17+
* 流程的操作人Id
18+
*/
19+
private long operatorId;
20+
21+
public boolean isCreateWorkflow() {
22+
return !id.matches("^[0-9]+$");
23+
}
24+
25+
public FlowDetailRequest(long id,long operatorId){
26+
this.id = String.valueOf(id);
27+
this.operatorId = operatorId;
28+
}
29+
30+
public FlowDetailRequest(String id, long operatorId) {
31+
this.id = id;
32+
this.operatorId = operatorId;
33+
}
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.codingapi.flow.pojo.request;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
6+
import java.util.Map;
7+
8+
/**
9+
* 流程节点记录请求
10+
*/
11+
@Data
12+
@NoArgsConstructor
13+
public class FlowProcessNodeRequest {
14+
/**
15+
* 详情id,可以是workId或者是recordId
16+
*/
17+
private String id;
18+
19+
/**
20+
* 流程的操作人Id
21+
*/
22+
private long operatorId;
23+
24+
/**
25+
* 表单数据
26+
*/
27+
private Map<String, Object> formData;
28+
29+
public FlowProcessNodeRequest(long id, long operatorId, Map<String, Object> formData) {
30+
this.id = String.valueOf(id);
31+
this.operatorId = operatorId;
32+
this.formData = formData;
33+
}
34+
35+
public FlowProcessNodeRequest(String id, long operatorId, Map<String, Object> formData) {
36+
this.id = id;
37+
this.operatorId = operatorId;
38+
this.formData = formData;
39+
}
40+
41+
public boolean isCreateWorkflow() {
42+
return !id.matches("^[0-9]+$");
43+
}
44+
}

flow-engine-framework/src/main/java/com/codingapi/flow/pojo/request/FlowRevokeRequest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import lombok.Data;
66
import lombok.NoArgsConstructor;
77

8+
/**
9+
* 流程撤回请求
10+
*/
811
@Data
912
@NoArgsConstructor
1013
@AllArgsConstructor

flow-engine-framework/src/main/java/com/codingapi/flow/pojo/request/FlowUrgeRequest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import lombok.Data;
66
import lombok.NoArgsConstructor;
77

8+
/**
9+
* 流程催办请求
10+
*/
811
@Data
912
@NoArgsConstructor
1013
@AllArgsConstructor

flow-engine-framework/src/main/java/com/codingapi/flow/pojo/response/FlowContent.java

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
import com.codingapi.flow.form.FormMeta;
55
import com.codingapi.flow.manager.ActionManager;
66
import com.codingapi.flow.manager.NodeStrategyManager;
7-
import com.codingapi.flow.manager.OperatorManager;
87
import com.codingapi.flow.node.IFlowNode;
98
import com.codingapi.flow.operator.IFlowOperator;
109
import com.codingapi.flow.record.FlowRecord;
11-
import com.codingapi.flow.session.FlowSession;
1210
import com.codingapi.flow.workflow.Workflow;
1311
import lombok.Data;
1412

@@ -95,36 +93,15 @@ public class FlowContent {
9593
*/
9694
private List<History> histories;
9795

98-
/**
99-
* 下一审批
100-
*/
101-
private List<NextNode> nextNodes;
102-
103-
public void pushNextNodes(FlowSession flowSession, List<IFlowNode> nextNodes) {
104-
List<NextNode> nextNodeList = new ArrayList<>();
105-
for (IFlowNode node : nextNodes){
106-
NextNode nextNode = new NextNode();
107-
nextNode.setNodeId(node.getId());
108-
nextNode.setNodeName(node.getName());
109-
nextNode.setNodeType(node.getType());
110-
111-
NodeStrategyManager nodeStrategyManager = node.strategyManager();
112-
OperatorManager operatorManager = nodeStrategyManager.loadOperators(flowSession);
113-
nextNode.setOperators(operatorManager.getOperators().stream().map(FlowOperator::new).toList());
114-
115-
nextNodeList.add(nextNode);
116-
}
117-
this.nextNodes = nextNodeList;
118-
}
11996

12097
public void pushCurrentNode(IFlowNode currentNode) {
12198
ActionManager actionManager = currentNode.actionManager();
12299
NodeStrategyManager strategyManager = currentNode.strategyManager();
123100
this.actions = actionManager.getActions();
124-
Map<String,Object> nodeData = currentNode.toMap();
125-
this.view = (String) nodeData.get("view");
126101
this.adviceNullable = strategyManager.isEnableAdvice();
127102
this.signable = strategyManager.isEnableSignable();
103+
Map<String,Object> nodeData = currentNode.toMap();
104+
this.view = (String) nodeData.get("view");
128105
}
129106

130107
public void pushWorkflow(Workflow workflow) {
@@ -176,30 +153,6 @@ public void pushCurrentOperator(IFlowOperator currentOperator) {
176153
}
177154

178155

179-
/**
180-
* 流程图
181-
*/
182-
@Data
183-
public static class NextNode{
184-
/**
185-
* 节点名称
186-
*/
187-
private String nodeId;
188-
/**
189-
* 节点名称
190-
*/
191-
private String nodeName;
192-
/**
193-
* 节点类型
194-
*/
195-
private String nodeType;
196-
197-
/**
198-
* 节点审批人
199-
*/
200-
private List<FlowOperator> operators;
201-
}
202-
203156
@Data
204157
public static class History{
205158
/**
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.codingapi.flow.pojo.response;
2+
3+
import com.codingapi.flow.node.IFlowNode;
4+
import com.codingapi.flow.operator.IFlowOperator;
5+
import com.codingapi.flow.record.FlowRecord;
6+
import com.codingapi.flow.workflow.Workflow;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
/**
14+
* 流程审批节点
15+
*/
16+
@Data
17+
@NoArgsConstructor
18+
public class ProcessNode {
19+
/**
20+
* 节点名称
21+
*/
22+
private String nodeId;
23+
/**
24+
* 节点名称
25+
*/
26+
private String nodeName;
27+
/**
28+
* 节点类型
29+
*/
30+
private String nodeType;
31+
32+
/**
33+
* 是否历史记录
34+
*/
35+
private boolean history;
36+
37+
/**
38+
* 节点审批人
39+
*/
40+
private List<FlowOperatorBody> operators;
41+
42+
43+
public ProcessNode(FlowRecord flowRecord, Workflow workflow) {
44+
this.nodeId = flowRecord.getNodeId();
45+
IFlowNode flowNode = workflow.getFlowNode(this.nodeId);
46+
this.nodeName = flowNode.getName();
47+
this.nodeType = flowNode.getType();
48+
this.operators = new ArrayList<>();
49+
this.history = true;
50+
this.operators.add(new FlowOperatorBody(flowRecord));
51+
}
52+
53+
54+
public ProcessNode(IFlowNode flowNode, List<IFlowOperator> operators) {
55+
this.nodeId = flowNode.getId();
56+
this.nodeName = flowNode.getName();
57+
this.nodeType = flowNode.getType();
58+
this.operators = operators.stream().map(FlowOperatorBody::new).toList();
59+
this.history = false;
60+
}
61+
62+
63+
/**
64+
* 审批意见内容,仅当历史节点存在数据
65+
*/
66+
@Data
67+
@NoArgsConstructor
68+
public static class FlowOperatorBody {
69+
70+
/**
71+
* 审批意见
72+
*/
73+
private String advice;
74+
75+
/**
76+
* 签名key
77+
*/
78+
private String signKey;
79+
80+
/**
81+
* 审批记录
82+
*/
83+
private FlowOperator flowOperator;
84+
/**
85+
* 审批时间
86+
*/
87+
private long approveTime;
88+
89+
public FlowOperatorBody(FlowRecord flowRecord) {
90+
this.advice = flowRecord.getAdvice();
91+
this.signKey = flowRecord.getSignKey();
92+
this.approveTime = flowRecord.getCreateTime();
93+
this.flowOperator = new FlowOperator(flowRecord.getCurrentOperatorId(), flowRecord.getCurrentOperatorName());
94+
}
95+
96+
public FlowOperatorBody(IFlowOperator flowOperator) {
97+
this.flowOperator = new FlowOperator(flowOperator);
98+
}
99+
100+
}
101+
102+
}

flow-engine-framework/src/main/java/com/codingapi/flow/record/FlowRecord.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ public class FlowRecord {
6060
*/
6161
private String nodeType;
6262
/**
63-
* 父节点id
63+
* 来源id
6464
*/
6565
private long fromId;
66+
/**
67+
* 父节点id(用于子流程中)
68+
*/
69+
private long parentId;
70+
6671
/**
6772
* 表单数据
6873
*/
@@ -294,6 +299,7 @@ public void extendsRecord(FlowRecord record) {
294299
this.fromId = record.id;
295300
this.processId = record.processId;
296301
this.delegateId = record.delegateId;
302+
this.parentId = record.getParentId();
297303
}
298304
}
299305

@@ -556,7 +562,10 @@ public boolean isForward() {
556562
* @param advice 节点审批信息
557563
* @return FlowSession
558564
*/
559-
public FlowSession createFlowSession( Workflow workflow,IFlowOperator currentOperator,FormData formData, FlowAdvice advice) {
565+
public FlowSession createFlowSession( Workflow workflow,
566+
IFlowOperator currentOperator,
567+
FormData formData,
568+
FlowAdvice advice) {
560569
List<FlowRecord> currentRecords = RepositoryHolderContext.getInstance().findCurrentNodeRecords(this.getFromId(), this.getNodeId());
561570
IFlowNode currentNode = workflow.getFlowNode(nodeId);
562571
return new FlowSession(

flow-engine-framework/src/main/java/com/codingapi/flow/script/node/SubProcessScript.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codingapi.flow.script.node;
22

33
import com.codingapi.flow.pojo.request.FlowCreateRequest;
4+
import com.codingapi.flow.record.FlowRecord;
45
import com.codingapi.flow.script.runtime.ScriptRuntimeContext;
56
import com.codingapi.flow.session.FlowSession;
67
import lombok.AllArgsConstructor;
@@ -18,7 +19,10 @@ public class SubProcessScript {
1819
private final String script;
1920

2021
public FlowCreateRequest execute(FlowSession request) {
21-
return ScriptRuntimeContext.getInstance().run(script, FlowCreateRequest.class, request);
22+
FlowRecord flowRecord = request.getCurrentRecord();
23+
FlowCreateRequest flowCreateRequest = ScriptRuntimeContext.getInstance().run(script, FlowCreateRequest.class, request);
24+
flowCreateRequest.setParentRecordId(flowRecord.getId());
25+
return flowCreateRequest;
2226
}
2327

2428
public static SubProcessScript defaultScript() {

0 commit comments

Comments
 (0)