|
@@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.flowable.bpmn.model.BpmnModel;
|
|
|
+import org.flowable.bpmn.model.FlowElement;
|
|
|
import org.flowable.bpmn.model.UserTask;
|
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
|
import org.flowable.engine.runtime.ProcessInstance;
|
|
@@ -89,31 +90,66 @@ public class BpmTaskCandidateInvoker {
|
|
|
* @return 用户编号集合
|
|
|
*/
|
|
|
@DataPermission(enable = false) // 忽略数据权限,避免因为过滤,导致找不到候选人
|
|
|
- public Set<Long> calculateUsers(DelegateExecution execution) {
|
|
|
+ public Set<Long> calculateUsersByTask(DelegateExecution execution) {
|
|
|
// 审批类型非人工审核时,不进行计算候选人。原因是:后续会自动通过、不通过
|
|
|
- Integer approveType = BpmnModelUtils.parseApproveType(execution.getCurrentFlowElement());
|
|
|
+ FlowElement flowElement = execution.getCurrentFlowElement();
|
|
|
+ Integer approveType = BpmnModelUtils.parseApproveType(flowElement);
|
|
|
if (ObjectUtils.equalsAny(approveType,
|
|
|
BpmUserTaskApproveTypeEnum.AUTO_APPROVE.getType(),
|
|
|
BpmUserTaskApproveTypeEnum.AUTO_REJECT.getType())) {
|
|
|
return new HashSet<>();
|
|
|
}
|
|
|
|
|
|
- Integer strategy = BpmnModelUtils.parseCandidateStrategy(execution.getCurrentFlowElement());
|
|
|
- String param = BpmnModelUtils.parseCandidateParam(execution.getCurrentFlowElement());
|
|
|
+ Integer strategy = BpmnModelUtils.parseCandidateStrategy(flowElement);
|
|
|
+ String param = BpmnModelUtils.parseCandidateParam(flowElement);
|
|
|
// 1.1 计算任务的候选人
|
|
|
- Set<Long> userIds = getCandidateStrategy(strategy).calculateUsers(execution, param);
|
|
|
- // 1.2 移除被禁用的用户 TODO @芋艿 在 calculateUsers 方法中默认已经移除了被禁用的用户, 这里还需要移除被禁用的用户吗?
|
|
|
+ Set<Long> userIds = getCandidateStrategy(strategy).calculateUsersByTask(execution, param);
|
|
|
+ // 1.2 移除被禁用的用户
|
|
|
removeDisableUsers(userIds);
|
|
|
|
|
|
// 2. 候选人为空时,根据“审批人为空”的配置补充
|
|
|
if (CollUtil.isEmpty(userIds)) {
|
|
|
userIds = getCandidateStrategy(BpmTaskCandidateStrategyEnum.ASSIGN_EMPTY.getStrategy())
|
|
|
- .calculateUsers(execution, param);
|
|
|
+ .calculateUsersByTask(execution, param);
|
|
|
// ASSIGN_EMPTY 策略,不需要移除被禁用的用户。原因是,再移除,可能会出现更没审批人了!!!
|
|
|
}
|
|
|
|
|
|
// 3. 移除发起人的用户
|
|
|
- removeStartUserIfSkip(execution, userIds);
|
|
|
+ ProcessInstance processInstance = SpringUtil.getBean(BpmProcessInstanceService.class)
|
|
|
+ .getProcessInstance(execution.getProcessInstanceId());
|
|
|
+ Assert.notNull(processInstance, "流程实例({}) 不存在", execution.getProcessInstanceId());
|
|
|
+ removeStartUserIfSkip(userIds, flowElement, Long.valueOf(processInstance.getStartUserId()));
|
|
|
+ return userIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId,
|
|
|
+ Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
|
|
|
+ // 审批类型非人工审核时,不进行计算候选人。原因是:后续会自动通过、不通过
|
|
|
+ FlowElement flowElement = BpmnModelUtils.getFlowElementById(bpmnModel, activityId);
|
|
|
+ Integer approveType = BpmnModelUtils.parseApproveType(flowElement);
|
|
|
+ if (ObjectUtils.equalsAny(approveType,
|
|
|
+ BpmUserTaskApproveTypeEnum.AUTO_APPROVE.getType(),
|
|
|
+ BpmUserTaskApproveTypeEnum.AUTO_REJECT.getType())) {
|
|
|
+ return new HashSet<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer strategy = BpmnModelUtils.parseCandidateStrategy(flowElement);
|
|
|
+ String param = BpmnModelUtils.parseCandidateParam(flowElement);
|
|
|
+ // 1.1 计算任务的候选人
|
|
|
+ Set<Long> userIds = getCandidateStrategy(strategy).calculateUsersByActivity(bpmnModel, activityId, param,
|
|
|
+ startUserId, processDefinitionId, processVariables);
|
|
|
+ // 1.2 移除被禁用的用户
|
|
|
+ removeDisableUsers(userIds);
|
|
|
+
|
|
|
+ // 2. 候选人为空时,根据“审批人为空”的配置补充
|
|
|
+ if (CollUtil.isEmpty(userIds)) {
|
|
|
+ userIds = getCandidateStrategy(BpmTaskCandidateStrategyEnum.ASSIGN_EMPTY.getStrategy())
|
|
|
+ .calculateUsersByActivity(bpmnModel, activityId, param, startUserId, processDefinitionId, processVariables);
|
|
|
+ // ASSIGN_EMPTY 策略,不需要移除被禁用的用户。原因是,再移除,可能会出现更没审批人了!!!
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 移除发起人的用户
|
|
|
+ removeStartUserIfSkip(userIds, flowElement, startUserId);
|
|
|
return userIds;
|
|
|
}
|
|
|
|
|
@@ -134,25 +170,23 @@ public class BpmTaskCandidateInvoker {
|
|
|
*
|
|
|
* 注意:如果只有一个候选人,则不处理,避免无法审批
|
|
|
*
|
|
|
- * @param execution 执行中的任务
|
|
|
* @param assigneeUserIds 当前分配的候选人
|
|
|
+ * @param flowElement 当前节点
|
|
|
+ * @param startUserId 发起人
|
|
|
*/
|
|
|
@VisibleForTesting
|
|
|
- void removeStartUserIfSkip(DelegateExecution execution, Set<Long> assigneeUserIds) {
|
|
|
+ void removeStartUserIfSkip(Set<Long> assigneeUserIds, FlowElement flowElement, Long startUserId) {
|
|
|
if (CollUtil.size(assigneeUserIds) <= 1) {
|
|
|
return;
|
|
|
}
|
|
|
- Integer assignStartUserHandlerType = BpmnModelUtils.parseAssignStartUserHandlerType(execution.getCurrentFlowElement());
|
|
|
+ Integer assignStartUserHandlerType = BpmnModelUtils.parseAssignStartUserHandlerType(flowElement);
|
|
|
if (ObjectUtil.notEqual(assignStartUserHandlerType, BpmUserTaskAssignStartUserHandlerTypeEnum.SKIP.getType())) {
|
|
|
return;
|
|
|
}
|
|
|
- ProcessInstance processInstance = SpringUtil.getBean(BpmProcessInstanceService.class)
|
|
|
- .getProcessInstance(execution.getProcessInstanceId());
|
|
|
- Assert.notNull(processInstance, "流程实例({}) 不存在", execution.getProcessInstanceId());
|
|
|
- assigneeUserIds.remove(Long.valueOf(processInstance.getStartUserId()));
|
|
|
+ assigneeUserIds.remove(startUserId);
|
|
|
}
|
|
|
|
|
|
- public BpmTaskCandidateStrategy getCandidateStrategy(Integer strategy) {
|
|
|
+ private BpmTaskCandidateStrategy getCandidateStrategy(Integer strategy) {
|
|
|
BpmTaskCandidateStrategyEnum strategyEnum = BpmTaskCandidateStrategyEnum.valueOf(strategy);
|
|
|
Assert.notNull(strategyEnum, "策略(%s) 不存在", strategy);
|
|
|
BpmTaskCandidateStrategy strategyObj = strategyMap.get(strategyEnum);
|