From c7ff541d4d36ae31a23c05645b14c12e257c02c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=B1=B3?= <470431449@qq.com> Date: Wed, 27 Dec 2023 12:51:59 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=BD=ACEbom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/cache/MaterialMateCache.java | 2 +- .../domain/EBom/EbomInitProjectType.java | 2 +- .../OriginalBom/OriginalBomToEBomConvert.java | 76 ++++++++++++------- 3 files changed, 51 insertions(+), 29 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/cache/MaterialMateCache.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/cache/MaterialMateCache.java index e1362714..f166347d 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/cache/MaterialMateCache.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/cache/MaterialMateCache.java @@ -32,7 +32,7 @@ public class MaterialMateCache { } Pattern p = Pattern.compile(namePattern); Pattern p2 = Pattern.compile(texturePattern); - if(p.matcher(materialName).find() && p2.matcher(materialTexture).find()){ + if(p.matcher(materialName).find() && p2.matcher(StrUtil.isBlank(materialTexture)?"":materialTexture ).find()){ return mate; } } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EbomInitProjectType.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EbomInitProjectType.java index 212df464..d7ad3a82 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EbomInitProjectType.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EbomInitProjectType.java @@ -34,7 +34,7 @@ public class EbomInitProjectType { public EbomInitProjectType(BomNewEbomParentVO inFirstParent, List inAllChild) { this.firstParent = inFirstParent; this.allChild = inAllChild; - allChild.add(firstParent); + } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OriginalBom/OriginalBomToEBomConvert.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OriginalBom/OriginalBomToEBomConvert.java index 27819c55..e7c24e62 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OriginalBom/OriginalBomToEBomConvert.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/OriginalBom/OriginalBomToEBomConvert.java @@ -23,6 +23,7 @@ import com.nflg.product.bomnew.pojo.vo.MaterialMateVO; import com.nflg.product.bomnew.service.BomNewEbomParentService; import com.nflg.product.bomnew.service.MaterialMainService; import com.nflg.product.bomnew.service.UserRoleService; +import com.nflg.product.bomnew.service.cache.MaterialMateCache; import com.nflg.product.bomnew.util.ListCommonUtil; import com.nflg.product.bomnew.util.VUtils; import com.nflg.product.bomnew.util.VersionUtil; @@ -131,19 +132,20 @@ public class OriginalBomToEBomConvert extends BaseConvert { } } else { - if (parentEnt.getShouldBomExist().equals(1)) { //应该有BOM + // if (parentEnt.getShouldBomExist().equals(1)) { //应该有BOM if (CollUtil.isNotEmpty(parentChild)) { // 有子级 List mergeResult = mergeBOM(parentChild); Long parentRowId = buildEBomParent(parentEnt); // buildEBomChild(mergeResult, parentRowId); + parentEnt.setEBomRowId(parentRowId); handlerChild(parentEnt, mergeResult); } else { //无子级 //一板零部件 if (parentEnt.getMaterialCategoryCode().equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE)) { //通过名称找子级 - BaseMaterialVO materialBaseInfo = getComSub(parentEnt); + BaseMaterialVO materialBaseInfo = getCommonMaterialByRel(parentEnt); if (Objects.nonNull(materialBaseInfo)) { List oldParenChild = SpringUtil.getBean(BomNewEbomChildMapper.class).getChildByMaterialNo(parentEnt.getMaterialNo()); @@ -157,9 +159,9 @@ public class OriginalBomToEBomConvert extends BaseConvert { this.eBomChildResult.add(newChild); } } else { - buildEBomParent(parentEnt); -// newChild.setParentRowId(parentRowId); -// this.eBomChildResult.add(newChild); + Long parentRowId= buildEBomParent(parentEnt); + newChild.setParentRowId(parentRowId); + this.eBomChildResult.add(newChild); } } else { @@ -169,7 +171,7 @@ public class OriginalBomToEBomConvert extends BaseConvert { buildEBomParent(parentEnt); } } - } + // } } @@ -185,7 +187,7 @@ public class OriginalBomToEBomConvert extends BaseConvert { List materialBaseInfo = SpringUtil.getBean(MaterialMainMapper.class).getMaterialBaseInfoByName(parentEnt.getMaterialName()); List material = materialBaseInfo.stream().filter(u -> !u.getMaterialNo().equals(parentEnt.getMaterialNo())).collect(Collectors.toList()); VUtils.isTure(material.size() > 1).throwMessage("一般零部件:" + parentEnt.getMaterialName() + "在主数据中存在多条数据"); - return CollUtil.isNotEmpty(material)? material.get(0):null; + return CollUtil.isNotEmpty(material) ? material.get(0) : null; } /** @@ -199,11 +201,12 @@ public class OriginalBomToEBomConvert extends BaseConvert { for (BomOriginalListVO childVo : parentChild) { if (StrUtil.isBlank(childVo.getMaterialNo())) { handlerCommonMaterialForReplace(childVo); - } else if (StrUtil.isNotBlank(childVo.getMaterialNo()) && StrUtil.isNotBlank(childVo.getMaterialCategoryCode()) && childVo.getMaterialCategoryCode().equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE)) { + } + else if (StrUtil.isNotBlank(childVo.getMaterialNo()) && StrUtil.isNotBlank(childVo.getMaterialCategoryCode()) && childVo.getMaterialCategoryCode().equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE)) { //找到对应物料 - BaseMaterialVO materialBaseInfo = getComSub(childVo); + BaseMaterialVO materialBaseInfo = getCommonMaterialByRel(childVo); if (Objects.nonNull(materialBaseInfo)) { List oldParenChild = SpringUtil.getBean(BomNewEbomChildMapper.class).getChildByMaterialNo(parentEntity.getMaterialNo()); @@ -217,43 +220,60 @@ public class OriginalBomToEBomConvert extends BaseConvert { this.eBomChildResult.add(newChild); } } else { - // Long parentRowId = buildEBomParent(childVo); - buildEBomChild(childVo, parentEntity.getRowId()); + Long parentRowId = buildEBomParent(childVo); + childVo.setEBomRowId(parentRowId); + BomNewEbomChildEntity childEntity = buildCommonEbomChildEntity(materialBaseInfo, childVo); + this.eBomChildResult.add(childEntity); } - continue; + } } - buildEBomChild(childVo, parentEntity.getRowId()); + buildEBomChild(childVo, parentEntity.getEBomRowId()); } } private void handlerCommonMaterialForReplace(BomOriginalListVO parentEntity) { - //通过规则获取物料编码 - MaterialMateVO materialMate = getMaterialByRel(parentEntity); - //找到对应物料 - if (Objects.nonNull(materialMate)) { - List materialBaseInfo = SpringUtil.getBean(MaterialMainMapper.class).getMaterialBaseInfo(ImmutableList.of(materialMate.getMaterialNo())); - if (CollUtil.isNotEmpty(materialBaseInfo)) { - //根据物料编码- - BaseMaterialVO baseMaterialVO = materialBaseInfo.get(0); - parentEntity.setMaterialNo(baseMaterialVO.getMaterialNo()); - parentEntity.setMaterialName(baseMaterialVO.getMaterialName()); - parentEntity.setMaterialDesc(baseMaterialVO.getMaterialDesc()); - parentEntity.setMaterialTexture(baseMaterialVO.getMaterialTexture()); - } + BaseMaterialVO baseMaterialVO = getCommonMaterialByRel(parentEntity); + if (Objects.nonNull(baseMaterialVO)) { + //根据物料编码- + parentEntity.setMaterialNo(baseMaterialVO.getMaterialNo()); + parentEntity.setMaterialName(baseMaterialVO.getMaterialName()); + parentEntity.setMaterialDesc(baseMaterialVO.getMaterialDesc()); + parentEntity.setMaterialTexture(baseMaterialVO.getMaterialTexture()); } } + private BaseMaterialVO getCommonMaterialByRel(BomOriginalListVO parentEntity) { + //通过规则获取物料编码 + MaterialMateVO materialMate = getMaterialByRelForToEBom(parentEntity); + //找到对应物料 + if (Objects.nonNull(materialMate)) { + List materialBaseInfo = SpringUtil.getBean(MaterialMainMapper.class).getMaterialBaseInfo(ImmutableList.of(materialMate.getMaterialNo())); + return materialBaseInfo.get(0); + + } + return null; + + + } + + private MaterialMateVO getMaterialByRelForToEBom(BaseMaterialVO originalPlmBomVO) { + MaterialMateCache mateCache = new MaterialMateCache(); + MaterialMateVO materialMate = mateCache.findMaterialByNameOrmaterialTexture(originalPlmBomVO.getMaterialName(), originalPlmBomVO.getMaterialTexture()); + return materialMate; + } + protected BomNewEbomChildEntity buildCommonEbomChildEntity(BaseMaterialVO material, BomOriginalListVO parent) { BomNewEbomChildEntity childEntity = new BomNewEbomChildEntity(); - childEntity.setParentRowId(parent.getRowId()); + childEntity.setParentRowId(parent.getEBomRowId()>0?parent.getEBomRowId(): parent.getRowId()); childEntity.setOrderNumber("001"); + childEntity.setIdentityNo(StrUtil.join("-", parent.getMaterialNo(), material.getMaterialNo())); childEntity.setDrawingNo(material.getDrawingNo()); childEntity.setMaterialNo(material.getMaterialNo()); childEntity.setMaterialName(material.getMaterialName()); @@ -339,6 +359,7 @@ public class OriginalBomToEBomConvert extends BaseConvert { */ private List mergeBOM(List list) { List result = new ArrayList(); + result.addAll(list.stream().filter(u->StrUtil.isBlank(u.getMaterialNo())).collect(Collectors.toList())); list = list.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.toList()); Map> mateiralNoMp = ListCommonUtil.listGroupMap(list, BomOriginalListVO::getMaterialNo); for (Map.Entry> entry : mateiralNoMp.entrySet()) { @@ -354,6 +375,7 @@ public class OriginalBomToEBomConvert extends BaseConvert { one.setTotalWeight(totalWeightResult); result.add(one); } + return result; }