Skip to content

Commit 8727e2f

Browse files
committed
fix script
1 parent f08c5ba commit 8727e2f

24 files changed

Lines changed: 341 additions & 135 deletions

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public class FlowContent {
101101
private boolean mergeable;
102102

103103
/**
104-
* 发起者id
104+
* 流程发起者
105105
*/
106106
private FlowOperator createOperator;
107107

108108
/**
109-
* 当前审批者id
109+
* 当前审批者
110110
*/
111111
private FlowOperator currentOperator;
112112

@@ -203,6 +203,7 @@ public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {
203203
for (FlowRecord item : mergeRecords) {
204204
Body body = new Body();
205205
body.setRecordId(item.getId());
206+
body.setSubmitOperator(new FlowOperator(item.getSubmitOperatorId(),item.getSubmitOperatorName()));
206207
body.setTitle(item.getTitle());
207208
body.setData(item.getFormData());
208209
body.setRecordState(item.getRecordState());
@@ -291,6 +292,14 @@ public static class Body {
291292
* 流程标题
292293
*/
293294
private String title;
295+
296+
297+
/**
298+
* 提交审批者
299+
*/
300+
private FlowOperator submitOperator;
301+
302+
294303
/**
295304
* 表单数据
296305
*/

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ public class FlowRecordContent {
6060
*/
6161
private String currentOperatorName;
6262

63+
/**
64+
* 提交审批人Id
65+
*/
66+
private Long submitOperatorId;
67+
68+
/**
69+
* 提交审批人名称
70+
*/
71+
private String submitOperatorName;
72+
6373
/**
6474
* 创建时间
6575
*/
@@ -127,6 +137,8 @@ public static FlowRecordContent convert(FlowRecord record){
127137
content.setReadTime(record.getReadTime());
128138
content.setCurrentOperatorId(record.getCurrentOperatorId());
129139
content.setCurrentOperatorName(record.getCurrentOperatorName());
140+
content.setSubmitOperatorId(record.getSubmitOperatorId());
141+
content.setSubmitOperatorName(record.getSubmitOperatorName());
130142
content.setCreateTime(record.getCreateTime());
131143
content.setCreateOperatorId(record.getCreateOperatorId());
132144
content.setCreateOperatorName(record.getCreateOperatorName());
@@ -152,6 +164,8 @@ public static FlowRecordContent convert(FlowTodoRecord todoRecord){
152164
content.setReadTime(todoRecord.getReadTime());
153165
content.setCurrentOperatorId(todoRecord.getCurrentOperatorId());
154166
content.setCurrentOperatorName(todoRecord.getCurrentOperatorName());
167+
content.setSubmitOperatorId(todoRecord.getSubmitOperatorId());
168+
content.setSubmitOperatorName(todoRecord.getSubmitOperatorName());
155169
content.setCreateTime(todoRecord.getCreateTime());
156170
content.setCreateOperatorId(todoRecord.getCreateOperatorId());
157171
content.setCreateOperatorName(todoRecord.getCreateOperatorName());

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ public class FlowRecord {
133133
*/
134134
private String currentOperatorName;
135135

136+
/**
137+
* 提交审批人Id
138+
*/
139+
private long submitOperatorId;
140+
141+
/**
142+
* 提交审批人名称
143+
*/
144+
private String submitOperatorName;
145+
136146
/**
137147
* 代替的审批人Id
138148
*/
@@ -293,6 +303,9 @@ public FlowRecord(FlowSession flowSession, int nodeOrder) {
293303
this.currentOperatorId = currentOperator.getUserId();
294304
this.currentOperatorName = currentOperator.getName();
295305

306+
this.submitOperatorId = flowSession.getSubmitOperatorId();
307+
this.submitOperatorName = flowSession.getSubmitOperatorName();
308+
296309
this.advice = flowSession.getAdvice().getAdvice();
297310
this.signKey = flowSession.getAdvice().getSignKey();
298311
this.flowState = SATE_FLOW_RUNNING;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public class FlowTodoRecord {
6969
*/
7070
private String currentOperatorName;
7171

72+
/**
73+
* 提交审批人Id
74+
*/
75+
private long submitOperatorId;
76+
77+
/**
78+
* 提交审批人名称
79+
*/
80+
private String submitOperatorName;
81+
7282
/**
7383
* 创建时间
7484
*/
@@ -129,6 +139,8 @@ public void update(FlowRecord flowRecord) {
129139
this.readTime = flowRecord.getReadTime();
130140
this.currentOperatorId = flowRecord.getCurrentOperatorId();
131141
this.currentOperatorName = flowRecord.getCurrentOperatorName();
142+
this.submitOperatorId = flowRecord.getSubmitOperatorId();
143+
this.submitOperatorName = flowRecord.getSubmitOperatorName();
132144
this.createTime = flowRecord.getCreateTime();
133145
this.createOperatorId = flowRecord.getCreateOperatorId();
134146
this.createOperatorName = flowRecord.getCreateOperatorName();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(request){
6767
// @SCRIPT_TITLE 流程创建者
6868
// @SCRIPT_META {"type":"creator"}
6969
def run(request){
70-
return [request.getCreatedOperator()]
70+
return [request.getCreatedOperatorId()]
7171
}
7272
""";
7373

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import lombok.AllArgsConstructor;
99
import lombok.Getter;
1010

11+
import java.util.ArrayList;
1112
import java.util.List;
1213

1314
/**
@@ -23,7 +24,12 @@ public class OperatorLoadScript {
2324
@SuppressWarnings("unchecked")
2425
public List<IFlowOperator> execute(FlowSession session) {
2526
GroovyScriptRequest request = new GroovyScriptRequest(session);
26-
return ScriptRuntimeContext.getInstance().run(script, List.class, request);
27+
List<Object> userIds = ScriptRuntimeContext.getInstance().run(script, List.class, request);
28+
List<Long> operatorIds = new ArrayList<>();
29+
for (Object userId : userIds) {
30+
operatorIds.add(Long.parseLong(String.valueOf(userId)));
31+
}
32+
return session.getRepositoryHolder().findOperatorByIds(operatorIds);
2733
}
2834

2935
/**

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,10 @@ public class GroovyScriptBind {
2020

2121
private final FlowScriptContext context;
2222

23-
public ErrorThrow createErrorThrow(IFlowOperator operator) {
24-
return context.createErrorThrow(operator);
25-
}
26-
2723
public ErrorThrow createErrorThrow(IFlowNode node) {
2824
return context.createErrorThrow(node);
2925
}
3026

31-
public ErrorThrow createErrorThrow(IFlowOperator... operators) {
32-
return context.createErrorThrow(operators);
33-
}
34-
3527
public ErrorThrow createErrorThrow(List<Long> userIds) {
3628
return context.createErrorThrow(userIds);
3729
}

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

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,6 @@
1818
*/
1919
public class GroovyScriptRequest {
2020

21-
/**
22-
* 当前操作人姓名
23-
*/
24-
@Getter
25-
private String operatorName;
26-
27-
/**
28-
* 当前操作人ID
29-
*/
30-
@Getter
31-
private long operatorId;
32-
33-
/**
34-
* 是否流程管理员
35-
*/
36-
@Getter
37-
private Boolean isFlowManager;
38-
3921
/**
4022
* 流程标题
4123
*/
@@ -54,12 +36,6 @@ public class GroovyScriptRequest {
5436
@Getter
5537
private String workCode;
5638

57-
/**
58-
* 流程创建人姓名
59-
*/
60-
@Getter
61-
private String creatorName;
62-
6339
/**
6440
* 当前节点名称
6541
*/
@@ -86,15 +62,26 @@ public class GroovyScriptRequest {
8662
private IFlowOperator createdOperator;
8763

8864
/**
89-
* 当前操作人(上一节点审批人)
65+
* 当前审批人
9066
*/
9167
@Getter
9268
private IFlowOperator currentOperator;
9369

70+
/**
71+
* 流程提交Id
72+
*/
73+
@Getter
74+
private long submitOperatorId;
9475

95-
private final FlowSession flowSession;
76+
/**
77+
* 流程提交人姓名
78+
*/
79+
@Getter
80+
private String submitOperatorName;
9681

9782

83+
private final FlowSession flowSession;
84+
9885
/**
9986
* 从FlowSession构建请求对象(模板方法模式)
10087
* @param session 流程会话(不能为null)
@@ -104,17 +91,15 @@ public GroovyScriptRequest(FlowSession session) {
10491
// 提取操作人信息
10592
if (session.getCurrentOperator() != null) {
10693
this.currentOperator = session.getCurrentOperator();
107-
this.operatorName = session.getCurrentOperator().getName();
108-
this.operatorId = (int) session.getCurrentOperator().getUserId();
109-
this.isFlowManager = session.getCurrentOperator().isFlowManager();
11094
}
11195

11296
// 提取流程信息
11397
if (session.getWorkflow() != null) {
11498
this.workflowTitle = session.getWorkflow().getTitle();
11599
this.workflowCode = session.getWorkflow().getCode();
100+
// 提取创建人信息
116101
if (session.getWorkflow().getCreatedOperator() != null) {
117-
this.creatorName = session.getWorkflow().getCreatedOperator().getName();
102+
this.createdOperator = session.getWorkflow().getCreatedOperator();
118103
}
119104
}
120105

@@ -127,18 +112,15 @@ public GroovyScriptRequest(FlowSession session) {
127112
// 提取流程编号(从record获取)
128113
if (session.getCurrentRecord() != null) {
129114
this.workCode = session.getCurrentRecord().getWorkCode();
115+
this.submitOperatorId = session.getSubmitOperatorId();
116+
this.submitOperatorName = session.getSubmitOperatorName();
130117
}
131118

132119
// 提取表单数据
133120
if (session.getFormData() != null) {
134121
this.formData = session.getFormData().toMapData();
135122
}
136123

137-
// 提取创建人信息
138-
if (session.getWorkflow() != null && session.getWorkflow().getCreatedOperator() != null) {
139-
this.createdOperator = session.getWorkflow().getCreatedOperator();
140-
}
141-
142124
}
143125

144126
/**
@@ -147,7 +129,37 @@ public GroovyScriptRequest(FlowSession session) {
147129
* @return 节点
148130
*/
149131
public IFlowNode getNode(String nodeId){
150-
return flowSession.getWorkflow().getFlowNode(nodeId);
132+
return flowSession.getNode(nodeId);
133+
}
134+
135+
136+
/**
137+
* 流程创建者Id
138+
*/
139+
public long getCreatedOperatorId(){
140+
return this.createdOperator.getUserId();
141+
}
142+
143+
/**
144+
* 流程创建者名称
145+
*/
146+
public String getCreatedOperatorName(){
147+
return this.createdOperator.getName();
148+
}
149+
150+
151+
/**
152+
* 流程审批者Id
153+
*/
154+
public long getCurrentOperatorId(){
155+
return this.currentOperator.getUserId();
156+
}
157+
158+
/**
159+
* 流程审批者名称
160+
*/
161+
public String getCurrentOperatorName(){
162+
return this.currentOperator.getName();
151163
}
152164

153165

flow-engine-framework/src/main/java/com/codingapi/flow/script/runtime/FlowScriptContext.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,6 @@ public ErrorThrow createErrorThrow(IFlowNode node) {
3333
.build();
3434
}
3535

36-
public ErrorThrow createErrorThrow(IFlowOperator... operators) {
37-
return ErrorThrow.builder()
38-
.operators(List.of(operators))
39-
.build();
40-
}
41-
42-
public ErrorThrow createErrorThrow(IFlowOperator operator) {
43-
return ErrorThrow.builder()
44-
.operators(List.of(operator))
45-
.build();
46-
}
47-
4836
public ErrorThrow createErrorThrow(List<Long> userIds) {
4937
List<IFlowOperator> operators = beanFactory.findOperatorsByIds(userIds);
5038
return ErrorThrow.builder()

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,27 @@ public IFlowOperator getCreatedOperator() {
179179
return workflow.getCreatedOperator();
180180
}
181181

182+
183+
/**
184+
* 获取流程的提交者Id
185+
*/
186+
public long getSubmitOperatorId(){
187+
if(this.currentRecord!=null) {
188+
return this.currentRecord.getCurrentOperatorId();
189+
}
190+
return 0;
191+
}
192+
193+
/**
194+
* 获取流程的提交者名称
195+
*/
196+
public String getSubmitOperatorName(){
197+
if(this.currentRecord!=null) {
198+
return this.currentRecord.getCurrentOperatorName();
199+
}
200+
return null;
201+
}
202+
182203
/**
183204
* 获取流程设计编号
184205
*/
@@ -253,4 +274,11 @@ public FlowSession updateSession(IFlowOperator currentOperator) {
253274
return new FlowSession(repositoryHolder,currentOperator, workflow, currentNode, currentAction, formData, currentRecord, currentNodeRecords, workflowRuntimeId, advice);
254275
}
255276

277+
/**
278+
* 获取节点
279+
* @param nodeId 节点id
280+
*/
281+
public IFlowNode getNode(String nodeId) {
282+
return this.workflow.getFlowNode(nodeId);
283+
}
256284
}

0 commit comments

Comments
 (0)