Merge branch 'feature/DM/nflg-bom-transition' of http://192.168.0.40:3000/root/nflg_project into feature/DM/nflg-bom-transition
This commit is contained in:
commit
a6cb884797
|
|
@ -25,6 +25,7 @@ import com.nflg.product.bomnew.util.VUtils;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -35,6 +36,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
|
|
@ -289,8 +291,16 @@ public class PBomApi extends BaseApi {
|
|||
@ApiOperation("发布Pbom")
|
||||
@LogRecord(success = "发布PBom,物料编码:{{#bom.materialNo}}-版本:{{#bom.currentVersion}} 操作结果:{{#_ret}}", bizNo = "{{#bomRowId}}",type = "发布PBom")
|
||||
public ResultVO<List<OperationErrorMsgVO>> realesePbom(@Valid @RequestBody @NotNull PbomImportToSAPQuery query) {
|
||||
bomNewPbomParentService.realesePbom(query.getRootBomRowId());
|
||||
BomNewPbomParentEntity parent = bomNewPbomParentService.realesePbom(query.getRootBomRowId());
|
||||
BomNewPbomParentEntity parentEnt = bomNewPbomParentService.getById(query.getRootBomRowId());
|
||||
if(Objects.isNull(parentEnt)){
|
||||
parentEnt = bomNewPbomParentService.lambdaQuery().eq(BomNewPbomParentEntity::getMaterialNo, parent.getMaterialNo())
|
||||
.eq(BomNewPbomParentEntity::getFacCode, parent.getFacCode())
|
||||
.last(" order by current_version desc limit 1").one();
|
||||
query.setRootBomRowId(parentEnt.getRowId());
|
||||
}
|
||||
return ResultVO.success(bomNewPbomParentService.importToSAP2(query));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.nflg.product.bomnew.pojo.vo;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.product.bomnew.util.MyStrUtil;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
|
@ -365,7 +366,13 @@ public class BomNewEbomParentVO extends BaseMaterialVO implements Serializable {
|
|||
private String materialNoAndNumAndProjectType;
|
||||
|
||||
public String getMaterialNoAndNumAndProjectType() {
|
||||
return StrUtil.join("",getMaterialNo(),getNum(),getProjectType());
|
||||
return MyStrUtil.joinStr(getMaterialNo(),getNum(),getProjectType());
|
||||
}
|
||||
|
||||
private String materialNoAndNum;
|
||||
|
||||
public String getMaterialNoAndNum() {
|
||||
return MyStrUtil.joinStr(getMaterialNo(),getNum());
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.nflg.product.bomnew.pojo.vo;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.product.bomnew.util.MyStrUtil;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
|
@ -316,13 +317,22 @@ public class BomNewPbomParentVO extends BaseMaterialVO implements Serializable {
|
|||
private String materialNoAndNumAndProjectType;
|
||||
|
||||
public String getMaterialNoAndProjectType() {
|
||||
return StrUtil.join("",getMaterialNo(),getProjectType());
|
||||
return MyStrUtil.joinStr(getMaterialNo(),getProjectType());
|
||||
}
|
||||
|
||||
public String getMaterialNoAndNumAndProjectType() {
|
||||
return StrUtil.join("",StrUtil.isNotBlank(getOriginalMaterialNo())?getOriginalMaterialNo(): getMaterialNo(),Objects.nonNull(getOriginalNum())?getOriginalNum(): getNum(),StrUtil.isNotBlank(getOriginalProjectType())?getOriginalProjectType(): getProjectType());
|
||||
return MyStrUtil.joinStr(StrUtil.isNotBlank(getOriginalMaterialNo())?getOriginalMaterialNo(): getMaterialNo(),Objects.nonNull(getOriginalNum())?getOriginalNum(): getNum(),StrUtil.isNotBlank(getOriginalProjectType())?getOriginalProjectType(): getProjectType());
|
||||
}
|
||||
|
||||
private String materialNoAndNum;
|
||||
|
||||
public String getMaterialNoAndNum() {
|
||||
return MyStrUtil.joinStr(StrUtil.isNotBlank(getOriginalMaterialNo())?getOriginalMaterialNo(): getMaterialNo(),Objects.nonNull(getOriginalNum())?getOriginalNum(): getNum());
|
||||
}
|
||||
|
||||
//发布PBOM 时 ,对比Pbom已发布版是否一致,一致则不转PBOM正式,直接删除PBOM 草稿数据
|
||||
private Integer delIs=0;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import com.nflg.product.base.core.conmon.util.SessionUtil;
|
|||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewEbomParentMapper;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
|
||||
import com.nflg.product.bomnew.mapper.master.MaterialMainMapper;
|
||||
import com.nflg.product.bomnew.pojo.dto.*;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
|
||||
|
|
@ -30,6 +31,9 @@ import com.nflg.product.bomnew.pojo.entity.*;
|
|||
import com.nflg.product.bomnew.pojo.query.*;
|
||||
import com.nflg.product.bomnew.pojo.vo.*;
|
||||
import com.nflg.product.bomnew.service.domain.EBom.*;
|
||||
import com.nflg.product.bomnew.service.domain.EBom.topbomnew.EBomToPBomForFormal31New;
|
||||
import com.nflg.product.bomnew.service.domain.EBom.topbomnew.EBomToPBomForFormalNew;
|
||||
import com.nflg.product.bomnew.service.domain.EBom.topbomnew.FormalEBomToPbomBase;
|
||||
import com.nflg.product.bomnew.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
|
|
@ -1108,11 +1112,19 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
parent.setChildBomRowId(parent.getRowId());
|
||||
parent.setParentRowId(0L);
|
||||
bomTree.add(parent);
|
||||
EBomToPbomBase eBomToPBom =parent.getMaterialNo().startsWith("31")? new EBomToPBomForFormal31(parent, bomTree, paramDto.getFacCodes(), 0L,EnumUtils.getValueEnum(ConvertToPBomModelEnum.class,paramDto.getConvertMode())):new EBomToPBomForFormal(parent, bomTree, paramDto.getFacCodes(), 0L,EnumUtils.getValueEnum(ConvertToPBomModelEnum.class,paramDto.getConvertMode()));
|
||||
FormalEBomToPbomBase eBomToPBom =parent.getMaterialNo().startsWith("31")? new EBomToPBomForFormal31New(parent, bomTree, paramDto.getFacCodes(), 0L,EnumUtils.getValueEnum(ConvertToPBomModelEnum.class,paramDto.getConvertMode())):new EBomToPBomForFormalNew(parent, bomTree, paramDto.getFacCodes(), 0L,EnumUtils.getValueEnum(ConvertToPBomModelEnum.class,paramDto.getConvertMode()));
|
||||
eBomToPBom.convert();
|
||||
// if(CollUtil.isNotEmpty(eBomToPBom.getDelParentRowIds())){
|
||||
// pBomChildService.getBaseMapper().batchDelByParentRowId(eBomToPBom.getDelParentRowIds());
|
||||
// }
|
||||
//检查是否用户跟用户节点()
|
||||
List<String> childMaterialNos = SpringUtil.getBean(BomNewPbomParentMapper.class).getPBomExistMaterialInChildForWorkList(parent.getMaterialNo());
|
||||
if(CollUtil.isEmpty(childMaterialNos)){
|
||||
List<BomNewPbomParentEntity> pBomParent = eBomToPBom.getPBomParentResult().stream().filter(u -> u.getMaterialNo().equals(parent.getMaterialNo())).collect(Collectors.toList());
|
||||
pBomParent.forEach(u->{
|
||||
u.setUserRootIs(1);
|
||||
});
|
||||
}
|
||||
|
||||
if (CollUtil.isNotEmpty(eBomToPBom.getPBomParentResult())) {
|
||||
pBomParentService.saveOrUpdateBatch(eBomToPBom.getPBomParentResult());
|
||||
|
|
|
|||
|
|
@ -265,6 +265,10 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
|||
t.setIDNRK("");
|
||||
t.setPOTX1(child.getMaterialDesc());
|
||||
}
|
||||
//项目类别为F项,则给POTX1 赋值来源EBOM的父级物料编码 by luohj 20240826
|
||||
if(ProjectTypeInputTypeEnum.ProjectTypeEnum.TYPE_F.getValue().equalsIgnoreCase(child.getProjectType())){
|
||||
t.setPOTX1(child.getSourceParentMaterialNo());
|
||||
}
|
||||
t.setChildRowId(child.getRowId());
|
||||
return t;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.*;
|
||||
import com.mzt.logapi.context.LogRecordContext;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
|
|
@ -424,6 +421,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
LogRecordContext.putVariable("bom",parent);
|
||||
|
||||
if (CollUtil.isNotEmpty(paramDTO.getChildList())) {
|
||||
paramDTO.getChildList().stream().filter(u->StrUtil.isBlank(u.getFacCode())).collect(Collectors.toList()).forEach(u->u.setFacCode(parent.getFacCode()));
|
||||
List<BomNewPbomChildEntity> childList = Convert.toList(BomNewPbomChildEntity.class, paramDTO.getChildList());
|
||||
List<Long> childIds = paramDTO.getChildList().stream().map(BomNewPbomParentVO::getRowId).collect(Collectors.toList());
|
||||
List<BomNewPbomChildEntity> pChildList = Lists.newArrayList();
|
||||
|
|
@ -1118,7 +1116,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
* @param bomRowId
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean realesePbom(Long bomRowId) {
|
||||
public BomNewPbomParentEntity realesePbom(Long bomRowId) {
|
||||
BomNewPbomParentEntity parent = this.getById(bomRowId);
|
||||
VUtils.isTure(parent.getStatus() >= PBomStatusEnum.PUBLISH.getValue()).throwMessage("pbom已发布无需在发布,请刷新数据");
|
||||
LogRecordContext.putVariable("bom", parent);
|
||||
|
|
@ -1129,6 +1127,13 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
materialMainService.checkMaterialFreeze(allBom);
|
||||
//更新root标志
|
||||
upRootMark(parent);
|
||||
//初始化转换后的版本
|
||||
initPBomCurrentVersion(allBom);
|
||||
//删除无需发布的PBom(和已发布版一致)
|
||||
List<Long> delNoReleaseBom = allBom.stream().filter(u -> u.getDelIs().equals(1)).map(u->u.getBomRowId()).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(delNoReleaseBom)){
|
||||
this.delPBom(delNoReleaseBom);
|
||||
}
|
||||
|
||||
List<Long> bomRowIds = allBom.stream().filter(u -> PBomStatusEnum.WAIT_PUBLISH.equalsValue(u.getStatus()) && u.getBomRowId() > 0).map(u -> u.getBomRowId()).collect(Collectors.toList());
|
||||
|
||||
|
|
@ -1136,7 +1141,19 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
parentMaterialNos.add(parent.getMaterialNo());
|
||||
//Integer state = (parent.getMaterialNo().startsWith("31") && parent.getFacCode().equals(EBomConstant.MAIN_FACTORY_CODE_1010)) ? PBomStatusEnum.WAIT_FACTORY.getValue() : PBomStatusEnum.PUBLISH.getValue();
|
||||
Integer state = parent.getMaterialNo().startsWith("31") ? PBomStatusEnum.FACTORY_CONFIRM.getValue() : PBomStatusEnum.PUBLISH.getValue();
|
||||
bomRowIds.add(bomRowId);
|
||||
|
||||
BomNewPbomParentVO parentVo = Convert.convert(BomNewPbomParentVO.class, parent);
|
||||
parentVo.setBomRowId(parentVo.getRowId());
|
||||
List<BomNewPbomParentVO> parentList=new ArrayList<>();
|
||||
parentList.add(parentVo);
|
||||
initPBomCurrentVersion(parentList);
|
||||
List<Long> delNoReleaseParentBom = parentList.stream().filter(u -> u.getDelIs().equals(1)).map(u->u.getBomRowId()).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(delNoReleaseParentBom)){
|
||||
this.delPBom(delNoReleaseParentBom);
|
||||
}
|
||||
else {
|
||||
bomRowIds.add(bomRowId);
|
||||
}
|
||||
this.getBaseMapper().bomRelease(state, SessionUtil.getUserName(), bomRowIds);
|
||||
//同步sap
|
||||
// saySyncDEMO();
|
||||
|
|
@ -1161,10 +1178,53 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
log.error("realesePbom", ex);
|
||||
throw new NflgBusinessException(STATE.BusinessError, "发布Pbom失败:" + ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
return parent;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 初始化Pbom版本号
|
||||
* @param allPBom
|
||||
*/
|
||||
private void initPBomCurrentVersion(List<BomNewPbomParentVO> allPBom){
|
||||
|
||||
List<BomNewPbomParentVO> waitReleaseBom = allPBom.stream().filter(u -> PBomStatusEnum.WAIT_PUBLISH.equalsValue(u.getStatus()) && u.getBomRowId() > 0).collect(Collectors.toList());
|
||||
for (BomNewPbomParentVO newPBom : waitReleaseBom) {
|
||||
|
||||
BomNewPbomParentEntity oldParent = SpringUtil.getBean(BomNewPbomParentService.class).lambdaQuery()
|
||||
.eq(BomNewPbomParentEntity::getMaterialNo, newPBom.getMaterialNo())
|
||||
.ge(BomNewPbomParentEntity::getStatus,PBomStatusEnum.PUBLISH.getValue())
|
||||
.eq(BomNewPbomParentEntity::getFacCode, newPBom.getFacCode()).last(" order by current_version desc limit 1").one();
|
||||
if(Objects.isNull(oldParent)){
|
||||
newPBom.setCurrentVersion(VersionUtil.getNextVersion(""));
|
||||
continue;
|
||||
}
|
||||
//旧bom除T项之外
|
||||
List<BomNewPbomParentVO> oldBomDetail = this.getBaseMapper().getParentChild(oldParent.getRowId());
|
||||
List<BomNewPbomParentVO> oldBomNoTChildren = oldBomDetail.stream().filter(u -> !EBomConstant.PROJECT_TYPE_T.equalsIgnoreCase(u.getProjectType())).collect(Collectors.toList());
|
||||
//新BOM 除T项外
|
||||
List<BomNewPbomParentVO> newChildren = this.getBaseMapper().getParentChild(newPBom.getBomRowId());
|
||||
List<BomNewPbomParentVO> newBomNoTChildren = newChildren.stream().filter(u -> !EBomConstant.PROJECT_TYPE_T.equalsIgnoreCase(u.getProjectType())).collect(Collectors.toList());
|
||||
Set<String> oldChildSet = oldBomNoTChildren.stream().map(u -> u.getMaterialNoAndNum()).collect(Collectors.toSet());
|
||||
Set<String> newChildSet = newBomNoTChildren.stream().map(u -> u.getMaterialNoAndNum()).collect(Collectors.toSet());
|
||||
|
||||
Set<String> oldChildSet0 = oldBomNoTChildren.stream().map(u -> u.getMaterialNoAndNumAndProjectType()).collect(Collectors.toSet());
|
||||
Set<String> newChildSet0 = newBomNoTChildren.stream().map(u -> u.getMaterialNoAndNumAndProjectType()).collect(Collectors.toSet());
|
||||
if(oldChildSet0.equals(newChildSet0)){
|
||||
newPBom.setStatus(PBomStatusEnum.PUBLISH.getValue());
|
||||
newPBom.setDelIs(1);
|
||||
}
|
||||
else if(oldChildSet.equals(newChildSet)){
|
||||
newPBom.setCurrentVersion( VersionUtil.getNextVersionForSmallVersion(oldParent.getCurrentVersion()));
|
||||
}
|
||||
else {
|
||||
newPBom.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void upRootMark(BomNewPbomParentEntity parent){
|
||||
Integer rootIs = this.getBaseMapper().checkIsRoot(parent.getMaterialNo());
|
||||
Integer userRootIs=this.getBaseMapper().checkIsUserRoot(parent.getMaterialNo(),parent.getCreatedBy());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,152 @@
|
|||
package com.nflg.product.bomnew.service.domain.EBom.topbomnew;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.excel.enums.BooleanEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.ConvertToPBomModelEnum;
|
||||
import com.nflg.product.bomnew.constant.EBomConstant;
|
||||
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.util.ListCommonUtil;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 31码转PBOM
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class EBomToPBomForFormal31New extends FormalEBomToPbomBase {
|
||||
|
||||
|
||||
|
||||
private Map<String,List<BomNewEbomParentVO>> facBomDataMp=new HashMap<>();
|
||||
|
||||
|
||||
public EBomToPBomForFormal31New(BomNewEbomParentVO inParent, List<BomNewEbomParentVO> inAllBomDetail, List<String> inFacCodes, Long parentRowId, ConvertToPBomModelEnum convertModelEnum) {
|
||||
this.parent = inParent;
|
||||
this.allBomDetail = inAllBomDetail;
|
||||
this.facCodes = inFacCodes;
|
||||
this.convertMode=convertModelEnum;
|
||||
|
||||
initEBomVersionFormal();
|
||||
|
||||
}
|
||||
|
||||
private void splitData(){
|
||||
this.facCodes=new ArrayList<>();
|
||||
//1020数据
|
||||
List<BomNewEbomParentVO> data1020=new ArrayList<>();
|
||||
List<BomNewEbomParentVO> deliveryPackage1020 = result.stream().filter(u -> u.getParentRowId().equals(parent.getRowId()) && u.getMaterialName().contains("仙桃") ).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(deliveryPackage1020)){
|
||||
facCodes.add(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
data1020.add(parent);
|
||||
for (BomNewEbomParentVO data: deliveryPackage1020){
|
||||
// List<BomNewEbomParentVO> subVos = result.stream().filter(u -> u.getLevelNumber().compareTo(data.getLevelNumber()) >= 0 && u.getLevelNumber().compareTo(NumberUtil.add(data.getLevelNumber(), BigDecimal.valueOf(0.01))) < 0).collect(Collectors.toList());
|
||||
List<BomNewEbomParentVO> subVos=getResultAllSubIncludeSelf(data);
|
||||
data1020.addAll(subVos);
|
||||
}
|
||||
facBomDataMp.put(EBomConstant.XIAN_TAO_FACTORY_CODE_1020,data1020);
|
||||
}
|
||||
|
||||
//1010 数据
|
||||
|
||||
List<BomNewEbomParentVO> data1010=new ArrayList<>();
|
||||
List<BomNewEbomParentVO> deliveryPackage1010 = result.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(deliveryPackage1010)){
|
||||
facCodes.add(EBomConstant.MAIN_FACTORY_CODE_1010);
|
||||
data1010.add(parent);
|
||||
for (BomNewEbomParentVO data: deliveryPackage1010){
|
||||
List<BomNewEbomParentVO> subVos = new ArrayList<>();// result.stream().filter(u -> u.getLevelNumber().compareTo(data.getLevelNumber()) >= 0 && u.getLevelNumber().compareTo(NumberUtil.add(data.getLevelNumber(), BigDecimal.valueOf(0.01))) < 0).collect(Collectors.toList());
|
||||
if(data.getMaterialName().contains("仙桃")){
|
||||
if(!data.getMaterialName().contains(VirtualPackageTypeEnum.PAINT_PACKAGE.getDescription())) {
|
||||
// subVos = result.stream().filter(u -> u.getMaterialName().contains("仙桃") && u.getLevelNumber().compareTo(data.getLevelNumber()) >= 0 && u.getLevelNumber().compareTo(NumberUtil.add(data.getLevelNumber(), BigDecimal.valueOf(0.01))) < 0).collect(Collectors.toList());
|
||||
subVos.add(data);
|
||||
subVos.addAll(result.stream().filter(u -> u.getParentRowId().equals(data.getBomRowId())).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// subVos = result.stream().filter(u -> u.getLevelNumber().compareTo(data.getLevelNumber()) >= 0 && u.getLevelNumber().compareTo(NumberUtil.add(data.getLevelNumber(), BigDecimal.valueOf(0.01))) < 0).collect(Collectors.toList());
|
||||
subVos=getResultAllSubIncludeSelf(data);
|
||||
}
|
||||
data1010.addAll(subVos);
|
||||
}
|
||||
facBomDataMp.put(EBomConstant.MAIN_FACTORY_CODE_1010,data1010);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 31項体层
|
||||
*/
|
||||
@Override
|
||||
public void convert() {
|
||||
|
||||
//效验数据是否OK
|
||||
check();
|
||||
//bom 提层
|
||||
liftingLayer();
|
||||
splitData();
|
||||
List<String> hasConvert = new ArrayList<>();
|
||||
|
||||
for (String facCode : facCodes) {
|
||||
List<BomNewEbomParentVO> parentList = ListCommonUtil.toDistinct(facBomDataMp.get(facCode).stream().filter(u -> u.getBomRowId() > 0)
|
||||
.collect(Collectors.toList()), BomNewEbomParentVO::getBomRowId);
|
||||
for (BomNewEbomParentVO vo : parentList) {
|
||||
String hasConvertKey = StrUtil.join("-", facCode, vo.getBomRowId());
|
||||
if (hasConvert.contains(hasConvertKey)) {
|
||||
continue;
|
||||
}
|
||||
hasConvert.add(hasConvertKey);
|
||||
//无需转换bom
|
||||
if(BooleanEnum.TRUE.equals(vo.getNoConvertToPBomIs()) ){
|
||||
continue;
|
||||
}
|
||||
//子级
|
||||
List<BomNewEbomParentVO> child = facBomDataMp.get(facCode).stream().filter(u -> u.getParentRowId().equals(vo.getBomRowId()) && !childDelMaterialNos.contains(u.getMaterialNo())).distinct().collect(Collectors.toList());
|
||||
List<BomNewEbomParentVO> mergeChild = mergeChild(child);
|
||||
//对比PBOM 版本是否一致(跟节点除外)
|
||||
if(!parent.getMaterialNo().equals(vo.getMaterialNo()) && !VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(vo.getVirtualPartType()) && !VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.equalsValue(vo.getVirtualPartType())){
|
||||
continue;
|
||||
}
|
||||
if(VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(vo.getVirtualPartType()) || VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.equalsValue(vo.getVirtualPartType())){
|
||||
if(compareContentIsSame(vo,mergeChild,facCode)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
BomNewPbomParentEntity parentEnt = buildPBomParent(vo, facCode,parentList);
|
||||
if(Objects.isNull(parentEnt)){
|
||||
continue;
|
||||
}
|
||||
|
||||
//子级
|
||||
if (CollUtil.isNotEmpty(child)) {
|
||||
//合并子级
|
||||
for (BomNewEbomParentVO eb : mergeChild) {
|
||||
BomNewPbomChildEntity childEnt = new BomNewPbomChildEntity();
|
||||
BeanUtil.copyProperties(eb, childEnt,"sourceRowId");
|
||||
childEnt.setRowId(IdWorker.getId());
|
||||
childEnt.setParentRowId(parentEnt.getRowId());
|
||||
childEnt.setFacCode(facCode);
|
||||
childEnt.setIdentityNo(StrUtil.join("-", parentEnt.getMaterialNo(), eb.getMaterialNo()));
|
||||
childEnt.setOriginalMaterialNo(eb.getMaterialNo());
|
||||
childEnt.setOriginalNum(eb.getNum());
|
||||
childEnt.setOriginalProjectType(eb.getProjectType());
|
||||
childEnt.setCreatedTime(LocalDateTime.now());
|
||||
childEnt.setCreatedBy(SessionUtil.getUserCode());
|
||||
this.pBomChildResult.add(childEnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package com.nflg.product.bomnew.service.domain.EBom.topbomnew;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.excel.enums.BooleanEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.ConvertToPBomModelEnum;
|
||||
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.service.domain.EBom.EBomToPbomBase;
|
||||
import com.nflg.product.bomnew.util.ListCommonUtil;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 正式版 Ebom 转Pbom
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class EBomToPBomForFormalNew extends FormalEBomToPbomBase {
|
||||
|
||||
|
||||
|
||||
|
||||
public EBomToPBomForFormalNew(BomNewEbomParentVO inParent, List<BomNewEbomParentVO> inAllBomDetail, List<String> inFacCodes, Long parentRowId, ConvertToPBomModelEnum convertModelEnum) {
|
||||
this.parent = inParent;
|
||||
this.allBomDetail = inAllBomDetail;
|
||||
this.facCodes = inFacCodes;
|
||||
this.convertMode=convertModelEnum;
|
||||
// generateDrawingNo(allBomDetail, parentRowId, "");
|
||||
initEBomVersionFormal();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 31項体层
|
||||
*/
|
||||
@Override
|
||||
public void convert() {
|
||||
|
||||
//效验数据是否OK
|
||||
check();
|
||||
//bom 提层
|
||||
liftingLayer();
|
||||
List<BomNewEbomParentVO> parentList = ListCommonUtil.toDistinct(result.stream().filter(u -> u.getBomRowId() > 0).collect(Collectors.toList()), BomNewEbomParentVO::getBomRowId);
|
||||
List<String> hasConvert = new ArrayList<>();
|
||||
|
||||
for (String facCode : facCodes) {
|
||||
//buildPBomParent(parent, facCode);
|
||||
for (BomNewEbomParentVO vo : parentList) {
|
||||
String hasConvertKey = StrUtil.join("-", facCode, vo.getBomRowId());
|
||||
if (hasConvert.contains(hasConvertKey) ) {
|
||||
continue;
|
||||
}
|
||||
hasConvert.add(hasConvertKey);
|
||||
|
||||
//无需转换bom
|
||||
if(BooleanEnum.TRUE.equals(vo.getNoConvertToPBomIs()) ){
|
||||
continue;
|
||||
}
|
||||
//子级
|
||||
List<BomNewEbomParentVO> child = result.stream().filter(u -> u.getParentRowId().equals(vo.getBomRowId()) && !childDelMaterialNos.contains(u.getMaterialNo())).distinct().collect(Collectors.toList());
|
||||
List<BomNewEbomParentVO> mergeChild = mergeChild(child);
|
||||
|
||||
//对比PBOM 版本是否一致(跟节点除外)
|
||||
if(!parent.getMaterialNo().equals(vo.getMaterialNo()) && !VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(vo.getVirtualPartType()) && !VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.equalsValue(vo.getVirtualPartType())){
|
||||
continue;
|
||||
}
|
||||
if(VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(vo.getVirtualPartType()) || VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.equalsValue(vo.getVirtualPartType())){
|
||||
if(compareContentIsSame(vo,mergeChild,facCode)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BomNewPbomParentEntity parentEnt = buildPBomParent(vo, facCode,parentList);
|
||||
if(Objects.isNull(parentEnt)){
|
||||
continue;
|
||||
}
|
||||
//检查是否用户跟用户节点()
|
||||
List<String> childMaterialNos = SpringUtil.getBean(BomNewPbomParentMapper.class).getPBomExistMaterialInChildForWorkList(parentEnt.getMaterialNo());
|
||||
if(CollUtil.isEmpty(childMaterialNos)){
|
||||
parentEnt.setUserRootIs(1);
|
||||
}
|
||||
//子级
|
||||
if (CollUtil.isNotEmpty(child)) {
|
||||
//合并子级
|
||||
for (BomNewEbomParentVO eb : mergeChild) {
|
||||
BomNewPbomChildEntity childEnt = new BomNewPbomChildEntity();
|
||||
BeanUtil.copyProperties(eb, childEnt,"sourceRowId");
|
||||
childEnt.setRowId(IdWorker.getId());
|
||||
childEnt.setParentRowId(parentEnt.getRowId());
|
||||
childEnt.setFacCode(facCode);
|
||||
childEnt.setSourceRowId(eb.getRowId());
|
||||
childEnt.setIdentityNo(StrUtil.join("-", parentEnt.getMaterialNo(), eb.getMaterialNo()));
|
||||
childEnt.setOriginalMaterialNo(eb.getMaterialNo());
|
||||
childEnt.setOriginalNum(eb.getNum());
|
||||
childEnt.setOriginalProjectType(eb.getProjectType());
|
||||
childEnt.setCreatedTime(LocalDateTime.now());
|
||||
childEnt.setCreatedBy(SessionUtil.getUserCode());
|
||||
this.pBomChildResult.add(childEnt);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,934 @@
|
|||
package com.nflg.product.bomnew.service.domain.EBom.topbomnew;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.pojo.entity.*;
|
||||
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
|
||||
import com.nflg.product.bomnew.service.*;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import com.nflg.product.bomnew.util.VersionUtil;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class FormalEBomToPbomBase {
|
||||
|
||||
protected BomNewEbomParentVO parent;
|
||||
|
||||
@ApiModelProperty("转换模式:0-常规 1-覆盖")
|
||||
protected ConvertToPBomModelEnum convertMode;
|
||||
|
||||
//工厂编码列表
|
||||
protected List<String> facCodes;
|
||||
|
||||
protected List<BomNewEbomParentVO> allBomDetail;
|
||||
|
||||
|
||||
protected List<BomNewEbomParentVO> result = new ArrayList<>();
|
||||
|
||||
protected BomNewEbomVirtualPackageCompositionService virtualPackageCompositionService = SpringUtil.getBean(BomNewEbomVirtualPackageCompositionService.class);
|
||||
|
||||
|
||||
@Getter
|
||||
protected List<BomNewPbomParentEntity> pBomParentResult = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
protected List<Long> newAddPBomParentResult = new ArrayList<>();
|
||||
@Getter
|
||||
protected List<BomNewPbomChildEntity> pBomChildResult = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
protected List<BomNewEbomVirtualPackageCompositionEntity> virtualPackageCompositionResult = new ArrayList<>();
|
||||
|
||||
|
||||
@Getter
|
||||
protected List<BomNewEbomUpgradeChangeEntity> upgradeChangeResult = new ArrayList<>();
|
||||
|
||||
//需覆盖的虚拟包
|
||||
@Getter
|
||||
protected List<BomNewEbomUpgradeChangeEntity> upgradeChangeResultForCover=new ArrayList<>();
|
||||
|
||||
//生成新版正式表后,需删除的旧版Ebom
|
||||
@Getter
|
||||
private List<Long> delOldEBom=new ArrayList<>();
|
||||
|
||||
//新生成正式的EBOM版本
|
||||
@Getter
|
||||
private List<Long> addEBomNew=new ArrayList<>();
|
||||
|
||||
//删除子表的父级行
|
||||
// @Getter
|
||||
// protected List<Long> delParentRowIds=new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
// protected List<BomNewEbomUpdateDetailEntity> upgradeChangeDetailResult = new ArrayList<>();
|
||||
|
||||
protected Set<String> hasBuildVNo = Sets.newHashSet();
|
||||
|
||||
//当子级为F项或Z项时-无需转的父级物料
|
||||
protected Set<String> childDelMaterialNos = new HashSet<>();
|
||||
|
||||
public abstract void convert();
|
||||
|
||||
/**
|
||||
* BOM 明细对比,如只有T项变化则,不升级直接修改
|
||||
*/
|
||||
protected Boolean compareContentIsSame(BomNewEbomParentVO pVo, List<BomNewEbomParentVO> newChildren, String facCode) {
|
||||
BomNewPbomParentEntity oldParent = SpringUtil.getBean(BomNewPbomParentService.class).lambdaQuery()
|
||||
.eq(BomNewPbomParentEntity::getMaterialNo, pVo.getMaterialNo())
|
||||
.eq(BomNewPbomParentEntity::getFacCode, facCode).last(" order by current_version desc limit 1").one();
|
||||
if (oldParent != null) {
|
||||
List<BomNewPbomParentVO> oldBomDetail = SpringUtil.getBean(BomNewPbomParentService.class).getBaseMapper().getParentChild(oldParent.getRowId());
|
||||
//旧bom除T项之外
|
||||
List<BomNewPbomParentVO> oldBomNoTChildren = oldBomDetail.stream().filter(u -> !EBomConstant.PROJECT_TYPE_T.equalsIgnoreCase(u.getProjectType())).collect(Collectors.toList());
|
||||
//新BOM 除T项外
|
||||
List<BomNewEbomParentVO> newBomNoTChildren = newChildren.stream().filter(u -> !EBomConstant.PROJECT_TYPE_T.equalsIgnoreCase(u.getProjectType())).collect(Collectors.toList());
|
||||
Set<String> oldChildSet = oldBomNoTChildren.stream().map(u -> u.getMaterialNoAndNumAndProjectType()).collect(Collectors.toSet());
|
||||
Set<String> newChildSet = newBomNoTChildren.stream().map(u -> u.getMaterialNoAndNumAndProjectType()).collect(Collectors.toSet());
|
||||
if(!oldChildSet.equals(newChildSet)){
|
||||
return false;
|
||||
}
|
||||
|
||||
//当T项外都一致时,直接更新T项
|
||||
List<BomNewPbomParentVO> bomDetailForT = oldBomDetail.stream().filter(u -> EBomConstant.PROJECT_TYPE_T.equalsIgnoreCase(u.getProcureType())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(bomDetailForT)) {
|
||||
List<Long> bomRowIdsForT = bomDetailForT.stream().map(u -> u.getRowId()).collect(Collectors.toList());
|
||||
SpringUtil.getBean(BomNewPbomChildService.class).getBaseMapper().deleteBatchIds(bomRowIdsForT);
|
||||
}
|
||||
List<BomNewEbomParentVO> newBomT = newChildren.stream().filter(u -> EBomConstant.PROJECT_TYPE_T.equalsIgnoreCase(u.getProcureType())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(newBomT)) {
|
||||
for (BomNewEbomParentVO netT : newBomT) {
|
||||
BomNewPbomChildEntity childEnt = new BomNewPbomChildEntity();
|
||||
BeanUtil.copyProperties(netT, childEnt);
|
||||
childEnt.setRowId(IdWorker.getId());
|
||||
childEnt.setParentRowId(oldParent.getRowId());
|
||||
childEnt.setFacCode(facCode);
|
||||
childEnt.setIdentityNo(StrUtil.join("-", oldParent.getMaterialNo(), netT.getMaterialNo()));
|
||||
childEnt.setOriginalMaterialNo(netT.getMaterialNo());
|
||||
childEnt.setOriginalNum(netT.getNum());
|
||||
childEnt.setOriginalProjectType(netT.getProjectType());
|
||||
this.pBomChildResult.add(childEnt);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
//合并子级
|
||||
public List<BomNewEbomParentVO> mergeChild(List<BomNewEbomParentVO> child) {
|
||||
|
||||
List<BomNewEbomParentVO> result = child.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())).collect(Collectors.toList());
|
||||
|
||||
Map<String, List<BomNewEbomParentVO>> listMp = child.stream().filter(u->StrUtil.isNotBlank(u.getMaterialNo())).collect(Collectors.groupingBy(BomNewEbomParentVO::getMaterialNo));
|
||||
|
||||
for (String key : listMp.keySet()) {
|
||||
List<BomNewEbomParentVO> voList = listMp.get(key);
|
||||
BomNewEbomParentVO ent = voList.get(0);
|
||||
ent.setNum(voList.stream().filter(u -> Objects.nonNull(u.getNum())).map(aa -> aa.getNum()).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
result.add(ent);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据效验
|
||||
*/
|
||||
protected void check() {
|
||||
//动态判断异常
|
||||
// CheckEBomExceptoinDynamic.check(allBomDetail);
|
||||
// List<BomNewEbomParentVO> collect = allBomDetail.stream().filter(u -> !EBomExceptionStatusEnum.OK.getValue().equals(u.getExceptionStatus())).collect(Collectors.toList());
|
||||
|
||||
// VUtils.isTure(CollUtil.isNotEmpty(collect)).throwMessage("存在异常数据,请处理完再转换");
|
||||
VUtils.isTure(!Objects.equals(parent.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())).throwMessage("存在异常数据,请处理完再转换");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建父
|
||||
*
|
||||
* @param parentVo
|
||||
* @return Pair<Integer, BomNewPbomParentEntity> key, 0-旧 1-新 value:pBomParent
|
||||
*/
|
||||
protected BomNewPbomParentEntity buildPBomParent(BomNewEbomParentVO parentVo, String facCode, List<BomNewEbomParentVO> parentList) {
|
||||
BomNewPbomParentEntity oldParent = SpringUtil.getBean(BomNewPbomParentService.class).lambdaQuery()
|
||||
.eq(BomNewPbomParentEntity::getMaterialNo, parentVo.getMaterialNo())
|
||||
.eq(BomNewPbomParentEntity::getFacCode, facCode).last(" order by current_version desc limit 1").one();
|
||||
|
||||
|
||||
if (Objects.isNull(oldParent)) {
|
||||
return buildParentEntity(parentVo, facCode, oldParent, StrUtil.isBlank(parentVo.getCurrentVersion())? VersionUtil.getNextVersion(""):parentVo.getCurrentVersion());
|
||||
|
||||
}
|
||||
//pbom 处于工作表
|
||||
else if (Objects.nonNull(oldParent) && oldParent.getStatus() < EBomStatusEnum.PUBLISHED.getValue()) {
|
||||
//if (oldParent.getCreatedBy().equals(parentVo.getCreatedBy())) {
|
||||
if (ConvertToPBomModelEnum.OVERRIDE.equalsValue(convertMode.getValue())) {
|
||||
SpringUtil.getBean(BomNewPbomChildService.class).getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldParent.getRowId()));
|
||||
oldParent.setSourceRowId(parentVo.getBomRowId());
|
||||
oldParent.setCreatedTime(LocalDateTime.now());
|
||||
oldParent.setCreatedBy(SessionUtil.getUserCode());
|
||||
oldParent.setDeptName(SessionUtil.getDepartName());
|
||||
oldParent.setDeptRowId(SessionUtil.getDepartRowId());
|
||||
this.pBomParentResult.add(oldParent);
|
||||
return oldParent;
|
||||
|
||||
} else {
|
||||
// 降parentVo 及其子节点标记为不转换
|
||||
markNoConvert(parentVo, parentList);
|
||||
}
|
||||
return null;
|
||||
|
||||
} else { //pbom-处于正式表(全部生成小版本)
|
||||
return buildParentEntity(parentVo, facCode, oldParent, VersionUtil.getNextVersionForSmallVersion(oldParent.getCurrentVersion()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Pbom-下一个版本(只是项目类别发生变化则生成小版本,否则大版本)
|
||||
*/
|
||||
private String getPBomNextVersion(BomNewPbomParentEntity oldPBomParent, List<BomNewEbomParentVO> newChildren){
|
||||
//旧bom除T项之外
|
||||
List<BomNewPbomParentVO> oldBomDetail = SpringUtil.getBean(BomNewPbomParentService.class).getBaseMapper().getParentChild(oldPBomParent.getRowId());
|
||||
List<BomNewPbomParentVO> oldBomNoTChildren = oldBomDetail.stream().filter(u -> !EBomConstant.PROJECT_TYPE_T.equalsIgnoreCase(u.getProjectType())).collect(Collectors.toList());
|
||||
//新BOM 除T项外
|
||||
List<BomNewEbomParentVO> newBomNoTChildren = newChildren.stream().filter(u -> !EBomConstant.PROJECT_TYPE_T.equalsIgnoreCase(u.getProjectType())).collect(Collectors.toList());
|
||||
Set<String> oldChildSet = oldBomNoTChildren.stream().map(u -> u.getMaterialNoAndNum()).collect(Collectors.toSet());
|
||||
Set<String> newChildSet = newBomNoTChildren.stream().map(u -> u.getMaterialNoAndNum()).collect(Collectors.toSet());
|
||||
if(oldChildSet.equals(newChildSet)){
|
||||
return VersionUtil.getNextVersionForSmallVersion(oldPBomParent.getCurrentVersion());
|
||||
}
|
||||
return VersionUtil.getNextVersion(oldPBomParent.getCurrentVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Pbom明细对比
|
||||
* @param pVo
|
||||
* @param newChildren
|
||||
* @param facCode
|
||||
* @return 一样则返回true 否则返回 false
|
||||
*/
|
||||
protected boolean pBomSameIs(BomNewEbomParentVO pVo, List<BomNewEbomParentVO> newChildren, String facCode){
|
||||
BomNewPbomParentEntity oldParent = SpringUtil.getBean(BomNewPbomParentService.class).lambdaQuery()
|
||||
.eq(BomNewPbomParentEntity::getMaterialNo, pVo.getMaterialNo())
|
||||
.eq(BomNewPbomParentEntity::getFacCode, facCode).last(" order by current_version desc limit 1").one();
|
||||
//正式才需对比
|
||||
if(Objects.nonNull(oldParent) && PBomStatusEnum.PUBLISH.getValue()<= oldParent.getStatus()){
|
||||
List<BomNewPbomChildEntity> pBomChildList = SpringUtil.getBean(BomNewPbomChildService.class).lambdaQuery().eq(BomNewPbomChildEntity::getParentRowId, oldParent.getRowId()).list();
|
||||
Set<String> oldSet = pBomChildList.stream().map(u -> StrUtil.join("",u.getMaterialNo(), u.getNum(), u.getProjectType())).collect(Collectors.toSet());
|
||||
Set<String> newSet = newChildren.stream().map(u -> StrUtil.join("", u.getMaterialNo(), u.getNum(), u.getProjectType())).collect(Collectors.toSet());
|
||||
if(oldSet.equals(newSet)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private BomNewPbomParentEntity buildParentEntity(BomNewEbomParentVO parentVo, String facCode, BomNewPbomParentEntity oldParent, String bomVersion) {
|
||||
BomNewPbomParentEntity pBomParent = new BomNewPbomParentEntity();
|
||||
BeanUtil.copyProperties(parentVo, pBomParent, "sourceRowId");
|
||||
pBomParent.setSourceRowId(parentVo.getBomRowId());
|
||||
pBomParent.setRowId(IdWorker.getId());
|
||||
pBomParent.setStatus(PBomStatusEnum.WAIT_PUBLISH.getValue());
|
||||
pBomParent.setLastVersionIs(1);
|
||||
pBomParent.setFacCode(facCode);
|
||||
pBomParent.setTechnologyUserCode(SessionUtil.getUserCode());
|
||||
pBomParent.setTechnologyUserName(SessionUtil.getRealName());
|
||||
pBomParent.setDeptRowId(SessionUtil.getDepartRowId());
|
||||
pBomParent.setCreatedTime(LocalDateTime.now());
|
||||
pBomParent.setCreatedBy(SessionUtil.getUserCode());
|
||||
//版本=EBom版本
|
||||
pBomParent.setCurrentVersion(bomVersion);
|
||||
pBomParent.setEditStatus(PBomEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
pBomParent.setDeptName(SessionUtil.getDepartName());
|
||||
pBomParent.setDeptRowId(SessionUtil.getDepartRowId());
|
||||
pBomParent.setCreatedBy(SessionUtil.getUserCode());
|
||||
pBomParent.setSource(PbomSourceEnum.FROM_EBOM.getValue());
|
||||
pBomParent.setSourceStatus(PbomSourceStatusEnum.EBOM.getValue());
|
||||
if (Objects.nonNull(oldParent)) {
|
||||
oldParent.setExpireEndTime(LocalDateTime.now());
|
||||
oldParent.setLastVersionIs(0);
|
||||
this.pBomParentResult.add(oldParent);
|
||||
}
|
||||
this.pBomParentResult.add(pBomParent);
|
||||
return pBomParent;
|
||||
}
|
||||
|
||||
public void markNoConvert(BomNewEbomParentVO parentVo, List<BomNewEbomParentVO> parentList) {
|
||||
List<BomNewEbomParentVO> subVos = getAllSubInListIncludeSelf(parentVo, parentList);
|
||||
for (BomNewEbomParentVO vo : subVos) {
|
||||
vo.setNoConvertToPBomIs(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 31提层
|
||||
*
|
||||
* @param
|
||||
* @param
|
||||
*/
|
||||
protected void liftingLayer() {
|
||||
result.add(parent);
|
||||
liftingLayerDo(parent, null, null, ImmutableList.of());
|
||||
}
|
||||
|
||||
private List<Long> hasCupmVo = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* @param parentVO 父项
|
||||
* @param directDeliveryVo 直发包
|
||||
* @param preAssemblyVo 发货前装配包
|
||||
*/
|
||||
public void liftingLayerDo(BomNewEbomParentVO parentVO, BomNewEbomParentVO directDeliveryVo, BomNewEbomParentVO preAssemblyVo, List<Long> parentRowIds) {
|
||||
List<BomNewEbomParentVO> firstLevelBoms = allBomDetail.stream().filter(u -> u.getParentRowId().equals(parentVO.getBomRowId())).sorted(Comparator.comparing(BomNewEbomParentVO::getVirtualPartType).reversed()).collect(Collectors.toList());
|
||||
|
||||
for (BomNewEbomParentVO firstLevelBom : firstLevelBoms) {
|
||||
if (hasCupmVo.contains(firstLevelBom.getRowId())) {
|
||||
firstLevelBom.getParentRowIds().clear();
|
||||
}
|
||||
//直发包
|
||||
firstLevelBom.getParentRowIds().add(firstLevelBom.getParentRowId());
|
||||
firstLevelBom.getParentRowIds().addAll(parentRowIds);
|
||||
List<BomNewEbomParentVO> directDeliveryVoList = firstLevelBoms.stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(directDeliveryVoList)) {
|
||||
directDeliveryVo = directDeliveryVoList.get(0);
|
||||
}
|
||||
List<BomNewEbomParentVO> preAssemblyVoList = firstLevelBoms.stream().filter(u -> VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(preAssemblyVoList)) {
|
||||
preAssemblyVo = preAssemblyVoList.get(0);
|
||||
}
|
||||
//虚拟包
|
||||
if (firstLevelBom.getVirtualPartType() > 0) {
|
||||
result.add(firstLevelBom);
|
||||
if(VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(firstLevelBom.getVirtualPartType()) && firstLevelBom.getBomRowId()<=0){
|
||||
firstLevelBom.setBomRowId(IdWorker.getId());
|
||||
firstLevelBom.setStatus(EBomStatusEnum.CHECKED.getValue());
|
||||
}
|
||||
} else if (VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey().equals(firstLevelBom.getProjectType())) {
|
||||
if (Objects.nonNull(directDeliveryVo)) {
|
||||
BomNewEbomParentVO newEnt = liftingLayerSummary(directDeliveryVo, firstLevelBom);
|
||||
newEnt.setRowId(IdWorker.getId());
|
||||
newEnt.setSourceRowId(String.valueOf(firstLevelBom.getParentRowId()));
|
||||
newEnt.setSourceParentMaterialNo(parentVO.getMaterialNo());
|
||||
newEnt.setParentRowId(directDeliveryVo.getBomRowId());
|
||||
result.add(newEnt);
|
||||
}
|
||||
} else if (firstLevelBom.getProjectType().equals(VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getProductTypeKey())) {
|
||||
if (Objects.nonNull(preAssemblyVo)) {
|
||||
BomNewEbomParentVO newEnt = liftingLayerSummary(preAssemblyVo, firstLevelBom);
|
||||
newEnt.setRowId(IdWorker.getId());
|
||||
newEnt.setSourceRowId(String.valueOf(firstLevelBom.getParentRowId()));
|
||||
newEnt.setSourceParentMaterialNo(parentVO.getMaterialNo());
|
||||
newEnt.setParentRowId(preAssemblyVo.getBomRowId());
|
||||
result.add(newEnt);
|
||||
}
|
||||
} else {
|
||||
result.add(firstLevelBom);
|
||||
}
|
||||
hasCupmVo.add(firstLevelBom.getRowId());
|
||||
if (firstLevelBom.getBomRowId() > 0) {
|
||||
liftingLayerDo(firstLevelBom, directDeliveryVo, preAssemblyVo, firstLevelBom.getParentRowIds());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提层汇总数量
|
||||
*
|
||||
* @param lastVirtualPackage 虚拟包
|
||||
* @param vo 提层项
|
||||
*/
|
||||
private BomNewEbomParentVO liftingLayerSummary(BomNewEbomParentVO lastVirtualPackage, BomNewEbomParentVO vo) {
|
||||
BigDecimal sum = vo.getNum();
|
||||
// String parentLevelNo = BomLevelUtil.getParentLevelNo(vo.getLevelNo());
|
||||
List<BomNewEbomParentVO> parentList = getAllParent(vo);
|
||||
BomNewEbomParentVO newEnt = new BomNewEbomParentVO();
|
||||
BeanUtil.copyProperties(vo, newEnt);
|
||||
|
||||
//构建虚拟包组成
|
||||
buildVirtualPackageComposition(lastVirtualPackage, vo);
|
||||
if (CollUtil.isNotEmpty(parentList)) {
|
||||
|
||||
for (BomNewEbomParentVO ent : parentList) {
|
||||
sum = NumberUtil.mul(sum, ent.getNum());
|
||||
|
||||
//构建虚拟包组成
|
||||
buildVirtualPackageComposition(lastVirtualPackage, ent);
|
||||
}
|
||||
}
|
||||
newEnt.setBomRowId(0L);
|
||||
newEnt.setChildBomRowId(0L);
|
||||
newEnt.setNum(sum);
|
||||
return newEnt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected List<BomNewEbomParentVO> getAllParent(BomNewEbomParentVO vo) {
|
||||
List<BomNewEbomParentVO> result = new ArrayList<>();
|
||||
BomNewEbomParentVO parentEnt = getParent(vo);
|
||||
Boolean flag = true;
|
||||
while (Objects.nonNull(parentEnt) && parentEnt.getParentRowId() > 0 && flag) {
|
||||
//制作
|
||||
if (VirtualPackageTypeEnum.MAKING_PACKAGE.getVirtualPartType().equals(parentEnt.getVirtualPartType())) {
|
||||
flag = false;
|
||||
|
||||
} else {
|
||||
result.add(parentEnt);
|
||||
}
|
||||
|
||||
parentEnt = getParent(parentEnt);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建虚拟包组成
|
||||
*
|
||||
* @param lastVirtualPackage
|
||||
* @param vo
|
||||
*/
|
||||
private void buildVirtualPackageComposition(BomNewEbomParentVO lastVirtualPackage, BomNewEbomParentVO vo) {
|
||||
|
||||
String facCode=lastVirtualPackage.getMaterialName().contains(EBomConstant.XIAN_TAO_FACTORY_Name_1020) ? "1020" : "1010";
|
||||
List<BomNewEbomParentVO> voParent = allBomDetail.stream().filter(u -> u.getBomRowId().equals(vo.getParentRowId())).collect(Collectors.toList());
|
||||
String key=StrUtil.join("", lastVirtualPackage.getMaterialNo(),voParent.get(0).getMaterialNo(),vo.getMaterialNo(),facCode);
|
||||
List<BomNewEbomVirtualPackageCompositionEntity> hasExists = virtualPackageCompositionResult.stream().filter(u -> u.getVirtualPackageMaterialNo().equals(lastVirtualPackage.getMaterialNo())
|
||||
&& u.getParentMaterialNo().equals(voParent.get(0).getMaterialNo()) && u.getChildMaterialNo().equals(vo.getMaterialNo()) && u.getFacCode().equals(facCode)).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(hasExists)){
|
||||
return;
|
||||
}
|
||||
BomNewEbomVirtualPackageCompositionEntity packageCompositionEntity = new BomNewEbomVirtualPackageCompositionEntity();
|
||||
packageCompositionEntity.setRowId(IdWorker.getId());
|
||||
packageCompositionEntity.setVirtualPackageMaterialNo(lastVirtualPackage.getMaterialNo());
|
||||
|
||||
packageCompositionEntity.setParentMaterialNo(voParent.get(0).getMaterialNo());
|
||||
packageCompositionEntity.setChildMaterialNo(vo.getMaterialNo());
|
||||
packageCompositionEntity.setNum(vo.getNum());
|
||||
packageCompositionEntity.setProjectType(vo.getProjectType());
|
||||
packageCompositionEntity.setUnitWeight(vo.getUnitWeight());
|
||||
packageCompositionEntity.setTotalWeight(vo.getTotalWeight());
|
||||
packageCompositionEntity.setUpdatedTime(LocalDateTime.now());
|
||||
packageCompositionEntity.setDeviseName(lastVirtualPackage.getDeviseName());
|
||||
packageCompositionEntity.setDeptName(lastVirtualPackage.getDeptName());
|
||||
packageCompositionEntity.setFromLiftingLayerState(0);
|
||||
packageCompositionEntity.setFacCode(facCode);
|
||||
if (!lastVirtualPackage.getBomRowId().equals(vo.getParentRowId())) {
|
||||
packageCompositionEntity.setFromLiftingLayerState(1);
|
||||
}
|
||||
packageCompositionEntity.setCurrentVersion(lastVirtualPackage.getCurrentVersion());
|
||||
List<BomNewEbomParentVO> vParentM = allBomDetail.stream().filter(u -> lastVirtualPackage.getParentRowId().equals(u.getBomRowId())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(vParentM)) {
|
||||
packageCompositionEntity.setVirtualMaterialParentMaterialNo(vParentM.get(0).getMaterialNo());
|
||||
}
|
||||
this.virtualPackageCompositionResult.add(packageCompositionEntity);
|
||||
}
|
||||
|
||||
protected void changeImpact() {
|
||||
|
||||
if( !EBomStatusEnum.PUBLISHED.equalsValue(parent.getStatus()) && parent.getVirtualPartType()<=0 && compareVirtualPackage(parent)){
|
||||
return;
|
||||
}
|
||||
changeImpactDo(parent);
|
||||
}
|
||||
|
||||
//
|
||||
protected void changeImpactDo(BomNewEbomParentVO parentVO) {
|
||||
|
||||
List<BomNewEbomParentVO> firstLevelBoms = allBomDetail.stream().filter(u -> u.getParentRowId().equals(parentVO.getBomRowId())).collect(Collectors.toList());
|
||||
for (BomNewEbomParentVO firstLevelBom : firstLevelBoms) {
|
||||
|
||||
if(firstLevelBom.getBomRowId()>0) {
|
||||
if( !EBomStatusEnum.PUBLISHED.equalsValue(firstLevelBom.getStatus()) && firstLevelBom.getVirtualPartType()<=0 && compareVirtualPackage(firstLevelBom)){
|
||||
break;
|
||||
}
|
||||
changeImpactDo(firstLevelBom);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Boolean compareVirtualPackage(BomNewEbomParentVO vo) {
|
||||
Boolean result = false;
|
||||
// if (EBomStatusEnum.PUBLISHED.equalsValue(vo.getStatus())) {
|
||||
// return result;
|
||||
// }
|
||||
List<BomNewEbomVirtualPackageCompositionEntity> impactVm = virtualPackageCompositionService.lambdaQuery()
|
||||
.eq(BomNewEbomVirtualPackageCompositionEntity::getParentMaterialNo, vo.getMaterialNo())
|
||||
.eq(BomNewEbomVirtualPackageCompositionEntity::getFromLiftingLayerState, 1).list();
|
||||
if (CollUtil.isNotEmpty(impactVm)) {
|
||||
List<BomNewEbomParentVO> childList = allBomDetail.stream().filter(u -> u.getParentRowId().equals(vo.getBomRowId())).collect(Collectors.toList());
|
||||
|
||||
Map<String, List<BomNewEbomVirtualPackageCompositionEntity>> impactVmMp = impactVm.stream().collect(Collectors.groupingBy(BomNewEbomVirtualPackageCompositionEntity::getVirtualPackageMaterialNo));
|
||||
//对比F项
|
||||
for (String vMaterialNo : impactVmMp.keySet()) {
|
||||
List<BomNewEbomVirtualPackageCompositionEntity> vMaterialList = impactVmMp.get(vMaterialNo);
|
||||
//当改BOM 存在该虚拟包则直接跳过
|
||||
List<BomNewEbomParentVO> existsV = allBomDetail.stream().filter(u -> u.getMaterialNo().equals(vMaterialNo)).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(existsV)) {
|
||||
continue;
|
||||
}
|
||||
//虚拟包原F项
|
||||
Set<String> fSet = vMaterialList.stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey().equals(u.getProjectType())).map(u -> StrUtil.join("", u.getChildMaterialNo(), u.getNum())).collect(Collectors.toSet());
|
||||
Set<String> newFSet = childList.stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey().equals(u.getProjectType())).map(u -> StrUtil.join("", u.getMaterialNo(), u.getNum())).collect(Collectors.toSet());
|
||||
if (!fSet.equals(newFSet)) {
|
||||
buildChangeImpactEntity(vMaterialList.get(0), vo);
|
||||
result = true;
|
||||
continue;
|
||||
}
|
||||
// 虚拟包Z项
|
||||
//虚拟包原F项
|
||||
Set<String> zSet = vMaterialList.stream().filter(u -> VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getProductTypeKey().equals(u.getProjectType())).map(u -> StrUtil.join("", u.getChildMaterialNo(), u.getNum())).collect(Collectors.toSet());
|
||||
Set<String> newZSet = childList.stream().filter(u -> VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getProductTypeKey().equals(u.getProjectType())).map(u -> StrUtil.join("", u.getMaterialNo(), u.getNum())).collect(Collectors.toSet());
|
||||
if (!zSet.equals(newZSet)) {
|
||||
buildChangeImpactEntity(vMaterialList.get(0), vo);
|
||||
result = true;
|
||||
continue;
|
||||
}
|
||||
//数量发生变化(非F,Z项 数量发生变化)
|
||||
List<BomNewEbomVirtualPackageCompositionEntity> noZOrFList = vMaterialList.stream().filter(u -> VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getProductTypeKey().equals(u.getProjectType())).collect(Collectors.toList());
|
||||
for (BomNewEbomVirtualPackageCompositionEntity vZOrF : noZOrFList) {
|
||||
List<BomNewEbomParentVO> collect = childList.stream().filter(u -> u.getMaterialNo().equals(vZOrF.getChildMaterialNo())).collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(collect)) {
|
||||
buildChangeImpactEntity(vMaterialList.get(0), vo);
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
//数量发生了变化
|
||||
else if (CollUtil.isNotEmpty(collect) && collect.get(0).getNum().equals(vZOrF.getNum())) {
|
||||
buildChangeImpactEntity(vMaterialList.get(0), vo);
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void buildChangeImpactEntity(BomNewEbomVirtualPackageCompositionEntity v, BomNewEbomParentVO vo) {
|
||||
|
||||
List<BomNewEbomUpgradeChangeEntity> checkExists = upgradeChangeResult.stream().filter(u -> u.getMaterialNo().equals(v.getVirtualPackageMaterialNo())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(checkExists)) {
|
||||
return;
|
||||
}
|
||||
List<BomNewEbomUpgradeChangeEntity> noHanlderV = SpringUtil.getBean(BomNewEbomUpgradeChangeService.class).lambdaQuery().eq(BomNewEbomUpgradeChangeEntity::getMaterialNo, v.getVirtualPackageMaterialNo())
|
||||
.eq(BomNewEbomUpgradeChangeEntity::getStatus, 0).list();
|
||||
if (CollUtil.isNotEmpty(noHanlderV)) {
|
||||
return;
|
||||
}
|
||||
BomNewEbomUpgradeChangeEntity changeEntity = new BomNewEbomUpgradeChangeEntity();
|
||||
changeEntity.setRowId(IdWorker.getId());
|
||||
changeEntity.setMaterialNo(v.getVirtualPackageMaterialNo());
|
||||
changeEntity.setVersionOld(vo.getCurrentVersion());
|
||||
changeEntity.setVersionNew(VersionUtil.getNextVersion(vo.getCurrentVersion()));
|
||||
List<BaseMaterialVO> materialBaseInfos = SpringUtil.getBean(MaterialMainService.class).getMaterialBaseInfo(ImmutableList.of(v.getVirtualPackageMaterialNo()));
|
||||
changeEntity.setMaterialName(materialBaseInfos.get(0).getMaterialName());
|
||||
changeEntity.setDrawingNo(materialBaseInfos.get(0).getDrawingNo());
|
||||
changeEntity.setDeviseName(v.getDeviseName());
|
||||
changeEntity.setDeptName(v.getDeptName());
|
||||
changeEntity.setRelMaterialNo(vo.getMaterialNo());
|
||||
changeEntity.setRelMaterialDesc(vo.getMaterialDesc());
|
||||
changeEntity.setStatus(0);
|
||||
changeEntity.setUpdatedTime(LocalDateTime.now());
|
||||
changeEntity.setFacCode(v.getFacCode());
|
||||
changeEntity.setVirtualMaterialParentMaterialNo(v.getVirtualMaterialParentMaterialNo());
|
||||
//虚拟包最新版PBom
|
||||
BomNewPbomParentEntity lastVirtrualPbomEnt = SpringUtil.getBean(BomNewPbomParentService.class).lambdaQuery()
|
||||
.eq(BomNewPbomParentEntity::getMaterialNo, v.getVirtualPackageMaterialNo())
|
||||
.eq(BomNewPbomParentEntity::getFacCode,v.getFacCode())
|
||||
.last("order by current_version desc limit 1").one();
|
||||
if(Objects.nonNull(lastVirtrualPbomEnt) && PBomStatusEnum.PUBLISH.getValue()>lastVirtrualPbomEnt.getStatus()){
|
||||
upgradeChangeResultForCover.add(changeEntity);
|
||||
}else {
|
||||
upgradeChangeResult.add(changeEntity);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String getParentMaterialNo(Long parentRowId) {
|
||||
List<BomNewEbomParentVO> collect = allBomDetail.stream().filter(u -> u.getBomRowId().equals(parentRowId)).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(collect)) {
|
||||
return collect.get(0).getMaterialNo();
|
||||
}
|
||||
return "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
private BomNewEbomParentVO getLastVirtualPackage(BomNewEbomParentVO vo, VirtualPackageTypeEnum virtualPackageTypeEnum) {
|
||||
List<BomNewEbomParentVO> zhiFaList = allBomDetail.stream().filter(u -> vo.getLevelNumber().compareTo(u.getLevelNumber()) > 0 && virtualPackageTypeEnum.getVirtualPartType().equals(u.getVirtualPartType())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(zhiFaList)) {
|
||||
return Collections.max(zhiFaList, Comparator.comparing(BomNewEbomParentVO::getLevelNumber));
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private BomNewEbomParentVO getLastVirtualPackageNew(BomNewEbomParentVO vo, Long parentRowId, VirtualPackageTypeEnum virtualPackageTypeEnum) {
|
||||
BomNewEbomParentVO parentEnt = getParent(vo, parentRowId);
|
||||
Boolean flag = true;
|
||||
while (Objects.nonNull(parentEnt) && parentEnt.getParentRowId() > 0 && flag) {
|
||||
//制作
|
||||
if (VirtualPackageTypeEnum.MAKING_PACKAGE.getVirtualPartType().equals(parentEnt.getVirtualPartType())) {
|
||||
Long parentEntParentRowId = parentEnt.getParentRowId();
|
||||
flag = false;
|
||||
return allBomDetail.stream().filter(u -> u.getParentRowId().equals(parentEntParentRowId) && virtualPackageTypeEnum.getVirtualPartType().equals(u.getVirtualPartType())).collect(Collectors.toList()).get(0);
|
||||
|
||||
}
|
||||
parentEnt = getParent(parentEnt);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private BomNewEbomParentVO getParent(BomNewEbomParentVO vo, Long parentRowId) {
|
||||
List<BomNewEbomParentVO> parents = allBomDetail.stream().filter(u -> u.getParentRowId().equals(parentRowId) && u.getBomRowId().equals(vo.getParentRowId())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(parents)) {
|
||||
return parents.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private BomNewEbomParentVO getParent(BomNewEbomParentVO vo) {
|
||||
List<BomNewEbomParentVO> parents = allBomDetail.stream().filter(u -> vo.getParentRowIds().contains(u.getParentRowId()) && u.getBomRowId().equals(vo.getParentRowId())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(parents)) {
|
||||
return parents.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private BomNewEbomParentVO getVirtualPackageByName(VirtualPackageTypeEnum virtualPackageTypeEnum) {
|
||||
List<BomNewEbomParentVO> list = allBomDetail.stream().filter(u -> u.getLevelNumber().compareTo(u.getLevelNumber()) > 0 && virtualPackageTypeEnum.getVirtualPartType().equals(u.getVirtualPartType())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成 层级号
|
||||
*
|
||||
* @param saveBomDetailParamDTO
|
||||
* @param bomRowID
|
||||
* @param parentDrawingNo
|
||||
*/
|
||||
public void generateDrawingNo(List<BomNewEbomParentVO> saveBomDetailParamDTO, Long bomRowID, String parentDrawingNo) {
|
||||
List<BomNewEbomParentVO> firstLevelBoms = saveBomDetailParamDTO.stream().filter(u -> u.getParentRowId().equals(bomRowID)).collect(Collectors.toList());
|
||||
String parentDrawingNoRe = StrUtil.isNotBlank(parentDrawingNo) ? parentDrawingNo : "";
|
||||
Integer gNo = 1;
|
||||
// List<Long> hasMarkRowId=new ArrayList<>();
|
||||
String preAssemblyPackageLevelNo = StrUtil.isNotBlank(parentDrawingNoRe) ? StrUtil.join("-", parentDrawingNoRe, "1") : "1";
|
||||
for (BomNewEbomParentVO firstLevelBom : firstLevelBoms) {
|
||||
// if( hasMarkRowId.contains(firstLevelBom.getRowId())){
|
||||
// BomNewEbomParentVO ent=new BomNewEbomParentVO();
|
||||
// BeanUtil.copyProperties(firstLevelBom,ent);
|
||||
// allBomDetail.add(ent);
|
||||
// firstLevelBom=ent;
|
||||
// }
|
||||
if (VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getVirtualPartType().equals(firstLevelBom.getVirtualPartType()) || VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getVirtualPartType().equals(firstLevelBom.getVirtualPartType())) {
|
||||
firstLevelBom.setLevelNumber(levelToNum(preAssemblyPackageLevelNo));
|
||||
firstLevelBom.setLevelNo(preAssemblyPackageLevelNo);
|
||||
|
||||
} else {
|
||||
|
||||
String levelKey = StrUtil.isNotBlank(parentDrawingNoRe) ? StrUtil.join("-", parentDrawingNoRe, gNo.toString()) : gNo.toString();
|
||||
firstLevelBom.setLevelNumber(levelToNum(levelKey));
|
||||
firstLevelBom.setLevelNo(levelKey);
|
||||
gNo++;
|
||||
}
|
||||
generateDrawingNo(saveBomDetailParamDTO, firstLevelBom.getChildBomRowId(), firstLevelBom.getLevelNo());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换层级号为数字
|
||||
*
|
||||
* @param strLevel
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal levelToNum(String strLevel) {
|
||||
if (StrUtil.isEmpty(strLevel)) {
|
||||
return null;
|
||||
}
|
||||
if (strLevel.indexOf('-') == -1) {
|
||||
return new BigDecimal(strLevel);
|
||||
}
|
||||
String[] fromArray = strLevel.split("-");
|
||||
String reuslt = "";
|
||||
for (int i = 0; i < fromArray.length; i++) {
|
||||
if (i == 0) {
|
||||
reuslt = fromArray[i] + '.';
|
||||
} else {
|
||||
reuslt += StrUtil.padPre(fromArray[i], 2, '0');
|
||||
}
|
||||
|
||||
}
|
||||
return new BigDecimal(reuslt);
|
||||
}
|
||||
|
||||
/**
|
||||
* BOM是否一致(物料编码+数量+项目类别)
|
||||
*
|
||||
* @param oldChildList
|
||||
* @param newChildList
|
||||
* @return
|
||||
*/
|
||||
private boolean isSameEBomV2(List<BomNewEbomChildEntity> oldChildList, List<BomNewEbomParentVO> newChildList) {
|
||||
if (oldChildList.size() != newChildList.size()) {
|
||||
return false;
|
||||
}
|
||||
Map<String, List<BomNewEbomChildEntity>> oldChildMap = oldChildList.stream().collect(Collectors.groupingBy(u -> StrUtil.join("", u.getMaterialNo(), u.getProjectType(), u.getNum())));
|
||||
for (BomNewEbomParentVO newChild : newChildList) {
|
||||
String key = StrUtil.join("", newChild.getMaterialNo(), newChild.getProjectType(), newChild.getNum());
|
||||
if (!oldChildMap.containsKey(key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* BOM是否一致(物料编码+数量)
|
||||
*
|
||||
* @param oldChildList
|
||||
* @param newChildList
|
||||
* @return
|
||||
*/
|
||||
private boolean isSameEBomV2FormMaterialNoAndNum(List<BomNewEbomChildEntity> oldChildList, List<BomNewEbomParentVO> newChildList) {
|
||||
if (oldChildList.size() != newChildList.size()) {
|
||||
return false;
|
||||
}
|
||||
Map<String, List<BomNewEbomChildEntity>> oldChildMap = oldChildList.stream().collect(Collectors.groupingBy(u -> StrUtil.join("", u.getMaterialNo(), u.getNum())));
|
||||
for (BomNewEbomParentVO newChild : newChildList) {
|
||||
String key = StrUtil.join("", newChild.getMaterialNo(), newChild.getNum());
|
||||
if (!oldChildMap.containsKey(key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换前生产EBom 版本号
|
||||
*/
|
||||
public void initEBomVersion() {
|
||||
List<BomNewEbomParentVO> parentBoms = allBomDetail.stream().filter(u -> u.getBomRowId() > 0).collect(Collectors.toList());
|
||||
for (BomNewEbomParentVO parentBom : parentBoms) {
|
||||
List<BomNewEbomParentVO> newParentChild = allBomDetail.stream().filter(u -> u.getParentRowId().equals(parentBom.getBomRowId())).collect(Collectors.toList());
|
||||
if (!EBomStatusEnum.PUBLISHED.equalsValue(parentBom.getStatus())) {
|
||||
//获取正式版
|
||||
BomNewEbomParentEntity oldEBom = SpringUtil.getBean(BomNewEbomParentService.class).lambdaQuery().eq(BomNewEbomParentEntity::getMaterialNo, parentBom.getMaterialNo())
|
||||
.eq(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
|
||||
.last(" order by current_version desc limit 1").one();
|
||||
if (Objects.nonNull(oldEBom)) {
|
||||
List<BomNewEbomChildEntity> oldParentChild = SpringUtil.getBean(BomNewEbomChildService.class).lambdaQuery().eq(BomNewEbomChildEntity::getParentRowId, oldEBom.getRowId()).list();
|
||||
|
||||
|
||||
//一样则无需转换
|
||||
if (isSameEBomV2(oldParentChild, newParentChild)) {
|
||||
parentBom.setNoConvertToPBomIs(1);
|
||||
parentBom.setHasChangeState(1);
|
||||
//只变化项目类别-则使用小版本
|
||||
} else if (isSameEBomV2FormMaterialNoAndNum(oldParentChild, newParentChild)) {
|
||||
parentBom.setCurrentVersion(VersionUtil.getNextVersionForSmallVersion(oldEBom.getCurrentVersion()));
|
||||
parentBom.setHasChangeState(2);
|
||||
delOldEBom.add(oldEBom.getRowId());
|
||||
addEBomNew.add(parentBom.getBomRowId());
|
||||
} else {
|
||||
parentBom.setCurrentVersion(VersionUtil.getNextVersion(oldEBom.getCurrentVersion()));
|
||||
parentBom.setHasChangeState(2);
|
||||
delOldEBom.add(oldEBom.getRowId());
|
||||
addEBomNew.add(parentBom.getBomRowId());
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
addEBomNew.add(parentBom.getBomRowId());
|
||||
}
|
||||
}
|
||||
//如子级都为F 项父级也不转
|
||||
Set<String> projectSet = newParentChild.stream().map(u -> u.getProjectType().toUpperCase()).collect(Collectors.toSet());
|
||||
if (CollUtil.isNotEmpty(projectSet)) {
|
||||
if (!VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey().equals(parentBom.getVirtualPartType()) && !VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getProductTypeKey().equals(parentBom.getVirtualPartType()) &&
|
||||
(ImmutableSet.of("F").equals(projectSet) || ImmutableSet.of("F", "Z").equals(projectSet) || ImmutableSet.of("Z").equals(projectSet))) {
|
||||
parentBom.setNoConvertToPBomIs(1);
|
||||
parentBom.setNotToPBomForFZ(BomConstant.YES);
|
||||
childDelMaterialNos.add(parentBom.getMaterialNo());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
List<BomNewEbomParentVO> FzItem = allBomDetail.stream().filter(u -> StrUtil.isNotBlank(u.getProjectType()) && ImmutableList.of("F", "Z").contains(u.getProjectType())).collect(Collectors.toList());
|
||||
FzItem.forEach(u->{
|
||||
u.setNotToPBomForFZ(BomConstant.YES);
|
||||
});
|
||||
//递归 F,Z项所有父级
|
||||
handlerFZEmptyBom();
|
||||
|
||||
}
|
||||
/**
|
||||
* 处理子级都是F项的空BOM
|
||||
*/
|
||||
private void handlerFZEmptyBom() {
|
||||
List<BomNewEbomParentVO> parentBoms = getParentForAllSubNodeIsNotToPBomForFZ();
|
||||
while (CollUtil.isNotEmpty(parentBoms)){
|
||||
parentBoms.forEach(u->{
|
||||
if (!VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey().equals(u.getVirtualPartType()) && !VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getProductTypeKey().equals(u.getVirtualPartType())) {
|
||||
u.setNoConvertToPBomIs(1);
|
||||
u.setNotToPBomForFZ(BomConstant.YES);
|
||||
childDelMaterialNos.add(u.getMaterialNo());
|
||||
}
|
||||
});
|
||||
parentBoms = getParentForAllSubNodeIsNotToPBomForFZ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<BomNewEbomParentVO> getParentForAllSubNodeIsNotToPBomForFZ(){
|
||||
Map<Long, List<BomNewEbomParentVO>> parentMp = allBomDetail.stream().filter(u->u.getParentRowId()>0).collect(Collectors.groupingBy(BomNewEbomParentVO::getParentRowId));
|
||||
List<BomNewEbomParentVO> result=new ArrayList<>();
|
||||
parentMp.forEach((k,v)->{
|
||||
List<BomNewEbomParentVO> parent = allBomDetail.stream().filter(u -> u.getBomRowId().equals(k)).collect(Collectors.toList());
|
||||
if(Objects.nonNull(parent) && CollUtil.isNotEmpty(parent) && BomConstant.NO.equals(parent.get(0).getNotToPBomForFZ()) ) {
|
||||
Optional<BomNewEbomParentVO> min = v.stream().min(Comparator.comparingInt(BomNewEbomParentVO::getNotToPBomForFZ));
|
||||
if (min.isPresent() && BomConstant.YES.equals(min.get().getNotToPBomForFZ())) {
|
||||
result.add(parent.get(0));
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 正式eBOM转换前生产 pBOM
|
||||
* 子项都为F 项则父项不转
|
||||
*/
|
||||
public void initEBomVersionFormal() {
|
||||
List<BomNewEbomParentVO> parentBoms = allBomDetail.stream().filter(u -> u.getBomRowId() > 0).collect(Collectors.toList());
|
||||
for (BomNewEbomParentVO parentBom : parentBoms) {
|
||||
|
||||
List<BomNewEbomParentVO> newParentChild = allBomDetail.stream().filter(u -> u.getParentRowId().equals(parentBom.getBomRowId())).collect(Collectors.toList());
|
||||
//如子级都为F 项父级也不转
|
||||
Set<String> projectSet = newParentChild.stream().map(u -> u.getProjectType().toUpperCase()).collect(Collectors.toSet());
|
||||
if (CollUtil.isNotEmpty(projectSet)) {
|
||||
if (!VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey().equals(parentBom.getVirtualPartType()) && !VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getProductTypeKey().equals(parentBom.getVirtualPartType()) &&
|
||||
(ImmutableSet.of("F").equals(projectSet) || ImmutableSet.of("F", "Z").equals(projectSet) || ImmutableSet.of("Z").equals(projectSet))) {
|
||||
parentBom.setNoConvertToPBomIs(1);
|
||||
parentBom.setNotToPBomForFZ(BomConstant.YES);
|
||||
childDelMaterialNos.add(parentBom.getMaterialNo());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
List<BomNewEbomParentVO> FzItem = allBomDetail.stream().filter(u -> StrUtil.isNotBlank(u.getProjectType()) && ImmutableList.of("F", "Z").contains(u.getProjectType())).collect(Collectors.toList());
|
||||
FzItem.forEach(u->{
|
||||
u.setNotToPBomForFZ(BomConstant.YES);
|
||||
});
|
||||
|
||||
//递归 F,Z项所有父级
|
||||
handlerFZEmptyBom();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点下的子节点(包含节点本身)
|
||||
*
|
||||
* @param parentVO
|
||||
* @return
|
||||
*/
|
||||
protected List<BomNewEbomParentVO> getResultAllSubIncludeSelf(BomNewEbomParentVO parentVO) {
|
||||
List<BomNewEbomParentVO> reusltSub = new ArrayList<>();
|
||||
reusltSub.add(parentVO);
|
||||
if(parentVO.getBomRowId()<=0){
|
||||
return reusltSub;
|
||||
}
|
||||
getAllSubData(ImmutableList.of(parentVO.getBomRowId()), reusltSub);
|
||||
|
||||
|
||||
return reusltSub.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected List<BomNewEbomParentVO> getAllSubInListIncludeSelf(BomNewEbomParentVO parentVO, List<BomNewEbomParentVO> list) {
|
||||
List<BomNewEbomParentVO> reusltSub = new ArrayList<>();
|
||||
reusltSub.add(parentVO);
|
||||
getAllSubData(ImmutableList.of(parentVO.getBomRowId()), reusltSub, list);
|
||||
|
||||
|
||||
return reusltSub.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
private void getAllSubData(List<Long> parentRowIds, List<BomNewEbomParentVO> subResult, List<BomNewEbomParentVO> list) {
|
||||
|
||||
List<BomNewEbomParentVO> subMaterials = list.stream().filter(u -> parentRowIds.contains(u.getParentRowId())).collect(Collectors.toList());
|
||||
while (CollUtil.isNotEmpty(subMaterials)) {
|
||||
subResult.addAll(subMaterials);
|
||||
List<Long> subMarterialBomRowIds = subMaterials.stream().filter(u -> u.getBomRowId() > 0).map(u -> u.getBomRowId()).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(subMarterialBomRowIds)) {
|
||||
subMaterials = list.stream().filter(u -> subMarterialBomRowIds.contains(u.getParentRowId())).collect(Collectors.toList());
|
||||
} else {
|
||||
subMaterials = Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发货包下子级
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
private void getAllSubData(List<Long> parentRowIds, List<BomNewEbomParentVO> subResult) {
|
||||
|
||||
|
||||
List<BomNewEbomParentVO> subMaterials = result.stream().filter(u -> parentRowIds.contains(u.getParentRowId())).collect(Collectors.toList());
|
||||
//直发包,发货前装配包不递归。
|
||||
while (CollUtil.isNotEmpty(subMaterials)) {
|
||||
subResult.addAll(subMaterials);
|
||||
|
||||
List<Long> subMarterialBomRowIds = subMaterials.stream().filter(u -> u.getBomRowId() > 0).map(u -> u.getBomRowId()).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(subMarterialBomRowIds)) {
|
||||
|
||||
subMaterials = result.stream().filter(u -> subMarterialBomRowIds.contains(u.getParentRowId())).collect(Collectors.toList());
|
||||
} else {
|
||||
subMaterials = Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -385,6 +385,7 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
|
|||
eBomParent.setConvertToEbomTime(LocalDateTime.now());
|
||||
eBomParent.setSourceRowId(StrUtil.isNotBlank(parentEnt.getSourceRowId()) ? parentEnt.getSourceRowId() : parentEnt.getRowId().toString());
|
||||
eBomParent.setLastVersionIs(1);
|
||||
eBomParent.setNum(new BigDecimal(1));
|
||||
eBomParent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
//eBomParent.setModifyTime(LocalDateTime.now());
|
||||
// eBomParent.setBomExist(parentEnt.getBomRowId() > 0 ? 1 : 0);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.nflg.product.bomnew.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
public class MyStrUtil extends StrUtil {
|
||||
|
||||
private static Joiner joiner=Joiner.on("").skipNulls();
|
||||
public static String joinStr(Object ... str){
|
||||
return joiner.join(str);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue