【代码评审】BPM:子流程的代码

This commit is contained in:
YunaiV 2025-03-25 12:49:34 +08:00
parent 2cf5e17f4b
commit f0c26d5b5a
3 changed files with 9 additions and 10 deletions

View File

@ -42,7 +42,7 @@ public interface ErrorCodeConstants {
ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_005, "流程取消失败,该流程不允许取消");
ErrorCode PROCESS_INSTANCE_HTTP_TRIGGER_CALL_ERROR = new ErrorCode(1_009_004_006, "流程 Http 触发器请求调用失败");
ErrorCode PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG = new ErrorCode(1_009_004_007, "下一个任务({})的审批人未配置");
ErrorCode CHILD_PROCESS_INSTANCE_CANCEL_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_008, "子流程取消失败,子流程不允许取消");
ErrorCode PROCESS_INSTANCE_CANCEL_CHILD_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_008, "子流程取消失败,子流程不允许取消");
// ========== 流程任务 1-009-005-000 ==========
ErrorCode TASK_OPERATE_FAIL_ASSIGN_NOT_SELF = new ErrorCode(1_009_005_001, "操作失败,原因:该任务的审批人不是你");

View File

@ -73,7 +73,7 @@ public class BpmApprovalDetailRespVO {
private List<UserSimpleBaseVO> candidateUsers; // 只包含未生成 ApprovalTaskInfo 的用户列表
@Schema(description = "流程编号", example = "8761d8e0-0922-11f0-bd37-00ff1db677bf")
private String processInstanceId;
private String processInstanceId; // 当且仅当该节点是子流程节点时才会有值CallActivity processInstanceId 字段
}

View File

@ -453,6 +453,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
approvalNodes.add(callActivity);
}
});
// 按照时间排序
approvalNodes.sort(Comparator.comparing(ActivityNode::getStartTime));
return approvalNodes;
}
@ -836,7 +838,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
}
// 1.4 子流程不允许取消
if (StrUtil.isNotBlank(instance.getSuperExecutionId())) {
throw exception(CHILD_PROCESS_INSTANCE_CANCEL_FAIL_NOT_ALLOW);
throw exception(PROCESS_INSTANCE_CANCEL_CHILD_FAIL_NOT_ALLOW);
}
// 2. 取消流程
@ -865,13 +867,10 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
runtimeService.setVariable(id, BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_REASON, reason);
// 2. 取消所有子流程
List<ProcessInstance> subProcessInstances = runtimeService.createProcessInstanceQuery()
.superProcessInstanceId(id)
.list();
subProcessInstances.forEach(processInstance -> {
updateProcessInstanceCancel(processInstance.getProcessInstanceId(),
BpmReasonEnum.CANCEL_CHILD_PROCESS_INSTANCE_BY_MAIN_PROCESS.getReason());
});
List<ProcessInstance> childProcessInstances = runtimeService.createProcessInstanceQuery()
.superProcessInstanceId(id).list();
childProcessInstances.forEach(processInstance -> updateProcessInstanceCancel(
processInstance.getProcessInstanceId(), BpmReasonEnum.CANCEL_CHILD_PROCESS_INSTANCE_BY_MAIN_PROCESS.getReason()));
// 3. 结束流程
taskService.moveTaskToEnd(id, reason);