2 コミット cb7cf18b9a ... 7fa1c3151f

作者 SHA1 メッセージ 日付
  zhangcl 7fa1c3151f Merge remote-tracking branch 'origin/master' 4 日 前
  zhangcl bed80b7942 pms 保养计划校验 相同设备只能存在1个保养计划中 4 日 前

+ 1 - 0
yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java

@@ -33,6 +33,7 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_MAINTAIN_MATERIAL_NOT_EXISTS = new ErrorCode(129, "工单物料不存在");
     ErrorCode IOT_INFORMATION_DB_NOT_EXISTS = new ErrorCode(130, "知识库不存在");
     ErrorCode IOT_LOCK_STOCK_FUSHU = new ErrorCode(131, "超过本地库存");
+    ErrorCode IOT_MAINTENANCE_SAME_DEVICE_EXISTS = new ErrorCode(163, "已经存在相同设备的保养计划");
     ErrorCode IOT_MAINTENANCE_PLAN_NOT_EXISTS = new ErrorCode(133, "保养计划明细不存在");
     ErrorCode IOT_MAINTENANCE_DETAILS_NOT_EXISTS = new ErrorCode(134, "保养计划明细不存在");
     ErrorCode IOT_STORAGE_AREA_NOT_EXISTS = new ErrorCode(131, "PMS 库区不存在");

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmaintenancebom/vo/IotMaintenanceBomPageReqVO.java

@@ -119,4 +119,7 @@ public class IotMaintenanceBomPageReqVO extends PageParam {
     private List<Long> bomNodeIds;
     @Schema(description = "保养项节点名称集合")
     private List<String> bomNodeNames;
+
+    @Schema(description = "保养计划id 唯一性校验", example = "18063")
+    private Long notPlanId;
 }

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotmaintenancebom/IotMaintenanceBomMapper.java

@@ -60,6 +60,7 @@ public interface IotMaintenanceBomMapper extends BaseMapperX<IotMaintenanceBomDO
     default List<IotMaintenanceBomDO> selectList(IotMaintenanceBomPageReqVO reqVO) {
         return selectList(new LambdaQueryWrapperX<IotMaintenanceBomDO>()
                 .eqIfPresent(IotMaintenanceBomDO::getPlanId, reqVO.getPlanId())
+                .neIfPresent(IotMaintenanceBomDO::getPlanId, reqVO.getNotPlanId())
                 .eqIfPresent(IotMaintenanceBomDO::getPlanDetailId, reqVO.getPlanDetailId())
                 .eqIfPresent(IotMaintenanceBomDO::getDeviceCategoryId, reqVO.getDeviceCategoryId())
                 .eqIfPresent(IotMaintenanceBomDO::getDeviceId, reqVO.getDeviceId())

+ 25 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintenance/IotMaintenancePlanServiceImpl.java

@@ -29,8 +29,7 @@ import java.util.*;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
-import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_MAINTENANCE_PLAN_NOT_EXISTS;
-import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_MAINTENANCE_PLAN_NO_EXISTS;
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.*;
 
 /**
  * 保养计划 Service 实现类
@@ -65,6 +64,18 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
         if (ObjectUtil.isEmpty(deviceBOMs)) {
             throw exception(IOT_MAINTENANCE_PLAN_NOT_EXISTS);
         }
+        // 校验保养计划明细中的设备只能出现在1个保养计划中
+        Set<Long> deviceIds = new HashSet<>();
+        // 查验保养计划明细中的设备 只存在于1个保养计划中
+        deviceBOMs.forEach(bom -> {
+            deviceIds.add(bom.getDeviceId());
+        });
+        IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
+        reqVO.setDeviceIds(new ArrayList<>(deviceIds));
+        List<IotMaintenanceBomDO> boms = iotMaintenanceBomMapper.selectList(reqVO);
+        if (CollUtil.isNotEmpty(boms)) {
+            throw exception(IOT_MAINTENANCE_SAME_DEVICE_EXISTS);
+        }
         // 先保存保养计划主表 再根据主表id更新明细
         IotMaintenancePlanSaveReqVO mainPlanSaveVO = createReqVO.getMainPlan();
         // 自动生成保养计划编号 BYJH202504300001
@@ -182,6 +193,18 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
         if (ObjectUtil.isEmpty(existPlan)) {
             throw exception(IOT_MAINTENANCE_PLAN_NOT_EXISTS);
         }
+        Set<Long> deviceIds = new HashSet<>();
+        // 查验保养计划明细中的设备 只存在于1个保养计划中
+        deviceBOMs.forEach(bom -> {
+            deviceIds.add(bom.getDeviceId());
+        });
+        IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
+        reqVO.setNotPlanId(updateReqVO.getMainPlan().getId());
+        reqVO.setDeviceIds(new ArrayList<>(deviceIds));
+        List<IotMaintenanceBomDO> boms = iotMaintenanceBomMapper.selectList(reqVO);
+        if (CollUtil.isNotEmpty(boms)) {
+            throw exception(IOT_MAINTENANCE_SAME_DEVICE_EXISTS);
+        }
         IotMaintenancePlanSaveReqVO mainPlanSaveVO = updateReqVO.getMainPlan();
         IotMaintenancePlanDO iotMaintenancePlan = BeanUtils.toBean(mainPlanSaveVO, IotMaintenancePlanDO.class);
         iotMaintenancePlanMapper.updateById(iotMaintenancePlan);