1.自动分配项目类别

This commit is contained in:
大米 2023-12-14 19:20:02 +08:00
parent c46cf90bc4
commit 30cb57cbc2
2 changed files with 178 additions and 1 deletions

View File

@ -13,7 +13,13 @@ public enum ProjectTypeInputTypeEnum implements ValueEnum<Integer> {
// 0-自动匹配 1-手工录入
AUTO_MATCH(0, "自动匹配"),
MANUAL_INPUT(1, "手工录入");
MANUAL_INPUT(1, "手工录入"),
MATERIAL_MAIN_DATA(2, "来自物料主数据"),
// 3-来自历史统计
HISTORY_STATISTICS(3, "来自历史统计");

View File

@ -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<BomNewEbomParentVO> allChild;
public EbomInitProjectType(BomNewEbomParentVO inFirstParent, List<BomNewEbomParentVO> inAllChild) {
this.firstParent = inFirstParent;
this.allChild = inAllChild;
allChild.add(firstParent);
initProjectType(allChild);
}
/**
* 初始化项目类别
*
* @param data
*/
private void initProjectType(List<BomNewEbomParentVO> 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<BomNewEbomParentVO> 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<BomNewEbomParentVO> sameLevleChilds = getChilds(child.getParentRowId());
List<BomNewEbomParentVO> sResult = sameLevleChilds.stream().filter(u -> u.getMaterialCategoryCode().startsWith("2005") || u.getMaterialCategoryCode().startsWith("2006")).collect(Collectors.toList());
if (CollUtil.isNotEmpty(sResult)) {
List<BomNewEbomParentVO> noProjectTypeList = sResult.stream().filter(u -> StrUtil.isBlank(u.getProjectType())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(noProjectTypeList)) {
initProjectType(noProjectTypeList);
}
List<String> 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<BomNewEbomParentVO> sameLevelChild = getChilds(child.getParentRowId());
//除紧固件外的其他物料
List<BomNewEbomParentVO> sResult = sameLevelChild.stream().filter(u -> !u.getMaterialCategoryCode().startsWith("1004")).collect(Collectors.toList());
if(CollUtil.isNotEmpty(sResult)) {
List<BomNewEbomParentVO> noProjectTypeList = sResult.stream().filter(u -> StrUtil.isBlank(u.getProjectType())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(noProjectTypeList)) {
initProjectType(noProjectTypeList);
}
List<String> 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<BomNewEbomParentVO> subChild= getChilds(child.getBomRowId());
List<BomNewEbomParentVO> 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<BomNewEbomParentVO> getChilds(Long parentRowId) {
return allChild.stream().filter(u -> u.getParentRowId().equals(parentRowId)).collect(Collectors.toList());
}
}