Commit 1ed449c8afb5a174a22ce6c04ff958b9d59cdaff
1 parent
8cb3b008
✨ feat(mes): 新增设备方案类型唯一性校验逻辑
新增跨方案类型唯一性校验,确保同一设备不能在多个同类型的方案中重复添加。此变更提升了设备管理的准确性和一致性,避免了潜在的业务逻辑冲突。
Showing
5 changed files
with
36 additions
and
5 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/MesDvCheckRecordSaveReqVO.java
| @@ -27,10 +27,6 @@ public class MesDvCheckRecordSaveReqVO { | @@ -27,10 +27,6 @@ public class MesDvCheckRecordSaveReqVO { | ||
| 27 | @Schema(description = "点检人编号", example = "1") | 27 | @Schema(description = "点检人编号", example = "1") |
| 28 | private Long userId; | 28 | private Long userId; |
| 29 | 29 | ||
| 30 | - // TODO @AI:这个字段,不允许提交 | ||
| 31 | - @Schema(description = "状态", example = "10") | ||
| 32 | - private Integer status; | ||
| 33 | - | ||
| 34 | @Schema(description = "备注", example = "测试备注") | 30 | @Schema(description = "备注", example = "测试备注") |
| 35 | private String remark; | 31 | private String remark; |
| 36 | 32 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/checkplan/MesDvCheckPlanMachineryMapper.java
| @@ -32,6 +32,10 @@ public interface MesDvCheckPlanMachineryMapper extends BaseMapperX<MesDvCheckPla | @@ -32,6 +32,10 @@ public interface MesDvCheckPlanMachineryMapper extends BaseMapperX<MesDvCheckPla | ||
| 32 | return selectCount(MesDvCheckPlanMachineryDO::getMachineryId, machineryId); | 32 | return selectCount(MesDvCheckPlanMachineryDO::getMachineryId, machineryId); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | + default List<MesDvCheckPlanMachineryDO> selectListByMachineryId(Long machineryId) { | ||
| 36 | + return selectList(MesDvCheckPlanMachineryDO::getMachineryId, machineryId); | ||
| 37 | + } | ||
| 38 | + | ||
| 35 | default MesDvCheckPlanMachineryDO selectByPlanIdAndMachineryId(Long planId, Long machineryId) { | 39 | default MesDvCheckPlanMachineryDO selectByPlanIdAndMachineryId(Long planId, Long machineryId) { |
| 36 | return selectOne(new LambdaQueryWrapperX<MesDvCheckPlanMachineryDO>() | 40 | return selectOne(new LambdaQueryWrapperX<MesDvCheckPlanMachineryDO>() |
| 37 | .eq(MesDvCheckPlanMachineryDO::getPlanId, planId) | 41 | .eq(MesDvCheckPlanMachineryDO::getPlanId, planId) |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
| @@ -170,6 +170,7 @@ public interface ErrorCodeConstants { | @@ -170,6 +170,7 @@ public interface ErrorCodeConstants { | ||
| 170 | // ========== MES 设备管理-点检方案设备(1-040-302-100) ========== | 170 | // ========== MES 设备管理-点检方案设备(1-040-302-100) ========== |
| 171 | ErrorCode DV_CHECK_PLAN_MACHINERY_NOT_EXISTS = new ErrorCode(1_040_302_100, "点检保养方案设备不存在"); | 171 | ErrorCode DV_CHECK_PLAN_MACHINERY_NOT_EXISTS = new ErrorCode(1_040_302_100, "点检保养方案设备不存在"); |
| 172 | ErrorCode DV_CHECK_PLAN_MACHINERY_DUPLICATE = new ErrorCode(1_040_302_101, "该设备已关联到当前方案,请勿重复添加"); | 172 | ErrorCode DV_CHECK_PLAN_MACHINERY_DUPLICATE = new ErrorCode(1_040_302_101, "该设备已关联到当前方案,请勿重复添加"); |
| 173 | + ErrorCode DV_CHECK_PLAN_MACHINERY_EXISTS_IN_SAME_TYPE = new ErrorCode(1_040_302_102, "该设备已存在于同类型的其他启用的或草稿的方案中,不允许同一设备添加多个同类型的方案"); | ||
| 173 | // ========== MES 设备管理-点检方案项目(1-040-302-200) ========== | 174 | // ========== MES 设备管理-点检方案项目(1-040-302-200) ========== |
| 174 | ErrorCode DV_CHECK_PLAN_SUBJECT_NOT_EXISTS = new ErrorCode(1_040_302_200, "点检保养方案项目不存在"); | 175 | ErrorCode DV_CHECK_PLAN_SUBJECT_NOT_EXISTS = new ErrorCode(1_040_302_200, "点检保养方案项目不存在"); |
| 175 | ErrorCode DV_CHECK_PLAN_SUBJECT_DUPLICATE = new ErrorCode(1_040_302_201, "该项目已关联到当前方案,请勿重复添加"); | 176 | ErrorCode DV_CHECK_PLAN_SUBJECT_DUPLICATE = new ErrorCode(1_040_302_201, "该项目已关联到当前方案,请勿重复添加"); |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryService.java
| @@ -59,4 +59,12 @@ public interface MesDvCheckPlanMachineryService { | @@ -59,4 +59,12 @@ public interface MesDvCheckPlanMachineryService { | ||
| 59 | */ | 59 | */ |
| 60 | Long getCheckPlanMachineryCountByMachineryId(Long machineryId); | 60 | Long getCheckPlanMachineryCountByMachineryId(Long machineryId); |
| 61 | 61 | ||
| 62 | + /** | ||
| 63 | + * 获得指定设备关联的方案设备列表 | ||
| 64 | + * | ||
| 65 | + * @param machineryId 设备编号 | ||
| 66 | + * @return 方案设备列表 | ||
| 67 | + */ | ||
| 68 | + List<MesDvCheckPlanMachineryDO> getCheckPlanMachineryListByMachineryId(Long machineryId); | ||
| 69 | + | ||
| 62 | } | 70 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryServiceImpl.java
| 1 | package cn.iocoder.yudao.module.mes.service.dv.checkplan; | 1 | package cn.iocoder.yudao.module.mes.service.dv.checkplan; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.hutool.core.util.ObjUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 4 | import cn.iocoder.yudao.module.mes.controller.admin.dv.checkplan.vo.machinery.MesDvCheckPlanMachinerySaveReqVO; | 6 | import cn.iocoder.yudao.module.mes.controller.admin.dv.checkplan.vo.machinery.MesDvCheckPlanMachinerySaveReqVO; |
| 7 | +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanDO; | ||
| 5 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanMachineryDO; | 8 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanMachineryDO; |
| 6 | import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkplan.MesDvCheckPlanMachineryMapper; | 9 | import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkplan.MesDvCheckPlanMachineryMapper; |
| 7 | import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService; | 10 | import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService; |
| @@ -26,6 +29,7 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine | @@ -26,6 +29,7 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine | ||
| 26 | 29 | ||
| 27 | @Resource | 30 | @Resource |
| 28 | private MesDvCheckPlanMachineryMapper checkPlanMachineryMapper; | 31 | private MesDvCheckPlanMachineryMapper checkPlanMachineryMapper; |
| 32 | + | ||
| 29 | @Resource | 33 | @Resource |
| 30 | @Lazy | 34 | @Lazy |
| 31 | private MesDvCheckPlanService checkPlanService; | 35 | private MesDvCheckPlanService checkPlanService; |
| @@ -35,13 +39,26 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine | @@ -35,13 +39,26 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine | ||
| 35 | @Override | 39 | @Override |
| 36 | public Long createCheckPlanMachinery(MesDvCheckPlanMachinerySaveReqVO createReqVO) { | 40 | public Long createCheckPlanMachinery(MesDvCheckPlanMachinerySaveReqVO createReqVO) { |
| 37 | // 1.1 校验方案草稿状态 | 41 | // 1.1 校验方案草稿状态 |
| 38 | - checkPlanService.validateCheckPlanPrepare(createReqVO.getPlanId()); | 42 | + MesDvCheckPlanDO currentPlan = checkPlanService.validateCheckPlanPrepare(createReqVO.getPlanId()); |
| 39 | // 1.2 校验设备存在 | 43 | // 1.2 校验设备存在 |
| 40 | machineryService.validateMachineryExists(createReqVO.getMachineryId()); | 44 | machineryService.validateMachineryExists(createReqVO.getMachineryId()); |
| 41 | // 1.3 校验同一方案下设备不重复 | 45 | // 1.3 校验同一方案下设备不重复 |
| 42 | if (checkPlanMachineryMapper.selectByPlanIdAndMachineryId(createReqVO.getPlanId(), createReqVO.getMachineryId()) != null) { | 46 | if (checkPlanMachineryMapper.selectByPlanIdAndMachineryId(createReqVO.getPlanId(), createReqVO.getMachineryId()) != null) { |
| 43 | throw exception(DV_CHECK_PLAN_MACHINERY_DUPLICATE); | 47 | throw exception(DV_CHECK_PLAN_MACHINERY_DUPLICATE); |
| 44 | } | 48 | } |
| 49 | + // 1.4 跨方案类型唯一性校验(对齐 KTG 业务约束:设备不能存在于同类型多个方案中) | ||
| 50 | + List<MesDvCheckPlanMachineryDO> existingMachineryList = getCheckPlanMachineryListByMachineryId(createReqVO.getMachineryId()); | ||
| 51 | + if (CollUtil.isNotEmpty(existingMachineryList)) { | ||
| 52 | + List<Long> existingPlanIds = existingMachineryList.stream().map(MesDvCheckPlanMachineryDO::getPlanId).toList(); | ||
| 53 | + List<MesDvCheckPlanDO> existingPlans = checkPlanService.getCheckPlanList(existingPlanIds); | ||
| 54 | + for (MesDvCheckPlanDO existPlan : existingPlans) { | ||
| 55 | + // 如果存在不同于当前方案、但类型一致的计划方案,则拦截(一机多计划,但不允许同一机多同类型计划) | ||
| 56 | + if (ObjUtil.notEqual(existPlan.getId(), currentPlan.getId()) | ||
| 57 | + && ObjUtil.equal(existPlan.getType(), currentPlan.getType())) { | ||
| 58 | + throw exception(DV_CHECK_PLAN_MACHINERY_EXISTS_IN_SAME_TYPE); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + } | ||
| 45 | 62 | ||
| 46 | // 2. 插入 | 63 | // 2. 插入 |
| 47 | MesDvCheckPlanMachineryDO planMachinery = BeanUtils.toBean(createReqVO, MesDvCheckPlanMachineryDO.class); | 64 | MesDvCheckPlanMachineryDO planMachinery = BeanUtils.toBean(createReqVO, MesDvCheckPlanMachineryDO.class); |
| @@ -83,4 +100,9 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine | @@ -83,4 +100,9 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine | ||
| 83 | return checkPlanMachineryMapper.selectCountByMachineryId(machineryId); | 100 | return checkPlanMachineryMapper.selectCountByMachineryId(machineryId); |
| 84 | } | 101 | } |
| 85 | 102 | ||
| 103 | + @Override | ||
| 104 | + public List<MesDvCheckPlanMachineryDO> getCheckPlanMachineryListByMachineryId(Long machineryId) { | ||
| 105 | + return checkPlanMachineryMapper.selectListByMachineryId(machineryId); | ||
| 106 | + } | ||
| 107 | + | ||
| 86 | } | 108 | } |