houzhongjian
2024-12-03 874287a4c02d0a980d8b97c4a691b4f37ec5e812
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.framework.flowable.core.candidate.strategy;
H 2
3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.lang.Assert;
5 import com.iailab.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
6 import com.iailab.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
7 import com.iailab.module.bpm.framework.flowable.core.util.BpmnModelUtils;
8 import com.iailab.module.bpm.framework.flowable.core.util.FlowableUtils;
9 import com.iailab.module.bpm.service.task.BpmProcessInstanceService;
10 import org.flowable.bpmn.model.BpmnModel;
11 import org.flowable.bpmn.model.UserTask;
12 import org.flowable.engine.delegate.DelegateExecution;
13 import org.flowable.engine.runtime.ProcessInstance;
14 import org.springframework.context.annotation.Lazy;
15 import org.springframework.stereotype.Component;
16
17 import javax.annotation.Resource;
18 import java.util.*;
19
20 /**
21  * 发起人自选 {@link BpmTaskCandidateUserStrategy} 实现类
22  *
23  * @author iailab
24  */
25 @Component
26 public class BpmTaskCandidateStartUserSelectStrategy implements BpmTaskCandidateStrategy {
27
28     @Resource
29     @Lazy // 延迟加载,避免循环依赖
30     private BpmProcessInstanceService processInstanceService;
31
32     @Override
33     public BpmTaskCandidateStrategyEnum getStrategy() {
34         return BpmTaskCandidateStrategyEnum.START_USER_SELECT;
35     }
36
37     @Override
38     public void validateParam(String param) {}
39
40     @Override
41     public Set<Long> calculateUsers(DelegateExecution execution, String param) {
42         ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
43         Assert.notNull(processInstance, "流程实例({})不能为空", execution.getProcessInstanceId());
44         Map<String, List<Long>> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance);
45         Assert.notNull(startUserSelectAssignees, "流程实例({}) 的发起人自选审批人不能为空",
46                 execution.getProcessInstanceId());
47         // 获得审批人
48         List<Long> assignees = startUserSelectAssignees.get(execution.getCurrentActivityId());
49         return new LinkedHashSet<>(assignees);
50     }
51
52     @Override
53     public boolean isParamRequired() {
54         return false;
55     }
56
57     /**
58      * 获得发起人自选审批人的 UserTask 列表
59      *
60      * @param bpmnModel BPMN 模型
61      * @return UserTask 列表
62      */
63     public static List<UserTask> getStartUserSelectUserTaskList(BpmnModel bpmnModel) {
64         if (bpmnModel == null) {
65             return null;
66         }
67         List<UserTask> userTaskList = BpmnModelUtils.getBpmnModelElements(bpmnModel, UserTask.class);
68         if (CollUtil.isEmpty(userTaskList)) {
69             return null;
70         }
71         userTaskList.removeIf(userTask -> !Objects.equals(BpmnModelUtils.parseCandidateStrategy(userTask),
72                 BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy()));
73         return userTaskList;
74     }
75
76 }