From 8ad11de234132eeb55d45a2985e9056f36024203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=B1=B3?= <470431449@qq.com> Date: Fri, 26 Jan 2024 14:38:25 +0800 Subject: [PATCH] =?UTF-8?q?BUG=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/BomNewPbomParentService.java | 2 +- .../service/domain/PBom/ConvertToMBom.java | 304 +----------------- 2 files changed, 2 insertions(+), 304 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java index 91a00337..7db5db01 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java @@ -807,7 +807,7 @@ public class BomNewPbomParentService extends ServiceImpl noProductionFactoryCodeList = allChild.stream().filter(u -> StrUtil.isBlank(u.getProductionFactoryCode())).map(u -> u.getMaterialNo()).collect(Collectors.toList()); VUtils.isTure(CollUtil.isNotEmpty(noProductionFactoryCodeList)).throwMessage(StrUtil.join(",", noProductionFactoryCodeList) + "物料暂未分工厂,请分完工厂再进行发布"); ConvertToMBom convertToMBom = new ConvertToMBom(rootParent, allChild); - convertToMBom.convertToMBom(false, true); + convertToMBom.convertToMBomNew(false, true); if (CollUtil.isNotEmpty(convertToMBom.getMBomParentResult())) { mBomParentService.saveOrUpdateBatch(convertToMBom.getMBomParentResult()); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/PBom/ConvertToMBom.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/PBom/ConvertToMBom.java index 577e3c59..fa8f2a2e 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/PBom/ConvertToMBom.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/PBom/ConvertToMBom.java @@ -48,9 +48,7 @@ public class ConvertToMBom { private List allChild_1010; - private List allChildTreeList_1020 = new ArrayList<>(); - - private List allChildTreeList_1010 = new ArrayList(); + @Getter List mBomParentResult = new ArrayList<>(); @@ -87,305 +85,5 @@ public class ConvertToMBom { } - /** - * 初始化1020 - */ - private void initFacAllChild_1020() { - List firstLevelNodes = allChild_1020.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList()); - for (ConvertToMBomDTO firstLevelNode : firstLevelNodes) { - firstLevelNode.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - - List firstChildNodes = allChild_1020.stream().filter(u -> u.getParentRowId().equals(firstLevelNode.getBomRowId())).collect(Collectors.toList()); - - for (ConvertToMBomDTO itemChild : firstChildNodes) { - - itemChild.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - } - } - - allChild_1020.forEach(k -> { - setDel(k, EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - }); - - - } - - /** - * 转换MBom - */ - public void convertToMBom(Boolean convert1010, Boolean convert1020) { - //handler1010(); - if (convert1020) { - handler1020(); - buildMBomFor1020(); - } - if (convert1010) { - buildMBomFor1010(); - } - - } - - - /** - * 构建MBom明细 - * - * @param - */ - private void buildMBomFor1020() { - BomNewMbomParentEntity mBomParent = buildMBomParent(EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - //当10120 bom 内容为空时,不创建31 的Mbom - - List bomContent1020 = allChildTreeList_1020.stream().filter(u -> u.getDelIs().equals(0) && u.getVirtualPartType().equals(0)).collect(Collectors.toList()); - if (CollUtil.isEmpty(bomContent1020)) { - return; - } - this.mBomParentResult.add(mBomParent); - List nodes1020 = allChildTreeList_1020.stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList()); - buildChildFor1020(EBomConstant.XIAN_TAO_FACTORY_CODE_1020, nodes1020, mBomParent.getRowId()); - } - - private void buildMBomFor1010() { - BomNewMbomParentEntity mBomParent = buildMBomParent(EBomConstant.MAIN_FACTORY_CODE_1010); - this.mBomParentResult.add(mBomParent); - allChild_1010.forEach(u -> { - u.setRelParentRowId(u.getParentRowId()); - }); - buildChildFor1010(EBomConstant.MAIN_FACTORY_CODE_1010, allChild_1010, mBomParent.getRowId()); - } - - private BomNewMbomParentEntity buildMBomParent(String facCode) { - BomNewMbomParentEntity mBomParent = new BomNewMbomParentEntity(); - BeanUtil.copyProperties(parent, mBomParent); - BomNewMbomParentEntity oldParent = SpringUtil.getBean(BomNewMbomParentService.class).lambdaQuery().eq(BomNewMbomParentEntity::getMaterialNo, parent.getMaterialNo()) - .eq(BomNewMbomParentEntity::getLastVersionIs, 1).eq(BomNewMbomParentEntity::getFacCode, facCode).one(); - if (Objects.nonNull(oldParent)) { - if (MBomConstantEnum.MBomStatusEnum.PUB_SAP.equalsValue(oldParent.getStatus())) { - - mBomParent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion())); - oldParent.setLastVersionIs(0); - this.mBomParentResult.add(oldParent); - } else { - SpringUtil.getBean(BomNewMbomDetailService.class).getBaseMapper().deleteByMap(ImmutableMap.of("bom_row_id", oldParent.getRowId())); - SpringUtil.getBean(BomNewMbomParentService.class).getBaseMapper().deleteById(oldParent.getRowId()); - mBomParent.setCurrentVersion(oldParent.getCurrentVersion()); - } - } else { - mBomParent.setCurrentVersion(VersionUtil.getNextVersion("")); - } - mBomParent.setRowId(IdWorker.getId()); - mBomParent.setFacCode(facCode); - mBomParent.setCreatedBy(SessionUtil.getUserCode()); - mBomParent.setCreatedTime(LocalDateTime.now()); - mBomParent.setModifyTime(LocalDateTime.now()); - mBomParent.setSourceRowId(parent.getRowId()); - mBomParent.setLastVersionIs(1); - mBomParent.setStatus(MBomConstantEnum.MBomStatusEnum.UNPUB_SAP.getValue()); - return mBomParent; - } - - - /** - * 构建子级 - * - * @param allChild - */ - private void buildChildFor1020(String facCode, List allChild, Long bomRowId) { - List childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId); - for (ConvertToMBomDTO item : childBomTree) { - //构建子级 - if (item.getDelIs().equals(0)) { - buildMBomChildDo(facCode, item, 0L, bomRowId); - } - - } - - } - - private void buildChildFor1010(String facCode, List allChild, Long bomRowId) { - List childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId); - - for (ConvertToMBomDTO item : childBomTree) { - buildMBomChildDo(facCode, item, 0L, bomRowId); - } - - } - - private void buildMBomChildDo(String facCode, ConvertToMBomDTO item, Long parentRowId, Long bomRowId) { - if (item.getDelIs().equals(0)) { - parentRowId = buildChildDo(facCode, item, bomRowId, parentRowId); - } - for (ConvertToMBomDTO itemChild : item.getChildNodes()) { - buildMBomChildDo(facCode, itemChild, parentRowId, bomRowId); - } - - } - - /** - * 处理制作下为空的虚拟包 - * 当制作下子级为空时--删除该发货,制作,和直发 - * - * @param - */ - private void handEmptyMakePackage(List childBomTree) { - -// List childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChildTreeList_1020, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId); - for (ConvertToMBomDTO item : childBomTree) { - if (VirtualPackageTypeEnum.DELIVERY_PACKAGE.equalsValue(item.getVirtualPartType())) { - List makeChild = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.MAKING_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList()); - List zhifaChild = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList()); - - if ((CollUtil.isEmpty(makeChild) || CollUtil.isEmpty(makeChild.get(0).getChildNodes().stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList()))) && - (CollUtil.isEmpty(zhifaChild) || CollUtil.isEmpty(zhifaChild.get(0).getChildNodes().stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList())))) { - item.setRelParentRowId(0L); - } - } - - } - } - - private Long buildChildDo(String facCode, ConvertToMBomDTO dto, Long bomRowId, Long parentRowId) { - BomNewMbomDetailEntity child = new BomNewMbomDetailEntity(); - BeanUtil.copyProperties(dto, child); - child.setRowId(IdWorker.getId()); - child.setBomRowId(bomRowId); -// child.setFacCode(dto.getProductionFactoryCode()); - child.setFacCode(facCode); - child.setParentRowId(parentRowId); - child.setCreatedBy(SessionUtil.getUserCode()); - child.setCreatedTime(LocalDateTime.now()); - child.setModifyTime(LocalDateTime.now()); - child.setSourceRowId(dto.getRowId()); - this.mBomDetailResult.add(child); - return child.getRowId(); - - } - - - private void handler1010() { - - List childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1010, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId); - for (ConvertToMBomDTO item : childBomTree) { - //默认 - recursionHandlerChild1010(item); - } - } - - private void recursionHandlerChild1010(ConvertToMBomDTO item) { - - item.setRelParentRowId(item.getParentRowId()); - setDel(item, EBomConstant.MAIN_FACTORY_CODE_1010); - handlerMaterial(item, EBomConstant.MAIN_FACTORY_CODE_1010); - - this.allChildTreeList_1010.add(item); - for (ConvertToMBomDTO itemChild : item.getChildNodes()) { - recursionHandlerChild1010(itemChild); - } - - } - - - private void handler1020() { - List childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1020, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId); - //虚拟包名称加仙桃 - initFac1020Info(childBomTree); - - for (ConvertToMBomDTO item : childBomTree) { - - ConvertToMBomDTO directDeliveryPackage = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList()).get(0); - VUtils.isTure(Objects.isNull(directDeliveryPackage)).throwMessage("发货包下,没有直发包"); - - recursionHandlerChild1020(item, directDeliveryPackage); - } - //处理制作包无下级的情况 - handEmptyMakePackage(childBomTree); - - } - - private void recursionHandlerChild1020(ConvertToMBomDTO item, ConvertToMBomDTO directDeliveryPackage) { - - - item.setRelParentRowId(item.getParentRowId()); - setDel(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - //非31下的直发包 - if (!item.getParentRowId().equals(parent.getRowId())) { - ConvertToMBomDTO parentNode = getParent(item.getParentRowId(), EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - if (VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(parentNode.getVirtualPartType()) && parentNode.getRowId() != directDeliveryPackage.getRowId()) { - handlerDirectDeliveryPackage(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020, directDeliveryPackage); - } else { - handlerMaterial(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - } - } - this.allChildTreeList_1020.add(item); - for (ConvertToMBomDTO itemChild : item.getChildNodes()) { - recursionHandlerChild1020(itemChild, directDeliveryPackage); - } - } - - - /** - * 处理直发包下的物料 - * 所有直发包,归到31下的直发包 - */ - private void handlerDirectDeliveryPackage(ConvertToMBomDTO childItem, String facCode, ConvertToMBomDTO directDeliveryPackage) { - if (!childItem.getParentRowId().equals(parent.getRowId())) { - ConvertToMBomDTO relParent = getParent(childItem.getParentRowId(), facCode); - while (Objects.nonNull(relParent) && !VirtualPackageTypeEnum.MAKING_PACKAGE.equalsValue(relParent.getVirtualPartType())) { - childItem.setNum(NumberUtil.mul(childItem.getNum(), relParent.getNum())); - relParent = getParent(relParent.getParentRowId(), facCode); - } - childItem.setRelParentRowId(directDeliveryPackage.getBomRowId()); - } - } - - /** - * 处理一般材料(提层) - * - * @param childItem - * @param facCode - */ - private void handlerMaterial(ConvertToMBomDTO childItem, String facCode) { - if (!childItem.getParentRowId().equals(parent.getRowId())) { - ConvertToMBomDTO relParent = getParent(childItem.getParentRowId(), facCode); - while (Objects.nonNull(relParent) && relParent.getDelIs().equals(1)) { - childItem.setNum(NumberUtil.mul(childItem.getNum(), relParent.getNum())); - relParent = getParent(relParent.getParentRowId(), facCode); - } - childItem.setRelParentRowId(relParent.getBomRowId()); - } - - } - - private void setDel(ConvertToMBomDTO item, String facCode) { - if (!item.getProductionFactoryCode().equals(facCode)) { - item.setDelIs(1); - } - } - - //获取父节点 - private ConvertToMBomDTO getParent(Long parentRowId, String facCode) { - if (parentRowId <= 0) return null; - List data = EBomConstant.MAIN_FACTORY_CODE_1010.equals(facCode) ? allChild_1010 : allChild_1020; - return data.stream().filter(u -> parentRowId.equals(u.getBomRowId())).collect(Collectors.toList()).get(0); - } - - - /** - * 1020-名称加仙桃 - */ - private void initFac1020Info(List childBomTree) { - - for (ConvertToMBomDTO item : childBomTree) { - item.setMaterialName(item.getMaterialName() + EBomConstant.XIAN_TAO_FACTORY_Name_1020); - item.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - - item.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.DEFAULT.getValue()); - for (ConvertToMBomDTO itemChild : item.getChildNodes()) { - itemChild.setMaterialName(itemChild.getMaterialName() + EBomConstant.XIAN_TAO_FACTORY_Name_1020); - itemChild.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020); - - itemChild.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.DEFAULT.getValue()); - } - } - } }