提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.bpm.framework.flowable.core.candidate.expression; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.util.number.NumberUtils; |
|
4 |
import com.iailab.module.bpm.service.task.BpmProcessInstanceService; |
|
5 |
import com.iailab.module.system.api.dept.DeptApi; |
|
6 |
import com.iailab.module.system.api.dept.dto.DeptRespDTO; |
|
7 |
import com.iailab.module.system.api.user.AdminUserApi; |
|
8 |
import com.iailab.module.system.api.user.dto.AdminUserRespDTO; |
|
9 |
import org.flowable.engine.delegate.DelegateExecution; |
|
10 |
import org.flowable.engine.runtime.ProcessInstance; |
|
11 |
import org.springframework.stereotype.Component; |
|
12 |
import org.springframework.util.Assert; |
|
13 |
|
|
14 |
import javax.annotation.Resource; |
|
15 |
import java.util.Set; |
|
16 |
|
|
17 |
import static com.iailab.framework.common.util.collection.SetUtils.asSet; |
|
18 |
import static java.util.Collections.emptySet; |
|
19 |
|
|
20 |
/** |
|
21 |
* 分配给发起人的 Leader 审批的 Expression 流程表达式 |
|
22 |
* 目前 Leader 的定义是,发起人所在部门的 Leader |
|
23 |
* |
|
24 |
* @author iailab |
|
25 |
*/ |
|
26 |
@Component |
|
27 |
public class BpmTaskAssignLeaderExpression { |
|
28 |
|
|
29 |
@Resource |
|
30 |
private AdminUserApi adminUserApi; |
|
31 |
@Resource |
|
32 |
private DeptApi deptApi; |
|
33 |
|
|
34 |
@Resource |
|
35 |
private BpmProcessInstanceService processInstanceService; |
|
36 |
|
|
37 |
/** |
|
38 |
* 计算审批的候选人 |
|
39 |
* |
|
40 |
* @param execution 流程执行实体 |
|
41 |
* @param level 指定级别 |
|
42 |
* @return 指定级别的领导 |
|
43 |
*/ |
|
44 |
public Set<Long> calculateUsers(DelegateExecution execution, int level) { |
|
45 |
Assert.isTrue(level > 0, "level 必须大于 0"); |
|
46 |
// 获得发起人 |
|
47 |
ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId()); |
|
48 |
Long startUserId = NumberUtils.parseLong(processInstance.getStartUserId()); |
|
49 |
// 获得对应 leve 的部门 |
|
50 |
DeptRespDTO dept = null; |
|
51 |
for (int i = 0; i < level; i++) { |
|
52 |
// 获得 level 对应的部门 |
|
53 |
if (dept == null) { |
|
54 |
dept = getStartUserDept(startUserId); |
|
55 |
if (dept == null) { // 找不到发起人的部门,所以无法使用该规则 |
|
56 |
return emptySet(); |
|
57 |
} |
|
58 |
} else { |
|
59 |
DeptRespDTO parentDept = deptApi.getDept(dept.getParentId()).getCheckedData(); |
|
60 |
if (parentDept == null) { // 找不到父级部门,所以只好结束寻找。原因是:例如说,级别比较高的人,所在部门层级比较少 |
|
61 |
break; |
|
62 |
} |
|
63 |
dept = parentDept; |
|
64 |
} |
|
65 |
} |
|
66 |
return dept.getLeaderUserId() != null ? asSet(dept.getLeaderUserId()) : emptySet(); |
|
67 |
} |
|
68 |
|
|
69 |
private DeptRespDTO getStartUserDept(Long startUserId) { |
|
70 |
AdminUserRespDTO startUser = adminUserApi.getUser(startUserId).getCheckedData(); |
|
71 |
if (startUser.getDeptId() == null) { // 找不到部门,所以无法使用该规则 |
|
72 |
return null; |
|
73 |
} |
|
74 |
return deptApi.getDept(startUser.getDeptId()).getCheckedData(); |
|
75 |
} |
|
76 |
|
|
77 |
} |