Преглед изворни кода

bug fix 岗位下超过5个人下发异常

cczhang пре 1 месец
родитељ
комит
9fd6789eb3
1 измењених фајлова са 301 додато и 0 уклоњено
  1. 301
    0
      src/main/java/com/horizon/workflow/support/action/DefaultSubmitAction.java

+ 301
- 0
src/main/java/com/horizon/workflow/support/action/DefaultSubmitAction.java Прегледај датотеку

@@ -0,0 +1,301 @@
1
+package com.horizon.workflow.support.action;
2
+
3
+import com.horizon.common.base.Joiner;
4
+import com.horizon.common.base.Objects;
5
+import com.horizon.common.base.Splitter;
6
+import com.horizon.common.collect.Lists;
7
+import com.horizon.common.collect.Maps;
8
+import com.horizon.core.HorizonCore;
9
+import com.horizon.language.Hi18n;
10
+import com.horizon.third.Authority;
11
+import com.horizon.third.Organization;
12
+import com.horizon.third.ThirdAdapterFactory;
13
+import com.horizon.third.adapter.WorkflowBaseAdapther;
14
+import com.horizon.third.entity.User;
15
+import com.horizon.third.init.WorkflowAdapterInit;
16
+import com.horizon.utils.HorizonPorps;
17
+import com.horizon.utils.StringUtil;
18
+import com.horizon.wf.core.node.INextNode;
19
+import com.horizon.wf.global.StaticVarExtend;
20
+import com.horizon.workflow.support.model.FlowAction;
21
+import com.horizon.workflow.support.model.FlowAuthor;
22
+import com.horizon.workflow.support.model.FlowNextNode;
23
+import com.horizon.workflow.support.util.ActionUtil;
24
+import org.slf4j.Logger;
25
+import org.slf4j.LoggerFactory;
26
+
27
+import java.util.List;
28
+import java.util.Map;
29
+
30
+import static com.horizon.wf.global.StaticVarExtend.*;
31
+
32
+/**
33
+ * 流程基本提交操作(submit)
34
+ *
35
+ * @author mwr
36
+ *
37
+ */
38
+public class DefaultSubmitAction extends ActionBaseStrategy {
39
+
40
+    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSubmitAction.class);
41
+
42
+    @Override
43
+    public FlowAction actionDo() {
44
+
45
+        int status = operator();
46
+        switch (status) {
47
+            case StaticVarExtend.F_STATUS_SelectAuthor:
48
+                setSelectUser();
49
+                break;
50
+            case StaticVarExtend.F_STATUS_SelectNode:
51
+                setSelectNode();
52
+                break;
53
+            case StaticVarExtend.F_STATUS_Success:
54
+                operateSuccess();
55
+                break;
56
+            case StaticVarExtend.F_STATUS_NoAuthor:
57
+                setSelectDefUser();
58
+                break;
59
+            default:
60
+                action.setOperateMsg(message());
61
+                action.setOperateStatus("error");
62
+                break;
63
+
64
+        }
65
+        action.setTrackId(trackId());
66
+        action.setWorkId(workId());
67
+        return action;
68
+    }
69
+
70
+    protected void setSelectDefUser() {
71
+
72
+        String openDefAuthor = HorizonPorps.getConfig("workflow.openDefAuthor");
73
+        if (Objects.equal(openDefAuthor, "true")) {
74
+            String tenantCode = HorizonCore.TENANT_CODE.value();
75
+            Authority authority = ThirdAdapterFactory.instanse(tenantCode).getAuthorityInstance();
76
+            String selectAuthorId = authority.getManager(workParaBean.getFlowId());
77
+            if (!StringUtil.hasValue(selectAuthorId)) {
78
+                LOGGER.error("属性workflow.openDefAuthor设置为true,流程 [{}] 并未设置管理员", workParaBean.getFlowId());
79
+                String message = message() + Hi18n.getVal(LANGUAGE_WORKFLOW,"notice") + getNonExistedAuthorNextNodes();
80
+                action.setOperateMsg(message);
81
+                action.setOperateStatus("error");
82
+            } else {
83
+                // 在没有办理人时,根据配置项设置默认办理人
84
+                action.setNextNodes(getNextNodes());
85
+                action.setOperateMsg(Hi18n.getVal(LANGUAGE_WORKFLOW,"notSelectUser"));
86
+                action.setOperateFlag(StaticVarExtend.Submit_Flag_Commit);
87
+            }
88
+        } else {
89
+            String message = message() + Hi18n.getVal(LANGUAGE_WORKFLOW,"notice") + getNonExistedAuthorNextNodes();
90
+            action.setOperateMsg(message);
91
+            action.setOperateStatus("error");
92
+        }
93
+    }
94
+    @Override
95
+    protected Map<String, FlowAuthor> getNextNodeAuthors(FlowNextNode flowNextNode) {
96
+
97
+        int result = Integer.parseInt(flowNextNode.getNodeStatus());
98
+        Map<String, FlowAuthor> authors = null;
99
+        String openDefAuthor = HorizonPorps.getConfig("workflow.openDefAuthor");
100
+        if ((result == StaticVarExtend.F_STATUS_NoAuthor) && Objects.equal(openDefAuthor, "true")) {
101
+            authors = getDefaultAuthor(flowNextNode);
102
+        } else {
103
+            authors = super.getNextNodeAuthors(flowNextNode);
104
+        }
105
+        return authors;
106
+    }
107
+
108
+    private Map<String, FlowAuthor> getDefaultAuthor(FlowNextNode flowNextNode) {
109
+
110
+        Map<String, FlowAuthor> authors = Maps.newHashMap();
111
+        String tenantCode = HorizonCore.TENANT_CODE.value();
112
+        Organization organization = ThirdAdapterFactory.instanse(tenantCode).getOrganizationInstance();
113
+        Authority authority = ThirdAdapterFactory.instanse(tenantCode).getAuthorityInstance();
114
+        String managerId = authority.getManager(workParaBean.getFlowId());
115
+        List<String> authorIds = getSelectAuthorId(managerId);
116
+        String selectAuthorId = Joiner.on(";").join(authorIds);
117
+        String selectAuthorName = organization.getNameByIds(managerId, tenantCode);
118
+        String selectType = getSelectType(flowNextNode.getNodeId(), StaticVarExtend.AUTH_AUTHOR);
119
+
120
+        FlowAuthor flowAuthor = new FlowAuthor();
121
+        flowAuthor.setAuthorId(StaticVarExtend.AUTH_AUTHOR);
122
+        flowAuthor.setAuthorName(getAuhorName(StaticVarExtend.AUTH_AUTHOR));
123
+        flowAuthor.setSelectType(selectType);
124
+
125
+        if (authorIds.size() == 1) {
126
+            flowAuthor.setIsDefUser("false");
127
+            flowAuthor.setIsSelect("false");
128
+            flowAuthor.setSelectAuthor(selectAuthorId);
129
+            flowAuthor.setSelectAuthorName(selectAuthorName);
130
+        } else {
131
+            if (Objects.equal(selectType, "radio")) {
132
+                flowAuthor.setIsDefUser("true");
133
+                flowAuthor.setIsSelect("true");
134
+                flowAuthor.setInitAuthor(ActionUtil.getAuthorMultimap(selectAuthorId, false));
135
+            } else {
136
+                flowAuthor.setIsDefUser("true");
137
+                flowAuthor.setIsSelect("true");
138
+                flowAuthor.setSelectAuthor(selectAuthorId);
139
+                flowAuthor.setSelectAuthorName(selectAuthorName);
140
+                flowAuthor.setInitAuthor(ActionUtil.getAuthorMultimap(selectAuthorId, false));
141
+            }
142
+        }
143
+        flowAuthor.setIsUser("false");
144
+        flowAuthor.setIsFree("false");
145
+        authors.put(StaticVarExtend.AUTH_AUTHOR, flowAuthor);
146
+        return authors;
147
+    }
148
+
149
+    private List<String> getSelectAuthorId(String managerId) {
150
+
151
+        List<String> authorIds = Lists.newArrayList();
152
+        List<String> list = Splitter.on(";").omitEmptyStrings().splitToList(managerId);
153
+        if (list != null && !list.isEmpty()) {
154
+            for (String id : list) {
155
+                if (id.indexOf('_') < 0) {
156
+                    id = "U_" + id;
157
+                }
158
+                authorIds.add(id);
159
+            }
160
+        }
161
+        return authorIds;
162
+    }
163
+
164
+    /**
165
+     * 一下节点办理人为自己时,自动打开流程,
166
+     */
167
+    @Override
168
+    protected boolean autoOpen() {
169
+
170
+        boolean isOpen = false;
171
+        if (super.autoOpen()) {
172
+            List<INextNode> nextNodes = workResult.getNextNodes();
173
+            if (nextNodes != null) {
174
+                for (INextNode nextNode : nextNodes) {
175
+                    String nodeKey = nextNode.getKeyid();
176
+                    String authorId = getSelectAuthor(nodeKey + "-Author");
177
+                    isOpen = hasNextAuthor(authorId);
178
+                }
179
+            }
180
+        }
181
+        return isOpen;
182
+    }
183
+    @Override
184
+    protected String getNextNodeGroup(INextNode nextNode) {
185
+
186
+        String nodeGroup = null;
187
+        String actionName = workResult.getWorkParaBean().getFunname();
188
+        if (Objects.equal(actionName.toLowerCase(), OPERATOR_FUNNAME_JUMP_REJECT.toLowerCase())
189
+                || Objects.equal(actionName.toLowerCase(), OPERATOR_FUNNAME_GOTO.toLowerCase())) {
190
+
191
+            nodeGroup = "Node0";
192
+        } else {
193
+            nodeGroup = StringUtil.null2Empty(nextNode.getGroupName());
194
+        }
195
+        return nodeGroup;
196
+    }
197
+    @Override
198
+    protected void setSelectAuthors(FlowAuthor flowAuthor, String authorKey) {
199
+
200
+        super.setSelectAuthors(flowAuthor, authorKey);
201
+        String initAuthor = getInitAuthor(authorKey);
202
+        boolean isOnlyUser = Boolean.parseBoolean(flowAuthor.getIsUser());
203
+        if (isOnlyUser && StringUtil.hasValue(initAuthor)) {
204
+            String tenantCode = workResult.getWorkParaBean().getTenantCode();
205
+            Organization organization = ThirdAdapterFactory.instanse(tenantCode).getOrganizationInstance();
206
+            WorkflowBaseAdapther adapther = WorkflowAdapterInit.getWorkflowAdapthers("orgs");
207
+            List<String> idList = Splitter.on(";").omitEmptyStrings().splitToList(initAuthor);
208
+            List<String> userIds = Lists.newArrayList();
209
+            for (String userId : idList) {
210
+                String type = ActionUtil.getType(userId);
211
+                if (!Objects.equal("U", type)) {
212
+                    String orgId = ActionUtil.replaceId(userId);
213
+                    List<User> users = adapther.findUserByOrgId(type, orgId);
214
+                    if (users != null || !users.isEmpty()) {
215
+                        for (User user : users) {
216
+                            String fixId = user.getFixId() + "/" + type.toUpperCase()+ "_" +orgId;
217
+                            userIds.add(fixId);
218
+                        }
219
+                    }
220
+                } else {
221
+                    userIds.add(userId);
222
+                }
223
+            }
224
+            if (Objects.equal("radio", flowAuthor.getSelectType()) && userIds.size() == 1) {
225
+                String selectId = Joiner.on(";").join(userIds.iterator());
226
+                String selectName = organization.getNameByIds(selectId, null);
227
+                flowAuthor.setSelectAuthorName(selectName);
228
+                flowAuthor.setSelectAuthor(selectId);
229
+            } else if (Objects.equal("checkbox", flowAuthor.getSelectType()) && userIds.size() <= 20) {
230
+                String selectId = Joiner.on(";").join(userIds.iterator());
231
+                String selectName = organization.getNameByIds(selectId, null);
232
+                flowAuthor.setSelectAuthorName(selectName);
233
+                flowAuthor.setSelectAuthor(selectId);
234
+            }
235
+
236
+        }
237
+    }
238
+
239
+    /**
240
+     * 提交操作时,如果是当前节点,移除协办和读者的办理人设置
241
+     */
242
+    private void removeAuthors() {
243
+
244
+        List<FlowNextNode> nextNodes = action.getNextNodes();
245
+        if (nextNodes == null || nextNodes.isEmpty()) {
246
+            return;
247
+        }
248
+        for (FlowNextNode nextNode : nextNodes) {
249
+            if (Objects.equal(nextNode.getNodeId(), nextNode.getSelectId())) {
250
+                Map<String, FlowAuthor> authorMap = nextNode.getAuthors();
251
+                authorMap.remove(AUTH_SECOND_AUTHOR);
252
+                authorMap.remove(AUTH_READER);
253
+            }
254
+        }
255
+    }
256
+
257
+    /**
258
+     * 提交操作成功
259
+     */
260
+    private void operateSuccess() {
261
+
262
+        String submitFlag = submitFlag();
263
+        action.setNextNodes(getNextNodes());
264
+        if (Objects.equal(submitFlag, "1")) {
265
+            action.setOperateMsg(Hi18n.getVal(LANGUAGE_WORKFLOW,"nextNodeAuthor"));
266
+            action.setOperateFlag(StaticVarExtend.Submit_Flag_Commit);
267
+            removeAuthors();
268
+        } else {
269
+            action.setOperateMsg(message());
270
+            action.setOperateStatus("success");
271
+            action.setReOpen(String.valueOf(autoOpen()));
272
+        }
273
+    }
274
+
275
+    /**
276
+     * 选择人员
277
+     */
278
+    private void setSelectUser() {
279
+
280
+        action.setNextNodes(getNextNodes());
281
+        action.setOperateMsg(message());
282
+        action.setOperateFlag(StaticVarExtend.Submit_Flag_Commit);
283
+    }
284
+
285
+    /**
286
+     * 选择节点
287
+     */
288
+    private void setSelectNode() {
289
+
290
+        // 设置节点
291
+        List<FlowNextNode> nextNodes = getNextNodes();
292
+        if (nextNodes == null || nextNodes.isEmpty()) {
293
+            action.setOperateMsg(Hi18n.getVal(LANGUAGE_WORKFLOW,"notGetFlowNodeList"));
294
+            action.setOperateStatus("error");
295
+        } else {
296
+            action.setNextNodes(getNextNodes());
297
+            action.setOperateMsg(message());
298
+            action.setOperateFlag(StaticVarExtend.Submit_Flag);
299
+        }
300
+    }
301
+}

Loading…
Откажи
Сачувај