Explorar o código

pms功能优化 设置BOM节点属性 功能优化

zhangcl hai 4 meses
pai
achega
18fcf14fa7

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

@@ -19,7 +19,8 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_INFO_NOT_EXISTS = new ErrorCode( 122, "资料数据不存在");
     ErrorCode IOT_TREE_NOT_EXISTS = new ErrorCode(122, "pms树不存在");
     ErrorCode IOT_COMMON_BOM_MATERIAL_NOT_EXISTS = new ErrorCode(123, "设备分类公共BOM挂载物料关联不存在");
+    ErrorCode IOT_COMMON_BOM_MATERIAL_EXISTS = new ErrorCode(127, "当前BOM节点已经存在此物料");
     ErrorCode IOT_DEVICE_CATEGORY_TEMPLATE_NOT_EXISTS = new ErrorCode(124, "设备分类属性公用模板不存在");
     ErrorCode IOT_DEVICE_CATEGORY_TEMPLATE_ATTRS_NOT_EXISTS = new ErrorCode(125, "设备分类公共模板属性不存在");
-    ErrorCode IOT_INFO_EXISTS = new ErrorCode(125, "存在子分类");
+    ErrorCode IOT_INFO_EXISTS = new ErrorCode(126, "存在子分类");
 }

+ 10 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotcommonbommaterial/IotCommonBomMaterialMapper.java

@@ -4,9 +4,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.module.pms.controller.admin.iotcommonbommaterial.vo.IotCommonBomMaterialPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotcommonbommaterial.vo.IotCommonBomMaterialSaveReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotcommonbommaterial.IotCommonBomMaterialDO;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * PMS 设备分类公共BOM挂载物料关联 Mapper
  *
@@ -29,4 +32,11 @@ public interface IotCommonBomMaterialMapper extends BaseMapperX<IotCommonBomMate
                 .orderByDesc(IotCommonBomMaterialDO::getId));
     }
 
+    default List<IotCommonBomMaterialDO> selectList(IotCommonBomMaterialSaveReqVO reqVO) {
+        return selectList(new LambdaQueryWrapperX<IotCommonBomMaterialDO>()
+                .eq(IotCommonBomMaterialDO::getDeviceCategoryId, reqVO.getDeviceCategoryId())
+                .eq(IotCommonBomMaterialDO::getBomNodeId, reqVO.getBomNodeId())
+                .eq(IotCommonBomMaterialDO::getMaterialId, reqVO.getMaterialId()));
+    }
+
 }

+ 3 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotmaterial/IotMaterialMapper.java

@@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmaterial.vo.IotMaterialPageReqVO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotcommonbommaterial.IotCommonBomMaterialDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicematerial.IotDeviceMaterialDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaterial.IotMaterialDO;
 import org.apache.ibatis.annotations.Mapper;
@@ -46,8 +47,8 @@ public interface IotMaterialMapper extends BaseMapperX<IotMaterialDO> {
 
     default PageResult<IotMaterialDO> getMaterialsByBomId(IotMaterialPageReqVO reqVO) {
         MPJLambdaWrapperX<IotMaterialDO> query = new MPJLambdaWrapperX<IotMaterialDO>();
-        query.leftJoin(IotDeviceMaterialDO.class, IotDeviceMaterialDO::getMaterialId, IotMaterialDO::getId)
-                .eq(ObjectUtil.isNotNull(reqVO.getBomId()), IotDeviceMaterialDO::getBomNodeId, reqVO.getBomId())
+        query.leftJoin(IotCommonBomMaterialDO.class, IotCommonBomMaterialDO::getMaterialId, IotMaterialDO::getId)
+                .eq(ObjectUtil.isNotNull(reqVO.getBomId()), IotCommonBomMaterialDO::getBomNodeId, reqVO.getBomId())
                 .like(IotDeviceMaterialDO::getName, reqVO.getName());
         return selectJoinPage(reqVO, IotMaterialDO.class, query);
     }

+ 9 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotcommonbommaterial/IotCommonBomMaterialServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.pms.service.iotcommonbommaterial;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.iotcommonbommaterial.vo.IotCommonBomMaterialPageReqVO;
@@ -11,7 +12,10 @@ import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 
+import java.util.List;
+
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_COMMON_BOM_MATERIAL_EXISTS;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_COMMON_BOM_MATERIAL_NOT_EXISTS;
 
 /**
@@ -30,6 +34,11 @@ public class IotCommonBomMaterialServiceImpl implements IotCommonBomMaterialServ
     public Long createIotCommonBomMaterial(IotCommonBomMaterialSaveReqVO createReqVO) {
         // 插入
         IotCommonBomMaterialDO iotCommonBomMaterial = BeanUtils.toBean(createReqVO, IotCommonBomMaterialDO.class);
+        // 校验 相同节点下是否存在相同id的物料
+        List<IotCommonBomMaterialDO> commonBomMaterials = iotCommonBomMaterialMapper.selectList(createReqVO);
+        if (CollUtil.isNotEmpty(commonBomMaterials)) {
+            throw exception(IOT_COMMON_BOM_MATERIAL_EXISTS);
+        }
         iotCommonBomMaterialMapper.insert(iotCommonBomMaterial);
         // 返回
         return iotCommonBomMaterial.getId();