Skip to content

Commit 8226a12

Browse files
authored
Merge pull request #94 from codingapi/dev
fix createdOperator bug
2 parents 17137b8 + ac16d4b commit 8226a12

9 files changed

Lines changed: 117 additions & 53 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,17 @@ public boolean isForward() {
600600
public FlowSession createFlowSession(IRepositoryHolder repositoryHolder,
601601
Workflow workflow,
602602
IFlowOperator currentOperator,
603+
IFlowOperator createdOperator,
604+
IFlowOperator submitOperator,
603605
FormData formData,
604606
FlowAdvice advice) {
605607
List<FlowRecord> currentRecords = repositoryHolder.findCurrentNodeRecords(this.getFromId(), this.getNodeId());
606608
IFlowNode currentNode = workflow.getFlowNode(nodeId);
607609
return new FlowSession(
608610
repositoryHolder,
609611
currentOperator,
612+
createdOperator,
613+
submitOperator,
610614
workflow,
611615
currentNode,
612616
advice.getAction(),

flow-engine-framework/src/main/java/com/codingapi/flow/script/request/GroovyScriptRequest.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class GroovyScriptRequest {
6565
* 流程提交Id
6666
*/
6767
@Getter
68-
private long submitOperatorId;
68+
private IFlowOperator submitOperator;
6969

7070
/**
7171
* 流程提交人姓名
@@ -87,14 +87,21 @@ public GroovyScriptRequest(FlowSession session) {
8787
this.currentOperator = session.getCurrentOperator();
8888
}
8989

90+
// 提取创建人信息
91+
if (session.getCreatedOperator() != null) {
92+
this.createdOperator = session.getCreatedOperator();
93+
}
94+
95+
// 提取提交人信息
96+
if (session.getSubmitOperator() != null) {
97+
this.submitOperator = session.getSubmitOperator();
98+
}
99+
90100
// 提取流程信息
91101
if (session.getWorkflow() != null) {
92102
this.workflowTitle = session.getWorkflow().getTitle();
93103
this.workflowCode = session.getWorkflow().getCode();
94-
// 提取创建人信息
95-
if (session.getWorkflow().getCreatedOperator() != null) {
96-
this.createdOperator = session.getWorkflow().getCreatedOperator();
97-
}
104+
98105
}
99106

100107
// 提取节点信息
@@ -103,12 +110,6 @@ public GroovyScriptRequest(FlowSession session) {
103110
this.nodeType = session.getCurrentNode().getType();
104111
}
105112

106-
// 提取流程编号(从record获取)
107-
if (session.getCurrentRecord() != null) {
108-
this.submitOperatorId = session.getSubmitOperatorId();
109-
this.submitOperatorName = session.getSubmitOperatorName();
110-
}
111-
112113
// 提取表单数据
113114
if (session.getFormData() != null) {
114115
this.formData = session.getFormData().toMapData();
@@ -169,6 +170,28 @@ public String getCurrentOperatorName(){
169170
return this.currentOperator.getName();
170171
}
171172

173+
/**
174+
* 流程审批者Id
175+
*/
176+
public long getSubmitOperatorId(){
177+
if(this.submitOperator!=null) {
178+
return this.submitOperator.getUserId();
179+
}
180+
return 0;
181+
}
182+
183+
/**
184+
* 流程审批者名称
185+
*/
186+
public String getSubmitOperatorName(){
187+
if(this.submitOperator!=null) {
188+
return this.submitOperator.getName();
189+
}else {
190+
return null;
191+
}
192+
}
193+
194+
172195

173196
/**
174197
* 获取开始节点

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public void action() {
5454
throw FlowStateException.recordAlreadyDone();
5555
}
5656

57+
IFlowOperator createdOperator = flowOperatorGateway.get(flowRecord.getCreateOperatorId());
58+
IFlowOperator submitOperator = flowOperatorGateway.get(flowRecord.getSubmitOperatorId());
59+
5760
WorkflowRuntime workflowRuntime = workflowService.getWorkflowRuntime(flowRecord.getWorkRuntimeId());
5861
if (workflowRuntime == null) {
5962
throw FlowNotFoundException.workflow(flowRecord.getWorkRuntimeId() + " not found");
@@ -79,7 +82,7 @@ public void action() {
7982
formData.reset(request.getFormData());
8083
FlowAdvice flowAdvice = request.toFlowAdvice(workflow, flowAction);
8184

82-
FlowSession session = flowRecord.createFlowSession(this.repositoryHolder,workflow,currentOperator,formData,flowAdvice);
85+
FlowSession session = flowRecord.createFlowSession(this.repositoryHolder,workflow,currentOperator,createdOperator,submitOperator,formData,flowAdvice);
8386
// 验证会话
8487
currentNode.verifySession(session);
8588
// 执行动作

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public void trigger() {
5555
Workflow workflow = workflowRuntime.toWorkflow();
5656
IFlowNode currentNode = workflow.getFlowNode(flowRecord.getNodeId());
5757

58+
IFlowOperator createdOperator = flowOperatorGateway.get(flowRecord.getCreateOperatorId());
59+
IFlowOperator submitOperator = flowOperatorGateway.get(flowRecord.getSubmitOperatorId());
5860
IFlowOperator currentOperator = flowOperatorGateway.get(flowRecord.getCurrentOperatorId());
5961
IFlowAction flowAction = currentNode.actionManager().getActionById(flowRecord.getActionId());
6062
FormData formData = new FormData(workflow.getForm());
@@ -67,7 +69,7 @@ public void trigger() {
6769
IFlowNode delayNode = workflow.getFlowNode(delayTask.getDelayNodeId());
6870

6971
// 执行后续任务
70-
FlowSession flowSession = new FlowSession(this.repositoryHolder,currentOperator, workflow, delayNode, flowAction, formData, flowRecord, currentRecords, flowRecord.getWorkRuntimeId(), advice);
72+
FlowSession flowSession = new FlowSession(this.repositoryHolder,currentOperator,createdOperator,submitOperator, workflow, delayNode, flowAction, formData, flowRecord, currentRecords, flowRecord.getWorkRuntimeId(), advice);
7173
flowAction.run(flowSession);
7274

7375
}

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class FlowProcessNodeService {
3232

3333
private final FlowProcessNodeRequest request;
3434
private final IFlowOperator currentOperator;
35+
private IFlowOperator createdOperator;
36+
private IFlowOperator submitOperator;
3537
private final FlowRecordService flowRecordService;
3638
private final WorkflowService workflowService;
3739

@@ -63,6 +65,8 @@ private void loadWorkflow() {
6365
if (this.request.isCreateWorkflow()) {
6466
this.workflow = workflowService.getWorkflow(id);
6567
this.currentNode = this.workflow.getStartNode();
68+
this.createdOperator = this.currentOperator;
69+
this.submitOperator = null;
6670
} else {
6771
FlowRecord flowRecord = flowRecordService.getFlowRecord(Long.parseLong(id));
6872
if (flowRecord == null) {
@@ -75,6 +79,8 @@ private void loadWorkflow() {
7579
}
7680
this.workflow = workflowRuntime.toWorkflow();
7781
this.currentNode = this.workflow.getFlowNode(flowRecord.getNodeId());
82+
this.createdOperator = this.repositoryHolder.getOperatorById(this.flowRecord.getCreateOperatorId());
83+
this.submitOperator = this.repositoryHolder.getOperatorById(this.flowRecord.getSubmitOperatorId());
7884
}
7985
}
8086

@@ -83,19 +89,19 @@ public List<ProcessNode> processNodes() {
8389
if (this.flowRecord != null) {
8490
backupId = this.flowRecord.getWorkRuntimeId();
8591
// 如果当前记录已结束,则不查询后续流程
86-
if(this.flowRecord.isDone()){
87-
List<FlowRecord> historyRecords = flowRecordService.findFlowRecordByProcessId(this.flowRecord.getProcessId());
92+
if (this.flowRecord.isDone()) {
93+
List<FlowRecord> historyRecords = flowRecordService.findFlowRecordByProcessId(this.flowRecord.getProcessId());
8894
for (FlowRecord historyRecord : historyRecords) {
8995
ProcessNode processNode = new ProcessNode(historyRecord, this.workflow);
9096
nodeList.add(processNode);
9197
}
92-
if(this.flowRecord.isFinish()){
98+
if (this.flowRecord.isFinish()) {
9399
nodeList.add(ProcessNode.createEndNode(this.workflow));
94-
}else {
100+
} else {
95101
this.loadNextNode(backupId);
96102
}
97103
return this.nodeList;
98-
}else {
104+
} else {
99105
// 查询历史记录
100106
List<FlowRecord> historyRecords = flowRecordService.findFlowRecordBeforeRecords(flowRecord.getProcessId(), flowRecord.getId());
101107
for (FlowRecord historyRecord : historyRecords) {
@@ -111,7 +117,7 @@ public List<ProcessNode> processNodes() {
111117
}
112118

113119

114-
private void loadNextNode(long backupId){
120+
private void loadNextNode(long backupId) {
115121

116122
ActionManager actionManager = currentNode.actionManager();
117123
IFlowAction flowAction = actionManager.getAction(PassAction.class);
@@ -121,6 +127,8 @@ private void loadNextNode(long backupId){
121127
FlowSession flowSession = new FlowSession(
122128
this.repositoryHolder,
123129
this.currentOperator,
130+
this.createdOperator,
131+
this.submitOperator,
124132
this.workflow,
125133
this.currentNode,
126134
flowAction,
@@ -132,7 +140,7 @@ private void loadNextNode(long backupId){
132140
);
133141

134142
NextNodeLoader nextNodeLoader = new NextNodeLoader(this.currentNode);
135-
List<ProcessNode> nextNodes = nextNodeLoader.loadNextNode(flowSession);
143+
List<ProcessNode> nextNodes = nextNodeLoader.loadNextNode(flowSession);
136144

137145
this.nodeList.addAll(nextNodes);
138146
}
@@ -170,12 +178,12 @@ private void fetchNextNode(FlowSession flowSession, List<IFlowNode> nexNodes) {
170178
}
171179

172180
public List<ProcessNode> loadNextNode(FlowSession flowSession) {
173-
this.fetchNextNode(flowSession,List.of(this.currentNode));
181+
this.fetchNextNode(flowSession, List.of(this.currentNode));
174182

175183
List<ProcessNode> displayNodes = nodeList.stream().filter(ProcessNode::isDisplay).toList();
176184
List<ProcessNode> processNodeList = new ArrayList<>();
177-
for (ProcessNode node:displayNodes){
178-
if(!processNodeList.contains(node)){
185+
for (ProcessNode node : displayNodes) {
186+
if (!processNodeList.contains(node)) {
179187
processNodeList.add(node);
180188
}
181189
}

flow-engine-framework/src/main/java/com/codingapi/flow/session/FlowSession.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,37 @@ public class FlowSession {
3131
private final IRepositoryHolder repositoryHolder;
3232

3333
/**
34-
* 当前操作者
34+
* 流程创建者
3535
*/
36+
@Getter
37+
private final IFlowOperator createdOperator;
38+
39+
/**
40+
* 流程提交人
41+
*/
42+
@Getter
43+
private final IFlowOperator submitOperator;
44+
45+
/**
46+
* 当前审批者
47+
*/
48+
@Getter
3649
private final IFlowOperator currentOperator;
3750
/**
3851
* 当前流程设计
3952
*/
53+
@Getter
4054
private final Workflow workflow;
4155
/**
4256
* 当前流程节点
4357
*/
58+
@Getter
4459
private final IFlowNode currentNode;
4560

4661
/**
4762
* 当前流程动作
4863
*/
64+
@Getter
4965
private final IFlowAction currentAction;
5066

5167
/**
@@ -57,25 +73,31 @@ public class FlowSession {
5773
/**
5874
* 当前节点的流程记录
5975
*/
76+
@Getter
6077
private final List<FlowRecord> currentNodeRecords;
6178

6279
/**
6380
* 当前流程表单数据
6481
*/
82+
@Getter
6583
private final FormData formData;
6684
/**
6785
* 流程备份id
6886
*/
87+
@Getter
6988
private final long workflowRuntimeId;
7089

7190
/**
7291
* 审批意见
7392
*/
93+
@Getter
7494
private final FlowAdvice advice;
7595

7696

7797
public FlowSession(IRepositoryHolder repositoryHolder,
7898
IFlowOperator currentOperator,
99+
IFlowOperator createdOperator,
100+
IFlowOperator submitOperator,
79101
Workflow workflow,
80102
IFlowNode currentNode,
81103
IFlowAction currentAction,
@@ -94,6 +116,8 @@ public FlowSession(IRepositoryHolder repositoryHolder,
94116
this.formData = formData;
95117
this.workflowRuntimeId = workflowRuntimeId;
96118
this.advice = advice;
119+
this.createdOperator = createdOperator;
120+
this.submitOperator = submitOperator;
97121
}
98122

99123

@@ -137,7 +161,7 @@ public static FlowSession startSession(
137161
IFlowAction currentAction,
138162
FormData formData,
139163
long backupId) {
140-
return new FlowSession(repositoryHolder, currentOperator, workflow, currentNode, currentAction, formData, null, new ArrayList<>(), backupId, new FlowAdvice());
164+
return new FlowSession(repositoryHolder, currentOperator, currentOperator,null,workflow, currentNode, currentAction, formData, null, new ArrayList<>(), backupId, new FlowAdvice());
141165
}
142166

143167

@@ -209,12 +233,6 @@ public IFlowNode getStartNode() {
209233
return workflow.getStartNode();
210234
}
211235

212-
/**
213-
* 获取流程的创建者
214-
*/
215-
public IFlowOperator getCreatedOperator() {
216-
return workflow.getCreatedOperator();
217-
}
218236

219237

220238
/**
@@ -287,7 +305,7 @@ public Object getFormData(String fieldCode) {
287305
* @return 新的会话
288306
*/
289307
public FlowSession updateSession(IFlowNode currentNode) {
290-
return new FlowSession(repositoryHolder,currentOperator, workflow, currentNode, currentAction, formData, currentRecord, currentNodeRecords, workflowRuntimeId, advice);
308+
return new FlowSession(repositoryHolder,currentOperator,createdOperator,submitOperator, workflow, currentNode, currentAction, formData, currentRecord, currentNodeRecords, workflowRuntimeId, advice);
291309
}
292310

293311

@@ -298,7 +316,7 @@ public FlowSession updateSession(IFlowNode currentNode) {
298316
* @return 新的会话
299317
*/
300318
public FlowSession updateSession(IFlowAction currentAction) {
301-
return new FlowSession(repositoryHolder,currentOperator, workflow, currentNode, currentAction, formData, currentRecord, currentNodeRecords, workflowRuntimeId, advice);
319+
return new FlowSession(repositoryHolder,currentOperator,createdOperator,submitOperator, workflow, currentNode, currentAction, formData, currentRecord, currentNodeRecords, workflowRuntimeId, advice);
302320
}
303321

304322
/**
@@ -308,7 +326,7 @@ public FlowSession updateSession(IFlowAction currentAction) {
308326
* @return 新的会话
309327
*/
310328
public FlowSession updateSession(IFlowOperator currentOperator) {
311-
return new FlowSession(repositoryHolder,currentOperator, workflow, currentNode, currentAction, formData, currentRecord, currentNodeRecords, workflowRuntimeId, advice);
329+
return new FlowSession(repositoryHolder,currentOperator,createdOperator,submitOperator, workflow, currentNode, currentAction, formData, currentRecord, currentNodeRecords, workflowRuntimeId, advice);
312330
}
313331

314332
/**

0 commit comments

Comments
 (0)