From 1ed449c8afb5a174a22ce6c04ff958b9d59cdaff Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 Apr 2026 08:43:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(mes):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=96=B9=E6=A1=88=E7=B1=BB=E5=9E=8B=E5=94=AF?= =?UTF-8?q?=E4=B8=80=E6=80=A7=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增跨方案类型唯一性校验,确保同一设备不能在多个同类型的方案中重复添加。此变更提升了设备管理的准确性和一致性,避免了潜在的业务逻辑冲突。 --- .../vo/MesDvCheckRecordSaveReqVO.java | 4 ---- .../MesDvCheckPlanMachineryMapper.java | 4 ++++ .../module/mes/enums/ErrorCodeConstants.java | 1 + .../MesDvCheckPlanMachineryService.java | 8 +++++++ .../MesDvCheckPlanMachineryServiceImpl.java | 24 ++++++++++++++++++- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/MesDvCheckRecordSaveReqVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/MesDvCheckRecordSaveReqVO.java index e22430efab..3abbc1bac9 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/MesDvCheckRecordSaveReqVO.java +++ b/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 { @Schema(description = "点检人编号", example = "1") private Long userId; - // TODO @AI:这个字段,不允许提交 - @Schema(description = "状态", example = "10") - private Integer status; - @Schema(description = "备注", example = "测试备注") private String remark; diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/checkplan/MesDvCheckPlanMachineryMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/checkplan/MesDvCheckPlanMachineryMapper.java index 0fb84d9ac6..8ff3c65440 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/checkplan/MesDvCheckPlanMachineryMapper.java +++ b/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 selectListByMachineryId(Long machineryId) { + return selectList(MesDvCheckPlanMachineryDO::getMachineryId, machineryId); + } + default MesDvCheckPlanMachineryDO selectByPlanIdAndMachineryId(Long planId, Long machineryId) { return selectOne(new LambdaQueryWrapperX() .eq(MesDvCheckPlanMachineryDO::getPlanId, planId) diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index ace7fb741c..65ed7ba596 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -170,6 +170,7 @@ public interface ErrorCodeConstants { // ========== MES 设备管理-点检方案设备(1-040-302-100) ========== ErrorCode DV_CHECK_PLAN_MACHINERY_NOT_EXISTS = new ErrorCode(1_040_302_100, "点检保养方案设备不存在"); ErrorCode DV_CHECK_PLAN_MACHINERY_DUPLICATE = new ErrorCode(1_040_302_101, "该设备已关联到当前方案,请勿重复添加"); + ErrorCode DV_CHECK_PLAN_MACHINERY_EXISTS_IN_SAME_TYPE = new ErrorCode(1_040_302_102, "该设备已存在于同类型的其他启用的或草稿的方案中,不允许同一设备添加多个同类型的方案"); // ========== MES 设备管理-点检方案项目(1-040-302-200) ========== ErrorCode DV_CHECK_PLAN_SUBJECT_NOT_EXISTS = new ErrorCode(1_040_302_200, "点检保养方案项目不存在"); ErrorCode DV_CHECK_PLAN_SUBJECT_DUPLICATE = new ErrorCode(1_040_302_201, "该项目已关联到当前方案,请勿重复添加"); diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryService.java index 7bea3f3955..e82ca8e8e9 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryService.java @@ -59,4 +59,12 @@ public interface MesDvCheckPlanMachineryService { */ Long getCheckPlanMachineryCountByMachineryId(Long machineryId); + /** + * 获得指定设备关联的方案设备列表 + * + * @param machineryId 设备编号 + * @return 方案设备列表 + */ + List getCheckPlanMachineryListByMachineryId(Long machineryId); + } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryServiceImpl.java index 62b7a27d80..543dce66c3 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkplan/MesDvCheckPlanMachineryServiceImpl.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.mes.service.dv.checkplan; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.dv.checkplan.vo.machinery.MesDvCheckPlanMachinerySaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanDO; import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanMachineryDO; import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkplan.MesDvCheckPlanMachineryMapper; import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService; @@ -26,6 +29,7 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine @Resource private MesDvCheckPlanMachineryMapper checkPlanMachineryMapper; + @Resource @Lazy private MesDvCheckPlanService checkPlanService; @@ -35,13 +39,26 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine @Override public Long createCheckPlanMachinery(MesDvCheckPlanMachinerySaveReqVO createReqVO) { // 1.1 校验方案草稿状态 - checkPlanService.validateCheckPlanPrepare(createReqVO.getPlanId()); + MesDvCheckPlanDO currentPlan = checkPlanService.validateCheckPlanPrepare(createReqVO.getPlanId()); // 1.2 校验设备存在 machineryService.validateMachineryExists(createReqVO.getMachineryId()); // 1.3 校验同一方案下设备不重复 if (checkPlanMachineryMapper.selectByPlanIdAndMachineryId(createReqVO.getPlanId(), createReqVO.getMachineryId()) != null) { throw exception(DV_CHECK_PLAN_MACHINERY_DUPLICATE); } + // 1.4 跨方案类型唯一性校验(对齐 KTG 业务约束:设备不能存在于同类型多个方案中) + List existingMachineryList = getCheckPlanMachineryListByMachineryId(createReqVO.getMachineryId()); + if (CollUtil.isNotEmpty(existingMachineryList)) { + List existingPlanIds = existingMachineryList.stream().map(MesDvCheckPlanMachineryDO::getPlanId).toList(); + List existingPlans = checkPlanService.getCheckPlanList(existingPlanIds); + for (MesDvCheckPlanDO existPlan : existingPlans) { + // 如果存在不同于当前方案、但类型一致的计划方案,则拦截(一机多计划,但不允许同一机多同类型计划) + if (ObjUtil.notEqual(existPlan.getId(), currentPlan.getId()) + && ObjUtil.equal(existPlan.getType(), currentPlan.getType())) { + throw exception(DV_CHECK_PLAN_MACHINERY_EXISTS_IN_SAME_TYPE); + } + } + } // 2. 插入 MesDvCheckPlanMachineryDO planMachinery = BeanUtils.toBean(createReqVO, MesDvCheckPlanMachineryDO.class); @@ -83,4 +100,9 @@ public class MesDvCheckPlanMachineryServiceImpl implements MesDvCheckPlanMachine return checkPlanMachineryMapper.selectCountByMachineryId(machineryId); } + @Override + public List getCheckPlanMachineryListByMachineryId(Long machineryId) { + return checkPlanMachineryMapper.selectListByMachineryId(machineryId); + } + }