diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/ProjectTypeInputTypeEnum.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/ProjectTypeInputTypeEnum.java index 94fce146..8b702f57 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/ProjectTypeInputTypeEnum.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/ProjectTypeInputTypeEnum.java @@ -13,7 +13,13 @@ public enum ProjectTypeInputTypeEnum implements ValueEnum { // 0-自动匹配 1-手工录入 AUTO_MATCH(0, "自动匹配"), - MANUAL_INPUT(1, "手工录入"); + MANUAL_INPUT(1, "手工录入"), + MATERIAL_MAIN_DATA(2, "来自物料主数据"), + // 3-来自历史统计 + HISTORY_STATISTICS(3, "来自历史统计"); + + + 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 new file mode 100644 index 00000000..b8240f2b --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EbomInitProjectType.java @@ -0,0 +1,171 @@ +package com.nflg.product.bomnew.service.domain.EBom; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.google.common.collect.Sets; +import com.nflg.product.bomnew.constant.ProjectTypeInputTypeEnum; +import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; +import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * 初始化项目类别 + * + * @author + * @date 2023/12/14 18:03 + */ +public class EbomInitProjectType { + + private BomNewEbomParentVO firstParent; + + private List allChild; + + public EbomInitProjectType(BomNewEbomParentVO inFirstParent, List inAllChild) { + this.firstParent = inFirstParent; + this.allChild = inAllChild; + allChild.add(firstParent); + initProjectType(allChild); + } + + + /** + * 初始化项目类别 + * + * @param data + */ + private void initProjectType(List data) { + + for (BomNewEbomParentVO child : data) { + + String materialProjectType = child.getProjectType(); + child.setProjectType(""); + if (StrUtil.isNotBlank(child.getMaterialCategoryCode()) && !ProjectTypeInputTypeEnum.MANUAL_INPUT.equalsValue(child.getProjectTypeInputType())) { + if (child.getMaterialCategoryCode().startsWith("1013") || child.getMaterialCategoryCode().startsWith("100601")) { + child.setProjectType("F"); + continue; + } + if (child.getMaterialCategoryCode().startsWith("2011")) { + child.setProjectType("L"); + continue; + } + + if (child.getMaterialCategoryCode().startsWith("2005") && child.getBomRowId() > 0) { + List childs = getChilds(child.getBomRowId()); + childs.forEach(u -> u.setProjectType("L")); + + } + if (child.getMaterialCategoryCode().startsWith("1001")) { + child.setProjectType("L"); + continue; + } + + if (child.getMaterialCategoryCode().startsWith("2005") && child.getMaterialName().contains("溜管")) { + child.setProjectType("Q"); + continue; + } + if (child.getMaterialCategoryCode().startsWith("2005") && !child.getMaterialName().contains("溜管")) { + child.setProjectType(materialProjectType); + child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MATERIAL_MAIN_DATA.getValue()); + continue; + } + if (child.getMaterialCategoryCode().startsWith("20") && !child.getMaterialCategoryCode().startsWith("2005") && child.getMaterialName().contains("清点")) { + child.setProjectType("Q"); + continue; + } + if (child.getMaterialCategoryCode().startsWith("20") && !child.getMaterialCategoryCode().startsWith("2005") && !child.getMaterialName().contains("清点")) { + child.setProjectType(materialProjectType); + child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MATERIAL_MAIN_DATA.getValue()); + continue; + } + //7 + if (child.getMaterialCategoryCode().startsWith("2009")) { + //获取同层物料 + if (child.getParentRowId() > 0) { + List sameLevleChilds = getChilds(child.getParentRowId()); + List sResult = sameLevleChilds.stream().filter(u -> u.getMaterialCategoryCode().startsWith("2005") || u.getMaterialCategoryCode().startsWith("2006")).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(sResult)) { + List noProjectTypeList = sResult.stream().filter(u -> StrUtil.isBlank(u.getProjectType())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(noProjectTypeList)) { + initProjectType(noProjectTypeList); + } + List projectType = sResult.stream().map(u -> u.getProjectType()).distinct().collect(Collectors.toList()); + if(projectType.size()==1 && projectType.get(0).equals("Q")){ + child.setProjectType("Q"); + } + + } + continue; + + } + //8 + if(child.getMaterialCategoryCode().startsWith("20") && !child.getMaterialCategoryCode().startsWith("2005") && !child.getMaterialName().contains("清点") + && !child.getMaterialCategoryCode().startsWith("2011")){ + child.setProjectType(materialProjectType); + child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MATERIAL_MAIN_DATA.getValue()); + continue; + } + //9 + if(child.getMaterialCategoryCode().startsWith("1004")){ + //同层物料 + List sameLevelChild = getChilds(child.getParentRowId()); + //除紧固件外的其他物料 + List sResult = sameLevelChild.stream().filter(u -> !u.getMaterialCategoryCode().startsWith("1004")).collect(Collectors.toList()); + if(CollUtil.isNotEmpty(sResult)) { + List noProjectTypeList = sResult.stream().filter(u -> StrUtil.isBlank(u.getProjectType())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(noProjectTypeList)) { + initProjectType(noProjectTypeList); + } + List projectType = sResult.stream().map(u -> u.getProjectType()).distinct().collect(Collectors.toList()); + Sets.newHashSet(""); + + } + } + //10 + BomNewEbomParentVO parent = getParent(child.getParentRowId()); + if(Objects.nonNull(parent) && parent.getProjectType().equals("Q")){ + List subChild= getChilds(child.getBomRowId()); + List collect = subChild.stream().filter(u -> u.getMaterialCategoryCode().startsWith("1004")).collect(Collectors.toList()); + collect.forEach(u->u.setProjectType("L")); + } + + + } + + } + if (StrUtil.isNotBlank(child.getMaterialCategoryCode()) && child.getMaterialCategoryCode().equals("200501")) { + child.setProjectType("L"); + } + + } + + + } + + + /** + * 获取父级 + * @param rowId + * @return + */ + public BomNewEbomParentVO getParent(Long rowId) { + return allChild.stream().filter(u -> u.getBomRowId().equals(rowId)).findFirst().orElse(null); + } + + + + + + + /** + * 获取子节点 + * + * @param parentRowId + * @return + */ + private List getChilds(Long parentRowId) { + return allChild.stream().filter(u -> u.getParentRowId().equals(parentRowId)).collect(Collectors.toList()); + } +}