Commit 71e42cb0a1d350b37308ccccf3ac68c687a497c2

Authored by YunaiV
1 parent fe3ca8de

【功能新增】审批节点的审批人与发起人相同时,对应的处理类型的配置

yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmBoundaryEventType.java
... ... @@ -4,7 +4,6 @@ import cn.hutool.core.util.ArrayUtil;
4 4 import lombok.AllArgsConstructor;
5 5 import lombok.Getter;
6 6  
7   -// TODO @jason:这个是不是可以去掉了哈?
8 7 /**
9 8 * BPM 边界事件 (boundary event) 自定义类型枚举
10 9 *
... ... @@ -14,8 +13,7 @@ import lombok.Getter;
14 13 @AllArgsConstructor
15 14 public enum BpmBoundaryEventType {
16 15  
17   - USER_TASK_TIMEOUT(1,"用户任务超时"),
18   - USER_TASK_REJECT_POST_PROCESS(2, "用户任务拒绝后处理");
  16 + USER_TASK_TIMEOUT(1,"用户任务超时");
19 17  
20 18 private final Integer type;
21 19 private final String name;
... ... @@ -23,4 +21,5 @@ public enum BpmBoundaryEventType {
23 21 public static BpmBoundaryEventType typeOf(Integer type) {
24 22 return ArrayUtil.firstMatch(eventType -> eventType.getType().equals(type), values());
25 23 }
  24 +
26 25 }
... ...
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmUserTaskAssignStartUserHandlerTypeEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bpm.enums.definition;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  4 +import lombok.Getter;
  5 +import lombok.RequiredArgsConstructor;
  6 +
  7 +/**
  8 + * BPM 用户任务的审批人与发起人相同时,处理类型枚举
  9 + *
  10 + * @author 芋道源码
  11 + */
  12 +@RequiredArgsConstructor
  13 +@Getter
  14 +public enum BpmUserTaskAssignStartUserHandlerTypeEnum implements IntArrayValuable {
  15 +
  16 + START_USER_AUDIT(1), // 由发起人对自己审批
  17 + SKIP(2), // 自动跳过【参考飞书】:1)如果当前节点还有其他审批人,则交由其他审批人进行审批;2)如果当前节点没有其他审批人,则该节点自动通过
  18 + ASSIGN_DEPT_LEADER(3); // 转交给部门负责人审批
  19 +
  20 + private final Integer type;
  21 +
  22 + @Override
  23 + public int[] array() {
  24 + return new int[0];
  25 + }
  26 +
  27 +}
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
1 1 package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple;
2 2  
3 3 import cn.iocoder.yudao.framework.common.validation.InEnum;
4   -import cn.iocoder.yudao.module.bpm.enums.definition.BpmApproveMethodEnum;
5   -import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType;
6   -import cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskRejectHandlerType;
7   -import cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskTimeoutHandlerType;
  4 +import cn.iocoder.yudao.module.bpm.enums.definition.*;
