Skip to content

Commit ff30a9c

Browse files
authored
Merge pull request #33 from codingapi/dev
#13
2 parents c538601 + a7d5c69 commit ff30a9c

13 files changed

Lines changed: 436 additions & 22 deletions

File tree

flow-engine-framework/src/main/java/com/codingapi/flow/form/FormData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static class DataBody {
123123
public DataBody(FormMeta formMeta) {
124124
this.formMeta = formMeta;
125125
this.data = new HashMap<>();
126-
this.fieldTypes = formMeta.getMainFieldTypeMaps();
126+
this.fieldTypes = formMeta.loadMainFieldTypeMaps();
127127
}
128128

129129

flow-engine-framework/src/main/java/com/codingapi/flow/form/FormMeta.java

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

3-
import com.alibaba.fastjson.JSON;
43
import lombok.Getter;
54
import lombok.Setter;
65

@@ -91,7 +90,7 @@ public static FormMeta fromMap(Map<String, Object> map) {
9190
/**
9291
* 获取表单字段名称
9392
*/
94-
public List<String> getFieldNames() {
93+
public List<String> loadFieldNames() {
9594
return fields.stream().map(FormFieldMeta::getName).toList();
9695
}
9796

@@ -118,7 +117,7 @@ private void initFormFieldTypes(FormMeta form, Map<String, String> types) {
118117
*
119118
* @return 表单字段类型
120119
*/
121-
public Map<String, String> getAllFieldTypeMaps() {
120+
public Map<String, String> loadAllFieldTypeMaps() {
122121
Map<String, String> types = new HashMap<>();
123122
List<FormMeta> forms = this.getSubForms();
124123
if (forms == null) {
@@ -137,7 +136,7 @@ public Map<String, String> getAllFieldTypeMaps() {
137136
*
138137
* @return 表单字段类型
139138
*/
140-
public Map<String, String> getMainFieldTypeMaps() {
139+
public Map<String, String> loadMainFieldTypeMaps() {
141140
Map<String, String> types = new HashMap<>();
142141
List<FormMeta> forms = new ArrayList<>();
143142
forms.add(this);

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

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
import com.codingapi.flow.action.IFlowAction;
44
import com.codingapi.flow.form.FormMeta;
5+
import com.codingapi.flow.manager.NodeStrategyManager;
6+
import com.codingapi.flow.manager.OperatorManager;
7+
import com.codingapi.flow.node.IFlowNode;
8+
import com.codingapi.flow.operator.IFlowOperator;
9+
import com.codingapi.flow.record.FlowRecord;
10+
import com.codingapi.flow.session.FlowSession;
11+
import com.codingapi.flow.strategy.node.OperatorLoadStrategy;
12+
import com.codingapi.flow.workflow.Workflow;
513
import lombok.Data;
614

15+
import java.util.ArrayList;
716
import java.util.List;
817
import java.util.Map;
918

@@ -48,7 +57,22 @@ public class FlowContent {
4857
/**
4958
* 发起者id
5059
*/
51-
private long createOperatorId;
60+
private FlowOperator createOperator;
61+
62+
/**
63+
* 当前审批者id
64+
*/
65+
private FlowOperator currentOperator;
66+
67+
/**
68+
* 流程状态 | 运行中、已完成、异常、删除
69+
*/
70+
private int flowState;
71+
72+
/**
73+
* 节点状态 | 待办、已办
74+
*/
75+
private int recordState;
5276

5377
/**
5478
* 历史记录
@@ -60,6 +84,78 @@ public class FlowContent {
6084
*/
6185
private List<NextNode> nextNodes;
6286

87+
public void pushNextNodes(FlowSession flowSession, List<IFlowNode> nextNodes) {
88+
List<NextNode> nextNodeList = new ArrayList<>();
89+
for (IFlowNode node : nextNodes){
90+
NextNode nextNode = new NextNode();
91+
nextNode.setNodeId(node.getId());
92+
nextNode.setNodeName(node.getName());
93+
nextNode.setNodeType(node.getType());
94+
95+
NodeStrategyManager nodeStrategyManager = node.strategyManager();
96+
OperatorManager operatorManager = nodeStrategyManager.loadOperators(flowSession);
97+
nextNode.setOperators(operatorManager.getOperators().stream().map(FlowOperator::new).toList());
98+
99+
nextNodeList.add(nextNode);
100+
}
101+
this.nextNodes = nextNodeList;
102+
}
103+
104+
public void pushCurrentNode(IFlowNode currentNode) {
105+
this.actions = currentNode.actionManager().getActions();
106+
Map<String,Object> nodeData = currentNode.toMap();
107+
this.view = (String) nodeData.get("view");
108+
}
109+
110+
public void pushWorkflow(Workflow workflow) {
111+
this.form = workflow.getForm();
112+
this.workflowCode = workflow.getCode();
113+
}
114+
115+
public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {
116+
this.recordId = record.getId();
117+
this.createOperator = new FlowOperator(record.getCreateOperatorId(), record.getCreateOperatorName());
118+
this.mergeable = record.isMergeable();
119+
this.flowState = record.getFlowState();
120+
this.recordState = record.getRecordState();
121+
122+
this.todos = new ArrayList<>();
123+
for (FlowRecord item : mergeRecords){
124+
Body body = new Body();
125+
body.setRecordId(item.getId());
126+
body.setTitle(item.getTitle());
127+
body.setData(item.getFormData());
128+
body.setRecordState(item.getRecordState());
129+
body.setFlowState(item.getFlowState());
130+
this.todos.add(body);
131+
}
132+
}
133+
134+
public void pushHistory(Workflow workflow,List<FlowRecord> historyRecords) {
135+
this.histories = new ArrayList<>();
136+
for (FlowRecord item : historyRecords){
137+
IFlowNode node = workflow.getFlowNode(item.getNodeId());
138+
History history = new History();
139+
history.setRecordId(item.getId());
140+
history.setTitle(item.getTitle());
141+
history.setAdvice(item.getAdvice());
142+
history.setSignKey(item.getSignKey());
143+
history.setNodeName(node.getName());
144+
history.setNodeId(item.getNodeId());
145+
history.setNodeType(item.getNodeType());
146+
history.setUpdateTime(item.getUpdateTime());
147+
history.setCurrentOperatorId(item.getCurrentOperatorId());
148+
history.setCurrentOperatorName(item.getCurrentOperatorName());
149+
this.histories.add(history);
150+
}
151+
}
152+
153+
public void pushCurrentOperator(IFlowOperator currentOperator) {
154+
this.currentOperator = new FlowOperator(currentOperator);
155+
this.createOperator = new FlowOperator(currentOperator);
156+
}
157+
158+
63159
/**
64160
* 流程图
65161
*/
@@ -77,6 +173,11 @@ public static class NextNode{
77173
* 节点类型
78174
*/
79175
private String nodeType;
176+
177+
/**
178+
* 节点审批人
179+
*/
180+
private List<FlowOperator> operators;
80181
}
81182

82183
@Data
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codingapi.flow.pojo.response;
2+
3+
import com.codingapi.flow.operator.IFlowOperator;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
7+
/**
8+
* 流程审批人
9+
*/
10+
@Data
11+
@AllArgsConstructor
12+
public class FlowOperator {
13+
14+
private long id;
15+
private String name;
16+
17+
public FlowOperator(IFlowOperator flowOperator) {
18+
this.id = flowOperator.getUserId();
19+
this.name = flowOperator.getName();
20+
}
21+
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.codingapi.flow.record;
22

33
import com.codingapi.flow.action.IFlowAction;
4+
import com.codingapi.flow.context.RepositoryHolderContext;
45
import com.codingapi.flow.exception.FlowValidationException;
6+
import com.codingapi.flow.form.FormData;
57
import com.codingapi.flow.manager.NodeStrategyManager;
68
import com.codingapi.flow.node.IFlowNode;
79
import com.codingapi.flow.operator.IFlowOperator;
@@ -14,6 +16,8 @@
1416
import lombok.Setter;
1517
import org.springframework.util.StringUtils;
1618

19+
import java.util.ArrayList;
20+
import java.util.List;
1721
import java.util.Map;
1822

1923
/**
@@ -543,4 +547,29 @@ public void newRecord() {
543547
public boolean isForward() {
544548
return forwardOperatorId > 0;
545549
}
550+
551+
552+
/**
553+
* 创建会话
554+
* @param workflow 流程设计器
555+
* @param currentOperator 当前操作人
556+
* @param formData 表单数据
557+
* @param advice 节点审批信息
558+
* @return FlowSession
559+
*/
560+
public FlowSession createFlowSession( Workflow workflow,IFlowOperator currentOperator,FormData formData, FlowAdvice advice) {
561+
List<FlowRecord> currentRecords = RepositoryHolderContext.getInstance().findCurrentNodeRecords(this.getFromId(), this.getNodeId());
562+
IFlowNode currentNode = workflow.getFlowNode(nodeId);
563+
return new FlowSession(
564+
currentOperator,
565+
workflow,
566+
currentNode,
567+
advice.getAction(),
568+
formData,
569+
this,
570+
currentRecords,
571+
this.workBackupId,
572+
advice
573+
);
574+
}
546575
}

flow-engine-framework/src/main/java/com/codingapi/flow/repository/FlowRecordRepository.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ public interface FlowRecordRepository {
1616
*/
1717
FlowRecord get(long id);
1818

19+
/**
20+
* 批量获取流程详细
21+
* @param ids 流程id列表
22+
* @return 批量流程记录
23+
*/
24+
List<FlowRecord> findByIds(List<Long> ids);
25+
1926
/**
2027
* 保存流程
2128
* 为何确保待办合并数据的一致性,保存流程需要通过 {@link com.codingapi.flow.context.RepositoryHolderContext#saveRecord(FlowRecord)} 保存
@@ -69,4 +76,13 @@ public interface FlowRecordRepository {
6976
*/
7077
List<FlowRecord> findAfterRecords(String processId, long fromId);
7178

79+
80+
/**
81+
* 查询所有之前的流程记录
82+
* @param processId 流程id
83+
* @param id 记录id
84+
* @return 记录列表
85+
*/
86+
List<FlowRecord> findBeforeRecords(String processId,long id);
87+
7288
}

flow-engine-framework/src/main/java/com/codingapi/flow/service/impl/FlowActionService.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import com.codingapi.flow.session.FlowSession;
1919
import com.codingapi.flow.workflow.Workflow;
2020

21-
import java.util.List;
22-
2321
/**
2422
* 节点动作服务
2523
*/
@@ -78,8 +76,7 @@ public void action() {
7876
formData.reset(request.getFormData());
7977
FlowAdvice flowAdvice = request.toFlowAdvice(workflow, flowAction);
8078

81-
List<FlowRecord> currentRecords = RepositoryHolderContext.getInstance().findCurrentNodeRecords(flowRecord.getFromId(), flowRecord.getNodeId());
82-
FlowSession session = new FlowSession(currentOperator, workflow, currentNode, flowAction, formData, flowRecord, currentRecords, workflowBackup.getId(), flowAdvice);
79+
FlowSession session = flowRecord.createFlowSession(workflow,currentOperator,formData,flowAdvice);
8380
// 验证会话
8481
currentNode.verifySession(session);
8582
// 执行动作

0 commit comments

Comments
 (0)