feat(procparam): 优化参数名称重复校验逻辑

This commit is contained in:
zxy 2026-05-09 11:03:24 +08:00
parent 2ab3545bc0
commit 3f736ac4b4
2 changed files with 16 additions and 1 deletions

View File

@ -60,6 +60,11 @@ public class ServiceExceptionUtil {
return exception0(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), messagePattern);
}
public static ServiceException exception(String message, Object... params) {
String messagePattern = MESSAGES.getOrDefault(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), message);
return exception0(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), messagePattern, params);
}
/**
* 创建指定编号的 ServiceException 的异常
*

View File

@ -1,11 +1,14 @@
package com.ningxia.yunxi.chemmes.module.biz.service.procparam;
import com.ningxia.yunxi.chemmes.framework.common.exception.util.ServiceExceptionUtil;
import com.ningxia.yunxi.chemmes.framework.common.pojo.PageResult;
import com.ningxia.yunxi.chemmes.framework.common.util.object.BeanUtils;
import com.ningxia.yunxi.chemmes.module.biz.controller.admin.procparam.vo.ProcParamPageReqVO;
import com.ningxia.yunxi.chemmes.module.biz.controller.admin.procparam.vo.ProcParamSaveReqVO;
import com.ningxia.yunxi.chemmes.module.biz.dal.dataobject.procparam.ProcParamDO;
import com.ningxia.yunxi.chemmes.module.biz.dal.mysql.procparam.ProcParamMapper;
import com.ningxia.yunxi.chemmes.module.system.dal.dataobject.dict.DictDataDO;
import com.ningxia.yunxi.chemmes.module.system.service.dict.DictDataService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -26,6 +29,9 @@ public class ProcParamServiceImpl implements ProcParamService {
@Resource
private ProcParamMapper procParamMapper;
@Resource
private DictDataService dictService;
@Override
public Integer createProcParam(ProcParamSaveReqVO createReqVO) {
// 插入
@ -67,7 +73,11 @@ public class ProcParamServiceImpl implements ProcParamService {
saveReqVO.getProcParamName());
if (existParam != null && !existParam.getId().equals(saveReqVO.getId())) {
throw exception("同一工序下同一参数类别的参数名称不能重复");
// 通过字典获取参数类别
DictDataDO paramType = dictService.getDictData("param_type", saveReqVO.getProcParamType());
// 方式二:使用 invalidParamException(支持占位符)
throw ServiceExceptionUtil.exception("工序({}+ 参数类别({}+ 参数名称已配置",
saveReqVO.getProcName(), paramType.getLabel());
}
}