diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateAbstractDeptLeaderStrategy.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateAbstractDeptLeaderStrategy.java index a6e0790c6e..3144280234 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateAbstractDeptLeaderStrategy.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateAbstractDeptLeaderStrategy.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; import cn.iocoder.yudao.module.system.api.dept.DeptApi; @@ -7,6 +8,7 @@ import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import java.util.Collections; import java.util.LinkedHashSet; +import java.util.List; import java.util.Set; /** @@ -26,7 +28,7 @@ public abstract class BpmTaskCandidateAbstractDeptLeaderStrategy implements BpmT * 获取上级部门的负责人 * * @param assignDept 指定部门 - * @param level 第几级 + * @param level 第几级 * @return 部门负责人 Id */ protected Long getAssignLevelDeptLeaderId(DeptRespDTO assignDept, Integer level) { @@ -48,26 +50,29 @@ public abstract class BpmTaskCandidateAbstractDeptLeaderStrategy implements BpmT /** * 获取连续上级部门的负责人, 包含指定部门的负责人 * - * @param assignDept 指定部门 - * @param level 第几级 + * @param assignDeptIds 指定部门 Ids + * @param level 第几级 * @return 连续部门负责人 Id */ - protected Set getMultiLevelDeptLeaderIds(DeptRespDTO assignDept, Integer level){ + protected Set getMultiLevelDeptLeaderIds(List assignDeptIds, Integer level) { Assert.isTrue(level > 0, "level 必须大于 0"); - if (assignDept == null) { + if (CollUtil.isEmpty(assignDeptIds)) { return Collections.emptySet(); } Set deptLeaderIds = new LinkedHashSet<>(); // 保证有序 - DeptRespDTO dept = assignDept; - for (int i = 0; i < level; i++) { - if (dept.getLeaderUserId() != null) { - deptLeaderIds.add(dept.getLeaderUserId()); + DeptRespDTO dept; + for (Long deptId : assignDeptIds) { + dept = deptApi.getDept(deptId); + for (int i = 0; i < level; i++) { + if (dept.getLeaderUserId() != null) { + deptLeaderIds.add(dept.getLeaderUserId()); + } + DeptRespDTO parentDept = deptApi.getDept(dept.getParentId()); + if (parentDept == null) { // 找不到父级部门. 已经到了最高层级了 + break; + } + dept = parentDept; } - DeptRespDTO parentDept = deptApi.getDept(dept.getParentId()); - if (parentDept == null) { // 找不到父级部门. 已经到了最高层级了 - break; - } - dept = parentDept; } return deptLeaderIds; } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateMultiLevelDeptLeaderStrategy.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateMultiLevelDeptLeaderStrategy.java index c3eb064e16..60730ed1ba 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateMultiLevelDeptLeaderStrategy.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateMultiLevelDeptLeaderStrategy.java @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; import cn.iocoder.yudao.module.system.api.dept.DeptApi; -import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import org.flowable.engine.delegate.DelegateExecution; import org.springframework.stereotype.Component; @@ -32,22 +31,21 @@ public class BpmTaskCandidateMultiLevelDeptLeaderStrategy extends BpmTaskCandida @Override public void validateParam(String param) { - // 参数格式: ,分割。 前面一个指定指定部门Id, 后面一个是部门的层级 + // 参数格式: ,分割。前面的部门Id. 可以为多个。 最后一个为部门层级 List params = StrUtils.splitToLong(param, ","); - Assert.isTrue(params.size() == 2, "参数格式不匹配"); - deptApi.validateDeptList(CollUtil.toList(params.get(0))); - Assert.isTrue(params.get(1) > 0, "部门层级必须大于 0"); + List> splitList = CollUtil.split(params, params.size() - 1); + Assert.isTrue(splitList.size() == 2, "参数格式不匹配"); + deptApi.validateDeptList(splitList.get(0)); + Assert.isTrue(splitList.get(1).get(0) > 0, "部门层级必须大于 0"); } @Override public Set calculateUsers(DelegateExecution execution, String param) { - // 参数格式: ,分割。 前面一个指定指定部门Id, 后面一个是审批的层级 + // 参数格式: ,分割。前面的部门Id. 可以为多个。 最后一个为部门层级 List params = StrUtils.splitToLong(param, ","); - // TODO @芋艿 是否要支持多个部门。 是不是这种场景,一个部门就可以了 - Long deptId = params.get(0); - Long level = params.get(1); - DeptRespDTO dept = deptApi.getDept(deptId); - return getMultiLevelDeptLeaderIds(dept, level.intValue()); + List> splitList = CollUtil.split(params, params.size() - 1); + Long level = splitList.get(1).get(0); + return getMultiLevelDeptLeaderIds(splitList.get(0), level.intValue()); } } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateStartUserMultiLevelDeptLeaderStrategy.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateStartUserMultiLevelDeptLeaderStrategy.java index 326ea88709..f8495e3437 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateStartUserMultiLevelDeptLeaderStrategy.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateStartUserMultiLevelDeptLeaderStrategy.java @@ -15,8 +15,11 @@ import org.flowable.engine.runtime.ProcessInstance; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; +import java.util.Collections; import java.util.Set; +import static cn.hutool.core.collection.ListUtil.toList; + /** * 发起人连续多级部门的负责人 {@link BpmTaskCandidateStrategy} 实现类 * @@ -52,9 +55,11 @@ public class BpmTaskCandidateStartUserMultiLevelDeptLeaderStrategy extends BpmTa // 获得流程发起人 ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId()); Long startUserId = NumberUtils.parseLong(processInstance.getStartUserId()); - DeptRespDTO dept = getStartUserDept(startUserId); - return getMultiLevelDeptLeaderIds(dept, Integer.valueOf(param)); // 参数是部门的层级 + if (dept == null) { + return Collections.emptySet(); + } + return getMultiLevelDeptLeaderIds(toList(dept.getId()), Integer.valueOf(param)); // 参数是部门的层级 } /**