| | |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.production.bean.dto.ProductStructureDto; |
| | | import com.ruoyi.technology.bean.dto.BomImportDto; |
| | | import com.ruoyi.technology.bean.dto.TechnologyBomDto; |
| | | import com.ruoyi.technology.bean.dto.TechnologyBomStructureDto; |
| | |
| | | |
| | | |
| | | @Override |
| | | public void exportBom(HttpServletResponse response, Integer bomId) { |
| | | public void exportBom(HttpServletResponse response, Long bomId) { |
| | | if (bomId == null) { |
| | | throw new ServiceException("BOM ID不能为空"); |
| | | } |
| | | |
| | | List<TechnologyBomStructureVo> treeData = technologyBomStructureService.listByBomId(bomId); |
| | | if (treeData == null || treeData.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | // List<ProductStructureDto> treeData = productStructureService.listBybomId(bomId); |
| | | // if (treeData == null || treeData.isEmpty()) { |
| | | // return; |
| | | // } |
| | | // |
| | | // // 将树形结构扁平化 使用 BFS算法 导出,按层级顺序 |
| | | // List<BomImportDto> exportList = new ArrayList<>(); |
| | | // |
| | | // // Map<ID, Node> idMap 用于查找父节点 |
| | | // Map<Long, ProductStructureDto> idMap = new HashMap<>(); |
| | | // populateMap(treeData, idMap); |
| | | // |
| | | // // treeData 的第一个是根节点 |
| | | // for (ProductStructureDto root : treeData) { |
| | | // // 添加根节点 |
| | | // BomImportDto rootRow = new BomImportDto(); |
| | | // rootRow.setParentName(root.getProductName()); |
| | | // rootRow.setParentSpec(root.getModel()); |
| | | // rootRow.setUnitQty(root.getUnitQuantity()); |
| | | // rootRow.setRemark(""); |
| | | // exportList.add(rootRow); |
| | | // |
| | | // // BFS 遍历-队列 |
| | | // Queue<ProductStructureDto> queue = new LinkedList<>(); |
| | | // if (root.getChildren() != null) { |
| | | // queue.addAll(root.getChildren()); |
| | | // } |
| | | // |
| | | // while (!queue.isEmpty()) { |
| | | // ProductStructureDto child = queue.poll(); |
| | | // |
| | | // // 查找父节点 |
| | | // ProductStructureDto parent = idMap.get(child.getParentId()); |
| | | // if (parent == null) { |
| | | // // 除了最外层节点,其他节点的父类肯定是不会为空的 |
| | | // continue; |
| | | // } |
| | | // |
| | | // BomImportDto row = new BomImportDto(); |
| | | // // 父类信息 |
| | | // row.setParentName(parent.getProductName()); |
| | | // row.setParentSpec(parent.getModel()); |
| | | // // 子类信息 |
| | | // row.setChildName(child.getProductName()); |
| | | // row.setChildSpec(child.getModel()); |
| | | // row.setUnitQty(child.getUnitQuantity()); |
| | | // row.setProcess(child.getProcessName()); |
| | | // |
| | | // exportList.add(row); |
| | | // |
| | | // // 将子节点的子节点加入队列-下一层 |
| | | // if (child.getChildren() != null && !child.getChildren().isEmpty()) { |
| | | // queue.addAll(child.getChildren()); |
| | | // } |
| | | // } |
| | | // } |
| | | // 将树形结构扁平化 使用 BFS算法 导出,按层级顺序 |
| | | List<BomImportDto> exportList = new ArrayList<>(); |
| | | |
| | | // Map<ID, Node> idMap 用于查找父节点 |
| | | Map<Long, TechnologyBomStructureVo> idMap = new HashMap<>(); |
| | | populateMap(treeData, idMap); |
| | | |
| | | // treeData 的第一个是根节点 |
| | | for (TechnologyBomStructureVo root : treeData) { |
| | | // 添加根节点 |
| | | BomImportDto rootRow = new BomImportDto(); |
| | | rootRow.setParentName(root.getProductName()); |
| | | rootRow.setParentSpec(root.getModel()); |
| | | rootRow.setUnitQty(root.getUnitQuantity()); |
| | | rootRow.setParentCode(root.getProductCode()); |
| | | rootRow.setRemark(""); |
| | | exportList.add(rootRow); |
| | | |
| | | // BFS 遍历-队列 |
| | | Queue<TechnologyBomStructureVo> queue = new LinkedList<>(); |
| | | if (root.getChildren() != null) { |
| | | queue.addAll(root.getChildren()); |
| | | } |
| | | |
| | | while (!queue.isEmpty()) { |
| | | TechnologyBomStructureVo child = queue.poll(); |
| | | |
| | | // 查找父节点 |
| | | TechnologyBomStructureVo parent = idMap.get(child.getParentId()); |
| | | if (parent == null) { |
| | | // 除了最外层节点,其他节点的父类肯定是不会为空的 |
| | | continue; |
| | | } |
| | | |
| | | BomImportDto row = new BomImportDto(); |
| | | // 父类信息 |
| | | row.setParentName(parent.getProductName()); |
| | | row.setParentSpec(parent.getModel()); |
| | | // 子类信息 |
| | | row.setChildName(child.getProductName()); |
| | | row.setChildSpec(child.getModel()); |
| | | row.setUnitQty(child.getUnitQuantity()); |
| | | row.setProcess(child.getOperationName()); |
| | | row.setChildCode(child.getProductCode()); |
| | | |
| | | exportList.add(row); |
| | | |
| | | // 将子节点的子节点加入队列-下一层 |
| | | if (child.getChildren() != null && !child.getChildren().isEmpty()) { |
| | | queue.addAll(child.getChildren()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | ExcelUtil<BomImportDto> util = new ExcelUtil<>(BomImportDto.class); |
| | | // util.exportExcel(response, exportList, "BOM结构导出"); |
| | | util.exportExcel(response, exportList, "BOM结构导出"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return s.replaceAll("[\\u00A0\\u3000]", "").trim(); |
| | | } |
| | | |
| | | private void populateMap(List<ProductStructureDto> nodes, Map<Long, ProductStructureDto> map) { |
| | | private void populateMap(List<TechnologyBomStructureVo> nodes, Map<Long, TechnologyBomStructureVo> map) { |
| | | if (nodes == null || nodes.isEmpty()) { |
| | | return; |
| | | } |
| | | for (ProductStructureDto node : nodes) { |
| | | for (TechnologyBomStructureVo node : nodes) { |
| | | map.put(node.getId(), node); |
| | | populateMap(node.getChildren(), map); |
| | | } |