Commit d9722c13469ed08ae967a3fce2064913998d0114
1 parent
f882ef58
✨ feat(mes): 新增质检指标结果值属性校验
Showing
2 changed files
with
26 additions
and
8 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
| ... | ... | @@ -294,6 +294,7 @@ public interface ErrorCodeConstants { |
| 294 | 294 | ErrorCode QC_INDICATOR_NOT_EXISTS = new ErrorCode(1_040_601_000, "质检指标不存在"); |
| 295 | 295 | ErrorCode QC_INDICATOR_CODE_DUPLICATE = new ErrorCode(1_040_601_001, "质检指标编码已存在"); |
| 296 | 296 | ErrorCode QC_INDICATOR_NAME_DUPLICATE = new ErrorCode(1_040_601_002, "质检指标名称已存在"); |
| 297 | + ErrorCode QC_INDICATOR_RESULT_SPECIFICATION_REQUIRED = new ErrorCode(1_040_601_003, "结果值属性不能为空"); | |
| 297 | 298 | |
| 298 | 299 | // ========== MES 质量管理-缺陷类型(1-040-602-000) ========== |
| 299 | 300 | ErrorCode QC_DEFECT_NOT_EXISTS = new ErrorCode(1_040_602_000, "缺陷类型不存在"); | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/indicator/MesQcIndicatorServiceImpl.java
| ... | ... | @@ -2,12 +2,15 @@ package cn.iocoder.yudao.module.mes.service.qc.indicator; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjUtil; |
| 5 | +import cn.hutool.core.util.StrUtil; | |
| 5 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | |
| 7 | 9 | import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorPageReqVO; |
| 8 | 10 | import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorSaveReqVO; |
| 9 | 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicator.MesQcIndicatorDO; |
| 10 | 12 | import cn.iocoder.yudao.module.mes.dal.mysql.qc.indicator.MesQcIndicatorMapper; |
| 13 | +import cn.iocoder.yudao.module.mes.enums.qc.MesQcResultValueTypeEnum; | |
| 11 | 14 | import jakarta.annotation.Resource; |
| 12 | 15 | import org.springframework.stereotype.Service; |
| 13 | 16 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -33,10 +36,8 @@ public class MesQcIndicatorServiceImpl implements MesQcIndicatorService { |
| 33 | 36 | |
| 34 | 37 | @Override |
| 35 | 38 | public Long createIndicator(MesQcIndicatorSaveReqVO createReqVO) { |
| 36 | - // 校验编码唯一 | |
| 37 | - validateIndicatorCodeUnique(null, createReqVO.getCode()); | |
| 38 | - // 校验名称唯一 | |
| 39 | - validateIndicatorNameUnique(null, createReqVO.getName()); | |
| 39 | + // 校验相关参数 | |
| 40 | + validateIndicatorSaveData(null, createReqVO); | |
| 40 | 41 | |
| 41 | 42 | // 插入 |
| 42 | 43 | MesQcIndicatorDO indicator = BeanUtils.toBean(createReqVO, MesQcIndicatorDO.class); |
| ... | ... | @@ -48,10 +49,8 @@ public class MesQcIndicatorServiceImpl implements MesQcIndicatorService { |
| 48 | 49 | public void updateIndicator(MesQcIndicatorSaveReqVO updateReqVO) { |
| 49 | 50 | // 校验存在 |
| 50 | 51 | validateIndicatorExists(updateReqVO.getId()); |
| 51 | - // 校验编码唯一 | |
| 52 | - validateIndicatorCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); | |
| 53 | - // 校验名称唯一 | |
| 54 | - validateIndicatorNameUnique(updateReqVO.getId(), updateReqVO.getName()); | |
| 52 | + // 校验相关参数 | |
| 53 | + validateIndicatorSaveData(updateReqVO.getId(), updateReqVO); | |
| 55 | 54 | |
| 56 | 55 | // 更新 |
| 57 | 56 | MesQcIndicatorDO updateObj = BeanUtils.toBean(updateReqVO, MesQcIndicatorDO.class); |
| ... | ... | @@ -66,6 +65,15 @@ public class MesQcIndicatorServiceImpl implements MesQcIndicatorService { |
| 66 | 65 | indicatorMapper.deleteById(id); |
| 67 | 66 | } |
| 68 | 67 | |
| 68 | + private void validateIndicatorSaveData(Long id, MesQcIndicatorSaveReqVO saveReqVO) { | |
| 69 | + // 校验编码唯一 | |
| 70 | + validateIndicatorCodeUnique(id, saveReqVO.getCode()); | |
| 71 | + // 校验名称唯一 | |
| 72 | + validateIndicatorNameUnique(id, saveReqVO.getName()); | |
| 73 | + // 校验结果值属性 | |
| 74 | + validateResultSpecification(saveReqVO.getResultType(), saveReqVO.getResultSpecification()); | |
| 75 | + } | |
| 76 | + | |
| 69 | 77 | private void validateIndicatorExists(Long id) { |
| 70 | 78 | if (indicatorMapper.selectById(id) == null) { |
| 71 | 79 | throw exception(QC_INDICATOR_NOT_EXISTS); |
| ... | ... | @@ -92,6 +100,15 @@ public class MesQcIndicatorServiceImpl implements MesQcIndicatorService { |
| 92 | 100 | } |
| 93 | 101 | } |
| 94 | 102 | |
| 103 | + private void validateResultSpecification(Integer resultType, String resultSpecification) { | |
| 104 | + if (ObjectUtils.equalsAny(resultType, MesQcResultValueTypeEnum.FILE.getType(), | |
| 105 | + MesQcResultValueTypeEnum.DICT.getType())) { | |
| 106 | + if (StrUtil.isBlank(resultSpecification)) { | |
| 107 | + throw exception(QC_INDICATOR_RESULT_SPECIFICATION_REQUIRED); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 95 | 112 | @Override |
| 96 | 113 | public MesQcIndicatorDO getIndicator(Long id) { |
| 97 | 114 | return indicatorMapper.selectById(id); | ... | ... |