|
@@ -1,18 +1,25 @@
|
|
package cn.iocoder.yudao.module.pms.service.iotcommonbommaterial;
|
|
package cn.iocoder.yudao.module.pms.service.iotcommonbommaterial;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
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.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
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.IotCommonBomMaterialPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotcommonbommaterial.vo.IotCommonBomMaterialSaveReqVO;
|
|
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.dataobject.iotcommonbommaterial.IotCommonBomMaterialDO;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotcommonbommaterial.IotCommonBomMaterialMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotcommonbommaterial.IotCommonBomMaterialMapper;
|
|
|
|
+import com.google.common.collect.ImmutableMap;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
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.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_EXISTS;
|
|
@@ -82,4 +89,54 @@ public class IotCommonBomMaterialServiceImpl implements IotCommonBomMaterialServ
|
|
return iotCommonBomMaterialMapper.selectList1(reqVO);
|
|
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;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|