Skip to content

Commit 4c43e6a

Browse files
committed
fix #80
1 parent 67742f7 commit 4c43e6a

7 files changed

Lines changed: 97 additions & 20 deletions

File tree

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
package com.codingapi.example.handler;
22

3-
public class MyFlowRecordUrgeEventHandler {
3+
import com.codingapi.flow.event.FlowRecordUrgeEvent;
4+
import com.codingapi.springboot.framework.event.IHandler;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.stereotype.Component;
7+
8+
@Slf4j
9+
@Component
10+
public class MyFlowRecordUrgeEventHandler implements IHandler<FlowRecordUrgeEvent> {
11+
12+
@Override
13+
public void handler(FlowRecordUrgeEvent event) {
14+
log.info("催办 event:{}",event);
15+
}
416
}

flow-engine-framework/src/main/java/com/codingapi/flow/manager/NodeStrategyManager.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public long getTimeoutTime() {
3838
/**
3939
* 是否可合并
4040
*/
41-
public boolean isMergeable() {
41+
public boolean isEnableMergeable() {
4242
List<INodeStrategy> strategies = this.strategies;
4343
for (INodeStrategy strategy : strategies) {
4444
if (strategy instanceof RecordMergeStrategy) {
@@ -48,6 +48,19 @@ public boolean isMergeable() {
4848
return false;
4949
}
5050

51+
/**
52+
* 是否支持撤回
53+
*/
54+
public boolean isEnableRevoke(){
55+
List<INodeStrategy> strategies = this.strategies;
56+
for (INodeStrategy strategy : strategies) {
57+
if (strategy instanceof RevokeStrategy) {
58+
return ((RevokeStrategy) strategy).isEnable();
59+
}
60+
}
61+
return false;
62+
}
63+
5164
/**
5265
* 是否按顺序执行的审批策略
5366
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void fillNewRecord(FlowSession session, FlowRecord flowRecord) {
6464
NodeStrategyManager nodeStrategyManager = this.strategyManager();
6565
flowRecord.setTitle(nodeStrategyManager.generateTitle(session));
6666
flowRecord.setTimeoutTime(nodeStrategyManager.getTimeoutTime());
67-
flowRecord.setMergeable(nodeStrategyManager.isMergeable());
67+
flowRecord.setMergeable(nodeStrategyManager.isEnableMergeable());
6868
flowRecord.newRecord();
6969
}
7070

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

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class FlowContent {
9393
/**
9494
* 流程按钮
9595
*/
96-
private List<Map<String,Object>> actions;
96+
private List<Map<String, Object>> actions;
9797

9898
/**
9999
* 是否可合并
@@ -130,6 +130,44 @@ public class FlowContent {
130130
*/
131131
private List<NodeOption> nodes;
132132

133+
/**
134+
* 支持撤销
135+
*/
136+
private boolean revoke;
137+
138+
/**
139+
* 支持催办
140+
*/
141+
private boolean urge;
142+
143+
144+
/**
145+
* 设置操作动作按钮
146+
*
147+
*/
148+
public void setOperationAction(Workflow workflow, FlowRecord flowRecord) {
149+
if (flowRecord == null) {
150+
this.revoke = false;
151+
this.urge = false;
152+
} else {
153+
if (flowRecord.isFinish()) {
154+
this.revoke = false;
155+
this.urge = false;
156+
}
157+
158+
if (flowRecord.isTodo()) {
159+
this.revoke = false;
160+
this.urge = false;
161+
}
162+
163+
if (flowRecord.isDone() && !flowRecord.isFinish()) {
164+
IFlowNode node = workflow.getFlowNode(flowRecord.getNodeId());
165+
this.revoke = node.strategyManager().isEnableRevoke();
166+
this.urge = workflow.strategyManager().isEnableUrge();
167+
}
168+
}
169+
}
170+
133171

134172
public void pushCurrentNode(IFlowNode currentNode) {
135173
ActionManager actionManager = currentNode.actionManager();
@@ -141,7 +179,7 @@ public void pushCurrentNode(IFlowNode currentNode) {
141179
this.nodeName = currentNode.getName();
142180
this.nodeType = currentNode.getType();
143181
this.fieldPermissions = strategyManager.getFieldPermissions();
144-
Map<String,Object> nodeData = currentNode.toMap();
182+
Map<String, Object> nodeData = currentNode.toMap();
145183
this.view = (String) nodeData.get("view");
146184
}
147185

@@ -162,7 +200,7 @@ public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {
162200
this.title = record.getTitle();
163201

164202
this.todos = new ArrayList<>();
165-
for (FlowRecord item : mergeRecords){
203+
for (FlowRecord item : mergeRecords) {
166204
Body body = new Body();
167205
body.setRecordId(item.getId());
168206
body.setTitle(item.getTitle());
@@ -173,9 +211,9 @@ public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {
173211
}
174212
}
175213

176-
public void pushHistory(Workflow workflow,List<FlowRecord> historyRecords) {
214+
public void pushHistory(Workflow workflow, List<FlowRecord> historyRecords) {
177215
this.histories = new ArrayList<>();
178-
for (FlowRecord item : historyRecords){
216+
for (FlowRecord item : historyRecords) {
179217
IFlowNode node = workflow.getFlowNode(item.getNodeId());
180218
History history = new History();
181219
history.setRecordId(item.getId());
@@ -193,18 +231,18 @@ public void pushHistory(Workflow workflow,List<FlowRecord> historyRecords) {
193231

194232
public void pushCurrentOperator(IFlowOperator currentOperator) {
195233
this.currentOperator = new FlowOperator(currentOperator);
196-
this.createOperator = new FlowOperator(currentOperator);
234+
this.createOperator = new FlowOperator(currentOperator);
197235
}
198236

199237

200238
@Data
201-
public static class History{
239+
public static class History {
202240
/**
203241
* 流程编号
204242
*/
205243
private long recordId;
206244
/**
207-
* 流程标题
245+
* 流程标题
208246
*/
209247
private String title;
210248

@@ -246,15 +284,15 @@ public static class History{
246284
@Data
247285
public static class Body {
248286
/**
249-
* 流程记录编号
287+
* 流程记录编号
250288
*/
251289
private long recordId;
252290
/**
253-
* 流程标题
291+
* 流程标题
254292
*/
255293
private String title;
256294
/**
257-
* 表单数据
295+
* 表单数据
258296
*/
259297
private Map<String, Object> data;
260298

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public void notifyRecord(FlowSession flowSession) {
461461
NodeStrategyManager nodeStrategyManager = currentNode.strategyManager();
462462
this.setTitle(nodeStrategyManager.generateTitle(flowSession));
463463
this.setTimeoutTime(nodeStrategyManager.getTimeoutTime());
464-
this.setMergeable(nodeStrategyManager.isMergeable());
464+
this.setMergeable(nodeStrategyManager.isEnableMergeable());
465465
this.update(flowSession, true);
466466
this.notify = true;
467467
this.forwardOperatorId = 0;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void loadWorkflow(){
8686

8787
private void loadTodoFlowRecords(){
8888
if(this.flowRecord!=null){
89-
if(this.flowRecord.isMergeable()){
89+
if(this.flowRecord.isMergeable() && this.flowRecord.isTodo()){
9090
List<FlowRecord> margeRecords = flowRecordService.getMergeRecord(flowRecord.getMergeKey());
9191
this.flowContent.pushRecords(this.flowRecord, margeRecords);
9292
}else {
@@ -122,6 +122,8 @@ public FlowContent create() {
122122
this.loadCurrentNode();
123123
this.loadTodoFlowRecords();
124124
this.loadHistoryRecords();
125+
126+
flowContent.setOperationAction(this.workflow,this.flowRecord);
125127
return flowContent;
126128
}
127129
}

flow-engine-starter-api/src/main/java/com/codingapi/flow/api/controller/FlowRecordController.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.codingapi.flow.api.controller;
22

33
import com.codingapi.flow.operator.IFlowOperator;
4-
import com.codingapi.flow.pojo.request.FlowActionRequest;
5-
import com.codingapi.flow.pojo.request.FlowCreateRequest;
6-
import com.codingapi.flow.pojo.request.FlowDetailRequest;
7-
import com.codingapi.flow.pojo.request.FlowProcessNodeRequest;
4+
import com.codingapi.flow.pojo.request.*;
85
import com.codingapi.flow.pojo.response.FlowContent;
96
import com.codingapi.flow.pojo.response.ProcessNode;
107
import com.codingapi.flow.service.FlowService;
@@ -45,6 +42,21 @@ public SingleResponse<Long> create(@RequestBody FlowCreateRequest request) {
4542
}
4643

4744

45+
@PostMapping("/urge")
46+
public Response urge(@RequestBody IdRequest request) {
47+
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
48+
flowService.urge(new FlowUrgeRequest(request.getLongId(),current.getUserId()));
49+
return Response.buildSuccess();
50+
}
51+
52+
@PostMapping("/revoke")
53+
public Response revoke(@RequestBody IdRequest request) {
54+
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
55+
flowService.revoke(new FlowRevokeRequest(request.getLongId(),current.getUserId()));
56+
return Response.buildSuccess();
57+
}
58+
59+
4860
@PostMapping("/action")
4961
public Response action(@RequestBody FlowActionRequest request) {
5062
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();

0 commit comments

Comments
 (0)