|
|
@@ -2,12 +2,15 @@ package cn.iocoder.yudao.module.mes.service.qc.indicator;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorPageReqVO;
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.qc.indicator.vo.MesQcIndicatorSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicator.MesQcIndicatorDO;
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.qc.indicator.MesQcIndicatorMapper;
|
|
|
+import cn.iocoder.yudao.module.mes.enums.qc.MesQcResultValueTypeEnum;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
@@ -33,10 +36,8 @@ public class MesQcIndicatorServiceImpl implements MesQcIndicatorService {
|
|
|
|
|
|
@Override
|
|
|
public Long createIndicator(MesQcIndicatorSaveReqVO createReqVO) {
|
|
|
- // 校验编码唯一
|
|
|
- validateIndicatorCodeUnique(null, createReqVO.getCode());
|
|
|
- // 校验名称唯一
|
|
|
- validateIndicatorNameUnique(null, createReqVO.getName());
|
|
|
+ // 校验相关参数
|
|
|
+ validateIndicatorSaveData(null, createReqVO);
|
|
|
|
|
|
// 插入
|
|
|
MesQcIndicatorDO indicator = BeanUtils.toBean(createReqVO, MesQcIndicatorDO.class);
|
|
|
@@ -48,10 +49,8 @@ public class MesQcIndicatorServiceImpl implements MesQcIndicatorService {
|
|
|
public void updateIndicator(MesQcIndicatorSaveReqVO updateReqVO) {
|
|
|
// 校验存在
|
|
|
validateIndicatorExists(updateReqVO.getId());
|
|
|
- // 校验编码唯一
|
|
|
- validateIndicatorCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
|
|
|
- // 校验名称唯一
|
|
|
- validateIndicatorNameUnique(updateReqVO.getId(), updateReqVO.getName());
|
|
|
+ // 校验相关参数
|
|
|
+ validateIndicatorSaveData(updateReqVO.getId(), updateReqVO);
|
|
|
|
|
|
// 更新
|
|
|
MesQcIndicatorDO updateObj = BeanUtils.toBean(updateReqVO, MesQcIndicatorDO.class);
|
|
|
@@ -66,6 +65,15 @@ public class MesQcIndicatorServiceImpl implements MesQcIndicatorService {
|
|
|
indicatorMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
+ private void validateIndicatorSaveData(Long id, MesQcIndicatorSaveReqVO saveReqVO) {
|
|
|
+ // 校验编码唯一
|
|
|
+ validateIndicatorCodeUnique(id, saveReqVO.getCode());
|
|
|
+ // 校验名称唯一
|
|
|
+ validateIndicatorNameUnique(id, saveReqVO.getName());
|
|
|
+ // 校验结果值属性
|
|
|
+ validateResultSpecification(saveReqVO.getResultType(), saveReqVO.getResultSpecification());
|
|
|
+ }
|
|
|
+
|
|
|
private void validateIndicatorExists(Long id) {
|
|
|
if (indicatorMapper.selectById(id) == null) {
|
|
|
throw exception(QC_INDICATOR_NOT_EXISTS);
|
|
|
@@ -92,6 +100,15 @@ public class MesQcIndicatorServiceImpl implements MesQcIndicatorService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void validateResultSpecification(Integer resultType, String resultSpecification) {
|
|
|
+ if (ObjectUtils.equalsAny(resultType, MesQcResultValueTypeEnum.FILE.getType(),
|
|
|
+ MesQcResultValueTypeEnum.DICT.getType())) {
|
|
|
+ if (StrUtil.isBlank(resultSpecification)) {
|
|
|
+ throw exception(QC_INDICATOR_RESULT_SPECIFICATION_REQUIRED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public MesQcIndicatorDO getIndicator(Long id) {
|
|
|
return indicatorMapper.selectById(id);
|