Commit b629e0a615de655d3bad497f6beca8c3c1f43bac

Authored by jason
1 parent 61c9a04f

【功能新增】 增加审批人分配策略:表单内的部门负责人

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateDeptLeaderOnFormStrategy.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.dept;
  2 +
  3 +import cn.hutool.core.convert.Convert;
  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;
  7 +import org.flowable.bpmn.model.BpmnModel;
  8 +import org.flowable.engine.delegate.DelegateExecution;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +import java.util.Map;
  12 +import java.util.Set;
  13 +
  14 +/**
  15 + * 表单内部门负责人 {@link BpmTaskCandidateStrategy} 实现类
  16 + *
  17 + * @author jason
  18 + */
  19 +@Component
  20 +public class BpmTaskCandidateDeptLeaderOnFormStrategy extends AbstractBpmTaskCandidateDeptLeaderStrategy {
  21 + @Override
  22 + public BpmTaskCandidateStrategyEnum getStrategy() {
  23 + return BpmTaskCandidateStrategyEnum.DEPT_LEADER_ON_FORM;
  24 + }
  25 +
  26 + @Override
  27 + public void validateParam(String param) {
  28 + // 参数格式: | 分隔:1)左边为表单内部门字段。2)右边为部门层级
  29 + String[] params = param.split("\\|");
  30 + Assert.isTrue(params.length == 2, "参数格式不匹配");
  31 + Assert.notEmpty(param, "表单内部门字段不能为空");
  32 + int level = Integer.parseInt(params[1]);
  33 + Assert.isTrue(level > 0, "部门层级必须大于 0");
  34 + }
  35 +
  36 + @Override
  37 + public Set<Long> calculateUsersByTask(DelegateExecution execution, String param) {
  38 + String[] params = param.split("\\|");
  39 + Object result = execution.getVariable(params[0]);
  40 + int level = Integer.parseInt(params[1]);
  41 + return super.getMultiLevelDeptLeaderIds(Convert.toList(Long.class, result), level);
  42 + }
  43 +
  44 + @Override
  45 + public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId,
  46 + String param, Long startUserId, String processDefinitionId,
  47 + Map<String, Object> processVariables) {
  48 + String[] params = param.split("\\|");
  49 + Object result = processVariables == null ? null : processVariables.get(params[0]);
  50 + int level = Integer.parseInt(params[1]);
  51 + return super.getMultiLevelDeptLeaderIds(Convert.toList(Long.class, result), level);
  52 + }
  53 +}
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/enums/BpmTaskCandidateStrategyEnum.java
@@ -30,6 +30,7 @@ public enum BpmTaskCandidateStrategyEnum implements IntArrayValuable { @@ -30,6 +30,7 @@ public enum BpmTaskCandidateStrategyEnum implements IntArrayValuable {
30 START_USER_DEPT_LEADER_MULTI(38, "发起人连续多级部门的负责人"), 30 START_USER_DEPT_LEADER_MULTI(38, "发起人连续多级部门的负责人"),
31 USER_GROUP(40, "用户组"), 31 USER_GROUP(40, "用户组"),
32 USER_FIELD_ON_FORM(50, "表单内用户字段"), 32 USER_FIELD_ON_FORM(50, "表单内用户字段"),
  33 + DEPT_LEADER_ON_FORM(51, "表单内部分负责人"),
33 EXPRESSION(60, "流程表达式"), // 表达式 ExpressionManager 34 EXPRESSION(60, "流程表达式"), // 表达式 ExpressionManager
34 ASSIGN_EMPTY(1, "审批人为空"), 35 ASSIGN_EMPTY(1, "审批人为空"),
35 ; 36 ;