|
@@ -202,34 +202,33 @@ public class IotBomServiceImpl implements IotBomService {
|
|
|
public void copyBomByCategory(Long deviceCategoryId, Long deviceId) {
|
|
|
// 1. 查询源数据(按创建时间排序保证基础顺序)
|
|
|
List<IotBomDO> sourceBoms = deviceCategoryBom(deviceCategoryId);
|
|
|
- if (CollUtil.isEmpty(sourceBoms)) {
|
|
|
- throw exception(IOT_BOM_NOT_EXISTS);
|
|
|
+ if (CollUtil.isNotEmpty(sourceBoms)) {
|
|
|
+ // 2. 构建树形结构并获取层级顺序
|
|
|
+ List<IotBomDO> orderedBoms = buildHierarchyOrder(sourceBoms);
|
|
|
+ // 查询当前所有BOM节点关联的所有物料
|
|
|
+ List<Long> bomIds = convertListByFlatMap(orderedBoms, bom -> Stream.of(bom.getId()));
|
|
|
+ IotCommonBomMaterialSaveReqVO reqVO = new IotCommonBomMaterialSaveReqVO();
|
|
|
+ reqVO.setBomNodeIds(bomIds);
|
|
|
+ List<IotCommonBomMaterialDO> bomMaterials = iotCommonBomMaterialMapper.selectList(reqVO);
|
|
|
+ Map<Long, List<IotCommonBomMaterialDO>> bomNodeMaterialMap = bomMaterials.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ IotCommonBomMaterialDO::getBomNodeId, // 分组键:提取 bomNodeId
|
|
|
+ Collectors.toList() // 分组值:保存为列表
|
|
|
+ ));
|
|
|
+ // 3. 生成ID映射关系
|
|
|
+ Map<Long, Long> idMapping = new LinkedHashMap<>();
|
|
|
+ orderedBoms.forEach(bom -> idMapping.put(bom.getId(), IdGenerator.nextId()));
|
|
|
+ // 4. 转换目标对象
|
|
|
+ List<IotDeviceBomDO> targetBoms = convertBoms(orderedBoms, idMapping, deviceId);
|
|
|
+ // 转换 bom关联的物料 目标对象
|
|
|
+ List<IotDeviceMaterialDO> targetDeviceMaterials = convertBomMaterials(idMapping, deviceCategoryId, deviceId, bomNodeMaterialMap);
|
|
|
+ // 批量插入 设备bom关联的物料 // 设备分类BOM已经挂载的物料 也要拷贝到 设备BOM关联物料表
|
|
|
+ iotDeviceMaterialMapper.insertBatch(targetDeviceMaterials);
|
|
|
+ // 批量插入设备BOM
|
|
|
+ iotDeviceBomMapper.insertBatch(targetBoms);
|
|
|
+ // 拷贝BOM成功后 设置设备 bom_sync_status 字段 为 1已同步
|
|
|
+ iotDeviceMapper.updateBomSyncStatus(deviceId);
|
|
|
}
|
|
|
- // 2. 构建树形结构并获取层级顺序
|
|
|
- List<IotBomDO> orderedBoms = buildHierarchyOrder(sourceBoms);
|
|
|
- // 查询当前所有BOM节点关联的所有物料
|
|
|
- List<Long> bomIds = convertListByFlatMap(orderedBoms, bom -> Stream.of(bom.getId()));
|
|
|
- IotCommonBomMaterialSaveReqVO reqVO = new IotCommonBomMaterialSaveReqVO();
|
|
|
- reqVO.setBomNodeIds(bomIds);
|
|
|
- List<IotCommonBomMaterialDO> bomMaterials = iotCommonBomMaterialMapper.selectList(reqVO);
|
|
|
- Map<Long, List<IotCommonBomMaterialDO>> bomNodeMaterialMap = bomMaterials.stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- IotCommonBomMaterialDO::getBomNodeId, // 分组键:提取 bomNodeId
|
|
|
- Collectors.toList() // 分组值:保存为列表
|
|
|
- ));
|
|
|
- // 3. 生成ID映射关系
|
|
|
- Map<Long, Long> idMapping = new LinkedHashMap<>();
|
|
|
- orderedBoms.forEach(bom -> idMapping.put(bom.getId(), IdGenerator.nextId()));
|
|
|
- // 4. 转换目标对象
|
|
|
- List<IotDeviceBomDO> targetBoms = convertBoms(orderedBoms, idMapping, deviceId);
|
|
|
- // 转换 bom关联的物料 目标对象
|
|
|
- List<IotDeviceMaterialDO> targetDeviceMaterials = convertBomMaterials(idMapping, deviceCategoryId, deviceId, bomNodeMaterialMap);
|
|
|
- // 批量插入 设备bom关联的物料 // 设备分类BOM已经挂载的物料 也要拷贝到 设备BOM关联物料表
|
|
|
- iotDeviceMaterialMapper.insertBatch(targetDeviceMaterials);
|
|
|
- // 批量插入设备BOM
|
|
|
- iotDeviceBomMapper.insertBatch(targetBoms);
|
|
|
- // 拷贝BOM成功后 设置设备 bom_sync_status 字段 为 1已同步
|
|
|
- iotDeviceMapper.updateBomSyncStatus(deviceId);
|
|
|
}
|
|
|
|
|
|
/**
|