Commit 72af865804a5baf31a960f789e1eb2e4565ef1fd
Merge branch 'develop' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into master-jdk17
Showing
3 changed files
with
38 additions
and
9 deletions
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/enums/task/BpmReasonEnum.java
| ... | ... | @@ -19,6 +19,7 @@ public enum BpmReasonEnum { |
| 19 | 19 | CANCEL_PROCESS_INSTANCE_BY_START_USER("用户主动取消流程,原因:{}"), // 场景:用户主动取消流程 |
| 20 | 20 | CANCEL_PROCESS_INSTANCE_BY_ADMIN("管理员【{}】取消流程,原因:{}"), // 场景:管理员取消流程 |
| 21 | 21 | CANCEL_CHILD_PROCESS_INSTANCE_BY_MAIN_PROCESS("子流程自动取消,原因:主流程已取消"), |
| 22 | + REJECT_CHILD_PROCESS("子流程审批不通过"), | |
| 22 | 23 | |
| 23 | 24 | // ========== 流程任务的独有原因 ========== |
| 24 | 25 | ... | ... |
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,29 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 949 | 951 | status); |
| 950 | 952 | } |
| 951 | 953 | |
| 954 | + // 1.3 如果子流程拒绝,设置其父流程也为拒绝状态,且结束父流程 | |
| 955 | + // 相关问题链接:https://t.zsxq.com/kZhyb | |
| 956 | + if (Objects.equals(status, BpmProcessInstanceStatusEnum.REJECT.getStatus()) | |
| 957 | + && StrUtil.isNotBlank(instance.getSuperExecutionId())) { | |
| 958 | + // 1.3.1 获取父流程实例 并标记为不通过 | |
| 959 | + Execution execution = runtimeService.createExecutionQuery().executionId(instance.getSuperExecutionId()).singleResult(); | |
| 960 | + ProcessInstance parentProcessInstance = getProcessInstance(execution.getProcessInstanceId()); | |
| 961 | + updateProcessInstanceReject(parentProcessInstance, REJECT_CHILD_PROCESS.getReason()); | |
| 962 | + | |
| 963 | + // 1.3.2 结束父流程。需要在子流程结束事务提交后执行 | |
| 964 | + TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { | |
| 965 | + | |
| 966 | + @Override | |
| 967 | + public void afterCompletion(int transactionStatus) { | |
| 968 | + // 回滚情况,直接返回 | |
| 969 | + if (ObjectUtil.equal(transactionStatus, TransactionSynchronization.STATUS_ROLLED_BACK)) { | |
| 970 | + return; | |
| 971 | + } | |
| 972 | + taskService.moveTaskToEnd(parentProcessInstance.getId(),REJECT_CHILD_PROCESS.getReason()); | |
| 973 | + } | |
| 974 | + }); | |
| 975 | + } | |
| 976 | + | |
| 952 | 977 | // 2. 发送对应的消息通知 |
| 953 | 978 | if (Objects.equals(status, BpmProcessInstanceStatusEnum.APPROVE.getStatus())) { |
| 954 | 979 | messageService.sendMessageWhenProcessInstanceApprove( |
| ... | ... | @@ -996,17 +1021,18 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 996 | 1021 | if (ObjUtil.notEqual(instance.getName(), name)) { |
| 997 | 1022 | runtimeService.setProcessInstanceName(instance.getProcessInstanceId(), name); |
| 998 | 1023 | } |
| 1024 | + | |
| 1025 | + // 流程前置通知:需要在流程启动后(事务提交后),保证 variables 已设置 | |
| 1026 | + // 相关问题链接:https://t.zsxq.com/DF7Kq | |
| 1027 | + if (ObjUtil.isNull(processDefinitionInfo.getProcessBeforeTriggerSetting())) { | |
| 1028 | + return; | |
| 1029 | + } | |
| 1030 | + BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getProcessBeforeTriggerSetting(); | |
| 1031 | + BpmHttpRequestUtils.executeBpmHttpRequest(instance, | |
| 1032 | + setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse()); | |
| 999 | 1033 | } |
| 1000 | 1034 | |
| 1001 | 1035 | }); |
| 1002 | - | |
| 1003 | - // 流程前置通知 | |
| 1004 | - if (ObjUtil.isNull(processDefinitionInfo.getProcessBeforeTriggerSetting())) { | |
| 1005 | - return; | |
| 1006 | - } | |
| 1007 | - BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getProcessBeforeTriggerSetting(); | |
| 1008 | - BpmHttpRequestUtils.executeBpmHttpRequest(instance, | |
| 1009 | - setting.getUrl(), setting.getHeader(), setting.getBody(), true, setting.getResponse()); | |
| 1010 | 1036 | } |
| 1011 | 1037 | |
| 1012 | 1038 | } | ... | ... |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -804,7 +804,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 804 | 804 | .setTargetTaskDefinitionKey(returnTaskId).setReason(reqVO.getReason())); |
| 805 | 805 | return; |
| 806 | 806 | } |
| 807 | - // 3.2 情况二:直接结束,审批不通过 | |
| 807 | + | |
| 808 | + // 3.2 情况二: 标记流程为不通过并结束流程 | |
| 808 | 809 | processInstanceService.updateProcessInstanceReject(instance, reqVO.getReason()); // 标记不通过 |
| 809 | 810 | moveTaskToEnd(task.getProcessInstanceId(), BpmCommentTypeEnum.REJECT.formatComment(reqVO.getReason())); // 结束流程 |
| 810 | 811 | } |
| ... | ... | @@ -986,6 +987,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 986 | 987 | } |
| 987 | 988 | |
| 988 | 989 | @Override |
| 990 | + @Transactional(rollbackFor = Exception.class) | |
| 989 | 991 | public void moveTaskToEnd(String processInstanceId, String reason) { |
| 990 | 992 | List<Task> taskList = getRunningTaskListByProcessInstanceId(processInstanceId, null, null); |
| 991 | 993 | if (CollUtil.isEmpty(taskList)) { | ... | ... |