zhangcl пре 2 месеци
родитељ
комит
a6acce8c3e

+ 17 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotcommonbommaterial/IotCommonBomMaterialController.java

@@ -43,6 +43,13 @@ public class IotCommonBomMaterialController {
         return success(iotCommonBomMaterialService.createIotCommonBomMaterial(createReqVO));
     }
 
+    @PostMapping("/addMaterials")
+    @Operation(summary = "批量 创建PMS 设备分类公共BOM挂载物料关联")
+    @PreAuthorize("@ss.hasPermission('pms:iot-common-bom-material:create')")
+    public CommonResult<Long> addMaterials(@Valid @RequestBody List<IotCommonBomMaterialSaveReqVO> materials) {
+        return success(iotCommonBomMaterialService.addMaterials(materials));
+    }
+
     @PutMapping("/update")
     @Operation(summary = "更新PMS 设备分类公共BOM挂载物料关联")
     @PreAuthorize("@ss.hasPermission('pms:iot-common-bom-material:update')")
@@ -60,6 +67,16 @@ public class IotCommonBomMaterialController {
         return success(true);
     }
 
+    @DeleteMapping("/deleteBomMaterial")
+    @Operation(summary = "删除PMS 设备分类公共BOM挂载物料关联")
+    @Parameter(name = "bomNodeId", description = "BOM节点id", required = true)
+    @Parameter(name = "code", description = "物料编码", required = true)
+    @PreAuthorize("@ss.hasPermission('pms:iot-common-bom-material:delete')")
+    public CommonResult<Boolean> deleteBomMaterial(@RequestParam("bomNodeId") Long bomNodeId, @RequestParam("code") String code) {
+        iotCommonBomMaterialService.deleteBomMaterial(bomNodeId, code);
+        return success(true);
+    }
+
     @GetMapping("/get")
     @Operation(summary = "获得PMS 设备分类公共BOM挂载物料关联")
     @Parameter(name = "id", description = "编号", required = true, example = "1024")

+ 2 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotbom/IotBomMapper.java

@@ -45,9 +45,9 @@ public interface IotBomMapper extends BaseMapperX<IotBomDO> {
     default List<IotBomDO> selectList(IotBomListReqVO reqVO, Set<Long> ids) {
         return selectList(new LambdaQueryWrapperX<IotBomDO>()
                 .likeIfPresent(IotBomDO::getName, reqVO.getName())
-                // .eqIfPresent(IotBomDO::getDeviceCategoryId, reqVO.getDeviceCategoryId())
                 .inIfPresent(IotBomDO::getDeviceCategoryId, ids)
-                .eqIfPresent(IotBomDO::getStatus, reqVO.getStatus()));
+                .eqIfPresent(IotBomDO::getStatus, reqVO.getStatus())
+                .orderByAsc(IotBomDO::getSort));
     }
 
     default IotBomDO selectParentNode(IotBomSaveReqVO reqVO) {

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

@@ -61,4 +61,22 @@ public interface IotCommonBomMaterialService {
      */
     List<IotCommonBomMaterialDO> getIotCommonBomMaterials(IotCommonBomMaterialSaveReqVO reqVO);
 
+    /**
+     * 获得PMS 设备分类公共BOM挂载物料关联列表
+     *
+     * @param bomNodeId bom节点id
+     * @param code 物料编码
+     * @return
+     *
+     */
+    void deleteBomMaterial(Long bomNodeId, String code);
+
+    /**
+     * 获得PMS 设备分类公共BOM挂载物料关联列表
+     *
+     * @param materials 批量选择的物料集合
+     * @return
+     *
+     */
+    Long addMaterials(List<IotCommonBomMaterialSaveReqVO> materials);
 }

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

@@ -1,18 +1,25 @@
 package cn.iocoder.yudao.module.pms.service.iotcommonbommaterial;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
+import cn.hutool.core.util.StrUtil;
 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;
 import cn.iocoder.yudao.module.pms.controller.admin.iotcommonbommaterial.vo.IotCommonBomMaterialSaveReqVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotcommonbommaterial.IotCommonBomMaterialDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotcommonbommaterial.IotCommonBomMaterialMapper;
+import com.google.common.collect.ImmutableMap;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 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;
@@ -82,4 +89,54 @@ public class IotCommonBomMaterialServiceImpl implements IotCommonBomMaterialServ
         return iotCommonBomMaterialMapper.selectList1(reqVO);
     }
 
+    @Override
+    public void deleteBomMaterial(Long bomNodeId, String code) {
+        if (ObjUtil.isEmpty(bomNodeId) || StrUtil.isBlank(code)) {
+            throw exception(IOT_COMMON_BOM_MATERIAL_NOT_EXISTS);
+        }
+        int count = iotCommonBomMaterialMapper.deleteByMap(ImmutableMap.of(
+                "bom_node_id", bomNodeId,
+                "code", code
+        ));
+    }
+
+    @Override
+    public Long addMaterials(List<IotCommonBomMaterialSaveReqVO> materials) {
+        if (CollUtil.isEmpty(materials)) {
+            throw exception(IOT_COMMON_BOM_MATERIAL_NOT_EXISTS);
+        }
+        Long bomNodeId = materials.get(0).getBomNodeId();
+        if (ObjUtil.isEmpty(bomNodeId)) {
+            throw exception(IOT_COMMON_BOM_MATERIAL_NOT_EXISTS);
+        }
+        // 先查询当前BOM节点下所有物料 与要添加的物料匹配 筛选出在数据库中不存在的物料 插入到数据库
+        IotCommonBomMaterialSaveReqVO reqVO = new IotCommonBomMaterialSaveReqVO();
+        reqVO.setBomNodeId(bomNodeId);
+        List<IotCommonBomMaterialDO> existMaterials = iotCommonBomMaterialMapper.selectList(reqVO);
+        List<IotCommonBomMaterialSaveReqVO> newMaterials = new ArrayList<>();
+        if (CollUtil.isNotEmpty(existMaterials)) {
+            // 提取已存在的物料编码集合
+            Set<String> existCodes = existMaterials.stream()
+                    .map(IotCommonBomMaterialDO::getCode) // 获取DO对象的code字段
+                    .filter(Objects::nonNull)             // 过滤可能的null值
+                    .collect(Collectors.toSet());
+            // 筛选出不存在的物料
+            newMaterials = materials.stream()
+                    .filter(material -> material.getCode() != null)     // 确保物料编码不为null
+                    .filter(material -> !existCodes.contains(material.getCode())) // 检查是否不存在
+                    .collect(Collectors.toList());
+        } else {
+            newMaterials = materials;
+        }
+        List<IotCommonBomMaterialDO> tobeAddedMaterials = new ArrayList<>();
+        if (CollUtil.isNotEmpty(newMaterials)) {
+            newMaterials.forEach(material -> {
+                IotCommonBomMaterialDO iotCommonBomMaterial = BeanUtils.toBean(material, IotCommonBomMaterialDO.class);
+                tobeAddedMaterials.add(iotCommonBomMaterial);
+            });
+            iotCommonBomMaterialMapper.insertBatch(tobeAddedMaterials);
+        }
+        return 1L;
+    }
+
 }