dengzedong
4 天以前 730d1944e3a13c517c77df2b0712df05645a38dd
提交 | 用户 | 时间
bb2880 1 package com.iailab.module.bpm.framework.flowable.core.candidate.strategy.dept;
H 2
3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.lang.Assert;
5 import cn.hutool.core.util.ObjectUtil;
6 import com.google.common.collect.Sets;
7 import com.iailab.module.bpm.framework.flowable.core.candidate.strategy.user.BpmTaskCandidateUserStrategy;
8 import com.iailab.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
9 import com.iailab.module.bpm.framework.flowable.core.util.BpmnModelUtils;
10 import com.iailab.module.bpm.framework.flowable.core.util.FlowableUtils;
11 import com.iailab.module.bpm.service.task.BpmProcessInstanceService;
12 import org.flowable.bpmn.model.BpmnModel;
13 import org.flowable.bpmn.model.ServiceTask;
14 import org.flowable.bpmn.model.Task;
15 import org.flowable.bpmn.model.UserTask;
16 import org.flowable.engine.delegate.DelegateExecution;
17 import org.flowable.engine.runtime.ProcessInstance;
18 import org.springframework.context.annotation.Lazy;
19 import org.springframework.stereotype.Component;
20
21 import javax.annotation.Resource;
22 import java.util.*;
23
24 /**
25  * 发起人自选 {@link BpmTaskCandidateUserStrategy} 实现类
26  *
27  * @author hou
28  */
29 @Component
30 public class BpmTaskCandidateStartUserSelectStrategy extends AbstractBpmTaskCandidateDeptLeaderStrategy {
31
32     @Resource
33     @Lazy // 延迟加载,避免循环依赖
34     private BpmProcessInstanceService processInstanceService;
35
36     @Override
37     public BpmTaskCandidateStrategyEnum getStrategy() {
38         return BpmTaskCandidateStrategyEnum.START_USER_SELECT;
39     }
40
41     @Override
42     public void validateParam(String param) {}
43
44     @Override
45     public boolean isParamRequired() {
46         return false;
47     }
48
49     @Override
50     public LinkedHashSet<Long> calculateUsersByTask(DelegateExecution execution, String param) {
51         ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
52         Assert.notNull(processInstance, "流程实例({})不能为空", execution.getProcessInstanceId());
53         Map<String, List<Long>> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance);
54         Assert.notNull(startUserSelectAssignees, "流程实例({}) 的发起人自选审批人不能为空",
55                 execution.getProcessInstanceId());
56         // 获得审批人
57         List<Long> assignees = startUserSelectAssignees.get(execution.getCurrentActivityId());
58         return new LinkedHashSet<>(assignees);
59     }
60
61     @Override
62     public LinkedHashSet<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param,
63                                                         Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
64         if (processVariables == null) {
65             return Sets.newLinkedHashSet();
66         }
67         Map<String, List<Long>> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processVariables);
68         if (startUserSelectAssignees == null) {
69             return Sets.newLinkedHashSet();
70         }
71         // 获得审批人
72         List<Long> assignees = startUserSelectAssignees.get(activityId);
73         return new LinkedHashSet<>(assignees);
74     }
75
76     /**
77      * 获得发起人自选审批人或抄送人的 Task 列表
78      *
79      * @param bpmnModel BPMN 模型
80      * @return Task 列表
81      */
82     public static List<Task> getStartUserSelectTaskList(BpmnModel bpmnModel) {
83         if (bpmnModel == null) {
84             return Collections.emptyList();
85         }
86         List<Task> tasks = new ArrayList<>();
87         tasks.addAll(BpmnModelUtils.getBpmnModelElements(bpmnModel, UserTask.class));
88         tasks.addAll(BpmnModelUtils.getBpmnModelElements(bpmnModel, ServiceTask.class));
89         if (CollUtil.isEmpty(tasks)) {
90             return Collections.emptyList();
91         }
92         tasks.removeIf(task -> ObjectUtil.notEqual(BpmnModelUtils.parseCandidateStrategy(task),
93                 BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy()));
94         return tasks;
95     }
96
97 }