!1297 fix: 修复simple设计器第一个发起人节点,审批时校验是否存在审批人导致流程异常

Merge pull request !1297 from SamllNorth_Lee/feature/bpm
This commit is contained in:
芋道源码 2025-03-22 14:51:58 +00:00 committed by Gitee
commit 26c1a10b0c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 17 additions and 12 deletions

View File

@ -267,7 +267,6 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey()); FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables); List<FlowNode> nextFlowNodes = BpmnModelUtils.getNextFlowNodes(flowElement, bpmnModel, processVariables);
// TODO @小北还是可以优化下哈4. 组装节点信息 只拼接出 candidateUserIds之后再第二次循环查询用户和部门信息进行拼接
// 2. 收集所有节点的候选用户 ID // 2. 收集所有节点的候选用户 ID
Set<Long> allCandidateUsers = new HashSet<>(); Set<Long> allCandidateUsers = new HashSet<>();
for (FlowNode node : nextFlowNodes) { for (FlowNode node : nextFlowNodes) {
@ -287,13 +286,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables); loginUserId, historicProcessInstance.getProcessDefinitionId(), processVariables);
// 4.2 组装候选用户信息 // 4.2 组装候选用户信息
List<UserSimpleBaseVO> candidateUsers = new ArrayList<>(); List<UserSimpleBaseVO> candidateUsers = convertList(candidateUserIds, userId -> {
for (Long userId : candidateUserIds) { AdminUserRespDTO user = userMap.get(userId);
UserSimpleBaseVO user = BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap);
if (user != null) { if (user != null) {
candidateUsers.add(user); return BpmProcessInstanceConvert.INSTANCE.buildUser(userId, userMap, deptMap);
} }
} return null;
});
// 4.3 构建节点信息 // 4.3 构建节点信息
return new ActivityNode() return new ActivityNode()

View File

@ -599,6 +599,10 @@ public class BpmTaskServiceImpl implements BpmTaskService {
*/ */
private Map<String, Object> validateAndSetNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel, private Map<String, Object> validateAndSetNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel,
Map<String, List<Long>> nextAssignees, ProcessInstance processInstance) { Map<String, List<Long>> nextAssignees, ProcessInstance processInstance) {
// Simple设计器第一个节点默认为发起人节点不校验是否存在审批人
if (taskDefinitionKey.equals(START_USER_NODE_ID)) {
return variables;
}
// 1. 获取下一个将要执行的节点集合 // 1. 获取下一个将要执行的节点集合
FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey); FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey);
List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables); List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables);
@ -609,16 +613,17 @@ public class BpmTaskServiceImpl implements BpmTaskService {
Integer candidateStrategy = parseCandidateStrategy(nextFlowNode); Integer candidateStrategy = parseCandidateStrategy(nextFlowNode);
// 2.1 情况一如果节点中的审批人策略为 发起人自选 // 2.1 情况一如果节点中的审批人策略为 发起人自选
if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy())) { if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy())) {
// 如果节点存在但未配置审批人 // 先从历史中获取审批人在发起人会把所有的审批人保存到历史中这里从历史中获取
List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
if (CollUtil.isEmpty(assignees)) {
throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
}
processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables()); processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables());
// 特殊如果当前节点已经存在审批人则不允许覆盖 // 特殊如果当前节点已经存在审批人则不允许覆盖
if (processVariables != null && CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) { if (processVariables != null && CollUtil.isNotEmpty(processVariables.get(nextFlowNode.getId()))) {
continue; continue;
} }
// 如果节点存在但未配置审批人
List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
if (CollUtil.isEmpty(assignees)) {
throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
}
// 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES // 设置 PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES
if (processVariables == null) { if (processVariables == null) {
processVariables = new HashMap<>(); processVariables = new HashMap<>();
@ -628,12 +633,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
} }
// 2.2 情况二如果节点中的审批人策略为 审批人在审批时选择下一个节点的审批人并且该节点的审批人为空 // 2.2 情况二如果节点中的审批人策略为 审批人在审批时选择下一个节点的审批人并且该节点的审批人为空
if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) { if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) {
// 获取审批人自选的历史变量
processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables());
// 如果节点存在但未配置审批人 // 如果节点存在但未配置审批人
List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null; List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
if (CollUtil.isEmpty(assignees)) { if (CollUtil.isEmpty(assignees)) {
throw exception(PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName()); throw exception(PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
} }
processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables());
if (processVariables == null) { if (processVariables == null) {
processVariables = new HashMap<>(); processVariables = new HashMap<>();
} }