|
@@ -7,6 +7,7 @@ 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;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotbom.vo.IotBomPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotbom.vo.IotBomPageReqVO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotbom.vo.IotBomRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotbom.vo.IotBomSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotbom.vo.IotBomSaveReqVO;
|
|
|
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.controller.admin.iotdevicebom.vo.IotDeviceBomListReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdevicebom.vo.IotDeviceBomListReqVO;
|
|
@@ -14,6 +15,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMain
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotbom.IotBomDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotbom.IotBomDO;
|
|
|
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.dataobject.iotdevicebom.IotDeviceBomDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicebom.IotDeviceBomDO;
|
|
@@ -405,6 +407,72 @@ public class IotBomServiceImpl implements IotBomService {
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public PageResult<IotBomRespVO> getBomTreePage(IotBomListReqVO reqVO) {
|
|
|
|
|
+ // 1. 查询所有符合条件的BOM节点(原逻辑)
|
|
|
|
|
+ Set<Long> deviceCategoryIds = new HashSet<>();
|
|
|
|
|
+ if (Objects.nonNull(reqVO.getDeviceCategoryId())) {
|
|
|
|
|
+ deviceCategoryIds = iotProductClassifyService.getChildIotProductClassifyList(reqVO.getDeviceCategoryId());
|
|
|
|
|
+ deviceCategoryIds.add(reqVO.getDeviceCategoryId());
|
|
|
|
|
+ }
|
|
|
|
|
+ List<IotBomDO> allNodes = iotBomMapper.selectList(reqVO, deviceCategoryIds);
|
|
|
|
|
+ if (CollUtil.isEmpty(allNodes)) {
|
|
|
|
|
+ return PageResult.empty();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 查询物料数量
|
|
|
|
|
+ List<Long> bomNodeIds = allNodes.stream().map(IotBomDO::getId).collect(Collectors.toList());
|
|
|
|
|
+ IotCommonBomMaterialSaveReqVO materialReq = new IotCommonBomMaterialSaveReqVO();
|
|
|
|
|
+ materialReq.setBomNodeIds(bomNodeIds);
|
|
|
|
|
+ List<IotCommonBomMaterialDO> materials = iotCommonBomMaterialMapper.selectList1(materialReq);
|
|
|
|
|
+ Map<Long, Integer> materialCountMap = materials.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(IotCommonBomMaterialDO::getBomNodeId, Collectors.summingInt(x -> 1)));
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 查询设备分类名称(保持原有逻辑)
|
|
|
|
|
+ Map<Long, IotProductClassifyDO> deviceCategoryMap = iotProductClassifyService.getIotProductClassifyMap(
|
|
|
|
|
+ allNodes.stream().map(IotBomDO::getDeviceCategoryId).distinct().collect(Collectors.toList()));
|
|
|
|
|
+
|
|
|
|
|
+ // 4. DO -> VO 并填充扩展字段
|
|
|
|
|
+ List<IotBomRespVO> allVoList = allNodes.stream().map(bom -> {
|
|
|
|
|
+ IotBomRespVO vo = BeanUtils.toBean(bom, IotBomRespVO.class);
|
|
|
|
|
+ vo.setMaterials(materialCountMap.getOrDefault(bom.getId(), 0));
|
|
|
|
|
+ Optional.ofNullable(bom.getDeviceCategoryId())
|
|
|
|
|
+ .map(deviceCategoryMap::get)
|
|
|
|
|
+ .ifPresent(c -> vo.setDeviceCategoryName(c.getName()));
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 构建树结构(按 parent_id 分组)
|
|
|
|
|
+ Map<Long, List<IotBomRespVO>> parentIdMap = allVoList.stream()
|
|
|
|
|
+ .filter(vo -> vo.getParentId() != null) // 防御 null,正常 parent_id 均有值
|
|
|
|
|
+ .collect(Collectors.groupingBy(IotBomRespVO::getParentId));
|
|
|
|
|
+
|
|
|
|
|
+ allVoList.forEach(vo -> {
|
|
|
|
|
+ List<IotBomRespVO> children = parentIdMap.getOrDefault(vo.getId(), Collections.emptyList());
|
|
|
|
|
+ children.sort(Comparator.comparingInt(IotBomRespVO::getSort)); // 子节点按 sort 升序
|
|
|
|
|
+ vo.setChildren(children);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 提取顶级节点(parentId == 0 视为顶级,同时兼容 null)
|
|
|
|
|
+ List<IotBomRespVO> rootNodes = allVoList.stream()
|
|
|
|
|
+ .filter(vo -> vo.getParentId() != null && vo.getParentId() == 0)
|
|
|
|
|
+ .sorted(Comparator.comparingInt(IotBomRespVO::getSort))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ // 7. 对顶级节点进行内存分页
|
|
|
|
|
+ int total = rootNodes.size();
|
|
|
|
|
+ int pageNo = reqVO.getPageNo();
|
|
|
|
|
+ int pageSize = reqVO.getPageSize();
|
|
|
|
|
+ int fromIndex = (pageNo - 1) * pageSize;
|
|
|
|
|
+ int toIndex = Math.min(fromIndex + pageSize, total);
|
|
|
|
|
+ if (fromIndex >= total) {
|
|
|
|
|
+ return new PageResult<>(Collections.emptyList(), (long) total);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<IotBomRespVO> pageRoots = rootNodes.subList(fromIndex, toIndex);
|
|
|
|
|
+
|
|
|
|
|
+ return new PageResult<>(pageRoots, (long) total);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public PageResult<IotBomDO> deviceAssociateBomPage(IotBomPageReqVO pageReqVO) {
|
|
public PageResult<IotBomDO> deviceAssociateBomPage(IotBomPageReqVO pageReqVO) {
|
|
|
return iotBomMapper.deviceAssociateBomPage(pageReqVO);
|
|
return iotBomMapper.deviceAssociateBomPage(pageReqVO);
|