Commit d42c63e8fd61900ab757aa8ed6974bf2fc2dddf0
1 parent
7f6d214e
【功能修改】任务的候选人的策略, 增加移除被禁用的用户接口
Showing
19 changed files
with
168 additions
and
66 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/BpmTaskCandidateInvoker.java
| @@ -111,7 +111,7 @@ public class BpmTaskCandidateInvoker { | @@ -111,7 +111,7 @@ public class BpmTaskCandidateInvoker { | ||
| 111 | removeStartUserIfSkip(execution, userIds); | 111 | removeStartUserIfSkip(execution, userIds); |
| 112 | 112 | ||
| 113 | // 2. 移除被禁用的用户 TODO @芋艿 移除禁用的用户是否应该放在 1.1 之后 | 113 | // 2. 移除被禁用的用户 TODO @芋艿 移除禁用的用户是否应该放在 1.1 之后 |
| 114 | - removeDisableUsers(userIds); | 114 | + // removeDisableUsers(userIds); @芋艿 把这个移到了 BpmTaskCandidateStrategy 下面。 看一下是否可以 |
| 115 | return userIds; | 115 | return userIds; |
| 116 | } | 116 | } |
| 117 | 117 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/BpmTaskCandidateStrategy.java
| @@ -56,7 +56,9 @@ public interface BpmTaskCandidateStrategy { | @@ -56,7 +56,9 @@ public interface BpmTaskCandidateStrategy { | ||
| 56 | * @return 用户编号集合 | 56 | * @return 用户编号集合 |
| 57 | */ | 57 | */ |
| 58 | default Set<Long> calculateUsers(DelegateExecution execution, String param) { | 58 | default Set<Long> calculateUsers(DelegateExecution execution, String param) { |
| 59 | - return calculateUsers(param); | 59 | + Set<Long> users = calculateUsers(param); |
| 60 | + removeDisableUsers(users); | ||
| 61 | + return users; | ||
| 60 | } | 62 | } |
| 61 | 63 | ||
| 62 | 64 | ||
| @@ -72,9 +74,19 @@ public interface BpmTaskCandidateStrategy { | @@ -72,9 +74,19 @@ public interface BpmTaskCandidateStrategy { | ||
| 72 | * @return 用户编号集合 | 74 | * @return 用户编号集合 |
| 73 | */ | 75 | */ |
| 74 | default Set<Long> calculateUsers(Long startUserId, ProcessInstance processInstance, String activityId, String param) { | 76 | default Set<Long> calculateUsers(Long startUserId, ProcessInstance processInstance, String activityId, String param) { |
| 75 | - return calculateUsers(param); | 77 | + Set<Long> users = calculateUsers(param); |
| 78 | + removeDisableUsers(users); | ||
| 79 | + return users; | ||
| 76 | } | 80 | } |
| 77 | 81 | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 移除被禁用的用户 | ||
| 85 | + * | ||
| 86 | + * @param users 用户 Ids | ||
| 87 | + */ | ||
| 88 | + void removeDisableUsers(Set<Long> users); | ||
| 89 | + | ||
| 78 | // TODO @芋艿:后续可以抽象一个 calculateUsers(String param),默认 calculateUsers 和 calculateUsers 调用它 | 90 | // TODO @芋艿:后续可以抽象一个 calculateUsers(String param),默认 calculateUsers 和 calculateUsers 调用它 |
| 79 | // TODO @芋艿 加了, review 一下 | 91 | // TODO @芋艿 加了, review 一下 |
| 80 | 92 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateAbstractDeptLeaderStrategy.java
| @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; | @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; | ||
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; |
| 6 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; | 6 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| 7 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; | 7 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| 8 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 8 | 9 | ||
| 9 | import java.util.*; | 10 | import java.util.*; |
| 10 | 11 | ||
| @@ -13,11 +14,12 @@ import java.util.*; | @@ -13,11 +14,12 @@ import java.util.*; | ||
| 13 | * | 14 | * |
| 14 | * @author jason | 15 | * @author jason |
| 15 | */ | 16 | */ |
| 16 | -public abstract class BpmTaskCandidateAbstractDeptLeaderStrategy implements BpmTaskCandidateStrategy { | 17 | +public abstract class BpmTaskCandidateAbstractDeptLeaderStrategy extends BpmTaskCandidateAbstractStrategy { |
| 17 | 18 | ||
| 18 | protected DeptApi deptApi; | 19 | protected DeptApi deptApi; |
| 19 | 20 | ||
| 20 | - public BpmTaskCandidateAbstractDeptLeaderStrategy(DeptApi deptApi) { | 21 | + public BpmTaskCandidateAbstractDeptLeaderStrategy(AdminUserApi adminUserApi, DeptApi deptApi) { |
| 22 | + super(adminUserApi); | ||
| 21 | this.deptApi = deptApi; | 23 | this.deptApi = deptApi; |
| 22 | } | 24 | } |
| 23 | 25 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateAbstractStrategy.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 5 | +import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; | ||
| 6 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 7 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 8 | + | ||
| 9 | +import java.util.Map; | ||
| 10 | +import java.util.Set; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * {@link BpmTaskCandidateStrategy} 抽象类 | ||
| 14 | + * | ||
| 15 | + * @author jason | ||
| 16 | + */ | ||
| 17 | +public abstract class BpmTaskCandidateAbstractStrategy implements BpmTaskCandidateStrategy { | ||
| 18 | + | ||
| 19 | + protected AdminUserApi adminUserApi; | ||
| 20 | + | ||
| 21 | + public BpmTaskCandidateAbstractStrategy(AdminUserApi adminUserApi) { | ||
| 22 | + this.adminUserApi = adminUserApi; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public void removeDisableUsers(Set<Long> users) { | ||
| 27 | + if (CollUtil.isEmpty(users)) { | ||
| 28 | + return; | ||
| 29 | + } | ||
| 30 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(users); | ||
| 31 | + users.removeIf(id -> { | ||
| 32 | + AdminUserRespDTO user = userMap.get(id); | ||
| 33 | + return user == null || !CommonStatusEnum.ENABLE.getStatus().equals(user.getStatus()); | ||
| 34 | + }); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | +} |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateAssignEmptyStrategy.java
| @@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCand | @@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCand | ||
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; | 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; |
| 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 8 | -import jakarta.annotation.Resource; | ||
| 9 | import org.flowable.engine.delegate.DelegateExecution; | 8 | import org.flowable.engine.delegate.DelegateExecution; |
| 10 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 11 | 10 | ||
| @@ -19,10 +18,11 @@ import java.util.Set; | @@ -19,10 +18,11 @@ import java.util.Set; | ||
| 19 | * @author kyle | 18 | * @author kyle |
| 20 | */ | 19 | */ |
| 21 | @Component | 20 | @Component |
| 22 | -public class BpmTaskCandidateAssignEmptyStrategy implements BpmTaskCandidateStrategy { | 21 | +public class BpmTaskCandidateAssignEmptyStrategy extends BpmTaskCandidateAbstractStrategy { |
| 23 | 22 | ||
| 24 | - @Resource | ||
| 25 | - private AdminUserApi adminUserApi; | 23 | + public BpmTaskCandidateAssignEmptyStrategy(AdminUserApi adminUserApi) { |
| 24 | + super(adminUserApi); | ||
| 25 | + } | ||
| 26 | 26 | ||
| 27 | @Override | 27 | @Override |
| 28 | public BpmTaskCandidateStrategyEnum getStrategy() { | 28 | public BpmTaskCandidateStrategyEnum getStrategy() { |
| @@ -38,7 +38,9 @@ public class BpmTaskCandidateAssignEmptyStrategy implements BpmTaskCandidateStra | @@ -38,7 +38,9 @@ public class BpmTaskCandidateAssignEmptyStrategy implements BpmTaskCandidateStra | ||
| 38 | // 情况一:指定人员审批 | 38 | // 情况一:指定人员审批 |
| 39 | Integer assignEmptyHandlerType = BpmnModelUtils.parseAssignEmptyHandlerType(execution.getCurrentFlowElement()); | 39 | Integer assignEmptyHandlerType = BpmnModelUtils.parseAssignEmptyHandlerType(execution.getCurrentFlowElement()); |
| 40 | if (Objects.equals(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.ASSIGN_USER.getType())) { | 40 | if (Objects.equals(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.ASSIGN_USER.getType())) { |
| 41 | - return new HashSet<>(BpmnModelUtils.parseAssignEmptyHandlerUserIds(execution.getCurrentFlowElement())); | 41 | + HashSet<Long> users = new HashSet<>(BpmnModelUtils.parseAssignEmptyHandlerUserIds(execution.getCurrentFlowElement())); |
| 42 | + removeDisableUsers(users); | ||
| 43 | + return users; | ||
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | // 情况二:流程管理员 | 46 | // 情况二:流程管理员 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateDeptLeaderMultiStrategy.java
| @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; | ||
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; |
| 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 7 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; | 7 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| 8 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 8 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 9 | 10 | ||
| 10 | import java.util.Set; | 11 | import java.util.Set; |
| @@ -17,8 +18,8 @@ import java.util.Set; | @@ -17,8 +18,8 @@ import java.util.Set; | ||
| 17 | @Component | 18 | @Component |
| 18 | public class BpmTaskCandidateDeptLeaderMultiStrategy extends BpmTaskCandidateAbstractDeptLeaderStrategy { | 19 | public class BpmTaskCandidateDeptLeaderMultiStrategy extends BpmTaskCandidateAbstractDeptLeaderStrategy { |
| 19 | 20 | ||
| 20 | - public BpmTaskCandidateDeptLeaderMultiStrategy(DeptApi deptApi) { | ||
| 21 | - super(deptApi); | 21 | + public BpmTaskCandidateDeptLeaderMultiStrategy(AdminUserApi adminUserApi, DeptApi deptApi) { |
| 22 | + super(adminUserApi, deptApi); | ||
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | @Override | 25 | @Override |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateDeptLeaderStrategy.java
| @@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCand | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCand | ||
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 6 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; | 6 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| 7 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; | 7 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| 8 | -import jakarta.annotation.Resource; | 8 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 9 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 10 | 10 | ||
| 11 | import java.util.List; | 11 | import java.util.List; |
| @@ -19,10 +19,14 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -19,10 +19,14 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 19 | * @author kyle | 19 | * @author kyle |
| 20 | */ | 20 | */ |
| 21 | @Component | 21 | @Component |
| 22 | -public class BpmTaskCandidateDeptLeaderStrategy implements BpmTaskCandidateStrategy { | 22 | +public class BpmTaskCandidateDeptLeaderStrategy extends BpmTaskCandidateAbstractStrategy { |
| 23 | 23 | ||
| 24 | - @Resource | ||
| 25 | - private DeptApi deptApi; | 24 | + private final DeptApi deptApi; |
| 25 | + | ||
| 26 | + public BpmTaskCandidateDeptLeaderStrategy(AdminUserApi adminUserApi, DeptApi deptApi) { | ||
| 27 | + super(adminUserApi); | ||
| 28 | + this.deptApi = deptApi; | ||
| 29 | + } | ||
| 26 | 30 | ||
| 27 | @Override | 31 | @Override |
| 28 | public BpmTaskCandidateStrategyEnum getStrategy() { | 32 | public BpmTaskCandidateStrategyEnum getStrategy() { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateDeptMemberStrategy.java
| @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidat | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidat | ||
| 6 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; | 6 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 8 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 8 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 9 | -import jakarta.annotation.Resource; | ||
| 10 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 11 | 10 | ||
| 12 | import java.util.List; | 11 | import java.util.List; |
| @@ -20,12 +19,14 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -20,12 +19,14 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 20 | * @author kyle | 19 | * @author kyle |
| 21 | */ | 20 | */ |
| 22 | @Component | 21 | @Component |
| 23 | -public class BpmTaskCandidateDeptMemberStrategy implements BpmTaskCandidateStrategy { | 22 | +public class BpmTaskCandidateDeptMemberStrategy extends BpmTaskCandidateAbstractStrategy { |
| 24 | 23 | ||
| 25 | - @Resource | ||
| 26 | - private DeptApi deptApi; | ||
| 27 | - @Resource | ||
| 28 | - private AdminUserApi adminUserApi; | 24 | + private final DeptApi deptApi; |
| 25 | + | ||
| 26 | + public BpmTaskCandidateDeptMemberStrategy(AdminUserApi adminUserApi, DeptApi deptApi) { | ||
| 27 | + super(adminUserApi); | ||
| 28 | + this.deptApi = deptApi; | ||
| 29 | + } | ||
| 29 | 30 | ||
| 30 | @Override | 31 | @Override |
| 31 | public BpmTaskCandidateStrategyEnum getStrategy() { | 32 | public BpmTaskCandidateStrategyEnum getStrategy() { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateExpressionStrategy.java
| @@ -4,6 +4,7 @@ import cn.hutool.core.convert.Convert; | @@ -4,6 +4,7 @@ import cn.hutool.core.convert.Convert; | ||
| 4 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; | 4 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; |
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; | 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; |
| 7 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 7 | import org.flowable.engine.delegate.DelegateExecution; | 8 | import org.flowable.engine.delegate.DelegateExecution; |
| 8 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 9 | 10 | ||
| @@ -15,7 +16,11 @@ import java.util.Set; | @@ -15,7 +16,11 @@ import java.util.Set; | ||
| 15 | * @author 芋道源码 | 16 | * @author 芋道源码 |
| 16 | */ | 17 | */ |
| 17 | @Component | 18 | @Component |
| 18 | -public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrategy { | 19 | +public class BpmTaskCandidateExpressionStrategy extends BpmTaskCandidateAbstractStrategy { |
| 20 | + | ||
| 21 | + public BpmTaskCandidateExpressionStrategy(AdminUserApi adminUserApi) { | ||
| 22 | + super(adminUserApi); | ||
| 23 | + } | ||
| 19 | 24 | ||
| 20 | @Override | 25 | @Override |
| 21 | public BpmTaskCandidateStrategyEnum getStrategy() { | 26 | public BpmTaskCandidateStrategyEnum getStrategy() { |
| @@ -30,7 +35,9 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat | @@ -30,7 +35,9 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat | ||
| 30 | @Override | 35 | @Override |
| 31 | public Set<Long> calculateUsers(DelegateExecution execution, String param) { | 36 | public Set<Long> calculateUsers(DelegateExecution execution, String param) { |
| 32 | Object result = FlowableUtils.getExpressionValue(execution, param); | 37 | Object result = FlowableUtils.getExpressionValue(execution, param); |
| 33 | - return Convert.toSet(Long.class, result); | 38 | + Set<Long> users = Convert.toSet(Long.class, result); |
| 39 | + removeDisableUsers(users); | ||
| 40 | + return users; | ||
| 34 | } | 41 | } |
| 35 | 42 | ||
| 36 | } | 43 | } |
| 37 | \ No newline at end of file | 44 | \ No newline at end of file |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateGroupStrategy.java
| @@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmUserGroupDO; | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmUserGroupDO; | ||
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; |
| 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 7 | import cn.iocoder.yudao.module.bpm.service.definition.BpmUserGroupService; | 7 | import cn.iocoder.yudao.module.bpm.service.definition.BpmUserGroupService; |
| 8 | -import jakarta.annotation.Resource; | 8 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 9 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 10 | 10 | ||
| 11 | import java.util.Collection; | 11 | import java.util.Collection; |
| @@ -20,10 +20,14 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -20,10 +20,14 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 20 | * @author kyle | 20 | * @author kyle |
| 21 | */ | 21 | */ |
| 22 | @Component | 22 | @Component |
| 23 | -public class BpmTaskCandidateGroupStrategy implements BpmTaskCandidateStrategy { | 23 | +public class BpmTaskCandidateGroupStrategy extends BpmTaskCandidateAbstractStrategy { |
| 24 | 24 | ||
| 25 | - @Resource | ||
| 26 | - private BpmUserGroupService userGroupService; | 25 | + private final BpmUserGroupService userGroupService; |
| 26 | + | ||
| 27 | + public BpmTaskCandidateGroupStrategy(AdminUserApi adminUserApi, BpmUserGroupService userGroupService) { | ||
| 28 | + super(adminUserApi); | ||
| 29 | + this.userGroupService = userGroupService; | ||
| 30 | + } | ||
| 27 | 31 | ||
| 28 | @Override | 32 | @Override |
| 29 | public BpmTaskCandidateStrategyEnum getStrategy() { | 33 | public BpmTaskCandidateStrategyEnum getStrategy() { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidatePostStrategy.java
| @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidat | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidat | ||
| 6 | import cn.iocoder.yudao.module.system.api.dept.PostApi; | 6 | import cn.iocoder.yudao.module.system.api.dept.PostApi; |
| 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 8 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 8 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 9 | -import jakarta.annotation.Resource; | ||
| 10 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 11 | 10 | ||
| 12 | import java.util.List; | 11 | import java.util.List; |
| @@ -20,12 +19,14 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -20,12 +19,14 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 20 | * @author kyle | 19 | * @author kyle |
| 21 | */ | 20 | */ |
| 22 | @Component | 21 | @Component |
| 23 | -public class BpmTaskCandidatePostStrategy implements BpmTaskCandidateStrategy { | 22 | +public class BpmTaskCandidatePostStrategy extends BpmTaskCandidateAbstractStrategy { |
| 24 | 23 | ||
| 25 | - @Resource | ||
| 26 | - private PostApi postApi; | ||
| 27 | - @Resource | ||
| 28 | - private AdminUserApi adminUserApi; | 24 | + private final PostApi postApi; |
| 25 | + | ||
| 26 | + public BpmTaskCandidatePostStrategy(AdminUserApi adminUserApi, PostApi postApi) { | ||
| 27 | + super(adminUserApi); | ||
| 28 | + this.postApi = postApi; | ||
| 29 | + } | ||
| 29 | 30 | ||
| 30 | @Override | 31 | @Override |
| 31 | public BpmTaskCandidateStrategyEnum getStrategy() { | 32 | public BpmTaskCandidateStrategyEnum getStrategy() { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateRoleStrategy.java
| @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCand | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCand | ||
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 6 | import cn.iocoder.yudao.module.system.api.permission.PermissionApi; | 6 | import cn.iocoder.yudao.module.system.api.permission.PermissionApi; |
| 7 | import cn.iocoder.yudao.module.system.api.permission.RoleApi; | 7 | import cn.iocoder.yudao.module.system.api.permission.RoleApi; |
| 8 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 8 | import jakarta.annotation.Resource; | 9 | import jakarta.annotation.Resource; |
| 9 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
| 10 | 11 | ||
| @@ -16,13 +17,17 @@ import java.util.Set; | @@ -16,13 +17,17 @@ import java.util.Set; | ||
| 16 | * @author kyle | 17 | * @author kyle |
| 17 | */ | 18 | */ |
| 18 | @Component | 19 | @Component |
| 19 | -public class BpmTaskCandidateRoleStrategy implements BpmTaskCandidateStrategy { | 20 | +public class BpmTaskCandidateRoleStrategy extends BpmTaskCandidateAbstractStrategy { |
| 20 | 21 | ||
| 21 | @Resource | 22 | @Resource |
| 22 | private RoleApi roleApi; | 23 | private RoleApi roleApi; |
| 23 | @Resource | 24 | @Resource |
| 24 | private PermissionApi permissionApi; | 25 | private PermissionApi permissionApi; |
| 25 | 26 | ||
| 27 | + public BpmTaskCandidateRoleStrategy(AdminUserApi adminUserApi) { | ||
| 28 | + super(adminUserApi); | ||
| 29 | + } | ||
| 30 | + | ||
| 26 | @Override | 31 | @Override |
| 27 | public BpmTaskCandidateStrategyEnum getStrategy() { | 32 | public BpmTaskCandidateStrategyEnum getStrategy() { |
| 28 | return BpmTaskCandidateStrategyEnum.ROLE; | 33 | return BpmTaskCandidateStrategyEnum.ROLE; |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateStartUserDeptLeaderMultiStrategy.java
| @@ -32,11 +32,8 @@ public class BpmTaskCandidateStartUserDeptLeaderMultiStrategy extends BpmTaskCan | @@ -32,11 +32,8 @@ public class BpmTaskCandidateStartUserDeptLeaderMultiStrategy extends BpmTaskCan | ||
| 32 | @Lazy | 32 | @Lazy |
| 33 | private BpmProcessInstanceService processInstanceService; | 33 | private BpmProcessInstanceService processInstanceService; |
| 34 | 34 | ||
| 35 | - @Resource | ||
| 36 | - private AdminUserApi adminUserApi; | ||
| 37 | - | ||
| 38 | - public BpmTaskCandidateStartUserDeptLeaderMultiStrategy(DeptApi deptApi) { | ||
| 39 | - super(deptApi); | 35 | + public BpmTaskCandidateStartUserDeptLeaderMultiStrategy(AdminUserApi adminUserApi, DeptApi deptApi) { |
| 36 | + super(adminUserApi, deptApi); | ||
| 40 | } | 37 | } |
| 41 | 38 | ||
| 42 | @Override | 39 | @Override |
| @@ -60,7 +57,9 @@ public class BpmTaskCandidateStartUserDeptLeaderMultiStrategy extends BpmTaskCan | @@ -60,7 +57,9 @@ public class BpmTaskCandidateStartUserDeptLeaderMultiStrategy extends BpmTaskCan | ||
| 60 | if (dept == null) { | 57 | if (dept == null) { |
| 61 | return new HashSet<>(); | 58 | return new HashSet<>(); |
| 62 | } | 59 | } |
| 63 | - return getMultiLevelDeptLeaderIds(toList(dept.getId()), Integer.valueOf(param)); // 参数是部门的层级 | 60 | + Set<Long> users = getMultiLevelDeptLeaderIds(toList(dept.getId()), Integer.valueOf(param)); // 参数是部门的层级 |
| 61 | + removeDisableUsers(users); | ||
| 62 | + return users; | ||
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | @Override | 65 | @Override |
| @@ -69,7 +68,9 @@ public class BpmTaskCandidateStartUserDeptLeaderMultiStrategy extends BpmTaskCan | @@ -69,7 +68,9 @@ public class BpmTaskCandidateStartUserDeptLeaderMultiStrategy extends BpmTaskCan | ||
| 69 | if (dept == null) { | 68 | if (dept == null) { |
| 70 | return new HashSet<>(); | 69 | return new HashSet<>(); |
| 71 | } | 70 | } |
| 72 | - return getMultiLevelDeptLeaderIds(toList(dept.getId()), Integer.valueOf(param)); // 参数是部门的层级 | 71 | + Set<Long> users = getMultiLevelDeptLeaderIds(toList(dept.getId()), Integer.valueOf(param)); // 参数是部门的层级 |
| 72 | + removeDisableUsers(users); | ||
| 73 | + return users; | ||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | /** | 76 | /** |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateStartUserDeptLeaderStrategy.java
| @@ -32,16 +32,13 @@ public class BpmTaskCandidateStartUserDeptLeaderStrategy extends BpmTaskCandidat | @@ -32,16 +32,13 @@ public class BpmTaskCandidateStartUserDeptLeaderStrategy extends BpmTaskCandidat | ||
| 32 | @Lazy // 避免循环依赖 | 32 | @Lazy // 避免循环依赖 |
| 33 | private BpmProcessInstanceService processInstanceService; | 33 | private BpmProcessInstanceService processInstanceService; |
| 34 | 34 | ||
| 35 | - @Resource | ||
| 36 | - private AdminUserApi adminUserApi; | ||
| 37 | - | ||
| 38 | @Override | 35 | @Override |
| 39 | public BpmTaskCandidateStrategyEnum getStrategy() { | 36 | public BpmTaskCandidateStrategyEnum getStrategy() { |
| 40 | return BpmTaskCandidateStrategyEnum.START_USER_DEPT_LEADER; | 37 | return BpmTaskCandidateStrategyEnum.START_USER_DEPT_LEADER; |
| 41 | } | 38 | } |
| 42 | 39 | ||
| 43 | - public BpmTaskCandidateStartUserDeptLeaderStrategy(DeptApi deptApi) { | ||
| 44 | - super(deptApi); | 40 | + public BpmTaskCandidateStartUserDeptLeaderStrategy(AdminUserApi adminUserApi, DeptApi deptApi) { |
| 41 | + super(adminUserApi, deptApi); | ||
| 45 | } | 42 | } |
| 46 | 43 | ||
| 47 | @Override | 44 | @Override |
| @@ -56,13 +53,17 @@ public class BpmTaskCandidateStartUserDeptLeaderStrategy extends BpmTaskCandidat | @@ -56,13 +53,17 @@ public class BpmTaskCandidateStartUserDeptLeaderStrategy extends BpmTaskCandidat | ||
| 56 | ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId()); | 53 | ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId()); |
| 57 | Long startUserId = NumberUtils.parseLong(processInstance.getStartUserId()); | 54 | Long startUserId = NumberUtils.parseLong(processInstance.getStartUserId()); |
| 58 | // 获取发起人的部门负责人 | 55 | // 获取发起人的部门负责人 |
| 59 | - return getStartUserDeptLeader(startUserId, param); | 56 | + Set<Long> users = getStartUserDeptLeader(startUserId, param); |
| 57 | + removeDisableUsers(users); | ||
| 58 | + return users; | ||
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | @Override | 61 | @Override |
| 63 | public Set<Long> calculateUsers(Long startUserId, ProcessInstance processInstance, String activityId, String param) { | 62 | public Set<Long> calculateUsers(Long startUserId, ProcessInstance processInstance, String activityId, String param) { |
| 64 | // 获取发起人的部门负责人 | 63 | // 获取发起人的部门负责人 |
| 65 | - return getStartUserDeptLeader(startUserId, param); | 64 | + Set<Long> users = getStartUserDeptLeader(startUserId, param); |
| 65 | + removeDisableUsers(users); | ||
| 66 | + return users; | ||
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | private Set<Long> getStartUserDeptLeader(Long startUserId, String param) { | 69 | private Set<Long> getStartUserDeptLeader(Long startUserId, String param) { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateStartUserSelectStrategy.java
| @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy; | @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 5 | -import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; | ||
| 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 7 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; | 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; |
| 8 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; | 7 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; |
| 9 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; | 8 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; |
| 9 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 10 | import jakarta.annotation.Resource; | 10 | import jakarta.annotation.Resource; |
| 11 | import org.flowable.bpmn.model.BpmnModel; | 11 | import org.flowable.bpmn.model.BpmnModel; |
| 12 | import org.flowable.bpmn.model.UserTask; | 12 | import org.flowable.bpmn.model.UserTask; |
| @@ -23,12 +23,16 @@ import java.util.*; | @@ -23,12 +23,16 @@ import java.util.*; | ||
| 23 | * @author 芋道源码 | 23 | * @author 芋道源码 |
| 24 | */ | 24 | */ |
| 25 | @Component | 25 | @Component |
| 26 | -public class BpmTaskCandidateStartUserSelectStrategy implements BpmTaskCandidateStrategy { | 26 | +public class BpmTaskCandidateStartUserSelectStrategy extends BpmTaskCandidateAbstractStrategy { |
| 27 | 27 | ||
| 28 | @Resource | 28 | @Resource |
| 29 | @Lazy // 延迟加载,避免循环依赖 | 29 | @Lazy // 延迟加载,避免循环依赖 |
| 30 | private BpmProcessInstanceService processInstanceService; | 30 | private BpmProcessInstanceService processInstanceService; |
| 31 | 31 | ||
| 32 | + public BpmTaskCandidateStartUserSelectStrategy(AdminUserApi adminUserApi) { | ||
| 33 | + super(adminUserApi); | ||
| 34 | + } | ||
| 35 | + | ||
| 32 | @Override | 36 | @Override |
| 33 | public BpmTaskCandidateStrategyEnum getStrategy() { | 37 | public BpmTaskCandidateStrategyEnum getStrategy() { |
| 34 | return BpmTaskCandidateStrategyEnum.START_USER_SELECT; | 38 | return BpmTaskCandidateStrategyEnum.START_USER_SELECT; |
| @@ -46,7 +50,9 @@ public class BpmTaskCandidateStartUserSelectStrategy implements BpmTaskCandidate | @@ -46,7 +50,9 @@ public class BpmTaskCandidateStartUserSelectStrategy implements BpmTaskCandidate | ||
| 46 | execution.getProcessInstanceId()); | 50 | execution.getProcessInstanceId()); |
| 47 | // 获得审批人 | 51 | // 获得审批人 |
| 48 | List<Long> assignees = startUserSelectAssignees.get(execution.getCurrentActivityId()); | 52 | List<Long> assignees = startUserSelectAssignees.get(execution.getCurrentActivityId()); |
| 49 | - return new LinkedHashSet<>(assignees); | 53 | + Set<Long> users = new LinkedHashSet<>(assignees); |
| 54 | + removeDisableUsers(users); | ||
| 55 | + return users; | ||
| 50 | } | 56 | } |
| 51 | 57 | ||
| 52 | @Override | 58 | @Override |
| @@ -58,7 +64,9 @@ public class BpmTaskCandidateStartUserSelectStrategy implements BpmTaskCandidate | @@ -58,7 +64,9 @@ public class BpmTaskCandidateStartUserSelectStrategy implements BpmTaskCandidate | ||
| 58 | Assert.notNull(startUserSelectAssignees, "流程实例({}) 的发起人自选审批人不能为空", processInstance.getId()); | 64 | Assert.notNull(startUserSelectAssignees, "流程实例({}) 的发起人自选审批人不能为空", processInstance.getId()); |
| 59 | // 获得审批人 | 65 | // 获得审批人 |
| 60 | List<Long> assignees = startUserSelectAssignees.get(activityId); | 66 | List<Long> assignees = startUserSelectAssignees.get(activityId); |
| 61 | - return new LinkedHashSet<>(assignees); | 67 | + Set<Long> users = new LinkedHashSet<>(assignees); |
| 68 | + removeDisableUsers(users); | ||
| 69 | + return users; | ||
| 62 | } | 70 | } |
| 63 | 71 | ||
| 64 | @Override | 72 | @Override |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateStartUserStrategy.java
| 1 | package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy; | 1 | package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; | 3 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; |
| 4 | -import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; | ||
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 4 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 6 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; | 5 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; |
| 6 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 7 | import jakarta.annotation.Resource; | 7 | import jakarta.annotation.Resource; |
| 8 | import org.flowable.engine.delegate.DelegateExecution; | 8 | import org.flowable.engine.delegate.DelegateExecution; |
| 9 | import org.flowable.engine.runtime.ProcessInstance; | 9 | import org.flowable.engine.runtime.ProcessInstance; |
| @@ -20,12 +20,16 @@ import java.util.Set; | @@ -20,12 +20,16 @@ import java.util.Set; | ||
| 20 | * @author jason | 20 | * @author jason |
| 21 | */ | 21 | */ |
| 22 | @Component | 22 | @Component |
| 23 | -public class BpmTaskCandidateStartUserStrategy implements BpmTaskCandidateStrategy { | 23 | +public class BpmTaskCandidateStartUserStrategy extends BpmTaskCandidateAbstractStrategy { |
| 24 | 24 | ||
| 25 | @Resource | 25 | @Resource |
| 26 | @Lazy // 延迟加载,避免循环依赖 | 26 | @Lazy // 延迟加载,避免循环依赖 |
| 27 | private BpmProcessInstanceService processInstanceService; | 27 | private BpmProcessInstanceService processInstanceService; |
| 28 | 28 | ||
| 29 | + public BpmTaskCandidateStartUserStrategy(AdminUserApi adminUserApi) { | ||
| 30 | + super(adminUserApi); | ||
| 31 | + } | ||
| 32 | + | ||
| 29 | @Override | 33 | @Override |
| 30 | public BpmTaskCandidateStrategyEnum getStrategy() { | 34 | public BpmTaskCandidateStrategyEnum getStrategy() { |
| 31 | return BpmTaskCandidateStrategyEnum.START_USER; | 35 | return BpmTaskCandidateStrategyEnum.START_USER; |
| @@ -43,12 +47,16 @@ public class BpmTaskCandidateStartUserStrategy implements BpmTaskCandidateStrate | @@ -43,12 +47,16 @@ public class BpmTaskCandidateStartUserStrategy implements BpmTaskCandidateStrate | ||
| 43 | @Override | 47 | @Override |
| 44 | public Set<Long> calculateUsers(DelegateExecution execution, String param) { | 48 | public Set<Long> calculateUsers(DelegateExecution execution, String param) { |
| 45 | ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId()); | 49 | ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId()); |
| 46 | - return SetUtils.asSet(Long.valueOf(processInstance.getStartUserId())); | 50 | + Set<Long> users = SetUtils.asSet(Long.valueOf(processInstance.getStartUserId())); |
| 51 | + removeDisableUsers(users); | ||
| 52 | + return users; | ||
| 47 | } | 53 | } |
| 48 | 54 | ||
| 49 | @Override | 55 | @Override |
| 50 | public Set<Long> calculateUsers(Long startUserId, ProcessInstance processInstance, String activityId, String param) { | 56 | public Set<Long> calculateUsers(Long startUserId, ProcessInstance processInstance, String activityId, String param) { |
| 51 | - return SetUtils.asSet(startUserId); | 57 | + Set<Long> users = SetUtils.asSet(startUserId); |
| 58 | + removeDisableUsers(users); | ||
| 59 | + return users; | ||
| 52 | } | 60 | } |
| 53 | 61 | ||
| 54 | } | 62 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateUserStrategy.java
| @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; | @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; | ||
| 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; | 5 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; |
| 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; | 6 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; |
| 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 8 | -import jakarta.annotation.Resource; | ||
| 9 | import org.springframework.stereotype.Component; | 8 | import org.springframework.stereotype.Component; |
| 10 | 9 | ||
| 11 | import java.util.LinkedHashSet; | 10 | import java.util.LinkedHashSet; |
| @@ -17,10 +16,11 @@ import java.util.Set; | @@ -17,10 +16,11 @@ import java.util.Set; | ||
| 17 | * @author kyle | 16 | * @author kyle |
| 18 | */ | 17 | */ |
| 19 | @Component | 18 | @Component |
| 20 | -public class BpmTaskCandidateUserStrategy implements BpmTaskCandidateStrategy { | 19 | +public class BpmTaskCandidateUserStrategy extends BpmTaskCandidateAbstractStrategy { |
| 21 | 20 | ||
| 22 | - @Resource | ||
| 23 | - private AdminUserApi adminUserApi; | 21 | + public BpmTaskCandidateUserStrategy(AdminUserApi adminUserApi) { |
| 22 | + super(adminUserApi); | ||
| 23 | + } | ||
| 24 | 24 | ||
| 25 | @Override | 25 | @Override |
| 26 | public BpmTaskCandidateStrategyEnum getStrategy() { | 26 | public BpmTaskCandidateStrategyEnum getStrategy() { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| 1 | -package cn.iocoder.yudao.module.bpm.service.task; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.PageUtils; import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ApprovalTaskInfo; import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert; import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.BpmTaskCandidateStartUserSelectStrategy; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants; import cn.iocoder.yudao.module.bpm.framework.flowable.core.event.BpmProcessInstanceEventPublisher; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils; import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService; import cn.iocoder.yudao.module.bpm.service.task.bo.AlreadyRunApproveNodeRespBO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import jakarta.annotation.Resource; import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.flowable.bpmn.model.BpmnModel; import org.flowable.bpmn.model.UserTask; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.api.variable.VariableContainer; import org.flowable.engine.HistoryService; import org.flowable.engine.ManagementService; import org.flowable.engine.RuntimeService; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.history.HistoricProcessInstanceQuery; import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.runtime.ProcessInstance; import org.flowable.task.api.history.HistoricTaskInstance; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import java.util.*; import java.util.stream.Stream; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ApprovalNodeInfo; import static cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.User; import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType.*; import static cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskApproveTypeEnum.USER; import static cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum.*; import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum.START_USER; import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID; /** * 流程实例 Service 实现类 * <p> * ProcessDefinition & ProcessInstance & Execution & Task 的关系: * 1. <a href="https://blog.csdn.net/bobozai86/article/details/105210414" /> * <p> * HistoricProcessInstance & ProcessInstance 的关系: * 1. <a href=" https://my.oschina.net/843294669/blog/71902" /> * <p> * 简单来说,前者 = 历史 + 运行中的流程实例,后者仅是运行中的流程实例 * * @author 芋道源码 */ @Service @Validated @Slf4j public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService { @Resource private RuntimeService runtimeService; @Resource private HistoryService historyService; @Resource private ManagementService managementService; @Resource private BpmActivityService activityService; @Resource private BpmProcessDefinitionService processDefinitionService; @Resource @Lazy // 避免循环依赖 private BpmTaskService taskService; @Resource private BpmMessageService messageService; @Resource private BpmTaskCandidateInvoker bpmTaskCandidateInvoker; @Resource private AdminUserApi adminUserApi; @Resource private BpmProcessInstanceEventPublisher processInstanceEventPublisher; // ========== Query 查询相关方法 ========== @Override public ProcessInstance getProcessInstance(String id) { return runtimeService.createProcessInstanceQuery() .includeProcessVariables() .processInstanceId(id) .singleResult(); } @Override public List<ProcessInstance> getProcessInstances(Set<String> ids) { return runtimeService.createProcessInstanceQuery().processInstanceIds(ids).list(); } @Override public HistoricProcessInstance getHistoricProcessInstance(String id) { return historyService.createHistoricProcessInstanceQuery().processInstanceId(id).includeProcessVariables().singleResult(); } @Override public List<HistoricProcessInstance> getHistoricProcessInstances(Set<String> ids) { return historyService.createHistoricProcessInstanceQuery().processInstanceIds(ids).list(); } @Override public PageResult<HistoricProcessInstance> getProcessInstancePage(Long userId, BpmProcessInstancePageReqVO pageReqVO) { // 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页 HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery() .includeProcessVariables() .processInstanceTenantId(FlowableUtils.getTenantId()) .orderByProcessInstanceStartTime().desc(); if (userId != null) { // 【我的流程】菜单时,需要传递该字段 processInstanceQuery.startedBy(String.valueOf(userId)); } else if (pageReqVO.getStartUserId() != null) { // 【管理流程】菜单时,才会传递该字段 processInstanceQuery.startedBy(String.valueOf(pageReqVO.getStartUserId())); } if (StrUtil.isNotEmpty(pageReqVO.getName())) { processInstanceQuery.processInstanceNameLike("%" + pageReqVO.getName() + "%"); } if (StrUtil.isNotEmpty(pageReqVO.getProcessDefinitionId())) { processInstanceQuery.processDefinitionId("%" + pageReqVO.getProcessDefinitionId() + "%"); } if (StrUtil.isNotEmpty(pageReqVO.getCategory())) { processInstanceQuery.processDefinitionCategory(pageReqVO.getCategory()); } if (pageReqVO.getStatus() != null) { processInstanceQuery.variableValueEquals(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, pageReqVO.getStatus()); } if (ArrayUtil.isNotEmpty(pageReqVO.getCreateTime())) { processInstanceQuery.startedAfter(DateUtils.of(pageReqVO.getCreateTime()[0])); processInstanceQuery.startedBefore(DateUtils.of(pageReqVO.getCreateTime()[1])); } // 查询数量 long processInstanceCount = processInstanceQuery.count(); if (processInstanceCount == 0) { return PageResult.empty(processInstanceCount); } // 查询列表 List<HistoricProcessInstance> processInstanceList = processInstanceQuery.listPage(PageUtils.getStart(pageReqVO), pageReqVO.getPageSize()); return new PageResult<>(processInstanceList, processInstanceCount); } @Override public Map<String, String> getFormFieldsPermission(BpmFormFieldsPermissionReqVO reqVO) { // 1.1 获取流程定义 Id String processDefinitionId = reqVO.getProcessDefinitionId(); if (StrUtil.isEmpty(processDefinitionId) && StrUtil.isNotEmpty(reqVO.getProcessInstanceId())) { HistoricProcessInstance processInstance = getHistoricProcessInstance(reqVO.getProcessInstanceId()); if (processInstance == null) { throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS); } processDefinitionId = processInstance.getProcessDefinitionId(); } // 1.2 获取流程活动编号 String activityId = reqVO.getActivityId(); if (StrUtil.isEmpty(activityId) && StrUtil.isNotEmpty(reqVO.getTaskId())) { // 流程活动 Id 为空。从流程任务中获取流程活动 Id activityId = Optional.ofNullable(taskService.getHistoricTask(reqVO.getTaskId())) .map(HistoricTaskInstance::getTaskDefinitionKey).orElse(null); } if (StrUtil.isEmpty(activityId)) { return null; } // 2. 从 BpmnModel 中解析表单字段权限 return BpmnModelUtils.parseFormFieldsPermission( processDefinitionService.getProcessDefinitionBpmnModel(processDefinitionId), activityId); } @Override public BpmApprovalDetailRespVO getApprovalDetail(Long loginUserId, BpmApprovalDetailReqVO reqVO) { // 1. 创建审批详情 BpmApprovalDetailRespVO respVO = new BpmApprovalDetailRespVO(); String processDefinitionId = reqVO.getProcessDefinitionId(); ProcessInstance runProcessInstance = null; // 正在运行的流程实例 Set<String> runNodeIds = new HashSet<>(); // 已经运行的节点 Ids (BPMN XML 节点 Id) Map<String, ApprovalNodeInfo> runningApprovalNodes = new HashMap<>(); // 正在运行的节点的审批信息 Long startUserId = loginUserId; // 审批节点信息 List<ApprovalNodeInfo> approvalNodes = new ArrayList<>(); // 2. 流程未发起 if (reqVO.getProcessInstanceId() == null) { respVO.setStatus(BpmProcessInstanceStatusEnum.NOT_START.getStatus()); // 3. 流程已发起 } else { // 3.1 获取流程实例信息 HistoricProcessInstance processInstance = getHistoricProcessInstance(reqVO.getProcessInstanceId()); if (processInstance == null) { throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS); } // 3.2 获取流程实例状态 Integer processInstanceStatus = FlowableUtils.getProcessInstanceStatus(processInstance); respVO.setStatus(processInstanceStatus); // 3.3 构建已运行节点的审批信息 List<HistoricActivityInstance> historicActivityList = activityService.getActivityListByProcessInstanceId(processInstance.getId()); AlreadyRunApproveNodeRespBO respBO = buildAlreadyRunApproveNodes(processInstance.getId(), historicActivityList); approvalNodes = respBO.getApproveNodes(); runNodeIds = respBO.getRunNodeIds(); // 3.4. 流程已经结束 if (BpmProcessInstanceStatusEnum.isProcessEndStatus(processInstanceStatus)) { respVO.setApproveNodes(approvalNodes); return respVO; } runningApprovalNodes = respBO.getRunningApprovalNodes(); processDefinitionId = processInstance.getProcessDefinitionId(); runProcessInstance = getProcessInstance(processInstance.getId()); startUserId = Long.valueOf(runProcessInstance.getStartUserId()); } // 4. 流程未结束,预测未运行节点的审批信息。需要区分 BPMN 设计器 和 SIMPLE 设计器 BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService.getProcessDefinitionInfo(processDefinitionId); // 4.1 仿钉钉流程设计器 if (Objects.equals(BpmModelTypeEnum.SIMPLE.getType(), processDefinitionInfo.getModelType())) { BpmSimpleModelNodeVO simpleModel = JsonUtils.parseObject(processDefinitionInfo.getSimpleModel(), BpmSimpleModelNodeVO.class); List<ApprovalNodeInfo> notRunApproveNodes = new ArrayList<>(); traverseSimpleModelNodeToBuildNotRunApproveNodes( startUserId, runProcessInstance, simpleModel, runNodeIds, runningApprovalNodes, notRunApproveNodes); approvalNodes.addAll(notRunApproveNodes); respVO.setApproveNodes(approvalNodes); // TODO @jason:会不会有极端的情况:对于依次审批来说,它是已经 running,但是当前节点也要计算其它审批人? // 4.2 BPMN 流程设计器 } else if (Objects.equals(BpmModelTypeEnum.BPMN.getType(), processDefinitionInfo.getModelType())) { // TODO Bpmn 设计器,构建未运行节点的审批信息;未完全实现 } return respVO; } /** * 遍历 SIMPLE 设计器模型 构建未运行节点的审批信息 * * @param startUserId 流程发起人编号 * @param processInstance 流程实例 * @param simpleModelNode SIMPLE 设计器模型 * @param runNodeIds 已经运行节点的 Ids * @param runningApprovalNodes 正在运行的节点的审批信息 * @param approveNodeList 未运行节点的审批信息列表 */ private void traverseSimpleModelNodeToBuildNotRunApproveNodes(Long startUserId, ProcessInstance processInstance, BpmSimpleModelNodeVO simpleModelNode, Set<String> runNodeIds, Map<String, ApprovalNodeInfo> runningApprovalNodes, List<ApprovalNodeInfo> approveNodeList) { if (!SimpleModelUtils.isValidNode(simpleModelNode)) { return; } buildNotRunApproveNodes(startUserId, processInstance, simpleModelNode, runNodeIds, runningApprovalNodes, approveNodeList); // 如果有子节点递归遍历子节点 traverseSimpleModelNodeToBuildNotRunApproveNodes( startUserId, processInstance, simpleModelNode.getChildNode(), runNodeIds, runningApprovalNodes, approveNodeList); } private void buildNotRunApproveNodes(Long startUserId, ProcessInstance processInstance, BpmSimpleModelNodeVO node, Set<String> runNodeIds, Map<String, ApprovalNodeInfo> runningApprovalNodes, List<ApprovalNodeInfo> approveNodeList) { if (!runNodeIds.contains(node.getId())) { // 节点未运行。需要进行预测 // 1. 对需要人工审批的审批节点。进行预测 if (APPROVE_NODE.getType().equals(node.getType()) && USER.getType().equals(node.getApproveType()) || START_USER_NODE.getType().equals(node.getType())) { ApprovalNodeInfo approvalNodeInfo = new ApprovalNodeInfo(); approvalNodeInfo.setNodeType(node.getType()); approvalNodeInfo.setName(node.getName()); approvalNodeInfo.setStatus(NOT_START.getStatus()); Integer candidateStrategy = node.getCandidateStrategy(); if (START_USER_NODE.getType().equals(node.getType())) { candidateStrategy = START_USER.getStrategy(); } approvalNodeInfo.setCandidateUserList( getNotRunTaskCandidateUserList(startUserId, processInstance, node.getId(), candidateStrategy, node.getCandidateParam())); approveNodeList.add(approvalNodeInfo); } // 2. 对分支节点进行预测 if (BpmSimpleModelNodeType.isBranchNode(node.getType())) { // 并行分支。不用预测条件。所有分支都需要遍历 if (PARALLEL_BRANCH_NODE.getType().equals(node.getType())) { node.getConditionNodes().forEach(conditionNode -> traverseSimpleModelNodeToBuildNotRunApproveNodes(startUserId, processInstance, conditionNode.getChildNode() , runNodeIds, runningApprovalNodes, approveNodeList) ); } else if (CONDITION_BRANCH_NODE.getType().equals(node.getType())) { for (BpmSimpleModelNodeVO conditionNode : node.getConditionNodes()) { // 满足一个条件, 遍历该分支并 if ((processInstance != null && evalConditionExpress(processInstance, SimpleModelUtils.buildConditionExpression(conditionNode))) // 预测条件表达式的值 || BooleanUtil.isTrue(conditionNode.getDefaultFlow())) { // 是否默认的序列 traverseSimpleModelNodeToBuildNotRunApproveNodes(startUserId, processInstance, conditionNode.getChildNode(), runNodeIds, runningApprovalNodes, approveNodeList); break; } } } // TODO 包容分支待实现 } // 3. 结束节点 if (END_NODE.getType().equals(node.getType())) { ApprovalNodeInfo nodeProgress = new ApprovalNodeInfo(); nodeProgress.setNodeType(node.getType()); nodeProgress.setName(node.getName()); nodeProgress.setStatus(NOT_START.getStatus()); approveNodeList.add(nodeProgress); } } else { // 节点已经运行。如果是分支节点。需要检查分支节点的运行情况 if (BpmSimpleModelNodeType.isBranchNode(node.getType()) && ArrayUtil.isNotEmpty(node.getConditionNodes())) { node.getConditionNodes().forEach(conditionNode -> { // 只有运行的条件,才需要遍历 if (runNodeIds.contains(conditionNode.getId())) { traverseSimpleModelNodeToBuildNotRunApproveNodes(startUserId, processInstance, conditionNode.getChildNode() , runNodeIds, runningApprovalNodes, approveNodeList); } }); } else if (SimpleModelUtils.isSequentialApproveNode(node) && runningApprovalNodes.containsKey(node.getId())) { // 如果是依次审批, 需要加其它未审批候选人 ApprovalNodeInfo approvalNodeInfo = runningApprovalNodes.get(node.getId()); List<User> candidateUserList = getNotRunTaskCandidateUserList( startUserId, processInstance, node.getId(), node.getCandidateStrategy(), node.getCandidateParam()); ApprovalTaskInfo approvalTaskInfo = CollUtil.getFirst(approvalNodeInfo.getTasks()); Long currentAssignedUserId = null; if (approvalTaskInfo != null && approvalTaskInfo.getAssigneeUser() != null) { currentAssignedUserId = approvalTaskInfo.getAssigneeUser().getId(); } // 找到当前审批人在候选人列表的位置 int index = 0; for (User user : candidateUserList) { if(user.getId().equals(currentAssignedUserId)) { break; } index++; } // 截取当前审批人位置后面的候选人, 不包含当前审批人 approvalNodeInfo.setCandidateUserList(CollUtil.sub(candidateUserList, ++index, candidateUserList.size())); } } } /** * 从已经运行活动节点构建的审批信息列表 * * @param processInstanceId 流程实例 Id * @param historicActivityList 已经运行活动 */ private AlreadyRunApproveNodeRespBO buildAlreadyRunApproveNodes(String processInstanceId, List<HistoricActivityInstance> historicActivityList) { // 1.1 获取待处理活动:只有 "userTask" 和 "endEvent" 需要处理 List<HistoricActivityInstance> pendingActivityNodes = filterList(historicActivityList, item -> BpmSimpleModelNodeType.isRecordNode(item.getActivityType())); // 1.2 已运行节点的 activityId Set<String> runNodeIds = convertSet(historicActivityList, HistoricActivityInstance::getActivityId); // 2.1 获取已运行的任务(包括运行中的任务) List<HistoricTaskInstance> taskList = taskService.getTaskListByProcessInstanceId(processInstanceId); Map<String, HistoricTaskInstance> taskMap = convertMap(taskList, HistoricTaskInstance::getId); // 2.2 获取加签的任务 Map<String, List<HistoricTaskInstance>> addSignTaskMap = convertMultiMap( filterList(taskList, task -> StrUtil.isNotEmpty(task.getParentTaskId())), HistoricTaskInstance::getParentTaskId); // 3.1 获取节点的用户信息 Set<Long> userIds = CollectionUtils.convertSetByFlatMap(pendingActivityNodes, activity -> { if (BPMN_USER_TASK_TYPE.equals(activity.getActivityType())) { HistoricTaskInstance task = taskMap.get(activity.getTaskId()); Set<Long> taskUsers = CollUtil.newHashSet(); CollUtil.addIfAbsent(taskUsers, NumberUtil.parseLong(task.getAssignee(), null)); CollUtil.addIfAbsent(taskUsers, NumberUtil.parseLong(task.getOwner(), null)); List<HistoricTaskInstance> addSignTasks = addSignTaskMap.get(activity.getTaskId()); if (CollUtil.isNotEmpty(addSignTasks)) { addSignTasks.forEach(item -> { CollUtil.addIfAbsent(taskUsers, NumberUtil.parseLong(item.getAssignee(), null)); CollUtil.addIfAbsent(taskUsers, NumberUtil.parseLong(item.getOwner(), null)); }); } return taskUsers.stream(); } else { return Stream.empty(); } }); Map<Long, AdminUserRespDTO> userMap = convertMap(adminUserApi.getUserList(userIds), AdminUserRespDTO::getId); // 3.2 已经结束的任务转换为审批信息。 final Multimap<String, HistoricActivityInstance> runningTask = ArrayListMultimap.create(); // 运行中的任务 List<ApprovalNodeInfo> approvalNodeList = CollectionUtils.convertList(pendingActivityNodes, activity -> { ApprovalNodeInfo approvalNodeInfo = new ApprovalNodeInfo().setId(activity.getId()).setName(activity.getActivityName()) .setStartTime(DateUtils.of(activity.getStartTime())).setEndTime(DateUtils.of(activity.getEndTime())); if (BPMN_USER_TASK_TYPE.equals(activity.getActivityType())) { // 用户任务 // nodeType approvalNodeInfo.setNodeType(START_USER_NODE_ID.equals(activity.getActivityId()) ? START_USER_NODE.getType() : APPROVE_NODE.getType()); // status HistoricTaskInstance task = taskMap.get(activity.getTaskId()); Integer taskStatus = FlowableUtils.getTaskStatus(task); // 运行中的任务, 会签,或签任务聚合在一起。 if (!BpmTaskStatusEnum.isEndStatus(taskStatus)) { runningTask.put(activity.getActivityId(), activity); return null; } // tasks ApprovalTaskInfo approveTask = convertApproveTaskInfo(task, userMap); List<ApprovalTaskInfo> approveTasks = CollUtil.newArrayList(approveTask); List<HistoricTaskInstance> addSignTasks = addSignTaskMap.get(activity.getTaskId()); if (CollUtil.isNotEmpty(addSignTasks)) { // 处理加签任务 approveTasks.addAll(CollectionUtils.convertList(addSignTasks, item -> convertApproveTaskInfo(item, userMap))); } approvalNodeInfo.setStatus(taskStatus); approvalNodeInfo.setTasks(approveTasks); } else if (END_NODE.getBpmnType().equals(activity.getActivityType())) { approvalNodeInfo.setNodeType(END_NODE.getType()); approvalNodeInfo.setStatus(APPROVE.getStatus()); } return approvalNodeInfo; }); // 3.3 运行中的任务转换为审批信息。 final Map<String, ApprovalNodeInfo> runningApprovalNodes = new HashMap<>(); // 正在运行节点的审批信息 runningTask.asMap().forEach((activityId, activities) -> { if (CollUtil.isNotEmpty(activities)) { ApprovalNodeInfo approvalNodeInfo = new ApprovalNodeInfo(); approvalNodeInfo.setNodeType(APPROVE_NODE.getType()); approvalNodeInfo.setStatus(RUNNING.getStatus()); List<ApprovalTaskInfo> approveTasks = CollUtil.newArrayList(); int i = 0; for (HistoricActivityInstance activity : activities) { HistoricTaskInstance task = taskMap.get(activity.getTaskId()); // 取第一个任务, 会签/或签的任务。开始时间相同的 if (i == 0) { approvalNodeInfo.setId(activity.getId()).setName(activity.getActivityName()). setStartTime(DateUtils.of(activity.getStartTime())); } // tasks ApprovalTaskInfo approveTask = convertApproveTaskInfo(task, userMap); approveTasks.add(approveTask); List<HistoricTaskInstance> addSignTasks = addSignTaskMap.get(activity.getTaskId()); if (CollUtil.isNotEmpty(addSignTasks)) { // 处理加签任务 approveTasks.addAll(CollectionUtils.convertList(addSignTasks, item -> convertApproveTaskInfo(item, userMap))); } i++; } approvalNodeInfo.setTasks(approveTasks); approvalNodeList.add(approvalNodeInfo); runningApprovalNodes.put(activityId, approvalNodeInfo); } }); return new AlreadyRunApproveNodeRespBO().setApproveNodes(approvalNodeList).setRunNodeIds(runNodeIds) .setRunningApprovalNodes(runningApprovalNodes); } private ApprovalTaskInfo convertApproveTaskInfo(HistoricTaskInstance task, Map<Long, AdminUserRespDTO> userMap) { if (task == null) { return null; } ApprovalTaskInfo approveTask = BeanUtils.toBean(task, ApprovalTaskInfo.class); approveTask.setStatus(FlowableUtils.getTaskStatus(task)).setReason(FlowableUtils.getTaskReason(task)); Long taskAssignee = NumberUtil.parseLong(task.getAssignee(), null); if (taskAssignee != null) { approveTask.setAssigneeUser(BeanUtils.toBean(userMap.get(taskAssignee), User.class)); } Long taskOwner = NumberUtil.parseLong(task.getOwner(), null); if (taskOwner != null) { approveTask.setOwnerUser(BeanUtils.toBean(userMap.get(taskOwner), User.class)); } return approveTask; } private List<User> getNotRunTaskCandidateUserList(Long startUserId, ProcessInstance processInstance, String activityId, Integer candidateStrategy, String candidateParam) { BpmTaskCandidateStrategy taskCandidateStrategy = bpmTaskCandidateInvoker.getCandidateStrategy(candidateStrategy); Set<Long> userIds = taskCandidateStrategy.calculateUsers(startUserId, processInstance, activityId, candidateParam); Map<Long, AdminUserRespDTO> adminUserMap = convertMap(adminUserApi.getUserList(userIds),AdminUserRespDTO::getId); // 需要按照候选人的顺序返回。依次审批需要按顺序展示用户 List<User> orderUserList = new ArrayList<>(); userIds.forEach(userId-> { orderUserList.add(BeanUtils.toBean(adminUserMap.get(userId), User.class)); }); return orderUserList; } /** * 计算条件表达式的值 * * @param processInstance 流程实例 * @param express 条件表达式 */ private Boolean evalConditionExpress(ProcessInstance processInstance, String express) { if (express == null) { return Boolean.FALSE; } Object result = managementService.executeCommand(context -> { try { return FlowableUtils.getExpressionValue((VariableContainer) processInstance, express); } catch (FlowableException ex) { log.error("[evalConditionExpress][条件表达式({}) 解析报错", express, ex); return Boolean.FALSE; } }); return Boolean.TRUE.equals(result); } // ========== Update 写入相关方法 ========== @Override @Transactional(rollbackFor = Exception.class) public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO) { // 获得流程定义 ProcessDefinition definition = processDefinitionService.getProcessDefinition(createReqVO.getProcessDefinitionId()); // 发起流程 return createProcessInstance0(userId, definition, createReqVO.getVariables(), null, createReqVO.getStartUserSelectAssignees()); } @Override public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) { // 获得流程定义 ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey()); // 发起流程 return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey(), createReqDTO.getStartUserSelectAssignees()); } private String createProcessInstance0(Long userId, ProcessDefinition definition, Map<String, Object> variables, String businessKey, Map<String, List<Long>> startUserSelectAssignees) { // 1.1 校验流程定义 if (definition == null) { throw exception(PROCESS_DEFINITION_NOT_EXISTS); } if (definition.isSuspended()) { throw exception(PROCESS_DEFINITION_IS_SUSPENDED); } // 1.2 校验发起人自选审批人 validateStartUserSelectAssignees(definition, startUserSelectAssignees); // 2. 创建流程实例 if (variables == null) { variables = new HashMap<>(); } FlowableUtils.filterProcessInstanceFormVariable(variables); // 过滤一下,避免 ProcessInstance 系统级的变量被占用 variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, // 流程实例状态:审批中 BpmProcessInstanceStatusEnum.RUNNING.getStatus()); if (CollUtil.isNotEmpty(startUserSelectAssignees)) { variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees); } ProcessInstance instance = runtimeService.createProcessInstanceBuilder() .processDefinitionId(definition.getId()) .businessKey(businessKey) .name(definition.getName().trim()) .variables(variables) .start(); return instance.getId(); } private void validateStartUserSelectAssignees(ProcessDefinition definition, Map<String, List<Long>> startUserSelectAssignees) { // 1. 获得发起人自选审批人的 UserTask 列表 BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(definition.getId()); List<UserTask> userTaskList = BpmTaskCandidateStartUserSelectStrategy.getStartUserSelectUserTaskList(bpmnModel); if (CollUtil.isEmpty(userTaskList)) { return; } // 2. 校验发起人自选审批人的 UserTask 是否都配置了 userTaskList.forEach(userTask -> { List<Long> assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(userTask.getId()) : null; if (CollUtil.isEmpty(assignees)) { throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, userTask.getName()); } Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(assignees); assignees.forEach(assignee -> { if (userMap.get(assignee) == null) { throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_EXISTS, userTask.getName(), assignee); } }); }); } @Override public void cancelProcessInstanceByStartUser(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO) { // 1.1 校验流程实例存在 ProcessInstance instance = getProcessInstance(cancelReqVO.getId()); if (instance == null) { throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS); } // 1.2 只能取消自己的 if (!Objects.equals(instance.getStartUserId(), String.valueOf(userId))) { throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF); } // 2. 取消流程 updateProcessInstanceCancel(cancelReqVO.getId(), BpmReasonEnum.CANCEL_PROCESS_INSTANCE_BY_START_USER.format(cancelReqVO.getReason())); } @Override public void cancelProcessInstanceByAdmin(Long userId, BpmProcessInstanceCancelReqVO cancelReqVO) { // 1.1 校验流程实例存在 ProcessInstance instance = getProcessInstance(cancelReqVO.getId()); if (instance == null) { throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS); } // 2. 取消流程 AdminUserRespDTO user = adminUserApi.getUser(userId); updateProcessInstanceCancel(cancelReqVO.getId(), BpmReasonEnum.CANCEL_PROCESS_INSTANCE_BY_ADMIN.format(user.getNickname(), cancelReqVO.getReason())); } private void updateProcessInstanceCancel(String id, String reason) { // 1. 更新流程实例 status runtimeService.setVariable(id, BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, BpmProcessInstanceStatusEnum.CANCEL.getStatus()); runtimeService.setVariable(id, BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_REASON, reason); // 2. 结束流程 taskService.moveTaskToEnd(id); } @Override public void updateProcessInstanceReject(ProcessInstance processInstance, String reason) { runtimeService.setVariable(processInstance.getProcessInstanceId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, BpmProcessInstanceStatusEnum.REJECT.getStatus()); runtimeService.setVariable(processInstance.getProcessInstanceId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_REASON, BpmReasonEnum.REJECT_TASK.format(reason)); } // ========== Event 事件相关方法 ========== @Override public void processProcessInstanceCompleted(ProcessInstance instance) { // 注意:需要基于 instance 设置租户编号,避免 Flowable 内部异步时,丢失租户编号 FlowableUtils.execute(instance.getTenantId(), () -> { // 1.1 获取当前状态 Integer status = (Integer) instance.getProcessVariables().get(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS); String reason = (String) instance.getProcessVariables().get(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_REASON); // 1.2 当流程状态还是审批状态中,说明审批通过了,则变更下它的状态 // 为什么这么处理?因为流程完成,并且完成了,说明审批通过了 if (Objects.equals(status, BpmProcessInstanceStatusEnum.RUNNING.getStatus())) { status = BpmProcessInstanceStatusEnum.APPROVE.getStatus(); runtimeService.setVariable(instance.getId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, status); } // 2. 发送对应的消息通知 if (Objects.equals(status, BpmProcessInstanceStatusEnum.APPROVE.getStatus())) { messageService.sendMessageWhenProcessInstanceApprove(BpmProcessInstanceConvert.INSTANCE.buildProcessInstanceApproveMessage(instance)); } else if (Objects.equals(status, BpmProcessInstanceStatusEnum.REJECT.getStatus())) { messageService.sendMessageWhenProcessInstanceReject( BpmProcessInstanceConvert.INSTANCE.buildProcessInstanceRejectMessage(instance, reason)); } // 3. 发送流程实例的状态事件 processInstanceEventPublisher.sendProcessInstanceResultEvent( BpmProcessInstanceConvert.INSTANCE.buildProcessInstanceStatusEvent(this, instance, status)); }); } } | ||
| 2 | \ No newline at end of file | 1 | \ No newline at end of file |
| 2 | +package cn.iocoder.yudao.module.bpm.service.task; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.PageUtils; import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ApprovalTaskInfo; import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert; import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.BpmTaskCandidateStartUserSelectStrategy; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants; import cn.iocoder.yudao.module.bpm.framework.flowable.core.event.BpmProcessInstanceEventPublisher; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils; import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService; import cn.iocoder.yudao.module.bpm.service.task.bo.AlreadyRunApproveNodeRespBO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import jakarta.annotation.Resource; import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.flowable.bpmn.model.BpmnModel; import org.flowable.bpmn.model.UserTask; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.api.variable.VariableContainer; import org.flowable.engine.HistoryService; import org.flowable.engine.ManagementService; import org.flowable.engine.RuntimeService; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.history.HistoricProcessInstanceQuery; import org.flowable.engine.repository.ProcessDefinition; import org.flowable.engine.runtime.ProcessInstance; import org.flowable.task.api.history.HistoricTaskInstance; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import java.util.*; import java.util.stream.Stream; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ApprovalNodeInfo; import static cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.User; import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType.*; import static cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskApproveTypeEnum.USER; import static cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum.*; import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum.START_USER; import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID; /** * 流程实例 Service 实现类 * <p> * ProcessDefinition & ProcessInstance & Execution & Task 的关系: * 1. <a href="https://blog.csdn.net/bobozai86/article/details/105210414" /> * <p> * HistoricProcessInstance & ProcessInstance 的关系: * 1. <a href=" https://my.oschina.net/843294669/blog/71902" /> * <p> * 简单来说,前者 = 历史 + 运行中的流程实例,后者仅是运行中的流程实例 * * @author 芋道源码 */ @Service @Validated @Slf4j public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService { @Resource private RuntimeService runtimeService; @Resource private HistoryService historyService; @Resource private ManagementService managementService; @Resource private BpmActivityService activityService; @Resource private BpmProcessDefinitionService processDefinitionService; @Resource @Lazy // 避免循环依赖 private BpmTaskService taskService; @Resource private BpmMessageService messageService; @Resource private BpmTaskCandidateInvoker bpmTaskCandidateInvoker; @Resource private AdminUserApi adminUserApi; @Resource private BpmProcessInstanceEventPublisher processInstanceEventPublisher; // ========== Query 查询相关方法 ========== @Override public ProcessInstance getProcessInstance(String id) { return runtimeService.createProcessInstanceQuery() .includeProcessVariables() .processInstanceId(id) .singleResult(); } @Override public List<ProcessInstance> getProcessInstances(Set<String> ids) { return runtimeService.createProcessInstanceQuery().processInstanceIds(ids).list(); } @Override public HistoricProcessInstance getHistoricProcessInstance(String id) { return historyService.createHistoricProcessInstanceQuery().processInstanceId(id).includeProcessVariables().singleResult(); } @Override public List<HistoricProcessInstance> getHistoricProcessInstances(Set<String> ids) { return historyService.createHistoricProcessInstanceQuery().processInstanceIds(ids).list(); } @Override public PageResult<HistoricProcessInstance> getProcessInstancePage(Long userId, BpmProcessInstancePageReqVO pageReqVO) { // 通过 BpmProcessInstanceExtDO 表,先查询到对应的分页 HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery() .includeProcessVariables() .processInstanceTenantId(FlowableUtils.getTenantId()) .orderByProcessInstanceStartTime().desc(); if (userId != null) { // 【我的流程】菜单时,需要传递该字段 processInstanceQuery.startedBy(String.valueOf(userId)); } else if (pageReqVO.getStartUserId() != null) { // 【管理流程】菜单时,才会传递该字段 processInstanceQuery.startedBy(String.valueOf(pageReqVO.getStartUserId())); } if (StrUtil.isNotEmpty(pageReqVO.getName())) { processInstanceQuery.processInstanceNameLike("%" + pageReqVO.getName() + "%"); } if (StrUtil.isNotEmpty(pageReqVO.getProcessDefinitionId())) { processInstanceQuery.processDefinitionId("%" + pageReqVO.getProcessDefinitionId() + "%"); } if (StrUtil.isNotEmpty(pageReqVO.getCategory())) { processInstanceQuery.processDefinitionCategory(pageReqVO.getCategory()); } if (pageReqVO.getStatus() != null) { processInstanceQuery.variableValueEquals(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, pageReqVO.getStatus()); } if (ArrayUtil.isNotEmpty(pageReqVO.getCreateTime())) { processInstanceQuery.startedAfter(DateUtils.of(pageReqVO.getCreateTime()[0])); processInstanceQuery.startedBefore(DateUtils.of(pageReqVO.getCreateTime()[1])); } // 查询数量 long processInstanceCount = processInstanceQuery.count(); if (processInstanceCount == 0) { return PageResult.empty(processInstanceCount); } // 查询列表 List<HistoricProcessInstance> processInstanceList = processInstanceQuery.listPage(PageUtils.getStart(pageReqVO), pageReqVO.getPageSize()); return new PageResult<>(processInstanceList, processInstanceCount); } @Override public Map<String, String> getFormFieldsPermission(BpmFormFieldsPermissionReqVO reqVO) { // 1.1 获取流程定义 Id String processDefinitionId = reqVO.getProcessDefinitionId(); if (StrUtil.isEmpty(processDefinitionId) && StrUtil.isNotEmpty(reqVO.getProcessInstanceId())) { HistoricProcessInstance processInstance = getHistoricProcessInstance(reqVO.getProcessInstanceId()); if (processInstance == null) { throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS); } processDefinitionId = processInstance.getProcessDefinitionId(); } // 1.2 获取流程活动编号 String activityId = reqVO.getActivityId(); if (StrUtil.isEmpty(activityId) && StrUtil.isNotEmpty(reqVO.getTaskId())) { // 流程活动 Id 为空。从流程任务中获取流程活动 Id activityId = Optional.ofNullable(taskService.getHistoricTask(reqVO.getTaskId())) .map(HistoricTaskInstance::getTaskDefinitionKey).orElse(null); } if (StrUtil.isEmpty(activityId)) { return null; } // 2. 从 BpmnModel 中解析表单字段权限 return BpmnModelUtils.parseFormFieldsPermission( processDefinitionService.getProcessDefinitionBpmnModel(processDefinitionId), activityId); } @Override public BpmApprovalDetailRespVO getApprovalDetail(Long loginUserId, BpmApprovalDetailReqVO reqVO) { // 1. 创建审批详情 BpmApprovalDetailRespVO respVO = new BpmApprovalDetailRespVO(); String processDefinitionId = reqVO.getProcessDefinitionId(); ProcessInstance runProcessInstance = null; // 正在运行的流程实例 Set<String> runNodeIds = new HashSet<>(); // 已经运行的节点 Ids (BPMN XML 节点 Id) Map<String, ApprovalNodeInfo> runningApprovalNodes = new HashMap<>(); // 正在运行的节点的审批信息 Long startUserId = loginUserId; // 审批节点信息 List<ApprovalNodeInfo> approvalNodes = new ArrayList<>(); // 2. 流程未发起 if (reqVO.getProcessInstanceId() == null) { respVO.setStatus(BpmProcessInstanceStatusEnum.NOT_START.getStatus()); // 3. 流程已发起 } else { // 3.1 获取流程实例信息 HistoricProcessInstance processInstance = getHistoricProcessInstance(reqVO.getProcessInstanceId()); if (processInstance == null) { throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS); } // 3.2 获取流程实例状态 Integer processInstanceStatus = FlowableUtils.getProcessInstanceStatus(processInstance); respVO.setStatus(processInstanceStatus); // 3.3 构建已运行节点的审批信息 List<HistoricActivityInstance> historicActivityList = activityService.getActivityListByProcessInstanceId(processInstance.getId()); AlreadyRunApproveNodeRespBO respBO = buildAlreadyRunApproveNodes(processInstance.getId(), historicActivityList); approvalNodes = respBO.getApproveNodes(); runNodeIds = respBO.getRunNodeIds(); // 3.4. 流程已经结束 if (BpmProcessInstanceStatusEnum.isProcessEndStatus(processInstanceStatus)) { respVO.setApproveNodes(approvalNodes); return respVO; } runningApprovalNodes = respBO.getRunningApprovalNodes(); processDefinitionId = processInstance.getProcessDefinitionId(); runProcessInstance = getProcessInstance(processInstance.getId()); startUserId = Long.valueOf(runProcessInstance.getStartUserId()); } // 4. 流程未结束,预测未运行节点的审批信息。需要区分 BPMN 设计器 和 SIMPLE 设计器 BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService.getProcessDefinitionInfo(processDefinitionId); // 4.1 仿钉钉流程设计器 if (Objects.equals(BpmModelTypeEnum.SIMPLE.getType(), processDefinitionInfo.getModelType())) { BpmSimpleModelNodeVO simpleModel = JsonUtils.parseObject(processDefinitionInfo.getSimpleModel(), BpmSimpleModelNodeVO.class); List<ApprovalNodeInfo> notRunApproveNodes = new ArrayList<>(); traverseSimpleModelNodeToBuildNotRunApproveNodes( startUserId, runProcessInstance, simpleModel, runNodeIds, runningApprovalNodes, notRunApproveNodes); approvalNodes.addAll(notRunApproveNodes); respVO.setApproveNodes(approvalNodes); // TODO @jason:会不会有极端的情况:对于依次审批来说,它是已经 running,但是当前节点也要计算其它审批人? // 4.2 BPMN 流程设计器 } else if (Objects.equals(BpmModelTypeEnum.BPMN.getType(), processDefinitionInfo.getModelType())) { // TODO Bpmn 设计器,构建未运行节点的审批信息;未完全实现 } return respVO; } /** * 遍历 SIMPLE 设计器模型 构建未运行节点的审批信息 * * @param startUserId 流程发起人编号 * @param processInstance 流程实例 * @param simpleModelNode SIMPLE 设计器模型 * @param runNodeIds 已经运行节点的 Ids * @param runningApprovalNodes 正在运行的节点的审批信息 * @param approveNodeList 未运行节点的审批信息列表 */ private void traverseSimpleModelNodeToBuildNotRunApproveNodes(Long startUserId, ProcessInstance processInstance, BpmSimpleModelNodeVO simpleModelNode, Set<String> runNodeIds, Map<String, ApprovalNodeInfo> runningApprovalNodes, List<ApprovalNodeInfo> approveNodeList) { if (!SimpleModelUtils.isValidNode(simpleModelNode)) { return; } buildNotRunApproveNodes(startUserId, processInstance, simpleModelNode, runNodeIds, runningApprovalNodes, approveNodeList); // 如果有子节点递归遍历子节点 traverseSimpleModelNodeToBuildNotRunApproveNodes( startUserId, processInstance, simpleModelNode.getChildNode(), runNodeIds, runningApprovalNodes, approveNodeList); } private void buildNotRunApproveNodes(Long startUserId, ProcessInstance processInstance, BpmSimpleModelNodeVO node, Set<String> runNodeIds, Map<String, ApprovalNodeInfo> runningApprovalNodes, List<ApprovalNodeInfo> approveNodeList) { if (!runNodeIds.contains(node.getId())) { // 节点未运行。需要进行预测 // 1. 对需要人工审批的审批节点。进行预测 if (APPROVE_NODE.getType().equals(node.getType()) && USER.getType().equals(node.getApproveType()) || START_USER_NODE.getType().equals(node.getType())) { ApprovalNodeInfo approvalNodeInfo = new ApprovalNodeInfo(); approvalNodeInfo.setNodeType(node.getType()); approvalNodeInfo.setName(node.getName()); approvalNodeInfo.setStatus(NOT_START.getStatus()); Integer candidateStrategy = node.getCandidateStrategy(); if (START_USER_NODE.getType().equals(node.getType())) { candidateStrategy = START_USER.getStrategy(); } approvalNodeInfo.setCandidateUserList( getNotRunTaskCandidateUserList(startUserId, processInstance, node.getId(), candidateStrategy, node.getCandidateParam())); approveNodeList.add(approvalNodeInfo); } // 2. 对分支节点进行预测 if (BpmSimpleModelNodeType.isBranchNode(node.getType())) { // 并行分支。不用预测条件。所有分支都需要遍历 if (PARALLEL_BRANCH_NODE.getType().equals(node.getType())) { node.getConditionNodes().forEach(conditionNode -> traverseSimpleModelNodeToBuildNotRunApproveNodes(startUserId, processInstance, conditionNode.getChildNode() , runNodeIds, runningApprovalNodes, approveNodeList) ); } else if (CONDITION_BRANCH_NODE.getType().equals(node.getType())) { for (BpmSimpleModelNodeVO conditionNode : node.getConditionNodes()) { // 满足一个条件, 遍历该分支并 if ((processInstance != null && evalConditionExpress(processInstance, SimpleModelUtils.buildConditionExpression(conditionNode))) // 预测条件表达式的值 || BooleanUtil.isTrue(conditionNode.getDefaultFlow())) { // 是否默认的序列 traverseSimpleModelNodeToBuildNotRunApproveNodes(startUserId, processInstance, conditionNode.getChildNode(), runNodeIds, runningApprovalNodes, approveNodeList); break; } } } // TODO 包容分支待实现 } // 3. 结束节点 if (END_NODE.getType().equals(node.getType())) { ApprovalNodeInfo nodeProgress = new ApprovalNodeInfo(); nodeProgress.setNodeType(node.getType()); nodeProgress.setName(node.getName()); nodeProgress.setStatus(NOT_START.getStatus()); approveNodeList.add(nodeProgress); } } else { // 节点已经运行。如果是分支节点。需要检查分支节点的运行情况 if (BpmSimpleModelNodeType.isBranchNode(node.getType()) && ArrayUtil.isNotEmpty(node.getConditionNodes())) { node.getConditionNodes().forEach(conditionNode -> { // 只有运行的条件,才需要遍历 if (runNodeIds.contains(conditionNode.getId())) { traverseSimpleModelNodeToBuildNotRunApproveNodes(startUserId, processInstance, conditionNode.getChildNode() , runNodeIds, runningApprovalNodes, approveNodeList); } }); } else if (SimpleModelUtils.isSequentialApproveNode(node) && runningApprovalNodes.containsKey(node.getId())) { // 如果是依次审批, 需要加其它未审批候选人 ApprovalNodeInfo approvalNodeInfo = runningApprovalNodes.get(node.getId()); List<User> candidateUserList = getNotRunTaskCandidateUserList( startUserId, processInstance, node.getId(), node.getCandidateStrategy(), node.getCandidateParam()); ApprovalTaskInfo approvalTaskInfo = CollUtil.getFirst(approvalNodeInfo.getTasks()); Long currentAssignedUserId = null; if (approvalTaskInfo != null && approvalTaskInfo.getAssigneeUser() != null) { currentAssignedUserId = approvalTaskInfo.getAssigneeUser().getId(); } // 找到当前审批人在候选人列表的位置 int index = 0; for (User user : candidateUserList) { if(user.getId().equals(currentAssignedUserId)) { break; } index++; } // 截取当前审批人位置后面的候选人, 不包含当前审批人 approvalNodeInfo.setCandidateUserList(CollUtil.sub(candidateUserList, ++index, candidateUserList.size())); } } } /** * 从已经运行活动节点构建的审批信息列表 * * @param processInstanceId 流程实例 Id * @param historicActivityList 已经运行活动 */ private AlreadyRunApproveNodeRespBO buildAlreadyRunApproveNodes(String processInstanceId, List<HistoricActivityInstance> historicActivityList) { // 1.1 获取待处理活动:只有 "userTask" 和 "endEvent" 需要处理 List<HistoricActivityInstance> pendingActivityNodes = filterList(historicActivityList, item -> BpmSimpleModelNodeType.isRecordNode(item.getActivityType())); // 1.2 已运行节点的 activityId Set<String> runNodeIds = convertSet(historicActivityList, HistoricActivityInstance::getActivityId); // 2.1 获取已运行的任务(包括运行中的任务) List<HistoricTaskInstance> taskList = taskService.getTaskListByProcessInstanceId(processInstanceId); Map<String, HistoricTaskInstance> taskMap = convertMap(taskList, HistoricTaskInstance::getId); // 2.2 获取加签的任务 Map<String, List<HistoricTaskInstance>> addSignTaskMap = convertMultiMap( filterList(taskList, task -> StrUtil.isNotEmpty(task.getParentTaskId())), HistoricTaskInstance::getParentTaskId); // 3.1 获取节点的用户信息 Set<Long> userIds = CollectionUtils.convertSetByFlatMap(pendingActivityNodes, activity -> { if (BPMN_USER_TASK_TYPE.equals(activity.getActivityType())) { HistoricTaskInstance task = taskMap.get(activity.getTaskId()); Set<Long> taskUsers = CollUtil.newHashSet(); CollUtil.addIfAbsent(taskUsers, NumberUtil.parseLong(task.getAssignee(), null)); CollUtil.addIfAbsent(taskUsers, NumberUtil.parseLong(task.getOwner(), null)); List<HistoricTaskInstance> addSignTasks = addSignTaskMap.get(activity.getTaskId()); if (CollUtil.isNotEmpty(addSignTasks)) { addSignTasks.forEach(item -> { CollUtil.addIfAbsent(taskUsers, NumberUtil.parseLong(item.getAssignee(), null)); CollUtil.addIfAbsent(taskUsers, NumberUtil.parseLong(item.getOwner(), null)); }); } return taskUsers.stream(); } else { return Stream.empty(); } }); Map<Long, AdminUserRespDTO> userMap = convertMap(adminUserApi.getUserList(userIds), AdminUserRespDTO::getId); // 3.2 已经结束的任务转换为审批信息。 final Multimap<String, HistoricActivityInstance> runningTask = ArrayListMultimap.create(); // 运行中的任务 List<ApprovalNodeInfo> approvalNodeList = CollectionUtils.convertList(pendingActivityNodes, activity -> { ApprovalNodeInfo approvalNodeInfo = new ApprovalNodeInfo().setId(activity.getId()).setName(activity.getActivityName()) .setStartTime(DateUtils.of(activity.getStartTime())).setEndTime(DateUtils.of(activity.getEndTime())); if (BPMN_USER_TASK_TYPE.equals(activity.getActivityType())) { // 用户任务 // nodeType approvalNodeInfo.setNodeType(START_USER_NODE_ID.equals(activity.getActivityId()) ? START_USER_NODE.getType() : APPROVE_NODE.getType()); // status HistoricTaskInstance task = taskMap.get(activity.getTaskId()); Integer taskStatus = FlowableUtils.getTaskStatus(task); // 运行中的任务, 会签,或签任务聚合在一起。 if (!BpmTaskStatusEnum.isEndStatus(taskStatus)) { runningTask.put(activity.getActivityId(), activity); return null; } // tasks ApprovalTaskInfo approveTask = convertApproveTaskInfo(task, userMap); List<ApprovalTaskInfo> approveTasks = CollUtil.newArrayList(approveTask); List<HistoricTaskInstance> addSignTasks = addSignTaskMap.get(activity.getTaskId()); if (CollUtil.isNotEmpty(addSignTasks)) { // 处理加签任务 approveTasks.addAll(CollectionUtils.convertList(addSignTasks, item -> convertApproveTaskInfo(item, userMap))); } approvalNodeInfo.setStatus(taskStatus); approvalNodeInfo.setTasks(approveTasks); } else if (END_NODE.getBpmnType().equals(activity.getActivityType())) { approvalNodeInfo.setNodeType(END_NODE.getType()); approvalNodeInfo.setStatus(APPROVE.getStatus()); } return approvalNodeInfo; }); // 3.3 运行中的任务转换为审批信息。 final Map<String, ApprovalNodeInfo> runningApprovalNodes = new HashMap<>(); // 正在运行节点的审批信息 runningTask.asMap().forEach((activityId, activities) -> { if (CollUtil.isNotEmpty(activities)) { ApprovalNodeInfo approvalNodeInfo = new ApprovalNodeInfo(); approvalNodeInfo.setNodeType(APPROVE_NODE.getType()); approvalNodeInfo.setStatus(RUNNING.getStatus()); List<ApprovalTaskInfo> approveTasks = CollUtil.newArrayList(); int i = 0; for (HistoricActivityInstance activity : activities) { HistoricTaskInstance task = taskMap.get(activity.getTaskId()); // 取第一个任务, 会签/或签的任务。开始时间相同的 if (i == 0) { approvalNodeInfo.setId(activity.getId()).setName(activity.getActivityName()). setStartTime(DateUtils.of(activity.getStartTime())); } // tasks ApprovalTaskInfo approveTask = convertApproveTaskInfo(task, userMap); approveTasks.add(approveTask); List<HistoricTaskInstance> addSignTasks = addSignTaskMap.get(activity.getTaskId()); if (CollUtil.isNotEmpty(addSignTasks)) { // 处理加签任务 approveTasks.addAll(CollectionUtils.convertList(addSignTasks, item -> convertApproveTaskInfo(item, userMap))); } i++; } approvalNodeInfo.setTasks(approveTasks); approvalNodeList.add(approvalNodeInfo); runningApprovalNodes.put(activityId, approvalNodeInfo); } }); return new AlreadyRunApproveNodeRespBO().setApproveNodes(approvalNodeList).setRunNodeIds(runNodeIds) .setRunningApprovalNodes(runningApprovalNodes); } private ApprovalTaskInfo convertApproveTaskInfo(HistoricTaskInstance task, Map<Long, AdminUserRespDTO> userMap) { if (task == null) { return null; } ApprovalTaskInfo approveTask = BeanUtils.toBean(task, ApprovalTaskInfo.class); approveTask.setStatus(FlowableUtils.getTaskStatus(task)).setReason(FlowableUtils.getTaskReason(task)); Long taskAssignee = NumberUtil.parseLong(task.getAssignee(), null); if (taskAssignee != null) { approveTask.setAssigneeUser(BeanUtils.toBean(userMap.get(taskAssignee), User.class)); } Long taskOwner = NumberUtil.parseLong(task.getOwner(), null); if (taskOwner != null) { approveTask.setOwnerUser(BeanUtils.toBean(userMap.get(taskOwner), User.class)); } return approveTask; } private List<User> getNotRunTaskCandidateUserList(Long startUserId, ProcessInstance processInstance, String activityId, Integer candidateStrategy, String candidateParam) { BpmTaskCandidateStrategy taskCandidateStrategy = bpmTaskCandidateInvoker.getCandidateStrategy(candidateStrategy); Set<Long> userIds = taskCandidateStrategy.calculateUsers(startUserId, processInstance, activityId, candidateParam); Map<Long, AdminUserRespDTO> adminUserMap = convertMap(adminUserApi.getUserList(userIds),AdminUserRespDTO::getId); // 需要按照候选人的顺序返回。依次审批需要按顺序展示用户 List<User> orderUserList = new ArrayList<>(); userIds.forEach(userId-> orderUserList.add(BeanUtils.toBean(adminUserMap.get(userId), User.class))); return orderUserList; } /** * 计算条件表达式的值 * * @param processInstance 流程实例 * @param express 条件表达式 */ private Boolean evalConditionExpress(ProcessInstance processInstance, String express) { if (express == null) { return Boolean.FALSE; } Object result = managementService.executeCommand(context -> { try { return FlowableUtils.getExpressionValue((VariableContainer) processInstance, express); } catch (FlowableException ex) { log.error("[evalConditionExpress][条件表达式({}) 解析报错", express, ex); return Boolean.FALSE; } }); return Boolean.TRUE.equals(result); } // ========== Update 写入相关方法 ========== @Override @Transactional(rollbackFor = Exception.class) public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqVO createReqVO) { // 获得流程定义 ProcessDefinition definition = processDefinitionService.getProcessDefinition(createReqVO.getProcessDefinitionId()); // 发起流程 return createProcessInstance0(userId, definition, createReqVO.getVariables(), null, createReqVO.getStartUserSelectAssignees()); } @Override public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) { // 获得流程定义 ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey()); // 发起流程 return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey(), createReqDTO.getStartUserSelectAssignees()); } private String createProcessInstance0(Long userId, ProcessDefinition definition, Map<String, Object> variables, String businessKey, Map<String, List<Long>> startUserSelectAssignees) { // 1.1 校验流程定义 if (definition == null) { throw exception(PROCESS_DEFINITION_NOT_EXISTS); } if (definition.isSuspended()) { throw exception(PROCESS_DEFINITION_IS_SUSPENDED); } // 1.2 校验发起人自选审批人 validateStartUserSelectAssignees(definition, startUserSelectAssignees); // 2. 创建流程实例 if (variables == null) { variables = new HashMap<>(); } FlowableUtils.filterProcessInstanceFormVariable(variables); // 过滤一下,避免 ProcessInstance 系统级的变量被占用 variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, // 流程实例状态:审批中 BpmProcessInstanceStatusEnum.RUNNING.getStatus()); if (CollUtil.isNotEmpty(startUserSelectAssignees)) { variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees); } ProcessInstance instance = runtimeService.createProcessInstanceBuilder() .processDefinitionId(definition.getId()) .businessKey(businessKey) .name(definition.getName().trim()) .variables(variables) .start(); return instance.getId(); } private void validateStartUserSelectAssignees(ProcessDefinition definition, Map<String, List<Long>> startUserSelectAssignees) { // 1. 获得发起人自选审批人的 UserTask 列表 BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(definition.getId()); List<UserTask> userTaskList = BpmTaskCandidateStartUserSelectStrategy.getStartUserSelectUserTaskList(bpmnModel); if (CollUtil.isEmpty(userTaskList)) { return; } // 2. 校验发起人自选审批人的 UserTask 是否都配置了 userTaskList.forEach(userTask -> { List<Long> assignees = startUserSelectAssignees != null ? startUserSelectAssignees.get(userTask.getId()) : null; if (CollUtil.isEmpty(assignees)) { throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, userTask.getName()); } Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(assignees); assignees.forEach(assignee -> { if (userMap.get(assignee) == null) { throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_EXISTS, userTask.getName(), assignee); } }); }); } @Override public void cancelProcessInstanceByStartUser(Long userId, @Valid BpmProcessInstanceCancelReqVO cancelReqVO) { // 1.1 校验流程实例存在 ProcessInstance instance = getProcessInstance(cancelReqVO.getId()); if (instance == null) { throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS); } // 1.2 只能取消自己的 if (!Objects.equals(instance.getStartUserId(), String.valueOf(userId))) { throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF); } // 2. 取消流程 updateProcessInstanceCancel(cancelReqVO.getId(), BpmReasonEnum.CANCEL_PROCESS_INSTANCE_BY_START_USER.format(cancelReqVO.getReason())); } @Override public void cancelProcessInstanceByAdmin(Long userId, BpmProcessInstanceCancelReqVO cancelReqVO) { // 1.1 校验流程实例存在 ProcessInstance instance = getProcessInstance(cancelReqVO.getId()); if (instance == null) { throw exception(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS); } // 2. 取消流程 AdminUserRespDTO user = adminUserApi.getUser(userId); updateProcessInstanceCancel(cancelReqVO.getId(), BpmReasonEnum.CANCEL_PROCESS_INSTANCE_BY_ADMIN.format(user.getNickname(), cancelReqVO.getReason())); } private void updateProcessInstanceCancel(String id, String reason) { // 1. 更新流程实例 status runtimeService.setVariable(id, BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, BpmProcessInstanceStatusEnum.CANCEL.getStatus()); runtimeService.setVariable(id, BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_REASON, reason); // 2. 结束流程 taskService.moveTaskToEnd(id); } @Override public void updateProcessInstanceReject(ProcessInstance processInstance, String reason) { runtimeService.setVariable(processInstance.getProcessInstanceId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, BpmProcessInstanceStatusEnum.REJECT.getStatus()); runtimeService.setVariable(processInstance.getProcessInstanceId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_REASON, BpmReasonEnum.REJECT_TASK.format(reason)); } // ========== Event 事件相关方法 ========== @Override public void processProcessInstanceCompleted(ProcessInstance instance) { // 注意:需要基于 instance 设置租户编号,避免 Flowable 内部异步时,丢失租户编号 FlowableUtils.execute(instance.getTenantId(), () -> { // 1.1 获取当前状态 Integer status = (Integer) instance.getProcessVariables().get(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS); String reason = (String) instance.getProcessVariables().get(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_REASON); // 1.2 当流程状态还是审批状态中,说明审批通过了,则变更下它的状态 // 为什么这么处理?因为流程完成,并且完成了,说明审批通过了 if (Objects.equals(status, BpmProcessInstanceStatusEnum.RUNNING.getStatus())) { status = BpmProcessInstanceStatusEnum.APPROVE.getStatus(); runtimeService.setVariable(instance.getId(), BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS, status); } // 2. 发送对应的消息通知 if (Objects.equals(status, BpmProcessInstanceStatusEnum.APPROVE.getStatus())) { messageService.sendMessageWhenProcessInstanceApprove(BpmProcessInstanceConvert.INSTANCE.buildProcessInstanceApproveMessage(instance)); } else if (Objects.equals(status, BpmProcessInstanceStatusEnum.REJECT.getStatus())) { messageService.sendMessageWhenProcessInstanceReject( BpmProcessInstanceConvert.INSTANCE.buildProcessInstanceRejectMessage(instance, reason)); } // 3. 发送流程实例的状态事件 processInstanceEventPublisher.sendProcessInstanceResultEvent( BpmProcessInstanceConvert.INSTANCE.buildProcessInstanceStatusEvent(this, instance, status)); }); } } | ||
| 3 | \ No newline at end of file | 3 | \ No newline at end of file |
yudao-module-bpm/yudao-module-bpm-biz/src/test/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/BpmTaskCandidateInvokerTest.java
| @@ -10,8 +10,8 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | @@ -10,8 +10,8 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 10 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 10 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 11 | import org.flowable.bpmn.model.UserTask; | 11 | import org.flowable.bpmn.model.UserTask; |
| 12 | import org.flowable.engine.delegate.DelegateExecution; | 12 | import org.flowable.engine.delegate.DelegateExecution; |
| 13 | +import org.junit.jupiter.api.BeforeEach; | ||
| 13 | import org.junit.jupiter.api.Test; | 14 | import org.junit.jupiter.api.Test; |
| 14 | -import org.mockito.InjectMocks; | ||
| 15 | import org.mockito.Mock; | 15 | import org.mockito.Mock; |
| 16 | import org.mockito.Spy; | 16 | import org.mockito.Spy; |
| 17 | 17 | ||
| @@ -34,15 +34,23 @@ import static org.mockito.Mockito.when; | @@ -34,15 +34,23 @@ import static org.mockito.Mockito.when; | ||
| 34 | */ | 34 | */ |
| 35 | public class BpmTaskCandidateInvokerTest extends BaseMockitoUnitTest { | 35 | public class BpmTaskCandidateInvokerTest extends BaseMockitoUnitTest { |
| 36 | 36 | ||
| 37 | - @InjectMocks | ||
| 38 | private BpmTaskCandidateInvoker taskCandidateInvoker; | 37 | private BpmTaskCandidateInvoker taskCandidateInvoker; |
| 39 | 38 | ||
| 40 | @Mock | 39 | @Mock |
| 41 | private AdminUserApi adminUserApi; | 40 | private AdminUserApi adminUserApi; |
| 41 | + | ||
| 42 | @Spy | 42 | @Spy |
| 43 | - private BpmTaskCandidateStrategy strategy = new BpmTaskCandidateUserStrategy(); | 43 | + private BpmTaskCandidateStrategy strategy ; |
| 44 | + | ||
| 44 | @Spy | 45 | @Spy |
| 45 | - private List<BpmTaskCandidateStrategy> strategyList = Collections.singletonList(strategy); | 46 | + private List<BpmTaskCandidateStrategy> strategyList ; |
| 47 | + | ||
| 48 | + @BeforeEach | ||
| 49 | + public void setUp() { | ||
| 50 | + strategy = new BpmTaskCandidateUserStrategy(adminUserApi); // 创建strategy实例 | ||
| 51 | + strategyList = Collections.singletonList(strategy); // 创建strategyList | ||
| 52 | + taskCandidateInvoker = new BpmTaskCandidateInvoker(strategyList, adminUserApi); | ||
| 53 | + } | ||
| 46 | 54 | ||
| 47 | @Test | 55 | @Test |
| 48 | public void testCalculateUsers() { | 56 | public void testCalculateUsers() { |