Commit 390b7d296960874930a2fd9fab85a9e0bb1b292b
1 parent
b4b7cb7a
✨ feat(mes): 重构机械类型校验逻辑,简化代码实现
Showing
1 changed file
with
17 additions
and
14 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryTypeServiceImpl.java
| @@ -36,12 +36,8 @@ public class MesDvMachineryTypeServiceImpl implements MesDvMachineryTypeService | @@ -36,12 +36,8 @@ public class MesDvMachineryTypeServiceImpl implements MesDvMachineryTypeService | ||
| 36 | 36 | ||
| 37 | @Override | 37 | @Override |
| 38 | public Long createMachineryType(MesDvMachineryTypeSaveReqVO createReqVO) { | 38 | public Long createMachineryType(MesDvMachineryTypeSaveReqVO createReqVO) { |
| 39 | - // 校验父类型编号的有效性 | ||
| 40 | - validateParentMachineryType(null, createReqVO.getParentId()); | ||
| 41 | - // 校验类型名称的唯一性 | ||
| 42 | - validateMachineryTypeNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); | ||
| 43 | - // 校验类型编码的唯一性 | ||
| 44 | - validateMachineryTypeCodeUnique(null, createReqVO.getParentId(), createReqVO.getCode()); | 39 | + // 校验 |
| 40 | + validateMachineryTypeSave(null, createReqVO.getParentId(), createReqVO.getName(), createReqVO.getCode()); | ||
| 45 | 41 | ||
| 46 | // 插入 | 42 | // 插入 |
| 47 | MesDvMachineryTypeDO machineryType = BeanUtils.toBean(createReqVO, MesDvMachineryTypeDO.class); | 43 | MesDvMachineryTypeDO machineryType = BeanUtils.toBean(createReqVO, MesDvMachineryTypeDO.class); |
| @@ -51,14 +47,8 @@ public class MesDvMachineryTypeServiceImpl implements MesDvMachineryTypeService | @@ -51,14 +47,8 @@ public class MesDvMachineryTypeServiceImpl implements MesDvMachineryTypeService | ||
| 51 | 47 | ||
| 52 | @Override | 48 | @Override |
| 53 | public void updateMachineryType(MesDvMachineryTypeSaveReqVO updateReqVO) { | 49 | public void updateMachineryType(MesDvMachineryTypeSaveReqVO updateReqVO) { |
| 54 | - // 校验存在 | ||
| 55 | - validateMachineryTypeExists(updateReqVO.getId()); | ||
| 56 | - // 校验父类型编号的有效性 | ||
| 57 | - validateParentMachineryType(updateReqVO.getId(), updateReqVO.getParentId()); | ||
| 58 | - // 校验类型名称的唯一性 | ||
| 59 | - validateMachineryTypeNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); | ||
| 60 | - // 校验类型编码的唯一性 | ||
| 61 | - validateMachineryTypeCodeUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getCode()); | 50 | + // 校验 |
| 51 | + validateMachineryTypeSave(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName(), updateReqVO.getCode()); | ||
| 62 | 52 | ||
| 63 | // 更新 | 53 | // 更新 |
| 64 | MesDvMachineryTypeDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMachineryTypeDO.class); | 54 | MesDvMachineryTypeDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMachineryTypeDO.class); |
| @@ -82,6 +72,18 @@ public class MesDvMachineryTypeServiceImpl implements MesDvMachineryTypeService | @@ -82,6 +72,18 @@ public class MesDvMachineryTypeServiceImpl implements MesDvMachineryTypeService | ||
| 82 | machineryTypeMapper.deleteById(id); | 72 | machineryTypeMapper.deleteById(id); |
| 83 | } | 73 | } |
| 84 | 74 | ||
| 75 | + private void validateMachineryTypeSave(Long id, Long parentId, String name, String code) { | ||
| 76 | + if (id != null) { | ||
| 77 | + validateMachineryTypeExists(id); | ||
| 78 | + } | ||
| 79 | + // 校验父级节点有效性 | ||
| 80 | + validateParentMachineryType(id, parentId); | ||
| 81 | + // 校验类型名称唯一性 | ||
| 82 | + validateMachineryTypeNameUnique(id, parentId, name); | ||
| 83 | + // 校验类型编码唯一性 | ||
| 84 | + validateMachineryTypeCodeUnique(id, parentId, code); | ||
| 85 | + } | ||
| 86 | + | ||
| 85 | private void validateMachineryTypeExists(Long id) { | 87 | private void validateMachineryTypeExists(Long id) { |
| 86 | if (machineryTypeMapper.selectById(id) == null) { | 88 | if (machineryTypeMapper.selectById(id) == null) { |
| 87 | throw exception(DV_MACHINERY_TYPE_NOT_EXISTS); | 89 | throw exception(DV_MACHINERY_TYPE_NOT_EXISTS); |
| @@ -133,6 +135,7 @@ public class MesDvMachineryTypeServiceImpl implements MesDvMachineryTypeService | @@ -133,6 +135,7 @@ public class MesDvMachineryTypeServiceImpl implements MesDvMachineryTypeService | ||
| 133 | } | 135 | } |
| 134 | 136 | ||
| 135 | private void validateMachineryTypeCodeUnique(Long id, Long parentId, String code) { | 137 | private void validateMachineryTypeCodeUnique(Long id, Long parentId, String code) { |
| 138 | + // TODO @yunai:类型编码的唯一性,建议全局校验,而非同一父级下校验 | ||
| 136 | MesDvMachineryTypeDO machineryType = machineryTypeMapper.selectByParentIdAndCode(parentId, code); | 139 | MesDvMachineryTypeDO machineryType = machineryTypeMapper.selectByParentIdAndCode(parentId, code); |
| 137 | if (machineryType == null) { | 140 | if (machineryType == null) { |
| 138 | return; | 141 | return; |