潘志宝
4 天以前 b8a0affd03b5fa9fa33cd6f870e90394c2df86c7
提交 | 用户 | 时间
bb2880 1 package com.iailab.module.bpm.framework.flowable.core.candidate.strategy.dept;
H 2
3 import cn.hutool.core.lang.Assert;
4 import com.iailab.framework.common.util.number.NumberUtils;
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.service.task.BpmProcessInstanceService;
8 import com.iailab.module.system.api.dept.dto.DeptRespDTO;
9 import org.flowable.bpmn.model.BpmnModel;
10 import org.flowable.engine.delegate.DelegateExecution;
11 import org.flowable.engine.runtime.ProcessInstance;
12 import org.springframework.context.annotation.Lazy;
13 import org.springframework.stereotype.Component;
14
15 import javax.annotation.Resource;
16 import java.util.HashSet;
17 import java.util.Map;
18 import java.util.Set;
19
20 import static cn.hutool.core.collection.ListUtil.toList;
21
22 /**
23  * 发起人连续多级部门的负责人 {@link BpmTaskCandidateStrategy} 实现类
24  *
25  * @author hou
26  */
27 @Component
28 public class BpmTaskCandidateStartUserDeptLeaderMultiStrategy extends AbstractBpmTaskCandidateDeptLeaderStrategy {
29
30     @Resource
31     @Lazy
32     private BpmProcessInstanceService processInstanceService;
33
34     @Override
35     public BpmTaskCandidateStrategyEnum getStrategy() {
36         return BpmTaskCandidateStrategyEnum.START_USER_DEPT_LEADER_MULTI;
37     }
38
39     @Override
40     public void validateParam(String param) {
41         int level = Integer.parseInt(param); // 参数是部门的层级
42         Assert.isTrue(level > 0, "部门的层级必须大于 0");
43     }
44
45     @Override
46     public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
47         int level = Integer.parseInt(param); // 参数是部门的层级
48         // 获得流程发起人
49         ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
50         Long startUserId = NumberUtils.parseLong(processInstance.getStartUserId());
51         // 获取发起人的 multi 部门负责人
52         DeptRespDTO dept = super.getStartUserDept(startUserId);
53         if (dept == null) {
54             return new HashSet<>();
55         }
56         return super.getMultiLevelDeptLeaderIds(toList(dept.getId()), level);
57     }
58
59     @Override
60     public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param,
61                                               Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
62         int level = Integer.parseInt(param); // 参数是部门的层级
63         DeptRespDTO dept = super.getStartUserDept(startUserId);
64         if (dept == null) {
65             return new HashSet<>();
66         }
67         return super.getMultiLevelDeptLeaderIds(toList(dept.getId()), level);
68     }
69
70 }