perf: [BPM 工作流] 子流程审批不通过,主流程审批不通过流程优化
This commit is contained in:
@@ -52,6 +52,7 @@ import org.flowable.engine.history.HistoricActivityInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstanceQuery;
|
||||
import org.flowable.engine.repository.ProcessDefinition;
|
||||
import org.flowable.engine.runtime.Execution;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.engine.runtime.ProcessInstanceBuilder;
|
||||
import org.flowable.task.api.Task;
|
||||
@@ -69,6 +70,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
import static cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ActivityNode;
|
||||
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum.REJECT_CHILD_PROCESS;
|
||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID;
|
||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.parseNodeType;
|
||||
import static java.util.Arrays.asList;
|
||||
@@ -949,6 +951,27 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
||||
status);
|
||||
}
|
||||
|
||||
// 1.3 如果子流程拒绝, 设置其父流程也为拒绝状态且结束父流程
|
||||
if (Objects.equals(status, BpmProcessInstanceStatusEnum.REJECT.getStatus())
|
||||
&& StrUtil.isNotBlank(instance.getSuperExecutionId())) {
|
||||
// 1.3.1 获取父流程实例 并标记为不通过
|
||||
Execution execution = runtimeService.createExecutionQuery().executionId(instance.getSuperExecutionId()).singleResult();
|
||||
ProcessInstance parentProcessInstance = getProcessInstance(execution.getProcessInstanceId());
|
||||
updateProcessInstanceReject(parentProcessInstance, REJECT_CHILD_PROCESS.getReason());
|
||||
|
||||
// 1.3.2 结束父流程。需要在子流程结束事务提交后执行
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCompletion(int transactionStatus) {
|
||||
// 回滚情况,直接返回
|
||||
if (ObjectUtil.equal(transactionStatus, TransactionSynchronization.STATUS_ROLLED_BACK)) {
|
||||
return;
|
||||
}
|
||||
taskService.moveTaskToEnd(parentProcessInstance.getId(),REJECT_CHILD_PROCESS.getReason());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 2. 发送对应的消息通知
|
||||
if (Objects.equals(status, BpmProcessInstanceStatusEnum.APPROVE.getStatus())) {
|
||||
messageService.sendMessageWhenProcessInstanceApprove(
|
||||
|
||||
@@ -67,7 +67,6 @@ import java.util.stream.Stream;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum.REJECT_CHILD_PROCESS;
|
||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID;
|
||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_RETURN_FLAG;
|
||||
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 {
|
||||
.setTargetTaskDefinitionKey(returnTaskId).setReason(reqVO.getReason()));
|
||||
return;
|
||||
}
|
||||
// 3.2 情况二:直接结束,审批不通过
|
||||
// 3.2.1 如果是子流程,需获取父流程。标记父流程为不通过。
|
||||
// 注意需要在子流程结束前标记,因为如果子流程是最后一个节点。在子流程结束后标记, 会报错
|
||||
ProcessInstance parentProcessInstance = null;
|
||||
if (StrUtil.isNotBlank(instance.getSuperExecutionId())) {
|
||||
Execution execution = runtimeService.createExecutionQuery().executionId(instance.getSuperExecutionId()).singleResult();
|
||||
parentProcessInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
|
||||
// 标记父流程不通过
|
||||
processInstanceService.updateProcessInstanceReject(parentProcessInstance, REJECT_CHILD_PROCESS.getReason());
|
||||
}
|
||||
// 3.2.2 标记流程为不通过并结束流程
|
||||
|
||||
// 3.2 情况二: 标记流程为不通过并结束流程
|
||||
processInstanceService.updateProcessInstanceReject(instance, reqVO.getReason()); // 标记不通过
|
||||
moveTaskToEnd(task.getProcessInstanceId(), BpmCommentTypeEnum.REJECT.formatComment(reqVO.getReason())); // 结束流程
|
||||
|
||||
// 3.2.3 如果是子流程,结束主流程
|
||||
if (parentProcessInstance!=null) {
|
||||
moveTaskToEnd(parentProcessInstance.getId(), BpmCommentTypeEnum.REJECT.formatComment(REJECT_CHILD_PROCESS.getReason()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1002,6 +987,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void moveTaskToEnd(String processInstanceId, String reason) {
|
||||
List<Task> taskList = getRunningTaskListByProcessInstanceId(processInstanceId, null, null);
|
||||
if (CollUtil.isEmpty(taskList)) {
|
||||
|
||||
Reference in New Issue
Block a user