review: 校验流程设计器第一个用户任务节点的规则类型是否为“审批人自选”

This commit is contained in:
smallNorthLee 2025-03-11 22:37:23 +08:00
parent 2123d7c067
commit cc61bb1a61
1 changed files with 11 additions and 10 deletions

View File

@ -40,10 +40,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
@ -210,11 +207,11 @@ public class BpmModelServiceImpl implements BpmModelService {
public void deployModel(Long userId, String id) { public void deployModel(Long userId, String id) {
// 1.1 校验流程模型存在 // 1.1 校验流程模型存在
Model model = validateModelManager(id, userId); Model model = validateModelManager(id, userId);
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
// 1.2 校验流程图 // 1.2 校验流程图
byte[] bpmnBytes = getModelBpmnXML(model.getId()); byte[] bpmnBytes = getModelBpmnXML(model.getId());
validateBpmnXml(bpmnBytes); validateBpmnXml(bpmnBytes, metaInfo.getType());
// 1.3 校验表单已配 // 1.3 校验表单已配
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
BpmFormDO form = validateFormConfig(metaInfo); BpmFormDO form = validateFormConfig(metaInfo);
// 1.4 校验任务分配规则已配置 // 1.4 校验任务分配规则已配置
taskCandidateInvoker.validateBpmnConfig(bpmnBytes); taskCandidateInvoker.validateBpmnConfig(bpmnBytes);
@ -234,7 +231,7 @@ public class BpmModelServiceImpl implements BpmModelService {
repositoryService.saveModel(model); repositoryService.saveModel(model);
} }
private void validateBpmnXml(byte[] bpmnBytes) { private void validateBpmnXml(byte[] bpmnBytes, int type) {
BpmnModel bpmnModel = BpmnModelUtils.getBpmnModel(bpmnBytes); BpmnModel bpmnModel = BpmnModelUtils.getBpmnModel(bpmnBytes);
if (bpmnModel == null) { if (bpmnModel == null) {
throw exception(MODEL_NOT_EXISTS); throw exception(MODEL_NOT_EXISTS);
@ -252,10 +249,14 @@ public class BpmModelServiceImpl implements BpmModelService {
} }
}); });
// 3. 校验第一个用户任务节点的规则类型是否为审批人自选 // 3. 校验第一个用户任务节点的规则类型是否为审批人自选
UserTask userTask = userTasks.get(0); Map<Integer, UserTask> userTaskMap = new HashMap<>();
Integer candidateStrategy = parseCandidateStrategy(userTask); // BPMN 设计器校验第一个用户任务节点
userTaskMap.put(BpmModelTypeEnum.BPMN.getType(), userTasks.get(0));
// SIMPLE 设计器第一个节点固定为发起人所以校验第二个用户任务节点
userTaskMap.put(BpmModelTypeEnum.SIMPLE.getType(), userTasks.get(1));
Integer candidateStrategy = parseCandidateStrategy(userTaskMap.get(type));
if (Objects.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) { if (Objects.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) {
throw exception(MODEL_DEPLOY_FAIL_FIRST_USER_TASK_CANDIDATE_STRATEGY_ERROR, userTask.getName()); throw exception(MODEL_DEPLOY_FAIL_FIRST_USER_TASK_CANDIDATE_STRATEGY_ERROR, userTaskMap.get(type).getName());
} }
} }