Commit ff555b51366c1e0df4a571f59a3cef4f812546fb

Authored by smallNorthLee
1 parent deef88f5

feat: 审批通过时,校验节点是否为下一个执行节点

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
... ... @@ -880,7 +880,7 @@ public class BpmnModelUtils {
880 880 * @param nextFlowNodes 下一个执行的流程节点集合
881 881 */
882 882 private static void handleExclusiveGateway(Gateway gateway, BpmnModel bpmnModel, Map<String, Object> variables, List<FlowNode> nextFlowNodes) {
883   - // TODO @小北: 这里findOne和simulateNextFlowElements中有重复代码,需要优化,@芋道:是否重构??
  883 + // TODO @小北: 这里和simulateNextFlowElements中有重复代码,是否重构??每个网关节点拆分出方法应该比较合理化,@芋道
884 884 SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
885 885 flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId())
886 886 && (evalConditionExpress(variables, flow.getConditionExpression())));
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
... ... @@ -523,9 +523,9 @@ public class BpmTaskServiceImpl implements BpmTaskService {
523 523 BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason()));
524 524 // 2.3 调用 BPM complete 去完成任务
525 525 // 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用
526   -// if (CollUtil.isNotEmpty(reqVO.getVariables())) {
  526 + if (CollUtil.isNotEmpty(reqVO.getVariables())) {
527 527 Map<String, Object> variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables());
528   - // 校验传递的参数中是否存在不是下一个执行的节点
  528 + // 校验传递的参数中是否为下一个将要执行的任务节点
529 529 validateNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(), bpmnModel, reqVO.getNextAssignees(), instance);
530 530 // 下个节点审批人如果不存在,则由前端传递
531 531 if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) {
... ... @@ -536,9 +536,9 @@ public class BpmTaskServiceImpl implements BpmTaskService {
536 536 }
537 537 runtimeService.setVariables(task.getProcessInstanceId(), variables);
538 538 taskService.complete(task.getId(), variables, true);
539   -// } else {
540   -// taskService.complete(task.getId());
541   -// }
  539 + } else {
  540 + taskService.complete(task.getId());
  541 + }
542 542  
543 543 // 【加签专属】处理加签任务
544 544 handleParentTaskIfSign(task.getParentTaskId());
... ... @@ -546,7 +546,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
546 546  
547 547  
548 548 /**
549   - * 校验传递的参数中是否存在不是下一个执行的节点
  549 + * 校验传递的参数中是否为下一个将要执行的任务节点
550 550 *
551 551 * @param taskDefinitionKey 当前任务节点id
552 552 * @param variables 流程变量
... ... @@ -555,39 +555,37 @@ public class BpmTaskServiceImpl implements BpmTaskService {
555 555 */
556 556 private void validateNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel,
557 557 Map<String, List<Long>> nextActivityNodes,ProcessInstance processInstance){
558   -
559 558 // 1、获取当前任务节点的信息
560 559 FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey);
561   - // 2、获取下一个应该执行的节点集合
  560 + // 2、获取下一个将要执行的节点集合
562 561 List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables);
563   - // 3、比较前端传递的节点和预测的下一个节点是否匹配,匹配则将该节点设置上审批人
  562 + // 3、循环下一个将要执行的节点集合
564 563 for (FlowNode nextFlowNode : nextFlowNodes) {
565   - // 获取下一个执行节点的属性 是否为 发起人自选
  564 + // 3.1、获取下一个将要执行节点的属性(是否为自选审批人等)
566 565 Map<String, List<ExtensionElement>> extensionElements = nextFlowNode.getExtensionElements();
567 566 List<ExtensionElement> elements = extensionElements.get(BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY);
568 567 if (CollUtil.isEmpty(elements)){
569 568 continue;
570 569 }
571   - // 获取节点中的审批人策略
  570 + // 3.2、获取节点中的审批人策略
572 571 Integer candidateStrategy = Integer.valueOf(elements.get(0).getElementText());
573   - // 获取流程实例中的发起人自选审批人
  572 + // 3.3、获取流程实例中的发起人自选审批人
574 573 Map<String, List<Long>> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables());
575 574 List<Long> startUserSelectAssignee = startUserSelectAssignees.get(nextFlowNode.getId());
  575 + // 3.4、如果节点中的审批人策略为 发起人自选,并且该节点的审批人为空
576 576 if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy()) && CollUtil.isEmpty(startUserSelectAssignee)) {
577   - // 先判断节点是否存在
  577 + // 先判断前端传递的参数节点节点是否为将要执行的节点
578 578 if (!nextActivityNodes.containsKey(nextFlowNode.getId())){
579 579 throw exception(TASK_TARGET_NODE_NOT_EXISTS, nextFlowNode.getName());
580 580 }
581   - // 如果节点存在,则判断节点中的审批人策略是否为 发起人自选
  581 + // 如果节点存在,则获取节点中的审批人
582 582 List<Long> nextAssignees = nextActivityNodes.get(nextFlowNode.getId());
583   - // 3.1、如果前端传递的节点为空,则抛出异常
  583 + // 如果前端传递的节点为空,则抛出异常
584 584 if (CollUtil.isEmpty(nextAssignees)) {
585 585 throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
586 586 }
587 587 }
588   -
589 588 }
590   -
591 589 }
592 590  
593 591 /**
... ...