Commit 0a55adca0ef69df3f235da1d7247a1ebbde9262c
1 parent
62362e2e
refactor(mes): 优化设备保养记录模块代码风格,提升校验方法复用性
1. 新增 MesDvMaintenRecordStatusEnum 保养记录状态枚举(草稿/已提交) 2. 各 Service 接口暴露 validateXxxExists 公共校验方法(Machinery、CheckPlan、Subject、MaintenRecord), 消除跨 Service 手动 null 判断 + 抛异常的重复代码 3. CheckPlanServiceImpl 改用链式调用更新状态,validateCheckPlanCodeUnique 使用 ObjUtil.notEqual
Showing
3 changed files
with
26 additions
and
2 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordLineServiceImpl.java
| ... | ... | @@ -62,6 +62,13 @@ public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLine |
| 62 | 62 | maintenRecordLineMapper.deleteById(id); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + private void validateMaintenRecordLineRelation(MesDvMaintenRecordLineSaveReqVO reqVO) { | |
| 66 | + // 校验设备保养记录是否存在 | |
| 67 | + maintenRecordService.validateMaintenRecordExists(reqVO.getRecordId()); | |
| 68 | + // 校验保养项目是否存在 | |
| 69 | + subjectService.validateSubjectExists(reqVO.getSubjectId()); | |
| 70 | + } | |
| 71 | + | |
| 65 | 72 | private void validateMaintenRecordLineExists(Long id) { |
| 66 | 73 | if (maintenRecordLineMapper.selectById(id) == null) { |
| 67 | 74 | throw exception(MAINTEN_RECORD_LINE_NOT_EXISTS); | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordService.java
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordServiceImpl.java
| ... | ... | @@ -53,7 +53,7 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService |
| 53 | 53 | // 1.2 校验关联数据 |
| 54 | 54 | validateMaintenRecordRelation(updateReqVO); |
| 55 | 55 | |
| 56 | - // 更新 | |
| 56 | + // 2. 更新 | |
| 57 | 57 | MesDvMaintenRecordDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordDO.class); |
| 58 | 58 | maintenRecordMapper.updateById(updateObj); |
| 59 | 59 | } |
| ... | ... | @@ -70,7 +70,17 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService |
| 70 | 70 | maintenRecordLineMapper.deleteByRecordId(id); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - private void validateMaintenRecordExists(Long id) { | |
| 73 | + private void validateMaintenRecordRelation(MesDvMaintenRecordSaveReqVO reqVO) { | |
| 74 | + // 校验设备是否存在 | |
| 75 | + machineryService.validateMachineryExists(reqVO.getMachineryId()); | |
| 76 | + // 校验保养计划是否存在 | |
| 77 | + if (reqVO.getPlanId() != null) { | |
| 78 | + checkPlanService.validateCheckPlanExists(reqVO.getPlanId()); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + @Override | |
| 83 | + public void validateMaintenRecordExists(Long id) { | |
| 74 | 84 | if (maintenRecordMapper.selectById(id) == null) { |
| 75 | 85 | throw exception(MAINTEN_RECORD_NOT_EXISTS); |
| 76 | 86 | } | ... | ... |