Commit 62362e2edeb116591a14083b3bedbea08cb92729
1 parent
17fedca9
refactor(mes): 优化设备保养记录模块代码风格,提升校验方法复用性
1. 新增 MesDvMaintenRecordStatusEnum 保养记录状态枚举(草稿/已提交) 2. 各 Service 接口暴露 validateXxxExists 公共校验方法(Machinery、CheckPlan、Subject、MaintenRecord), 消除跨 Service 手动 null 判断 + 抛异常的重复代码 3. CheckPlanServiceImpl 改用链式调用更新状态,validateCheckPlanCodeUnique 使用 ObjUtil.notEqual
Showing
8 changed files
with
170 additions
and
18 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/DictTypeConstants.java
| @@ -30,5 +30,9 @@ public interface DictTypeConstants { | @@ -30,5 +30,9 @@ public interface DictTypeConstants { | ||
| 30 | String MES_QC_IQC_STATUS = "mes_qc_iqc_status"; // MES 检验单状态 | 30 | String MES_QC_IQC_STATUS = "mes_qc_iqc_status"; // MES 检验单状态 |
| 31 | String MES_QC_CHECK_RESULT = "mes_qc_check_result"; // MES 检测结果 | 31 | String MES_QC_CHECK_RESULT = "mes_qc_check_result"; // MES 检测结果 |
| 32 | String MES_QC_SOURCE_DOC_TYPE = "mes_qc_source_doc_type"; // MES 来源单据类型 | 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 +6,12 @@ import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachine | ||
| 6 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO; | 6 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO; |
| 7 | import jakarta.validation.Valid; | 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 | * MES 设备台账 Service 接口 | 16 | * MES 设备台账 Service 接口 |
| 11 | * | 17 | * |
| @@ -59,4 +65,29 @@ public interface MesDvMachineryService { | @@ -59,4 +65,29 @@ public interface MesDvMachineryService { | ||
| 59 | */ | 65 | */ |
| 60 | Long getMachineryCountByMachineryTypeId(Long machineryTypeId); | 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 | package cn.iocoder.yudao.module.mes.service.dv.machinery; | 1 | package cn.iocoder.yudao.module.mes.service.dv.machinery; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| @@ -13,6 +14,10 @@ import org.springframework.context.annotation.Lazy; | @@ -13,6 +14,10 @@ import org.springframework.context.annotation.Lazy; | ||
| 13 | import org.springframework.stereotype.Service; | 14 | import org.springframework.stereotype.Service; |
| 14 | import org.springframework.validation.annotation.Validated; | 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 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 21 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 17 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; | 22 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| 18 | 23 | ||
| @@ -77,7 +82,8 @@ public class MesDvMachineryServiceImpl implements MesDvMachineryService { | @@ -77,7 +82,8 @@ public class MesDvMachineryServiceImpl implements MesDvMachineryService { | ||
| 77 | machineryMapper.deleteById(id); | 82 | machineryMapper.deleteById(id); |
| 78 | } | 83 | } |
| 79 | 84 | ||
| 80 | - private void validateMachineryExists(Long id) { | 85 | + @Override |
| 86 | + public void validateMachineryExists(Long id) { | ||
| 81 | if (machineryMapper.selectById(id) == null) { | 87 | if (machineryMapper.selectById(id) == null) { |
| 82 | throw exception(DV_MACHINERY_NOT_EXISTS); | 88 | throw exception(DV_MACHINERY_NOT_EXISTS); |
| 83 | } | 89 | } |
| @@ -111,4 +117,12 @@ public class MesDvMachineryServiceImpl implements MesDvMachineryService { | @@ -111,4 +117,12 @@ public class MesDvMachineryServiceImpl implements MesDvMachineryService { | ||
| 111 | return machineryMapper.selectCountByMachineryTypeId(machineryTypeId); | 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,16 +6,17 @@ import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.Mes | ||
| 6 | import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLineSaveReqVO; | 6 | import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLineSaveReqVO; |
| 7 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordLineDO; | 7 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordLineDO; |
| 8 | import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordLineMapper; | 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 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 10 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 11 | -import jakarta.annotation.Resource; | ||
| 12 | 14 | ||
| 13 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 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 | * @author 芋道源码 | 21 | * @author 芋道源码 |
| 21 | */ | 22 | */ |
| @@ -26,9 +27,18 @@ public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLine | @@ -26,9 +27,18 @@ public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLine | ||
| 26 | @Resource | 27 | @Resource |
| 27 | private MesDvMaintenRecordLineMapper maintenRecordLineMapper; | 28 | private MesDvMaintenRecordLineMapper maintenRecordLineMapper; |
| 28 | 29 | ||
| 30 | + @Resource | ||
| 31 | + @Lazy | ||
| 32 | + private MesDvMaintenRecordService maintenRecordService; | ||
| 33 | + @Resource | ||
| 34 | + private MesDvSubjectService subjectService; | ||
| 35 | + | ||
| 29 | @Override | 36 | @Override |
| 30 | public Long createMaintenRecordLine(MesDvMaintenRecordLineSaveReqVO createReqVO) { | 37 | public Long createMaintenRecordLine(MesDvMaintenRecordLineSaveReqVO createReqVO) { |
| 31 | - // TODO @AI:必要的校验 | 38 | + // 1. 校验关联数据 |
| 39 | + validateMaintenRecordLineRelation(createReqVO); | ||
| 40 | + | ||
| 41 | + // 2. 插入 | ||
| 32 | MesDvMaintenRecordLineDO maintenRecordLine = BeanUtils.toBean(createReqVO, MesDvMaintenRecordLineDO.class); | 42 | MesDvMaintenRecordLineDO maintenRecordLine = BeanUtils.toBean(createReqVO, MesDvMaintenRecordLineDO.class); |
| 33 | maintenRecordLineMapper.insert(maintenRecordLine); | 43 | maintenRecordLineMapper.insert(maintenRecordLine); |
| 34 | return maintenRecordLine.getId(); | 44 | return maintenRecordLine.getId(); |
| @@ -36,8 +46,12 @@ public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLine | @@ -36,8 +46,12 @@ public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLine | ||
| 36 | 46 | ||
| 37 | @Override | 47 | @Override |
| 38 | public void updateMaintenRecordLine(MesDvMaintenRecordLineSaveReqVO updateReqVO) { | 48 | public void updateMaintenRecordLine(MesDvMaintenRecordLineSaveReqVO updateReqVO) { |
| 39 | - // TODO @AI:必要的校验 | 49 | + // 1.1 校验存在 |
| 40 | validateMaintenRecordLineExists(updateReqVO.getId()); | 50 | validateMaintenRecordLineExists(updateReqVO.getId()); |
| 51 | + // 1.2 校验关联数据 | ||
| 52 | + validateMaintenRecordLineRelation(updateReqVO); | ||
| 53 | + | ||
| 54 | + // 2. 更新 | ||
| 41 | MesDvMaintenRecordLineDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordLineDO.class); | 55 | MesDvMaintenRecordLineDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordLineDO.class); |
| 42 | maintenRecordLineMapper.updateById(updateObj); | 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,19 +5,20 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordPageReqVO; | 5 | import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordPageReqVO; |
| 6 | import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordSaveReqVO; | 6 | import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordSaveReqVO; |
| 7 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordDO; | 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 | import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordLineMapper; | 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 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| 12 | import org.springframework.validation.annotation.Validated; | 15 | import org.springframework.validation.annotation.Validated; |
| 13 | -import jakarta.annotation.Resource; | ||
| 14 | 16 | ||
| 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 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 | * @author 芋道源码 | 23 | * @author 芋道源码 |
| 23 | */ | 24 | */ |
| @@ -27,14 +28,19 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService | @@ -27,14 +28,19 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService | ||
| 27 | 28 | ||
| 28 | @Resource | 29 | @Resource |
| 29 | private MesDvMaintenRecordMapper maintenRecordMapper; | 30 | private MesDvMaintenRecordMapper maintenRecordMapper; |
| 30 | - | ||
| 31 | @Resource | 31 | @Resource |
| 32 | private MesDvMaintenRecordLineMapper maintenRecordLineMapper; | 32 | private MesDvMaintenRecordLineMapper maintenRecordLineMapper; |
| 33 | + @Resource | ||
| 34 | + private MesDvMachineryService machineryService; | ||
| 35 | + @Resource | ||
| 36 | + private MesDvCheckPlanService checkPlanService; | ||
| 33 | 37 | ||
| 34 | @Override | 38 | @Override |
| 35 | public Long createMaintenRecord(MesDvMaintenRecordSaveReqVO createReqVO) { | 39 | public Long createMaintenRecord(MesDvMaintenRecordSaveReqVO createReqVO) { |
| 36 | - // TODO @AI:必要的校验 | ||
| 37 | - // 插入 | 40 | + // 1. 校验关联数据 |
| 41 | + validateMaintenRecordRelation(createReqVO); | ||
| 42 | + | ||
| 43 | + // 2. 插入 | ||
| 38 | MesDvMaintenRecordDO maintenRecord = BeanUtils.toBean(createReqVO, MesDvMaintenRecordDO.class); | 44 | MesDvMaintenRecordDO maintenRecord = BeanUtils.toBean(createReqVO, MesDvMaintenRecordDO.class); |
| 39 | maintenRecordMapper.insert(maintenRecord); | 45 | maintenRecordMapper.insert(maintenRecord); |
| 40 | return maintenRecord.getId(); | 46 | return maintenRecord.getId(); |
| @@ -42,9 +48,10 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService | @@ -42,9 +48,10 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService | ||
| 42 | 48 | ||
| 43 | @Override | 49 | @Override |
| 44 | public void updateMaintenRecord(MesDvMaintenRecordSaveReqVO updateReqVO) { | 50 | public void updateMaintenRecord(MesDvMaintenRecordSaveReqVO updateReqVO) { |
| 45 | - // TODO @AI:必要的校验 | ||
| 46 | - // 校验存在 | 51 | + // 1.1 校验存在 |
| 47 | validateMaintenRecordExists(updateReqVO.getId()); | 52 | validateMaintenRecordExists(updateReqVO.getId()); |
| 53 | + // 1.2 校验关联数据 | ||
| 54 | + validateMaintenRecordRelation(updateReqVO); | ||
| 48 | 55 | ||
| 49 | // 更新 | 56 | // 更新 |
| 50 | MesDvMaintenRecordDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordDO.class); | 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 +6,12 @@ import cn.iocoder.yudao.module.mes.controller.admin.dv.subject.vo.MesDvSubjectSa | ||
| 6 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.subject.MesDvSubjectDO; | 6 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.subject.MesDvSubjectDO; |
| 7 | import jakarta.validation.Valid; | 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 | * MES 点检保养项目 Service 接口 | 16 | * MES 点检保养项目 Service 接口 |
| 11 | * | 17 | * |
| @@ -51,4 +57,29 @@ public interface MesDvSubjectService { | @@ -51,4 +57,29 @@ public interface MesDvSubjectService { | ||
| 51 | */ | 57 | */ |
| 52 | PageResult<MesDvSubjectDO> getSubjectPage(MesDvSubjectPageReqVO pageReqVO); | 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 | package cn.iocoder.yudao.module.mes.service.dv.subject; | 1 | package cn.iocoder.yudao.module.mes.service.dv.subject; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| @@ -11,6 +12,10 @@ import jakarta.annotation.Resource; | @@ -11,6 +12,10 @@ import jakarta.annotation.Resource; | ||
| 11 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 12 | import org.springframework.validation.annotation.Validated; | 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 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 19 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 15 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; | 20 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| 16 | 21 | ||
| @@ -57,7 +62,8 @@ public class MesDvSubjectServiceImpl implements MesDvSubjectService { | @@ -57,7 +62,8 @@ public class MesDvSubjectServiceImpl implements MesDvSubjectService { | ||
| 57 | subjectMapper.deleteById(id); | 62 | subjectMapper.deleteById(id); |
| 58 | } | 63 | } |
| 59 | 64 | ||
| 60 | - private void validateSubjectExists(Long id) { | 65 | + @Override |
| 66 | + public void validateSubjectExists(Long id) { | ||
| 61 | if (subjectMapper.selectById(id) == null) { | 67 | if (subjectMapper.selectById(id) == null) { |
| 62 | throw exception(DV_SUBJECT_NOT_EXISTS); | 68 | throw exception(DV_SUBJECT_NOT_EXISTS); |
| 63 | } | 69 | } |
| @@ -86,4 +92,12 @@ public class MesDvSubjectServiceImpl implements MesDvSubjectService { | @@ -86,4 +92,12 @@ public class MesDvSubjectServiceImpl implements MesDvSubjectService { | ||
| 86 | return subjectMapper.selectPage(pageReqVO); | 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 | } |