|
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.pms.service.iotbom;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.lang.Snowflake;
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
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.iotbom.vo.IotBomListReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotbom.vo.IotBomListReqVO;
|
|
@@ -84,20 +85,48 @@ public class IotBomServiceImpl implements IotBomService {
|
|
// 更新
|
|
// 更新
|
|
IotBomDO updateObj = BeanUtils.toBean(updateReqVO, IotBomDO.class);
|
|
IotBomDO updateObj = BeanUtils.toBean(updateReqVO, IotBomDO.class);
|
|
iotBomMapper.updateById(updateObj);
|
|
iotBomMapper.updateById(updateObj);
|
|
|
|
+ syncDeviceBomAndMaterials(updateObj.getDeviceCategoryId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量更新设备的 bom_sync_status = 1
|
|
|
|
+ * @param ids
|
|
|
|
+ */
|
|
|
|
+ private void batchUpdateBomSyncStatus(List<Long> ids) {
|
|
|
|
+ LambdaUpdateWrapper<IotDeviceDO> wrapper = new LambdaUpdateWrapper<>();
|
|
|
|
+ wrapper.in(IotDeviceDO::getId, ids) // WHERE id IN (ids)
|
|
|
|
+ .set(IotDeviceDO::getBomSyncStatus, 1); // SET bom_sync_status = 1
|
|
|
|
+ iotDeviceMapper.update(wrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void deleteIotBom(Long id) {
|
|
|
|
+ // 校验存在
|
|
|
|
+ IotBomDO bom = validateIotBomExists(id);
|
|
|
|
+ // 删除
|
|
|
|
+ iotBomMapper.deleteById(id);
|
|
|
|
+ // 将设备分类BOM同步到 关联了当前设备分类的 设备 BOM
|
|
|
|
+ syncDeviceBomAndMaterials(bom.getDeviceCategoryId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 将设备分类BOM及bom节点挂载的物料同步到 设备bom
|
|
|
|
+ */
|
|
|
|
+ public void syncDeviceBomAndMaterials (Long deviceCategoryId){
|
|
// 选择了相同设备分类的设备,如果未同步过设备分类BOM, 应该将设备分类BOM同步复制到设备BOM。
|
|
// 选择了相同设备分类的设备,如果未同步过设备分类BOM, 应该将设备分类BOM同步复制到设备BOM。
|
|
// 设备分类BOM已经挂载的物料 也要拷贝到 设备BOM关联物料表
|
|
// 设备分类BOM已经挂载的物料 也要拷贝到 设备BOM关联物料表
|
|
// 1. 根据当前BOM节点关联的设备分类查询所有已经关联了此分类但是未同步过 设备分类BOM 的设备
|
|
// 1. 根据当前BOM节点关联的设备分类查询所有已经关联了此分类但是未同步过 设备分类BOM 的设备
|
|
IotDevicePageReqVO reqVO = new IotDevicePageReqVO();
|
|
IotDevicePageReqVO reqVO = new IotDevicePageReqVO();
|
|
- reqVO.setAssetClass(updateObj.getDeviceCategoryId());
|
|
|
|
|
|
+ reqVO.setAssetClass(deviceCategoryId);
|
|
reqVO.setBomSyncStatus(0);
|
|
reqVO.setBomSyncStatus(0);
|
|
List<IotDeviceDO> devices = iotDeviceMapper.selectList(reqVO);
|
|
List<IotDeviceDO> devices = iotDeviceMapper.selectList(reqVO);
|
|
if (CollUtil.isNotEmpty(devices)) {
|
|
if (CollUtil.isNotEmpty(devices)) {
|
|
// 2. 批量将当前设备分类BOM复制到每个设备
|
|
// 2. 批量将当前设备分类BOM复制到每个设备
|
|
- List<IotBomDO> bomList = deviceCategoryBom(updateObj.getDeviceCategoryId());
|
|
|
|
|
|
+ List<IotBomDO> bomList = deviceCategoryBom(deviceCategoryId);
|
|
// 3. 构建树形结构并获取层级顺序
|
|
// 3. 构建树形结构并获取层级顺序
|
|
- List<IotBomDO> orderedBoms = buildHierarchyOrder(bomList);
|
|
|
|
|
|
+ List<IotBomDO> orderedBomS = buildHierarchyOrder(bomList);
|
|
// 当前设备分类下所有bom节点id
|
|
// 当前设备分类下所有bom节点id
|
|
- List<Long> bomIds = convertListByFlatMap(orderedBoms, bom -> Stream.of(bom.getId()));
|
|
|
|
|
|
+ List<Long> bomIds = convertListByFlatMap(orderedBomS, bom -> Stream.of(bom.getId()));
|
|
IotCommonBomMaterialSaveReqVO saveReqVO = new IotCommonBomMaterialSaveReqVO();
|
|
IotCommonBomMaterialSaveReqVO saveReqVO = new IotCommonBomMaterialSaveReqVO();
|
|
saveReqVO.setBomNodeIds(bomIds);
|
|
saveReqVO.setBomNodeIds(bomIds);
|
|
List<IotCommonBomMaterialDO> bomMaterials = iotCommonBomMaterialMapper.selectList(saveReqVO);
|
|
List<IotCommonBomMaterialDO> bomMaterials = iotCommonBomMaterialMapper.selectList(saveReqVO);
|
|
@@ -115,15 +144,18 @@ public class IotBomServiceImpl implements IotBomService {
|
|
deviceIds.add(device.getId());
|
|
deviceIds.add(device.getId());
|
|
// 4. 生成ID映射关系
|
|
// 4. 生成ID映射关系
|
|
Map<Long, Long> idMapping = new LinkedHashMap<>();
|
|
Map<Long, Long> idMapping = new LinkedHashMap<>();
|
|
- orderedBoms.forEach(bom -> idMapping.put(bom.getId(), IdGenerator.nextId()));
|
|
|
|
|
|
+ orderedBomS.forEach(bom -> idMapping.put(bom.getId(), IdGenerator.nextId()));
|
|
// 5. 转换目标对象
|
|
// 5. 转换目标对象
|
|
- List<IotDeviceBomDO> targetBoms = convertBoms(orderedBoms, idMapping, device.getId());
|
|
|
|
|
|
+ List<IotDeviceBomDO> targetBoms = convertBoms(orderedBomS, idMapping, device.getId());
|
|
// 转换 bom关联的物料 目标对象
|
|
// 转换 bom关联的物料 目标对象
|
|
List<IotDeviceMaterialDO> targetDeviceMaterials = convertBomMaterials(idMapping, device.getAssetClass(), device.getId(), bomNodeMaterialMap);
|
|
List<IotDeviceMaterialDO> targetDeviceMaterials = convertBomMaterials(idMapping, device.getAssetClass(), device.getId(), bomNodeMaterialMap);
|
|
resultDeviceBomList.addAll(targetBoms);
|
|
resultDeviceBomList.addAll(targetBoms);
|
|
deviceMaterialList.addAll(targetDeviceMaterials);
|
|
deviceMaterialList.addAll(targetDeviceMaterials);
|
|
});
|
|
});
|
|
if (CollUtil.isNotEmpty(resultDeviceBomList)) {
|
|
if (CollUtil.isNotEmpty(resultDeviceBomList)) {
|
|
|
|
+ // 先删除相关设备的BOM 及 BOM节点已经关联的物料 (如果存在)
|
|
|
|
+ Integer count = iotDeviceBomMapper.deleteByDeviceIds(deviceIds);
|
|
|
|
+ Integer materialCount = iotDeviceMaterialMapper.deleteByDeviceIds(deviceIds);
|
|
// 批量插入设备BOM
|
|
// 批量插入设备BOM
|
|
iotDeviceBomMapper.insertBatch(resultDeviceBomList);
|
|
iotDeviceBomMapper.insertBatch(resultDeviceBomList);
|
|
if (CollUtil.isNotEmpty(deviceMaterialList)) {
|
|
if (CollUtil.isNotEmpty(deviceMaterialList)) {
|
|
@@ -131,34 +163,18 @@ public class IotBomServiceImpl implements IotBomService {
|
|
iotDeviceMaterialMapper.insertBatch(deviceMaterialList);
|
|
iotDeviceMaterialMapper.insertBatch(deviceMaterialList);
|
|
}
|
|
}
|
|
// 批量设置 设备 的BOM同步标识 bom_sync_status = 1
|
|
// 批量设置 设备 的BOM同步标识 bom_sync_status = 1
|
|
- batchUpdateBomSyncStatus(deviceIds);
|
|
|
|
|
|
+ // 单独修改设备BOM后再将 bom_sync_status 设置为 1
|
|
|
|
+ // batchUpdateBomSyncStatus(deviceIds);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 批量更新设备的 bom_sync_status = 1
|
|
|
|
- * @param ids
|
|
|
|
- */
|
|
|
|
- private void batchUpdateBomSyncStatus(List<Long> ids) {
|
|
|
|
- LambdaUpdateWrapper<IotDeviceDO> wrapper = new LambdaUpdateWrapper<>();
|
|
|
|
- wrapper.in(IotDeviceDO::getId, ids) // WHERE id IN (ids)
|
|
|
|
- .set(IotDeviceDO::getBomSyncStatus, 1); // SET bom_sync_status = 1
|
|
|
|
- iotDeviceMapper.update(wrapper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void deleteIotBom(Long id) {
|
|
|
|
- // 校验存在
|
|
|
|
- validateIotBomExists(id);
|
|
|
|
- // 删除
|
|
|
|
- iotBomMapper.deleteById(id);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void validateIotBomExists(Long id) {
|
|
|
|
- if (iotBomMapper.selectById(id) == null) {
|
|
|
|
|
|
+ private IotBomDO validateIotBomExists(Long id) {
|
|
|
|
+ IotBomDO bom = iotBomMapper.selectById(id);
|
|
|
|
+ if (ObjUtil.isEmpty(bom)) {
|
|
throw exception(IOT_BOM_NOT_EXISTS);
|
|
throw exception(IOT_BOM_NOT_EXISTS);
|
|
}
|
|
}
|
|
|
|
+ return bom;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -226,8 +242,9 @@ public class IotBomServiceImpl implements IotBomService {
|
|
iotDeviceMaterialMapper.insertBatch(targetDeviceMaterials);
|
|
iotDeviceMaterialMapper.insertBatch(targetDeviceMaterials);
|
|
// 批量插入设备BOM
|
|
// 批量插入设备BOM
|
|
iotDeviceBomMapper.insertBatch(targetBoms);
|
|
iotDeviceBomMapper.insertBatch(targetBoms);
|
|
- // 拷贝BOM成功后 设置设备 bom_sync_status 字段 为 1已同步
|
|
|
|
- iotDeviceMapper.updateBomSyncStatus(deviceId);
|
|
|
|
|
|
+ // 拷贝BOM成功后 设置设备 bom_sync_status 字段 为 1 已同步
|
|
|
|
+ // 只有在修改 设备BOM后才会将 关联设备的 bom_sync_status 设置为 1
|
|
|
|
+ // iotDeviceMapper.updateBomSyncStatus(deviceId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|