dongyukun
2024-12-16 ed8fc5f674544d3af63c6f68093ffc038385c493
提交 | 用户 | 时间
bb2880 1 package com.iailab.module.bpm.framework.flowable.core.candidate.strategy.other;
H 2
3 import cn.hutool.core.lang.Assert;
4 import com.iailab.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
5 import com.iailab.module.bpm.enums.definition.BpmUserTaskAssignEmptyHandlerTypeEnum;
6 import com.iailab.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
7 import com.iailab.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
8 import com.iailab.module.bpm.framework.flowable.core.util.BpmnModelUtils;
9 import com.iailab.module.bpm.service.definition.BpmProcessDefinitionService;
10 import org.flowable.bpmn.model.BpmnModel;
11 import org.flowable.bpmn.model.FlowElement;
12 import org.flowable.engine.delegate.DelegateExecution;
13 import org.springframework.context.annotation.Lazy;
14 import org.springframework.stereotype.Component;
15
16 import javax.annotation.Resource;
17 import java.util.HashSet;
18 import java.util.Map;
19 import java.util.Objects;
20 import java.util.Set;
21
22 /**
23  * 审批人为空 {@link BpmTaskCandidateStrategy} 实现类
24  *
25  * @author hou
26  */
27 @Component
28 public class BpmTaskCandidateAssignEmptyStrategy implements BpmTaskCandidateStrategy {
29
30     @Resource
31     @Lazy // 延迟加载,避免循环依赖
32     private BpmProcessDefinitionService processDefinitionService;
33
34     @Override
35     public BpmTaskCandidateStrategyEnum getStrategy() {
36         return BpmTaskCandidateStrategyEnum.ASSIGN_EMPTY;
37     }
38
39     @Override
40     public void validateParam(String param) {
41     }
42
43     @Override
44     public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
45         return getCandidateUsers(execution.getProcessDefinitionId(), execution.getCurrentFlowElement());
46     }
47
48     @Override
49     public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param,
50                                               Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
51         FlowElement flowElement = BpmnModelUtils.getFlowElementById(bpmnModel, activityId);
52         return getCandidateUsers(processDefinitionId, flowElement);
53     }
54
55     private Set<Long> getCandidateUsers(String processDefinitionId, FlowElement flowElement) {
56         // 情况一:指定人员审批
57         Integer assignEmptyHandlerType = BpmnModelUtils.parseAssignEmptyHandlerType(flowElement);
58         if (Objects.equals(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.ASSIGN_USER.getType())) {
59             return new HashSet<>(BpmnModelUtils.parseAssignEmptyHandlerUserIds(flowElement));
60         }
61
62         // 情况二:流程管理员
63         if (Objects.equals(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.ASSIGN_ADMIN.getType())) {
64             BpmProcessDefinitionInfoDO processDefinition = processDefinitionService.getProcessDefinitionInfo(processDefinitionId);
65             Assert.notNull(processDefinition, "流程定义({})不存在", processDefinitionId);
66             return new HashSet<>(processDefinition.getManagerUserIds());
67         }
68
69         // 都不满足,还是返回空
70         return new HashSet<>();
71     }
72
73 }