Commit 7925af994bd99d1933bfda95668faf63e5bd302f
1 parent
d6643c9a
perf: [BPM 工作流] 子流程审批不通过,主流程审批不通过流程优化
Showing
2 changed files
with
26 additions
and
17 deletions
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| ... | ... | @@ -52,6 +52,7 @@ import org.flowable.engine.history.HistoricActivityInstance; |
| 52 | 52 | import org.flowable.engine.history.HistoricProcessInstance; |
| 53 | 53 | import org.flowable.engine.history.HistoricProcessInstanceQuery; |
| 54 | 54 | import org.flowable.engine.repository.ProcessDefinition; |
| 55 | +import org.flowable.engine.runtime.Execution; | |
| 55 | 56 | import org.flowable.engine.runtime.ProcessInstance; |
| 56 | 57 | import org.flowable.engine.runtime.ProcessInstanceBuilder; |
| 57 | 58 | import org.flowable.task.api.Task; |
| ... | ... | @@ -69,6 +70,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU |
| 69 | 70 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 70 | 71 | import static cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ActivityNode; |
| 71 | 72 | import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; |
| 73 | +import static cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum.REJECT_CHILD_PROCESS; | |
| 72 | 74 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID; |
| 73 | 75 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.parseNodeType; |
| 74 | 76 | import static java.util.Arrays.asList; |
| ... | ... | @@ -949,6 +951,27 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 949 | 951 | status); |
| 950 | 952 | } |
| 951 | 953 | |
| 954 | + // 1.3 如果子流程拒绝, 设置其父流程也为拒绝状态且结束父流程 | |
| 955 | + if (Objects.equals(status, BpmProcessInstanceStatusEnum.REJECT.getStatus()) | |
| 956 | + && StrUtil.isNotBlank(instance.getSuperExecutionId())) { | |
| 957 | + // 1.3.1 获取父流程实例 并标记为不通过 | |
| 958 | + Execution execution = runtimeService.createExecutionQuery().executionId(instance.getSuperExecutionId()).singleResult(); | |
| 959 | + ProcessInstance parentProcessInstance = getProcessInstance(execution.getProcessInstanceId()); | |
| 960 | + updateProcessInstanceReject(parentProcessInstance, REJECT_CHILD_PROCESS.getReason()); | |
| 961 | + | |
| 962 | + // 1.3.2 结束父流程。需要在子流程结束事务提交后执行 | |
| 963 | + TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { | |
| 964 | + @Override | |
| 965 | + public void afterCompletion(int transactionStatus) { | |
| 966 | + // 回滚情况,直接返回 | |
| 967 | + if (ObjectUtil.equal(transactionStatus, TransactionSynchronization.STATUS_ROLLED_BACK)) { | |
| 968 | + return; | |
| 969 | + } | |
| 970 | + taskService.moveTaskToEnd(parentProcessInstance.getId(),REJECT_CHILD_PROCESS.getReason()); | |
| 971 | + } | |
| 972 | + }); | |
| 973 | + } | |
| 974 | + | |
| 952 | 975 | // 2. 发送对应的消息通知 |
| 953 | 976 | if (Objects.equals(status, BpmProcessInstanceStatusEnum.APPROVE.getStatus())) { |
| 954 | 977 | messageService.sendMessageWhenProcessInstanceApprove( | ... | ... |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -67,7 +67,6 @@ import java.util.stream.Stream; |
| 67 | 67 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 68 | 68 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 69 | 69 | import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; |
| 70 | -import static cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum.REJECT_CHILD_PROCESS; | |
| 71 | 70 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID; |
| 72 | 71 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_RETURN_FLAG; |
| 73 | 72 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_SKIP_START_USER_NODE; |
| ... | ... | @@ -805,24 +804,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 805 | 804 | .setTargetTaskDefinitionKey(returnTaskId).setReason(reqVO.getReason())); |
| 806 | 805 | return; |
| 807 | 806 | } |
| 808 | - // 3.2 情况二:直接结束,审批不通过 | |
| 809 | - // 3.2.1 如果是子流程,需获取父流程。标记父流程为不通过。 | |
| 810 | - // 注意需要在子流程结束前标记,因为如果子流程是最后一个节点。在子流程结束后标记, 会报错 | |
| 811 | - ProcessInstance parentProcessInstance = null; | |
| 812 | - if (StrUtil.isNotBlank(instance.getSuperExecutionId())) { | |
| 813 | - Execution execution = runtimeService.createExecutionQuery().executionId(instance.getSuperExecutionId()).singleResult(); | |
| 814 | - parentProcessInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId()); | |
| 815 | - // 标记父流程不通过 | |
| 816 | - processInstanceService.updateProcessInstanceReject(parentProcessInstance, REJECT_CHILD_PROCESS.getReason()); | |
| 817 | - } | |
| 818 | - // 3.2.2 标记流程为不通过并结束流程 | |
| 807 | + | |
| 808 | + // 3.2 情况二: 标记流程为不通过并结束流程 | |
| 819 | 809 | processInstanceService.updateProcessInstanceReject(instance, reqVO.getReason()); // 标记不通过 |
| 820 | 810 | moveTaskToEnd(task.getProcessInstanceId(), BpmCommentTypeEnum.REJECT.formatComment(reqVO.getReason())); // 结束流程 |
| 821 | - | |
| 822 | - // 3.2.3 如果是子流程,结束主流程 | |
| 823 | - if (parentProcessInstance!=null) { | |
| 824 | - moveTaskToEnd(parentProcessInstance.getId(), BpmCommentTypeEnum.REJECT.formatComment(REJECT_CHILD_PROCESS.getReason())); | |
| 825 | - } | |
| 826 | 811 | } |
| 827 | 812 | |
| 828 | 813 | /** |
| ... | ... | @@ -1002,6 +987,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 1002 | 987 | } |
| 1003 | 988 | |
| 1004 | 989 | @Override |
| 990 | + @Transactional(rollbackFor = Exception.class) | |
| 1005 | 991 | public void moveTaskToEnd(String processInstanceId, String reason) { |
| 1006 | 992 | List<Task> taskList = getRunningTaskListByProcessInstanceId(processInstanceId, null, null); |
| 1007 | 993 | if (CollUtil.isEmpty(taskList)) { | ... | ... |