Commit 0a55adca0ef69df3f235da1d7247a1ebbde9262c

Authored by YunaiV
1 parent 62362e2e

refactor(mes): 优化设备保养记录模块代码风格,提升校验方法复用性

1. 新增 MesDvMaintenRecordStatusEnum 保养记录状态枚举(草稿/已提交)
2. 各 Service 接口暴露 validateXxxExists 公共校验方法(Machinery、CheckPlan、Subject、MaintenRecord),
   消除跨 Service 手动 null 判断 + 抛异常的重复代码
3. CheckPlanServiceImpl 改用链式调用更新状态,validateCheckPlanCodeUnique 使用 ObjUtil.notEqual
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,6 +62,13 @@ public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLine
62 maintenRecordLineMapper.deleteById(id); 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 private void validateMaintenRecordLineExists(Long id) { 72 private void validateMaintenRecordLineExists(Long id) {
66 if (maintenRecordLineMapper.selectById(id) == null) { 73 if (maintenRecordLineMapper.selectById(id) == null) {
67 throw exception(MAINTEN_RECORD_LINE_NOT_EXISTS); 74 throw exception(MAINTEN_RECORD_LINE_NOT_EXISTS);
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordService.java
@@ -37,6 +37,13 @@ public interface MesDvMaintenRecordService { @@ -37,6 +37,13 @@ public interface MesDvMaintenRecordService {
37 void deleteMaintenRecord(Long id); 37 void deleteMaintenRecord(Long id);
38 38
39 /** 39 /**
  40 + * 校验设备保养记录存在
  41 + *
  42 + * @param id 编号
  43 + */
  44 + void validateMaintenRecordExists(Long id);
  45 +
  46 + /**
40 * 获得设备保养记录 47 * 获得设备保养记录
41 * 48 *
42 * @param id 编号 49 * @param id 编号
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,7 +53,7 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService
53 // 1.2 校验关联数据 53 // 1.2 校验关联数据
54 validateMaintenRecordRelation(updateReqVO); 54 validateMaintenRecordRelation(updateReqVO);
55 55
56 - // 更新 56 + // 2. 更新
57 MesDvMaintenRecordDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordDO.class); 57 MesDvMaintenRecordDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordDO.class);
58 maintenRecordMapper.updateById(updateObj); 58 maintenRecordMapper.updateById(updateObj);
59 } 59 }
@@ -70,7 +70,17 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService @@ -70,7 +70,17 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService
70 maintenRecordLineMapper.deleteByRecordId(id); 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 if (maintenRecordMapper.selectById(id) == null) { 84 if (maintenRecordMapper.selectById(id) == null) {
75 throw exception(MAINTEN_RECORD_NOT_EXISTS); 85 throw exception(MAINTEN_RECORD_NOT_EXISTS);
76 } 86 }