Commit 093e563b80ef8c34ccc6fb88e1d3e54502bd8a70
1 parent
6c6992c8
feat: add TODO
Showing
1 changed file
with
42 additions
and
16 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| @@ -529,7 +529,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -529,7 +529,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 529 | String taskDefinitionKey = task.getTaskDefinitionKey(); | 529 | String taskDefinitionKey = task.getTaskDefinitionKey(); |
| 530 | List<FlowNode> nextFlowNodes = getNextFlowNodes(taskDefinitionKey, bpmnModel, variables); | 530 | List<FlowNode> nextFlowNodes = getNextFlowNodes(taskDefinitionKey, bpmnModel, variables); |
| 531 | System.out.println(nextFlowNodes); | 531 | System.out.println(nextFlowNodes); |
| 532 | - validateNextAssignees(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); | 532 | +// validateNextAssignees(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); |
| 533 | // 下个节点审批人如果不存在,则由前端传递 | 533 | // 下个节点审批人如果不存在,则由前端传递 |
| 534 | if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { | 534 | if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { |
| 535 | // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 | 535 | // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 |
| @@ -548,34 +548,44 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -548,34 +548,44 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 548 | } | 548 | } |
| 549 | 549 | ||
| 550 | /** | 550 | /** |
| 551 | - * | ||
| 552 | - * @param taskDefinitionKey 当前节点id | ||
| 553 | - * @param bpmnModel bpmnModel | 551 | + * 根据当前节点 ID 获取下一个执行的 FlowNode 列表 |
| 552 | + * @param taskDefinitionKey 当前节点 ID | ||
| 553 | + * @param bpmnModel BPMN 模型 | ||
| 554 | + * @param variables 流程变量,用于条件判断 | ||
| 555 | + * @return 下一个执行的 FlowNode 列表 | ||
| 554 | */ | 556 | */ |
| 555 | - private List<FlowNode> getNextFlowNodes(String taskDefinitionKey, BpmnModel bpmnModel, Map<String, Object> variables){ | ||
| 556 | - FlowNode flowElement = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey); | ||
| 557 | - // 存储下一个执行的节点 | 557 | + public List<FlowNode> getNextFlowNodes(String taskDefinitionKey, BpmnModel bpmnModel, Map<String, Object> variables) { |
| 558 | + if (taskDefinitionKey == null || bpmnModel == null) { | ||
| 559 | + throw new IllegalArgumentException("taskDefinitionKey and bpmnModel cannot be null"); | ||
| 560 | + } | ||
| 561 | + FlowNode currentNode = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey); | ||
| 562 | + if (currentNode == null) { | ||
| 563 | + throw new IllegalArgumentException("FlowElement with given taskDefinitionKey not found in BpmnModel"); | ||
| 564 | + } | ||
| 558 | List<FlowNode> nextFlowNodes = new ArrayList<>(); | 565 | List<FlowNode> nextFlowNodes = new ArrayList<>(); |
| 559 | - resolveNextNodes(flowElement, bpmnModel, variables, nextFlowNodes); | 566 | + resolveNextNodes(currentNode, bpmnModel, variables, nextFlowNodes); |
| 560 | return nextFlowNodes; | 567 | return nextFlowNodes; |
| 561 | } | 568 | } |
| 562 | 569 | ||
| 570 | + /** | ||
| 571 | + * 递归解析下一个执行节点 | ||
| 572 | + * @param currentNode 当前节点 | ||
| 573 | + * @param bpmnModel BPMN 模型 | ||
| 574 | + * @param variables 流程变量,用于条件判断 | ||
| 575 | + * @param nextFlowNodes 存储下一个执行节点的列表 | ||
| 576 | + */ | ||
| 563 | private void resolveNextNodes(FlowNode currentNode, BpmnModel bpmnModel, Map<String, Object> variables, List<FlowNode> nextFlowNodes) { | 577 | private void resolveNextNodes(FlowNode currentNode, BpmnModel bpmnModel, Map<String, Object> variables, List<FlowNode> nextFlowNodes) { |
| 564 | List<SequenceFlow> outgoingFlows = currentNode.getOutgoingFlows(); | 578 | List<SequenceFlow> outgoingFlows = currentNode.getOutgoingFlows(); |
| 565 | for (SequenceFlow sequenceFlow : outgoingFlows) { | 579 | for (SequenceFlow sequenceFlow : outgoingFlows) { |
| 566 | - // 如果是排他网关,需要根据条件表达式判断 | ||
| 567 | - if (currentNode instanceof ExclusiveGateway) { | ||
| 568 | - String conditionExpression = sequenceFlow.getConditionExpression(); | ||
| 569 | - if (conditionExpression != null && !BpmnModelUtils.evalConditionExpress(variables,conditionExpression)) { | ||
| 570 | - continue; | ||
| 571 | - } | 580 | + if (!shouldFollowSequenceFlow(currentNode, sequenceFlow, variables)) { |
| 581 | + continue; | ||
| 572 | } | 582 | } |
| 573 | FlowElement targetElement = bpmnModel.getFlowElement(sequenceFlow.getTargetRef()); | 583 | FlowElement targetElement = bpmnModel.getFlowElement(sequenceFlow.getTargetRef()); |
| 574 | if (targetElement instanceof FlowNode targetNode) { | 584 | if (targetElement instanceof FlowNode targetNode) { |
| 575 | if (targetNode instanceof Gateway) { | 585 | if (targetNode instanceof Gateway) { |
| 576 | - // 如果目标节点还是网关,递归处理 | 586 | + // 如果目标节点是网关,递归处理 |
| 577 | resolveNextNodes(targetNode, bpmnModel, variables, nextFlowNodes); | 587 | resolveNextNodes(targetNode, bpmnModel, variables, nextFlowNodes); |
| 578 | - } else { | 588 | + }else { |
| 579 | nextFlowNodes.add(targetNode); | 589 | nextFlowNodes.add(targetNode); |
| 580 | } | 590 | } |
| 581 | } | 591 | } |
| @@ -583,6 +593,22 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -583,6 +593,22 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 583 | } | 593 | } |
| 584 | 594 | ||
| 585 | /** | 595 | /** |
| 596 | + * 判断是否应该遵循当前序列流 | ||
| 597 | + * @param currentNode 当前节点 | ||
| 598 | + * @param sequenceFlow 序列流 | ||
| 599 | + * @param variables 流程变量,用于条件判断 | ||
| 600 | + * @return 是否应该遵循该序列流 | ||
| 601 | + */ | ||
| 602 | + private boolean shouldFollowSequenceFlow(FlowNode currentNode, SequenceFlow sequenceFlow, Map<String, Object> variables) { | ||
| 603 | + if (currentNode instanceof ExclusiveGateway) { | ||
| 604 | + String conditionExpression = sequenceFlow.getConditionExpression(); | ||
| 605 | + return conditionExpression == null || BpmnModelUtils.evalConditionExpress(variables, conditionExpression); | ||
| 606 | + } | ||
| 607 | + return true; | ||
| 608 | + } | ||
| 609 | + | ||
| 610 | + | ||
| 611 | + /** | ||
| 586 | * 校验传递的参数中是否存在不是下一个执行的节点 | 612 | * 校验传递的参数中是否存在不是下一个执行的节点 |
| 587 | * | 613 | * |
| 588 | * @param loginUserId 流程发起人 | 614 | * @param loginUserId 流程发起人 |