Repository navigation
Expand file tree
/
Copy pathBaseAction.java
More file actions
179 lines (159 loc) · 5.81 KB
/
Copy pathBaseAction.java
File metadata and controls
179 lines (159 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package com.codingapi.flow.action;
import com.codingapi.flow.common.IMapConvertor;
import com.codingapi.flow.event.FlowRecordDoneEvent;
import com.codingapi.flow.event.FlowRecordTodoEvent;
import com.codingapi.flow.event.IFlowEvent;
import com.codingapi.flow.node.IFlowNode;
import com.codingapi.flow.record.FlowRecord;
import com.codingapi.flow.session.FlowSession;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
@Getter
@Setter
public abstract class BaseAction implements IFlowAction {
protected String id;
protected String type;
protected String title;
protected boolean enable;
protected ActionDisplay display;
@Override
public String type() {
return type;
}
@Override
public String id() {
return id;
}
@Override
public String title() {
return title;
}
@Override
public ActionDisplay display() {
return display;
}
@Override
public boolean show(FlowSession flowSession) {
return this.display.show(flowSession);
}
@Override
public boolean enable() {
return enable;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof BaseAction action) {
return action.getId().equals(id);
}
return super.equals(obj);
}
@Override
public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<>();
map.put("id", id);
map.put("type", type);
map.put("title", title);
map.put("enable", enable);
map.put("display", display != null ? display.toMap() : null);
return map;
}
@Override
public List<FlowRecord> generateRecords(FlowSession flowSession) {
return List.of();
}
@Override
public void copy(IFlowAction action) {
this.id = action.id();
this.type = action.type();
this.title = action.title();
this.display = action.display();
this.enable = action.enable();
}
@SneakyThrows
@SuppressWarnings("unchecked")
protected static <T extends BaseAction> T fromMap(Map<String, Object> data, Class<T> clazz) {
T action = IMapConvertor.fromMap(data, clazz);
action.setId((String) data.get("id"));
action.setType((String) data.get("type"));
action.setTitle((String) data.get("title"));
if(data.get("enable")!=null) {
action.setEnable((boolean) data.get("enable"));
}else {
action.setEnable(false);
}
Map<String, Object> display = (Map<String, Object>) data.get("display");
if (display != null) {
action.setDisplay(ActionDisplay.fromMap(display));
}
return action;
}
@Override
public void run(FlowSession flowSession) {
}
/**
* 是否为结束节点虚拟记录的待办事件(非真实业务待办,推送时需要拦截)
*/
protected boolean isEndNodeTodoEvent(IFlowEvent event) {
return event instanceof FlowRecordTodoEvent todoEvent
&& !todoEvent.getFlowRecord().isNotEndNode();
}
/**
* 将当前节点实例中其他未办理的待办记录自动办结。
*
* <p>退回({@link com.codingapi.flow.action.actions.ReturnAction})、拒绝
* ({@link com.codingapi.flow.action.actions.RejectAction})意味着当前节点就此结束,
* 同节点其他审批人(或签/并签的候选审批人)的待办不能继续办理:否则会遗留待办,
* 流程视图仍停留在当前节点,发起人重新提交后还会出现同流程的重复待办(issue #235 / #255)。
*
* <p>自动办结采用 {@link FlowRecord#autoDone()}:记录置为已办但不带审批动作,
* 展示层标记为「自动跳过」,与或签/并签节点完成后遗留待办的处理口径一致。
* 仅处理同一流程实例内的记录,避免仓储按 {@code (fromId, nodeId)} 查询时误伤其他流程实例。
*
* @param flowSession 当前会话,同节点记录取自 {@link FlowSession#getCurrentNodeRecords()}
* @param recordList 待保存的记录集合,自动办结的记录会追加其中
* @param flowEvents 待推送的事件集合,每条自动办结记录都会追加一条已办事件
*/
protected void autoDoneSiblingTodos(FlowSession flowSession,
List<FlowRecord> recordList,
List<IFlowEvent> flowEvents) {
FlowRecord currentRecord = flowSession.getCurrentRecord();
for (FlowRecord record : flowSession.getCurrentNodeRecords()) {
if (record.getId() == currentRecord.getId()) {
continue;
}
if (!record.isTodo()) {
continue;
}
if (!currentRecord.getProcessId().equals(record.getProcessId())) {
continue;
}
record.autoDone();
recordList.add(record);
flowEvents.add(new FlowRecordDoneEvent(record, flowSession.isMock()));
}
}
/**
* 触发并执行后续节点
*
* @param flowSession 当前会话
* @param consumer 节点处理
*/
public void triggerNode(FlowSession flowSession, Consumer<FlowSession> consumer) {
List<IFlowNode> nextNodes = flowSession.matchNextNodes();
for (IFlowNode node : nextNodes) {
FlowSession triggerSession = flowSession.updateSession(node);
if (node.handle(triggerSession)) {
this.triggerNode(triggerSession, consumer);
} else {
if (consumer != null) {
consumer.accept(triggerSession);
}
}
}
}
}