8 5 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
9 6 import com.fasterxml.jackson.annotation.JsonIgnore;
10 7 import com.fasterxml.jackson.annotation.JsonInclude;
... ... @@ -84,6 +81,10 @@ public class BpmSimpleModelNodeVO {
84 81 */
85 82 private TimeoutHandler timeoutHandler;
86 83  
  84 + @Schema(description = "审批节点的审批人与发起人相同时,对应的处理类型", example = "1")
  85 + @InEnum(BpmUserTaskAssignStartUserHandlerTypeEnum.class)
  86 + private Integer assignStartUserHandlerType;
  87 +
87 88 @Data
88 89 @Schema(description = "审批节点拒绝处理策略")
89 90 public static class RejectHandler {
... ... @@ -132,14 +133,7 @@ public class BpmSimpleModelNodeVO {
132 133 }
133 134  
134 135 // Map<String, Integer> formPermissions; 表单权限;仅发起、审批、抄送节点会使用
135   - // Integer approveMethod; 审批方式;仅审批节点会使用
136   - // TODO @jason 后面和前端一起调整一下;下面的 ①、②、③ 是优先级
137   - // TODO @芋艿:① 审批人的选择;
138 136 // TODO @芋艿:⑥ 没有人的策略?
139   - // TODO @芋艿:② 审批拒绝的策略?
140   - // TODO @芋艿:③ 配置的可操作列表?(操作权限)
141   - // TODO @芋艿:④ 表单的权限列表?
142   - // TODO @芋艿:⑨ 超时配置;要支持指定时间点、指定时间间隔;
143 137 // TODO @芋艿:条件;建议可以固化的一些选项;然后有个表达式兜底;要支持
144 138  
145 139 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmTaskConvert.java
... ... @@ -176,7 +176,6 @@ public interface BpmTaskConvert {
176 176 childTask.setParentTaskId(parentTask.getId());
177 177 childTask.setProcessDefinitionId(parentTask.getProcessDefinitionId());
178 178 childTask.setProcessInstanceId(parentTask.getProcessInstanceId());
179   -// childTask.setExecutionId(parentTask.getExecutionId()); // TODO 芋艿:新加的,不太确定;尴尬,不加时,子任务不通过会失败(报错);加了,子任务审批通过会失败(报错)
180 179 childTask.setTaskDefinitionKey(parentTask.getTaskDefinitionKey());
181 180 childTask.setTaskDefinitionId(parentTask.getTaskDefinitionId());
182 181 childTask.setPriority(parentTask.getPriority());
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/enums/BpmnModelConstants.java
... ... @@ -29,12 +29,17 @@ public interface BpmnModelConstants {
29 29 String BOUNDARY_EVENT_TYPE = "boundaryEventType";
30 30  
31 31 // TODO @jason:这个命名,应该也要改哈
  32 + // TODO @jason:1)是不是上面的 timeoutAction 改成 timeoutHandler;
32 33 /**
33 34 * BPMN ExtensionElement 的扩展属性,用于标记用户任务超时执行动作
34 35 */
35 36 String USER_TASK_TIMEOUT_HANDLER_ACTION = "timeoutAction";
36 37  
37   - // TODO @jason:1)是不是上面的 timeoutAction 改成 timeoutHandler;2)rejectHandlerType 改成 rejectHandler 哇?
  38 + /**
  39 + * BPMN ExtensionElement 的扩展属性,用于标记用户任务的审批人与发起人相同时,对应的处理类型
  40 + */
  41 + String USER_TASK_ASSIGN_START_USER_HANDLER_TYPE = "assignStartUserHandlerType";
  42 +
38 43 /**
39 44 * BPMN ExtensionElement 的扩展属性,用于标记用户任务拒绝处理类型
40 45 */
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
... ... @@ -10,6 +10,7 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
10 10 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
11 11 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.RejectHandler;
12 12 import cn.iocoder.yudao.module.bpm.enums.definition.BpmApproveMethodEnum;
  13 +import cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventType;
13 14 import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModeConditionType;
14 15 import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType;
15 16 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
... ... @@ -25,7 +26,6 @@ import java.util.Objects;
25 26  
26 27 import static cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.OperationButtonSetting;
27 28 import static cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TimeoutHandler;
28   -import static cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventType.USER_TASK_TIMEOUT;
29 29 import static cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType.*;
30 30 import static cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskTimeoutHandlerType.REMINDER;
31 31 import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.*;
... ... @@ -338,8 +338,9 @@ public class SimpleModelUtils {
338 338 List<FlowElement> flowElements = new ArrayList<>();
339 339 UserTask userTask = buildBpmnUserTask(node);
340 340 flowElements.add(userTask);
  341 +
  342 + // 添加用户任务的 Timer Boundary Event, 用于任务的审批超时处理
341 343 if (node.getTimeoutHandler() != null && node.getTimeoutHandler().getEnable()) {
342   - // 添加用户任务的 Timer Boundary Event, 用于任务的超时处理
343 344 BoundaryEvent boundaryEvent = buildUserTaskTimerBoundaryEvent(userTask, node.getTimeoutHandler());
344 345 flowElements.add(boundaryEvent);
345 346 }
... ... @@ -347,31 +348,31 @@ public class SimpleModelUtils {
347 348 }
348 349  
349 350 /**
350   - * 添加 UserTask 用户审批的 BoundaryEvent 超时事件
  351 + * 添加 UserTask 用户的审批超时 BoundaryEvent 事件
351 352 *
352 353 * @param userTask 审批任务
353 354 * @param timeoutHandler 超时处理器
354   - * @return
  355 + * @return BoundaryEvent 超时事件
355 356 */
356 357 private static BoundaryEvent buildUserTaskTimerBoundaryEvent(UserTask userTask, TimeoutHandler timeoutHandler) {
357   - // 定时器边界事件
  358 + // 1.1 定时器边界事件
358 359 BoundaryEvent boundaryEvent = new BoundaryEvent();
359 360 boundaryEvent.setId("Event-" + IdUtil.fastUUID());
360   - // 设置关联的任务为不会被中断
361   - boundaryEvent.setCancelActivity(false);
  361 + boundaryEvent.setCancelActivity(false); // 设置关联的任务为不会被中断
362 362 boundaryEvent.setAttachedToRef(userTask);
  363 + // 1.2 定义超时时间、最大提醒次数
363 364 TimerEventDefinition eventDefinition = new TimerEventDefinition();
364 365 eventDefinition.setTimeDuration(timeoutHandler.getTimeDuration());
365 366 if (Objects.equals(REMINDER.getAction(), timeoutHandler.getAction()) &&
366 367 timeoutHandler.getMaxRemindCount() != null && timeoutHandler.getMaxRemindCount() > 1) {
367   - // 最大提醒次数
368   - eventDefinition.setTimeCycle(String.format("R%d/%s", timeoutHandler.getMaxRemindCount(), timeoutHandler.getTimeDuration()));
  368 + eventDefinition.setTimeCycle(String.format("R%d/%s",
  369 + timeoutHandler.getMaxRemindCount(), timeoutHandler.getTimeDuration()));
369 370 }
370 371 boundaryEvent.addEventDefinition(eventDefinition);
371 372  
372   - // 添加定时器边界事件类型
373   - addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, USER_TASK_TIMEOUT.getType().toString());
374   - // 添加超时执行动作元素
  373 + // 2.1 添加定时器边界事件类型
  374 + addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, BpmBoundaryEventType.USER_TASK_TIMEOUT.getType().toString());
  375 + // 2.2 添加超时执行动作元素
375 376 addExtensionElement(boundaryEvent, USER_TASK_TIMEOUT_HANDLER_ACTION, StrUtil.toStringOrNull(timeoutHandler.getAction()));
376 377 return boundaryEvent;
377 378 }
... ... @@ -455,8 +456,6 @@ public class SimpleModelUtils {
455 456 userTask.setDueDate(node.getTimeoutHandler().getTimeDuration());
456 457 }
457 458  
458   - // TODO 芋艿 + jason:要不要基于服务任务,实现或签下的审批不通过?或者说,按比例审批
459   -
460 459 // TODO @jason:addCandidateElements、processMultiInstanceLoopCharacteristics 建议一起搞哈?
461 460 // 添加候选人元素
462 461 addCandidateElements(node.getCandidateStrategy(), node.getCandidateParam(), userTask);
... ... @@ -468,10 +467,11 @@ public class SimpleModelUtils {
468 467 processMultiInstanceLoopCharacteristics(node.getApproveMethod(), node.getApproveRatio(), userTask);
469 468 // 添加任务被拒绝的处理元素
470 469 addTaskRejectElements(node.getRejectHandler(), userTask);
  470 + // 添加用户任务的审批人与发起人相同时的处理元素
  471 + addAssignStartUserHandlerType(node.getAssignStartUserHandlerType(), userTask);
471 472 return userTask;
472 473 }
473 474  
474   -
475 475 private static void addTaskRejectElements(RejectHandler rejectHandler, UserTask userTask) {
476 476 if (rejectHandler == null) {
477 477 return;
... ... @@ -480,6 +480,13 @@ public class SimpleModelUtils {
480 480 addExtensionElement(userTask, USER_TASK_REJECT_RETURN_TASK_ID, rejectHandler.getReturnNodeId());
481 481 }
482 482  
  483 + private static void addAssignStartUserHandlerType(Integer assignStartUserHandlerType, UserTask userTask) {
  484 + if (assignStartUserHandlerType == null) {
  485 + return;
  486 + }
  487 + addExtensionElement(userTask, USER_TASK_ASSIGN_START_USER_HANDLER_TYPE, assignStartUserHandlerType.toString());
  488 + }
  489 +
483 490 private static void processMultiInstanceLoopCharacteristics(Integer approveMethod, Integer approveRatio, UserTask userTask) {
484 491 BpmApproveMethodEnum bpmApproveMethodEnum = BpmApproveMethodEnum.valueOf(approveMethod);
485 492 if (bpmApproveMethodEnum == null || bpmApproveMethodEnum == BpmApproveMethodEnum.RANDOM) {
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.service.task;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.*;
  5 +import cn.hutool.extra.spring.SpringUtil;
5 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 7 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
7 8 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
... ... @@ -79,7 +80,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
79 80 @Resource
80 81 private BpmProcessInstanceCopyService processInstanceCopyService;
81 82 @Resource
82   - private BpmModelService bpmModelService;
  83 + private BpmModelService modelService;
83 84 @Resource
84 85 private BpmMessageService messageService;
85 86  
... ... @@ -228,7 +229,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
228 229 // 1.1 校验当前任务 task 存在
229 230 Task task = validateTaskExist(id);
230 231 // 1.2 根据流程定义获取流程模型信息
231   - BpmnModel bpmnModel = bpmModelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId());
  232 + BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId());
232 233 FlowElement source = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
233 234 if (source == null) {
234 235 throw exception(TASK_NOT_EXISTS);
... ... @@ -498,7 +499,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
498 499 }
499 500  
500 501 // 3. 根据不同的 RejectHandler 处理策略
501   - BpmnModel bpmnModel = bpmModelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId());
  502 + BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId());
502 503 FlowElement flowElement = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
503 504 // 3.1 情况一:驳回到指定的任务节点
504 505 BpmUserTaskRejectHandlerType userTaskRejectHandlerType = BpmnModelUtils.parseRejectHandlerType(flowElement);
... ... @@ -562,7 +563,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
562 563 */
563 564 private FlowElement validateTargetTaskCanReturn(String sourceKey, String targetKey, String processDefinitionId) {
564 565 // 1.1 获取流程模型信息
565   - BpmnModel bpmnModel = bpmModelService.getBpmnModelByDefinitionId(processDefinitionId);
  566 + BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processDefinitionId);
566 567 // 1.3 获取当前任务节点元素
567 568 FlowElement source = BpmnModelUtils.getFlowElementById(bpmnModel, sourceKey);
568 569 // 1.3 获取跳转的节点元素
... ... @@ -690,7 +691,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
690 691 });
691 692  
692 693 // 2. 终止流程
693   - BpmnModel bpmnModel = bpmModelService.getBpmnModelByDefinitionId(taskList.get(0).getProcessDefinitionId());
  694 + BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(taskList.get(0).getProcessDefinitionId());
694 695 List<String> activityIds = CollUtil.newArrayList(convertSet(taskList, Task::getTaskDefinitionKey));
695 696 EndEvent endEvent = BpmnModelUtils.getEndEvent(bpmnModel);
696 697 Assert.notNull(endEvent, "结束节点不能未空");
... ... @@ -915,13 +916,29 @@ public class BpmTaskServiceImpl implements BpmTaskService {
915 916 @Override
916 917 public void afterCommit() {
917 918 if (StrUtil.isEmpty(task.getAssignee())) {
  919 + log.error("[processTaskAssigned][taskId({}) 没有分配到负责人]", task.getId());
918 920 return;
919 921 }
920 922 ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
921   - if (processInstance != null) {
922   - AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId()));
923   - messageService.sendMessageWhenTaskAssigned(BpmTaskConvert.INSTANCE.convert(processInstance, startUser, task));
  923 + if (processInstance == null) {
  924 + log.error("[processTaskAssigned][taskId({}) 没有找到流程实例]", task.getId());
  925 + return;
  926 + }
  927 + BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId());
  928 + if (bpmnModel == null) {
  929 + log.error("[processTaskAssigned][taskId({}) 没有找到流程模型]", task.getId());
  930 + return;
  931 + }
  932 +
  933 + // 审批人与提交人为同一人时,根据策略进行处理
  934 + if (StrUtil.equals(task.getAssignee(), processInstance.getStartUserId())) {
  935 + getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO()
  936 + .setId(task.getId()).setReason("审批人与提交人为同一人时,自动通过"));
  937 + return;
924 938 }
  939 +
  940 + AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId()));
  941 + messageService.sendMessageWhenTaskAssigned(BpmTaskConvert.INSTANCE.convert(processInstance, startUser, task));
925 942 }
926 943  
927 944 });
... ... @@ -966,4 +983,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
966 983 }));
967 984 }
968 985  
  986 + /**
  987 + * 获得自身的代理对象,解决 AOP 生效问题
  988 + *
  989 + * @return 自己
  990 + */
  991 + private BpmTaskServiceImpl getSelf() {
  992 + return SpringUtil.getBean(getClass());
  993 + }
  994 +
969 995 }
... ...