Commit 62362e2edeb116591a14083b3bedbea08cb92729

Authored by YunaiV
1 parent 17fedca9

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/enums/DictTypeConstants.java
... ... @@ -30,5 +30,9 @@ public interface DictTypeConstants {
30 30 String MES_QC_IQC_STATUS = "mes_qc_iqc_status"; // MES 检验单状态
31 31 String MES_QC_CHECK_RESULT = "mes_qc_check_result"; // MES 检测结果
32 32 String MES_QC_SOURCE_DOC_TYPE = "mes_qc_source_doc_type"; // MES 来源单据类型
  33 + String MES_DV_CYCLE_TYPE = "mes_dv_cycle_type"; // MES 点检保养周期类型
  34 + String MES_DV_CHECK_PLAN_STATUS = "mes_dv_check_plan_status"; // MES 点检保养方案状态
  35 + String MES_MAINTEN_RECORD_STATUS = "mes_mainten_record_status"; // MES 保养记录状态
  36 + String MES_MAINTEN_STATUS = "mes_mainten_status"; // MES 保养结果
33 37  
34 38 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/dv/MesDvMaintenRecordStatusEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.enums.dv;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.ArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * MES 设备保养记录状态枚举
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Getter
  15 +@AllArgsConstructor
  16 +public enum MesDvMaintenRecordStatusEnum implements ArrayValuable<Integer> {
  17 +
  18 + PREPARE(0, "草稿"),
  19 + SUBMITTED(1, "已提交");
  20 +
  21 + public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesDvMaintenRecordStatusEnum::getStatus).toArray(Integer[]::new);
  22 +
  23 + /**
  24 + * 状态值
  25 + */
  26 + private final Integer status;
  27 + /**
  28 + * 状态名
  29 + */
  30 + private final String name;
  31 +
  32 + @Override
  33 + public Integer[] array() {
  34 + return ARRAYS;
  35 + }
  36 +
  37 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryService.java
... ... @@ -6,6 +6,12 @@ import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachine
6 6 import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO;
7 7 import jakarta.validation.Valid;
8 8  
  9 +import java.util.Collection;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
  14 +
9 15 /**
10 16 * MES 设备台账 Service 接口
11 17 *
... ... @@ -59,4 +65,29 @@ public interface MesDvMachineryService {
59 65 */
60 66 Long getMachineryCountByMachineryTypeId(Long machineryTypeId);
61 67  
  68 + /**
  69 + * 校验设备存在
  70 + *
  71 + * @param id 编号
  72 + */
  73 + void validateMachineryExists(Long id);
  74 +
  75 + /**
  76 + * 获得设备列表
  77 + *
  78 + * @param ids 编号数组
  79 + * @return 设备列表
  80 + */
  81 + List<MesDvMachineryDO> getMachineryList(Collection<Long> ids);
  82 +
  83 + /**
  84 + * 获得设备 Map
  85 + *
  86 + * @param ids 编号数组
  87 + * @return 设备 Map
  88 + */
  89 + default Map<Long, MesDvMachineryDO> getMachineryMap(Collection<Long> ids) {
  90 + return convertMap(getMachineryList(ids), MesDvMachineryDO::getId);
  91 + }
  92 +
62 93 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java
1 1 package cn.iocoder.yudao.module.mes.service.dv.machinery;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
3 4 import cn.hutool.core.util.ObjUtil;
4 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
... ... @@ -13,6 +14,10 @@ import org.springframework.context.annotation.Lazy;
13 14 import org.springframework.stereotype.Service;
14 15 import org.springframework.validation.annotation.Validated;
15 16  
  17 +import java.util.Collection;
  18 +import java.util.Collections;
  19 +import java.util.List;
  20 +
16 21 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
17 22 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
18 23  
... ... @@ -77,7 +82,8 @@ public class MesDvMachineryServiceImpl implements MesDvMachineryService {
77 82 machineryMapper.deleteById(id);
78 83 }
79 84  
80   - private void validateMachineryExists(Long id) {
  85 + @Override
  86 + public void validateMachineryExists(Long id) {
81 87 if (machineryMapper.selectById(id) == null) {
82 88 throw exception(DV_MACHINERY_NOT_EXISTS);
83 89 }
... ... @@ -111,4 +117,12 @@ public class MesDvMachineryServiceImpl implements MesDvMachineryService {
111 117 return machineryMapper.selectCountByMachineryTypeId(machineryTypeId);
112 118 }
113 119  
  120 + @Override
  121 + public List<MesDvMachineryDO> getMachineryList(Collection<Long> ids) {
  122 + if (CollUtil.isEmpty(ids)) {
  123 + return Collections.emptyList();
  124 + }
  125 + return machineryMapper.selectByIds(ids);
  126 + }
  127 +
114 128 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordLineServiceImpl.java
... ... @@ -6,16 +6,17 @@ import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.Mes
6 6 import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLineSaveReqVO;
7 7 import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordLineDO;
8 8 import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordLineMapper;
  9 +import cn.iocoder.yudao.module.mes.service.dv.subject.MesDvSubjectService;
  10 +import jakarta.annotation.Resource;
  11 +import org.springframework.context.annotation.Lazy;
9 12 import org.springframework.stereotype.Service;
10 13 import org.springframework.validation.annotation.Validated;
11   -import jakarta.annotation.Resource;
12 14  
13 15 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
14   -import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.MAINTEN_RECORD_LINE_NOT_EXISTS;
  16 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
15 17  
16   -// TODO @AI:注释风格;
17 18 /**
18   - * 设备保养记录明细 Service 实现类
  19 + * MES 设备保养记录明细 Service 实现类
19 20 *
20 21 * @author 芋道源码
21 22 */
... ... @@ -26,9 +27,18 @@ public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLine
26 27 @Resource
27 28 private MesDvMaintenRecordLineMapper maintenRecordLineMapper;
28 29  
  30 + @Resource
  31 + @Lazy
  32 + private MesDvMaintenRecordService maintenRecordService;
  33 + @Resource
  34 + private MesDvSubjectService subjectService;
  35 +
29 36 @Override
30 37 public Long createMaintenRecordLine(MesDvMaintenRecordLineSaveReqVO createReqVO) {
31   - // TODO @AI:必要的校验
  38 + // 1. 校验关联数据
  39 + validateMaintenRecordLineRelation(createReqVO);
  40 +
  41 + // 2. 插入
32 42 MesDvMaintenRecordLineDO maintenRecordLine = BeanUtils.toBean(createReqVO, MesDvMaintenRecordLineDO.class);
33 43 maintenRecordLineMapper.insert(maintenRecordLine);
34 44 return maintenRecordLine.getId();
... ... @@ -36,8 +46,12 @@ public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLine
36 46  
37 47 @Override
38 48 public void updateMaintenRecordLine(MesDvMaintenRecordLineSaveReqVO updateReqVO) {
39   - // TODO @AI:必要的校验
  49 + // 1.1 校验存在
40 50 validateMaintenRecordLineExists(updateReqVO.getId());
  51 + // 1.2 校验关联数据
  52 + validateMaintenRecordLineRelation(updateReqVO);
  53 +
  54 + // 2. 更新
41 55 MesDvMaintenRecordLineDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordLineDO.class);
42 56 maintenRecordLineMapper.updateById(updateObj);
43 57 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordServiceImpl.java
... ... @@ -5,19 +5,20 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 5 import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordPageReqVO;
6 6 import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordSaveReqVO;
7 7 import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordDO;
8   -import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordMapper;
9 8 import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordLineMapper;
  9 +import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordMapper;
  10 +import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanService;
  11 +import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService;
  12 +import jakarta.annotation.Resource;
10 13 import org.springframework.stereotype.Service;
11 14 import org.springframework.transaction.annotation.Transactional;
12 15 import org.springframework.validation.annotation.Validated;
13   -import jakarta.annotation.Resource;
14 16  
15 17 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
16   -import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.MAINTEN_RECORD_NOT_EXISTS;
  18 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
17 19  
18   -// TODO @AI:注释风格;
19 20 /**
20   - * 设备保养记录 Service 实现类
  21 + * MES 设备保养记录 Service 实现类
21 22 *
22 23 * @author 芋道源码
23 24 */
... ... @@ -27,14 +28,19 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService
27 28  
28 29 @Resource
29 30 private MesDvMaintenRecordMapper maintenRecordMapper;
30   -
31 31 @Resource
32 32 private MesDvMaintenRecordLineMapper maintenRecordLineMapper;
  33 + @Resource
  34 + private MesDvMachineryService machineryService;
  35 + @Resource
  36 + private MesDvCheckPlanService checkPlanService;
33 37  
34 38 @Override
35 39 public Long createMaintenRecord(MesDvMaintenRecordSaveReqVO createReqVO) {
36   - // TODO @AI:必要的校验
37   - // 插入
  40 + // 1. 校验关联数据
  41 + validateMaintenRecordRelation(createReqVO);
  42 +
  43 + // 2. 插入
38 44 MesDvMaintenRecordDO maintenRecord = BeanUtils.toBean(createReqVO, MesDvMaintenRecordDO.class);
39 45 maintenRecordMapper.insert(maintenRecord);
40 46 return maintenRecord.getId();
... ... @@ -42,9 +48,10 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService
42 48  
43 49 @Override
44 50 public void updateMaintenRecord(MesDvMaintenRecordSaveReqVO updateReqVO) {
45   - // TODO @AI:必要的校验
46   - // 校验存在
  51 + // 1.1 校验存在
47 52 validateMaintenRecordExists(updateReqVO.getId());
  53 + // 1.2 校验关联数据
  54 + validateMaintenRecordRelation(updateReqVO);
48 55  
49 56 // 更新
50 57 MesDvMaintenRecordDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordDO.class);
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/subject/MesDvSubjectService.java
... ... @@ -6,6 +6,12 @@ import cn.iocoder.yudao.module.mes.controller.admin.dv.subject.vo.MesDvSubjectSa
6 6 import cn.iocoder.yudao.module.mes.dal.dataobject.dv.subject.MesDvSubjectDO;
7 7 import jakarta.validation.Valid;
8 8  
  9 +import java.util.Collection;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
  14 +
9 15 /**
10 16 * MES 点检保养项目 Service 接口
11 17 *
... ... @@ -51,4 +57,29 @@ public interface MesDvSubjectService {
51 57 */
52 58 PageResult<MesDvSubjectDO> getSubjectPage(MesDvSubjectPageReqVO pageReqVO);
53 59  
  60 + /**
  61 + * 校验点检保养项目存在
  62 + *
  63 + * @param id 编号
  64 + */
  65 + void validateSubjectExists(Long id);
  66 +
  67 + /**
  68 + * 获得点检保养项目列表
  69 + *
  70 + * @param ids 编号数组
  71 + * @return 点检保养项目列表
  72 + */
  73 + List<MesDvSubjectDO> getSubjectList(Collection<Long> ids);
  74 +
  75 + /**
  76 + * 获得点检保养项目 Map
  77 + *
  78 + * @param ids 编号数组
  79 + * @return 点检保养项目 Map
  80 + */
  81 + default Map<Long, MesDvSubjectDO> getSubjectMap(Collection<Long> ids) {
  82 + return convertMap(getSubjectList(ids), MesDvSubjectDO::getId);
  83 + }
  84 +
54 85 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/subject/MesDvSubjectServiceImpl.java
1 1 package cn.iocoder.yudao.module.mes.service.dv.subject;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
3 4 import cn.hutool.core.util.ObjUtil;
4 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
... ... @@ -11,6 +12,10 @@ import jakarta.annotation.Resource;
11 12 import org.springframework.stereotype.Service;
12 13 import org.springframework.validation.annotation.Validated;
13 14  
  15 +import java.util.Collection;
  16 +import java.util.Collections;
  17 +import java.util.List;
  18 +
14 19 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
15 20 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
16 21  
... ... @@ -57,7 +62,8 @@ public class MesDvSubjectServiceImpl implements MesDvSubjectService {
57 62 subjectMapper.deleteById(id);
58 63 }
59 64  
60   - private void validateSubjectExists(Long id) {
  65 + @Override
  66 + public void validateSubjectExists(Long id) {
61 67 if (subjectMapper.selectById(id) == null) {
62 68 throw exception(DV_SUBJECT_NOT_EXISTS);
63 69 }
... ... @@ -86,4 +92,12 @@ public class MesDvSubjectServiceImpl implements MesDvSubjectService {
86 92 return subjectMapper.selectPage(pageReqVO);
87 93 }
88 94  
  95 + @Override
  96 + public List<MesDvSubjectDO> getSubjectList(Collection<Long> ids) {
  97 + if (CollUtil.isEmpty(ids)) {
  98 + return Collections.emptyList();
  99 + }
  100 + return subjectMapper.selectByIds(ids);
  101 + }
  102 +
89 103 }
... ...