From 33a4847aa781714115433dab974dc1f0295444e2 Mon Sep 17 00:00:00 2001 From: yinq Date: Tue, 11 Mar 2025 17:27:34 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E7=89=A9=E6=96=99BOM=E9=80=92?= =?UTF-8?q?=E5=BD=92=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ProdMaterialBomServiceImpl.java | 38 +++++++++---------- .../mapper/mes/ProdMaterialBomMapper.xml | 2 +- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdMaterialBomServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdMaterialBomServiceImpl.java index 997beff7..6b7f62b5 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdMaterialBomServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdMaterialBomServiceImpl.java @@ -238,7 +238,7 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { topProdMaterialBomVo.setMaterialTypeId(1L); prodMaterialBomVos.add(topProdMaterialBomVo); - List tempList = prodMaterialBomVos.stream().map(ProdMaterialBomVo::getMaterialBomId).collect(Collectors.toList()); + List tempList = prodMaterialBomVos.stream().map(ProdMaterialBomVo::getMaterialBomId).toList(); for (ProdMaterialBomVo prodMaterialBomVo : prodMaterialBomVos) { // 如果是顶级节点, 遍历该父节点的所有子节点 if (!tempList.contains(prodMaterialBomVo.getParentId())) { @@ -267,33 +267,29 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService { /** * 递归列表 */ - private void recursionFn(List list, ProdMaterialBomVo t) { - // 得到子节点列表 - List childList = getChildList(list, t); - t.setChildren(childList); - for (ProdMaterialBomVo tChild : childList) { - if (hasChild(list, tChild)) { - recursionFn(list, tChild); + private void recursionFn(List list, ProdMaterialBomVo parent) { + // 获取子节点 + List childList = getChildList(list, parent); + parent.setChildren(childList); + + // 递归处理子节点 + for (ProdMaterialBomVo child : childList) { + // 确保子节点继承 BOM 版本信息 + if (StringUtils.isBlank(child.getMaterialBomVersion()) && StringUtils.isNotBlank(parent.getMaterialBomVersion())) { + child.setMaterialBomVersion(parent.getMaterialBomVersion()); } + recursionFn(list, child); } } /** * 得到子节点列表 */ - private List getChildList(List list, ProdMaterialBomVo t) { - List tlist = new ArrayList(); - Iterator it = list.iterator(); - while (it.hasNext()) { - ProdMaterialBomVo n = (ProdMaterialBomVo) it.next(); - if(StringUtils.isNotBlank(t.getMaterialBomVersion())){ - n.setMaterialBomVersion(t.getMaterialBomVersion()); - } - if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getMaterialBomId().longValue()) { - tlist.add(n); - } - } - return tlist; + private List getChildList(List list, ProdMaterialBomVo parent) { + return list.stream() + .filter(n -> StringUtils.isNotNull(n.getParentId()) && + n.getParentId().equals(parent.getMaterialBomId())) + .collect(Collectors.toList()); } /** diff --git a/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/ProdMaterialBomMapper.xml b/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/ProdMaterialBomMapper.xml index cda6aa14..b7aa5cc7 100644 --- a/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/ProdMaterialBomMapper.xml +++ b/ruoyi-modules/hwmom-mes/src/main/resources/mapper/mes/ProdMaterialBomMapper.xml @@ -27,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and pmb.parent_id = #{parentId} - order by pmb.material_bom_id desc + order by pmb.material_bom_id, pmb.material_bom_version desc