|
@@ -5,8 +5,10 @@ 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.IotCommonBomMaterialSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicematerial.vo.IotDeviceMaterialPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicematerial.vo.IotDeviceMaterialSaveReqVO;
|
|
|
+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.mysql.IotDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicematerial.IotDeviceMaterialMapper;
|
|
@@ -16,9 +18,14 @@ 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_NOT_EXISTS;
|
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_DEVICE_MATERIAL_NOT_EXISTS;
|
|
|
|
|
|
|
|
@@ -110,8 +117,52 @@ public class IotDeviceMaterialServiceImpl implements IotDeviceMaterialService {
|
|
|
"code", code
|
|
|
));
|
|
|
// 设置关联设备的 bom_sync_status = 1
|
|
|
- // 将设备分类BOM及BOM节点挂载的物料同步到设备BOM
|
|
|
- iotBomService.syncDeviceBomAndMaterials(deviceMaterials.get(0).getDeviceCategoryId());
|
|
|
+ iotDeviceMapper.updateBomSyncStatus(deviceMaterials.get(0).getDeviceId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long addMaterials(List<IotDeviceMaterialSaveReqVO> materials) {
|
|
|
+ Long resultCount = 0L;
|
|
|
+ if (CollUtil.isEmpty(materials)) {
|
|
|
+ throw exception(IOT_DEVICE_MATERIAL_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ Long bomNodeId = materials.get(0).getBomNodeId();
|
|
|
+ Long deviceId = materials.get(0).getDeviceId();
|
|
|
+
|
|
|
+ if (ObjUtil.isEmpty(bomNodeId)) {
|
|
|
+ throw exception(IOT_DEVICE_MATERIAL_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ // 先查询当前BOM节点下所有物料 与要添加的物料匹配 筛选出在数据库中不存在的物料 插入到数据库
|
|
|
+ IotDeviceMaterialPageReqVO reqVO = new IotDeviceMaterialPageReqVO();
|
|
|
+ reqVO.setBomNodeId(bomNodeId);
|
|
|
+ List<IotDeviceMaterialDO> existMaterials = iotDeviceMaterialMapper.selectList(reqVO);
|
|
|
+ List<IotDeviceMaterialSaveReqVO> newMaterials = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(existMaterials)) {
|
|
|
+ // 提取已存在的物料编码集合
|
|
|
+ Set<String> existCodes = existMaterials.stream()
|
|
|
+ .map(IotDeviceMaterialDO::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<IotDeviceMaterialDO> tobeAddedMaterials = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(newMaterials)) {
|
|
|
+ newMaterials.forEach(material -> {
|
|
|
+ IotDeviceMaterialDO iotCommonBomMaterial = BeanUtils.toBean(material, IotDeviceMaterialDO.class);
|
|
|
+ tobeAddedMaterials.add(iotCommonBomMaterial);
|
|
|
+ });
|
|
|
+ iotDeviceMaterialMapper.insertBatch(tobeAddedMaterials);
|
|
|
+ resultCount = Long.valueOf(tobeAddedMaterials.size());
|
|
|
+ }
|
|
|
+ // 设置设备bom同步状态 sync_bom_status = 1
|
|
|
+ iotDeviceMapper.updateBomSyncStatus(deviceId);
|
|
|
+ return resultCount;
|
|
|
}
|
|
|
|
|
|
}
|