houzhongjian
4 天以前 f4f9405f99cb35e2fd6cfeae4c54617304228fda
提交 | 用户 | 时间
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 com.iailab.framework.common.util.collection.SetUtils.asSet;
21
22 /**
23  * 发起人的部门负责人, 可以是上级部门负责人 {@link BpmTaskCandidateStrategy} 实现类
24  *
25  * @author hou
26  */
27 @Component
28 public class BpmTaskCandidateStartUserDeptLeaderStrategy 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;
37     }
38
39     @Override
40     public void validateParam(String param) {
41         // 参数是部门的层级
42         Assert.isTrue(Integer.parseInt(param) > 0, "部门的层级必须大于 0");
43     }
44
45     @Override
46     public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
47         // 获得流程发起人
48         ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
49         Long startUserId = NumberUtils.parseLong(processInstance.getStartUserId());
50         // 获取发起人的部门负责人
51         return getStartUserDeptLeader(startUserId, param);
52     }
53
54     @Override
55     public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param,
56                                               Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
57         // 获取发起人的部门负责人
58         return getStartUserDeptLeader(startUserId, param);
59     }
60
61     private Set<Long> getStartUserDeptLeader(Long startUserId, String param) {
62         int level = Integer.parseInt(param); // 参数是部门的层级
63         DeptRespDTO dept = super.getStartUserDept(startUserId);
64         if (dept == null) {
65             return new HashSet<>();
66         }
67         Long deptLeaderId = super.getAssignLevelDeptLeaderId(dept, level);
68         return deptLeaderId != null ? asSet(deptLeaderId) : new HashSet<>();
69     }
70
71 }