Merge branch 'refs/heads/feature/DM/nflg-bom' into feature/DM/nflg-bom-transition
This commit is contained in:
commit
34fe4b7540
|
|
@ -870,9 +870,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
parent.setChildBomRowId(parent.getRowId());
|
||||
parent.setParentRowId(0L);
|
||||
bomTree.add(parent);
|
||||
EBomToPBom eBomToPBom = new EBomToPBom(parent, bomTree
|
||||
, parent.getMaterialNo().startsWith("31") ? Collections.singletonList("1010") : paramDto.getFacCodes()
|
||||
, 0L);
|
||||
EBomToPbomBase eBomToPBom =parent.getMaterialNo().startsWith("31")? new EBomToPBomFor31(parent, bomTree, paramDto.getFacCodes(), 0L):new EBomToPBom(parent, bomTree, paramDto.getFacCodes(), 0L);
|
||||
eBomToPBom.convert();
|
||||
|
||||
if (CollUtil.isNotEmpty(eBomToPBom.getPBomParentResult())) {
|
||||
|
|
|
|||
|
|
@ -2,65 +2,27 @@ package com.nflg.product.bomnew.service.domain.EBom;
|
|||
|
||||
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.ImmutableMap;
|
||||
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.constant.PBomStatusEnum;
|
||||
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.pojo.vo.BomNewPbomParentVO;
|
||||
import com.nflg.product.bomnew.service.BomNewEbomVirtualPackageCompositionService;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomChildService;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomParentService;
|
||||
import com.nflg.product.bomnew.util.BomLevelUtil;
|
||||
import com.nflg.product.bomnew.util.ListCommonUtil;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import com.nflg.product.bomnew.util.VersionUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Ebom 转Pbom
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class EBomToPBom {
|
||||
|
||||
private BomNewEbomParentVO parent;
|
||||
|
||||
//工厂编码列表
|
||||
private List<String> facCodes;
|
||||
|
||||
private List<BomNewEbomParentVO> allBomDetail;
|
||||
public class EBomToPBom extends EBomToPbomBase {
|
||||
|
||||
|
||||
private List<BomNewEbomParentVO> result = new ArrayList<>();
|
||||
|
||||
|
||||
@Getter
|
||||
private List<BomNewPbomParentEntity> pBomParentResult = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private List<BomNewPbomChildEntity> pBomChildResult = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private List<BomNewEbomVirtualPackageCompositionEntity> virtualPackageCompositionResult = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private List<BomNewEbomUpgradeChangeEntity> upgradeChangeResult = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private List<BomNewEbomUpdateDetailEntity> upgradeChangeDetailResult = new ArrayList<>();
|
||||
|
||||
private Set<String> hasBuildVNo = Sets.newHashSet();
|
||||
|
||||
|
||||
public EBomToPBom(BomNewEbomParentVO inParent, List<BomNewEbomParentVO> inAllBomDetail, List<String> inFacCodes, Long parentRowId) {
|
||||
|
|
@ -74,6 +36,7 @@ public class EBomToPBom {
|
|||
/**
|
||||
* 31項体层
|
||||
*/
|
||||
@Override
|
||||
public void convert() {
|
||||
|
||||
//效验数据是否OK
|
||||
|
|
@ -122,373 +85,7 @@ public class EBomToPBom {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BOM 明细对比,如只有T项变化则,不升级直接修改
|
||||
*/
|
||||
private 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());
|
||||
if(oldBomNoTChildren.size()!= newBomNoTChildren.size()) {
|
||||
return false;
|
||||
}
|
||||
//除T项外的对比
|
||||
Map<String, BomNewPbomParentVO> oldBomMap = oldBomNoTChildren.stream().collect(Collectors.toMap(BomNewPbomParentVO::getMaterialNoAndProjectType, u -> u, (k1, k2) -> k1));
|
||||
for (BomNewEbomParentVO newVo : newBomNoTChildren) {
|
||||
if(!oldBomMap.containsKey(newVo.getMaterialNoAndProductType()) || !Objects.equals(newVo.getNum(),oldBomMap.get(newVo.getMaterialNoAndProductType()).getNum())){
|
||||
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()));
|
||||
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 = ListCommonUtil.listGroupMap(child, BomNewEbomParentVO::getMaterialNo);
|
||||
|
||||
for (String key : listMp.keySet()) {
|
||||
List<BomNewEbomParentVO> voList = listMp.get(key);
|
||||
BomNewEbomParentVO ent = voList.get(0);
|
||||
ent.setNum(voList.stream().map(aa -> aa.getNum()).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
result.add(ent);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据效验
|
||||
*/
|
||||
private 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
|
||||
*/
|
||||
private BomNewPbomParentEntity buildPBomParent(BomNewEbomParentVO parentVo, String facCode) {
|
||||
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();
|
||||
|
||||
// this.hasConvertEBomRowIds.add(parentVo.getRowId());
|
||||
if (Objects.nonNull(oldParent) && !EBomStatusEnum.PUBLISHED.equalsValue(oldParent.getStatus())) {
|
||||
SpringUtil.getBean(BomNewPbomChildService.class).getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldParent.getRowId()));
|
||||
oldParent.setCurrentVersion(parentVo.getCurrentVersion());
|
||||
this.pBomParentResult.add(oldParent);
|
||||
return oldParent;
|
||||
} else {
|
||||
BomNewPbomParentEntity pBomParent = new BomNewPbomParentEntity();
|
||||
BeanUtil.copyProperties(parentVo, pBomParent);
|
||||
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.setCurrentVersion(VersionUtil.getNextVersion(""));
|
||||
//版本=EBom版本
|
||||
pBomParent.setCurrentVersion(parentVo.getCurrentVersion());
|
||||
pBomParent.setEditStatus(PBomEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
if (Objects.nonNull(oldParent)) {
|
||||
// pBomParent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
|
||||
oldParent.setExpireEndTime(LocalDateTime.now());
|
||||
oldParent.setLastVersionIs(0);
|
||||
}
|
||||
this.pBomParentResult.add(pBomParent);
|
||||
return pBomParent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 31提层
|
||||
*
|
||||
* @param
|
||||
* @param
|
||||
*/
|
||||
private void liftingLayer() {
|
||||
for (BomNewEbomParentVO vo : allBomDetail) {
|
||||
if (StrUtil.isNotBlank(vo.getProjectType()) && vo.getProjectType().equals(VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey())) {
|
||||
BomNewEbomParentVO lastVirtualPackage = getLastVirtualPackage(vo, VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE);
|
||||
if (Objects.nonNull(lastVirtualPackage)) {
|
||||
liftingLayerSummary(lastVirtualPackage, vo);
|
||||
vo.setSourceRowId(String.valueOf(vo.getParentRowId()));
|
||||
vo.setSourceParentMaterialNo(getParentMaterialNo(vo.getBomRowId()));
|
||||
vo.setParentRowId(lastVirtualPackage.getBomRowId());
|
||||
result.add(vo);
|
||||
}
|
||||
//当没找到直发包时,丢弃
|
||||
// else {
|
||||
// // buildUpgradeChange(vo);
|
||||
// }
|
||||
continue;
|
||||
}
|
||||
if (StrUtil.isNotBlank(vo.getProjectType()) && vo.getProjectType().equals(VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getProductTypeKey())) {
|
||||
BomNewEbomParentVO lastVirtualPackage = getLastVirtualPackage(vo, VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE);
|
||||
if (Objects.nonNull(lastVirtualPackage)) {
|
||||
liftingLayerSummary(lastVirtualPackage, vo);
|
||||
vo.setSourceRowId(String.valueOf(vo.getParentRowId()));
|
||||
vo.setSourceParentMaterialNo(getParentMaterialNo(vo.getBomRowId()));
|
||||
vo.setParentRowId(lastVirtualPackage.getBomRowId());
|
||||
result.add(vo);
|
||||
}
|
||||
// else { //当没找到直发包时,丢弃
|
||||
// // buildUpgradeChange(vo);
|
||||
// }
|
||||
continue;
|
||||
}
|
||||
result.add(vo);
|
||||
}
|
||||
}
|
||||
|
||||
//变更记录(明细)
|
||||
private void buildUpgradeChangeDetail(BomNewEbomParentVO parent, VirtualPackageTypeEnum packageTypeEnum) {
|
||||
|
||||
List<BomNewEbomVirtualPackageCompositionEntity> list = SpringUtil.getBean(BomNewEbomVirtualPackageCompositionService.class).lambdaQuery()
|
||||
.eq(BomNewEbomVirtualPackageCompositionEntity::getParentMaterialNo, parent.getMaterialNo())
|
||||
.eq(BomNewEbomVirtualPackageCompositionEntity::getProjectType, packageTypeEnum.getProductTypeKey()).list();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
//老的虚拟包组成
|
||||
Set<String> oldMaterialNoAndNumSet = list.stream().filter(u -> u.getParentMaterialNo().equals(parent.getMaterialNo())).map(u -> StrUtil.join("-", u.getChildMaterialNo(), u.getNum())).collect(Collectors.toSet());
|
||||
|
||||
List<BomNewEbomParentVO> parentChildren = allBomDetail.stream().filter(u -> u.getParentRowId().equals(parent.getBomRowId())).collect(Collectors.toList());
|
||||
//物料编码 +数量
|
||||
Set<String> newSet = parentChildren.stream().filter(u -> Objects.nonNull(u.getProjectType()) && VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey().equals(u.getProjectType())).map(u -> StrUtil.join("-", u.getMaterialNo(), u.getNum())).collect(Collectors.toSet());
|
||||
//bom 发生了改变-影响了虚拟包
|
||||
if (CollUtil.isNotEmpty(Sets.difference(oldMaterialNoAndNumSet, newSet)) || CollUtil.isNotEmpty(Sets.difference(newSet, oldMaterialNoAndNumSet))) {
|
||||
|
||||
List<String> vmaterialNoList = list.stream().map(u -> u.getVirtualPackageMaterialNo()).distinct().collect(Collectors.toList());
|
||||
//记录变更明细行
|
||||
buildChangeDetailD0(vmaterialNoList, parent, parentChildren);
|
||||
//变更
|
||||
buildUpgradeChange(list, parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buildChangeDetailD0(List<String> vmaterialNoList, BomNewEbomParentVO parent, List<BomNewEbomParentVO> parentChildren) {
|
||||
for (BomNewEbomParentVO vo : parentChildren) {
|
||||
for (String vNo : vmaterialNoList) {
|
||||
BomNewEbomUpdateDetailEntity changeDetailEnt = new BomNewEbomUpdateDetailEntity();
|
||||
changeDetailEnt.setRowId(IdWorker.getId());
|
||||
changeDetailEnt.setVirtualPackageMaterialNo(vNo);
|
||||
changeDetailEnt.setParentMaterialNo(parent.getMaterialNo());
|
||||
changeDetailEnt.setCurrentVersion(parent.getCurrentVersion());
|
||||
changeDetailEnt.setChildMaterialNo(vo.getMaterialNo());
|
||||
changeDetailEnt.setNum(vo.getNum());
|
||||
changeDetailEnt.setProjectType(vo.getProjectType());
|
||||
changeDetailEnt.setUpdatedTime(LocalDateTime.now());
|
||||
changeDetailEnt.setEbomSourceRowId(vo.getRowId());
|
||||
this.upgradeChangeDetailResult.add(changeDetailEnt);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void buildUpgradeChange(List<BomNewEbomVirtualPackageCompositionEntity> changeList, BomNewEbomParentVO parent) {
|
||||
List<String> vmaterialNoList = changeList.stream().map(u -> u.getVirtualPackageMaterialNo()).distinct().collect(Collectors.toList());
|
||||
for (String vmaterialNo : vmaterialNoList) {
|
||||
String key = StrUtil.join("-", vmaterialNo, parent.getMaterialNo());
|
||||
if (hasBuildVNo.contains(key)) {
|
||||
continue;
|
||||
}
|
||||
BomNewEbomUpgradeChangeEntity changeEntity = new BomNewEbomUpgradeChangeEntity();
|
||||
changeEntity.setRowId(IdWorker.getId());
|
||||
changeEntity.setMaterialNo(vmaterialNo);
|
||||
changeEntity.setVersionOld(parent.getCurrentVersion());
|
||||
changeEntity.setVersionNew(VersionUtil.getNextVersionForSmallVersion(parent.getCurrentVersion()));
|
||||
changeEntity.setDeviseName(SessionUtil.getRealName());
|
||||
changeEntity.setDeptName(SessionUtil.getDepartName());
|
||||
changeEntity.setRelMaterialNo(parent.getMaterialNo());
|
||||
changeEntity.setRelMaterialDesc(parent.getMaterialDesc());
|
||||
changeEntity.setStatus(0);
|
||||
upgradeChangeResult.add(changeEntity);
|
||||
|
||||
hasBuildVNo.add(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提层汇总数量
|
||||
*
|
||||
* @param lastVirtualPackage 虚拟包
|
||||
* @param vo 提层项
|
||||
*/
|
||||
private void liftingLayerSummary(BomNewEbomParentVO lastVirtualPackage, BomNewEbomParentVO vo) {
|
||||
BigDecimal sum = vo.getNum();
|
||||
String parentLevelNo = BomLevelUtil.getParentLevelNo(vo.getLevelNo());
|
||||
List<BigDecimal> parentFullPathNum = new ArrayList<>();
|
||||
while (parentLevelNo.length() >= lastVirtualPackage.getLevelNo().length()) {
|
||||
String pNo = parentLevelNo;
|
||||
List<BomNewEbomParentVO> parentList = allBomDetail.stream().filter(u -> u.getLevelNo().equals(pNo)).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(parentList)) {
|
||||
sum = NumberUtil.mul(sum, parentList.get(0).getNum());
|
||||
parentFullPathNum.add(parentList.get(0).getNum());
|
||||
}
|
||||
// else {
|
||||
// parentFullPathNum.add(parentList.get(0).getNum());
|
||||
// }
|
||||
parentLevelNo = BomLevelUtil.getParentLevelNo(parentLevelNo);
|
||||
|
||||
}
|
||||
vo.setNum(sum);
|
||||
//构建虚拟包组成
|
||||
buildVirtualPackageComposition(lastVirtualPackage, vo, parentFullPathNum);
|
||||
|
||||
}
|
||||
|
||||
private void buildVirtualPackageComposition(BomNewEbomParentVO lastVirtualPackage, BomNewEbomParentVO vo, List<BigDecimal> parentFullPathNum) {
|
||||
|
||||
BomNewEbomVirtualPackageCompositionEntity packageCompositionEntity = new BomNewEbomVirtualPackageCompositionEntity();
|
||||
packageCompositionEntity.setRowId(IdWorker.getId());
|
||||
packageCompositionEntity.setVirtualPackageMaterialNo(lastVirtualPackage.getMaterialNo());
|
||||
List<BomNewEbomParentVO> voParent = allBomDetail.stream().filter(u -> u.getBomRowId().equals(vo.getParentRowId())).collect(Collectors.toList());
|
||||
VUtils.isTure(CollUtil.isEmpty(voParent)).throwMessage(vo.getMaterialNo() + " 未找到父级");
|
||||
packageCompositionEntity.setParentMaterialNo(voParent.get(0).getMaterialNo());
|
||||
packageCompositionEntity.setChildMaterialNo(vo.getMaterialNo());
|
||||
packageCompositionEntity.setParentFullPathNum(StrUtil.join(",", parentFullPathNum));
|
||||
packageCompositionEntity.setProjectType(vo.getProjectType());
|
||||
packageCompositionEntity.setUnitWeight(vo.getUnitWeight());
|
||||
packageCompositionEntity.setTotalWeight(vo.getTotalWeight());
|
||||
packageCompositionEntity.setUpdatedTime(LocalDateTime.now());
|
||||
this.virtualPackageCompositionResult.add(packageCompositionEntity);
|
||||
}
|
||||
|
||||
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 "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
private BomNewEbomParentVO getLastVirtualPackage(BomNewEbomParentVO vo, VirtualPackageTypeEnum virtualPackageTypeEnum) {
|
||||
List<BomNewEbomParentVO> zhiFaList = allBomDetail.stream().filter(u -> vo.getLevelNumber().compareTo(u.getLevelNumber()) > 0 && u.getMaterialName().contains(virtualPackageTypeEnum.getConMaterialName())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(zhiFaList)) {
|
||||
return Collections.max(zhiFaList, Comparator.comparing(BomNewEbomParentVO::getLevelNumber));
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private BomNewEbomParentVO getVirtualPackageByName(VirtualPackageTypeEnum virtualPackageTypeEnum) {
|
||||
List<BomNewEbomParentVO> list = allBomDetail.stream().filter(u -> u.getMaterialName().contains(virtualPackageTypeEnum.getConMaterialName())).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());
|
||||
parentDrawingNo = StrUtil.isNotBlank(parentDrawingNo) ? parentDrawingNo : "";
|
||||
Integer gNo = 1;
|
||||
|
||||
String preAssemblyPackageLevelNo = StrUtil.isNotBlank(parentDrawingNo) ? StrUtil.join("-", parentDrawingNo, "1") : "1";
|
||||
for (BomNewEbomParentVO firstLevelBom : firstLevelBoms) {
|
||||
|
||||
if (firstLevelBom.getMaterialName().contains(VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getConMaterialName()) || firstLevelBom.getMaterialName().contains(VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getConMaterialName())) {
|
||||
firstLevelBom.setLevelNumber(levelToNum(preAssemblyPackageLevelNo));
|
||||
firstLevelBom.setLevelNo(preAssemblyPackageLevelNo);
|
||||
continue;
|
||||
}
|
||||
|
||||
String levelKey = StrUtil.isNotBlank(parentDrawingNo) ? StrUtil.join("-", parentDrawingNo, 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,126 @@
|
|||
package com.nflg.product.bomnew.service.domain.EBom;
|
||||
|
||||
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 com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.bomnew.constant.EBomConstant;
|
||||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
||||
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 lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import com.nflg.product.bomnew.util.ListCommonUtil;
|
||||
|
||||
/**
|
||||
* 31码转PBOM
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class EBomToPBomFor31 extends EBomToPbomBase {
|
||||
|
||||
|
||||
|
||||
private Map<String,List<BomNewEbomParentVO>> facBomDataMp=new HashMap<>();
|
||||
|
||||
|
||||
public EBomToPBomFor31(BomNewEbomParentVO inParent, List<BomNewEbomParentVO> inAllBomDetail, List<String> inFacCodes, Long parentRowId) {
|
||||
this.parent = inParent;
|
||||
this.allBomDetail = inAllBomDetail;
|
||||
this.facCodes = inFacCodes;
|
||||
generateDrawingNo(allBomDetail, parentRowId, "");
|
||||
|
||||
}
|
||||
|
||||
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("仙桃") && 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(), new BigDecimal(0.01))) < 0).collect(Collectors.toList());
|
||||
data1020.addAll(subVos);
|
||||
}
|
||||
facBomDataMp.put(EBomConstant.XIAN_TAO_FACTORY_CODE_1020,data1020);
|
||||
}
|
||||
|
||||
//1010 数据
|
||||
facCodes.add(EBomConstant.MAIN_FACTORY_CODE_1010);
|
||||
List<BomNewEbomParentVO> data1010=new ArrayList<>();
|
||||
List<BomNewEbomParentVO> deliveryPackage1010 = result.stream().filter(u -> u.getParentRowId().equals(parent.getRowId()) && !u.getMaterialName().contains("仙桃") && u.getMaterialName().contains("发货")).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(deliveryPackage1010)){
|
||||
data1010.add(parent);
|
||||
for (BomNewEbomParentVO data: deliveryPackage1010){
|
||||
List<BomNewEbomParentVO> subVos = result.stream().filter(u -> u.getLevelNumber().compareTo(data.getLevelNumber()) >= 0 && u.getLevelNumber().compareTo(NumberUtil.add(data.getLevelNumber(), new BigDecimal(0.01))) < 0).collect(Collectors.toList());
|
||||
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) || PBomStatusEnum.PUBLISH.equalsValue(vo.getStatus())) {
|
||||
continue;
|
||||
}
|
||||
hasConvert.add(hasConvertKey);
|
||||
//构建变更明细
|
||||
buildUpgradeChangeDetail(vo, VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE);
|
||||
buildUpgradeChangeDetail(vo, VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE);
|
||||
|
||||
//子级
|
||||
List<BomNewEbomParentVO> child = result.stream().filter(u -> u.getParentRowId().equals(vo.getBomRowId())).distinct().collect(Collectors.toList());
|
||||
List<BomNewEbomParentVO> mergeChild = mergeChild(child);
|
||||
if( compareContentIsSame(vo, mergeChild, facCode)){
|
||||
continue;
|
||||
}
|
||||
|
||||
BomNewPbomParentEntity parentEnt = buildPBomParent(vo, facCode);
|
||||
//子级
|
||||
if (CollUtil.isNotEmpty(child)) {
|
||||
//合并子级
|
||||
for (BomNewEbomParentVO eb : mergeChild) {
|
||||
BomNewPbomChildEntity childEnt = new BomNewPbomChildEntity();
|
||||
BeanUtil.copyProperties(eb, childEnt);
|
||||
childEnt.setRowId(IdWorker.getId());
|
||||
childEnt.setParentRowId(parentEnt.getRowId());
|
||||
childEnt.setFacCode(facCode);
|
||||
childEnt.setIdentityNo(StrUtil.join("-", parentEnt.getMaterialNo(), eb.getMaterialNo()));
|
||||
this.pBomChildResult.add(childEnt);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,428 @@
|
|||
package com.nflg.product.bomnew.service.domain.EBom;
|
||||
|
||||
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.ImmutableMap;
|
||||
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.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
|
||||
import com.nflg.product.bomnew.service.BomNewEbomVirtualPackageCompositionService;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomChildService;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomParentService;
|
||||
import com.nflg.product.bomnew.util.BomLevelUtil;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import com.nflg.product.bomnew.util.VersionUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class EBomToPbomBase {
|
||||
|
||||
protected BomNewEbomParentVO parent;
|
||||
|
||||
//工厂编码列表
|
||||
protected List<String> facCodes;
|
||||
|
||||
protected List<BomNewEbomParentVO> allBomDetail;
|
||||
|
||||
|
||||
protected List<BomNewEbomParentVO> result = new ArrayList<>();
|
||||
|
||||
|
||||
@Getter
|
||||
protected List<BomNewPbomParentEntity> pBomParentResult = 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<BomNewEbomUpdateDetailEntity> upgradeChangeDetailResult = new ArrayList<>();
|
||||
|
||||
protected Set<String> hasBuildVNo = Sets.newHashSet();
|
||||
|
||||
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());
|
||||
if(oldBomNoTChildren.size()!= newBomNoTChildren.size()) {
|
||||
return false;
|
||||
}
|
||||
//除T项外的对比
|
||||
Map<String, BomNewPbomParentVO> oldBomMap = oldBomNoTChildren.stream().collect(Collectors.toMap(BomNewPbomParentVO::getMaterialNoAndProjectType, u -> u, (k1, k2) -> k1));
|
||||
for (BomNewEbomParentVO newVo : newBomNoTChildren) {
|
||||
if(!oldBomMap.containsKey(newVo.getMaterialNoAndProductType()) || !Objects.equals(newVo.getNum(),oldBomMap.get(newVo.getMaterialNoAndProductType()).getNum())){
|
||||
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()));
|
||||
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().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().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) {
|
||||
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();
|
||||
|
||||
// this.hasConvertEBomRowIds.add(parentVo.getRowId());
|
||||
if (Objects.nonNull(oldParent) && !EBomStatusEnum.PUBLISHED.equalsValue(oldParent.getStatus())) {
|
||||
SpringUtil.getBean(BomNewPbomChildService.class).getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldParent.getRowId()));
|
||||
oldParent.setCurrentVersion(parentVo.getCurrentVersion());
|
||||
this.pBomParentResult.add(oldParent);
|
||||
return oldParent;
|
||||
} else {
|
||||
BomNewPbomParentEntity pBomParent = new BomNewPbomParentEntity();
|
||||
BeanUtil.copyProperties(parentVo, pBomParent);
|
||||
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.setCurrentVersion(VersionUtil.getNextVersion(""));
|
||||
//版本=EBom版本
|
||||
pBomParent.setCurrentVersion(parentVo.getCurrentVersion());
|
||||
pBomParent.setEditStatus(PBomEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
if (Objects.nonNull(oldParent)) {
|
||||
// pBomParent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
|
||||
oldParent.setExpireEndTime(LocalDateTime.now());
|
||||
oldParent.setLastVersionIs(0);
|
||||
}
|
||||
this.pBomParentResult.add(pBomParent);
|
||||
return pBomParent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 31提层
|
||||
*
|
||||
* @param
|
||||
* @param
|
||||
*/
|
||||
protected void liftingLayer() {
|
||||
for (BomNewEbomParentVO vo : allBomDetail) {
|
||||
if (StrUtil.isNotBlank(vo.getProjectType()) && vo.getProjectType().equals(VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey())) {
|
||||
BomNewEbomParentVO lastVirtualPackage = getLastVirtualPackage(vo, VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE);
|
||||
if (Objects.nonNull(lastVirtualPackage)) {
|
||||
liftingLayerSummary(lastVirtualPackage, vo);
|
||||
vo.setSourceRowId(String.valueOf(vo.getParentRowId()));
|
||||
vo.setSourceParentMaterialNo(getParentMaterialNo(vo.getBomRowId()));
|
||||
vo.setParentRowId(lastVirtualPackage.getBomRowId());
|
||||
result.add(vo);
|
||||
}
|
||||
//当没找到直发包时,丢弃
|
||||
// else {
|
||||
// // buildUpgradeChange(vo);
|
||||
// }
|
||||
continue;
|
||||
}
|
||||
if (StrUtil.isNotBlank(vo.getProjectType()) && vo.getProjectType().equals(VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getProductTypeKey())) {
|
||||
BomNewEbomParentVO lastVirtualPackage = getLastVirtualPackage(vo, VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE);
|
||||
if (Objects.nonNull(lastVirtualPackage)) {
|
||||
liftingLayerSummary(lastVirtualPackage, vo);
|
||||
vo.setSourceRowId(String.valueOf(vo.getParentRowId()));
|
||||
vo.setSourceParentMaterialNo(getParentMaterialNo(vo.getBomRowId()));
|
||||
vo.setParentRowId(lastVirtualPackage.getBomRowId());
|
||||
result.add(vo);
|
||||
}
|
||||
// else { //当没找到直发包时,丢弃
|
||||
// // buildUpgradeChange(vo);
|
||||
// }
|
||||
continue;
|
||||
}
|
||||
result.add(vo);
|
||||
}
|
||||
}
|
||||
|
||||
//变更记录(明细)
|
||||
protected void buildUpgradeChangeDetail(BomNewEbomParentVO parent, VirtualPackageTypeEnum packageTypeEnum) {
|
||||
|
||||
List<BomNewEbomVirtualPackageCompositionEntity> list = SpringUtil.getBean(BomNewEbomVirtualPackageCompositionService.class).lambdaQuery()
|
||||
.eq(BomNewEbomVirtualPackageCompositionEntity::getParentMaterialNo, parent.getMaterialNo())
|
||||
.eq(BomNewEbomVirtualPackageCompositionEntity::getProjectType, packageTypeEnum.getProductTypeKey()).list();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
//老的虚拟包组成
|
||||
Set<String> oldMaterialNoAndNumSet = list.stream().filter(u -> u.getParentMaterialNo().equals(parent.getMaterialNo())).map(u -> StrUtil.join("-", u.getChildMaterialNo(), u.getNum())).collect(Collectors.toSet());
|
||||
|
||||
List<BomNewEbomParentVO> parentChildren = allBomDetail.stream().filter(u -> u.getParentRowId().equals(parent.getBomRowId())).collect(Collectors.toList());
|
||||
//物料编码 +数量
|
||||
Set<String> newSet = parentChildren.stream().filter(u -> Objects.nonNull(u.getProjectType()) && VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getProductTypeKey().equals(u.getProjectType())).map(u -> StrUtil.join("-", u.getMaterialNo(), u.getNum())).collect(Collectors.toSet());
|
||||
//bom 发生了改变-影响了虚拟包
|
||||
if (CollUtil.isNotEmpty(Sets.difference(oldMaterialNoAndNumSet, newSet)) || CollUtil.isNotEmpty(Sets.difference(newSet, oldMaterialNoAndNumSet))) {
|
||||
|
||||
List<String> vmaterialNoList = list.stream().map(u -> u.getVirtualPackageMaterialNo()).distinct().collect(Collectors.toList());
|
||||
//记录变更明细行
|
||||
buildChangeDetailD0(vmaterialNoList, parent, parentChildren);
|
||||
//变更
|
||||
buildUpgradeChange(list, parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buildChangeDetailD0(List<String> vmaterialNoList, BomNewEbomParentVO parent, List<BomNewEbomParentVO> parentChildren) {
|
||||
for (BomNewEbomParentVO vo : parentChildren) {
|
||||
for (String vNo : vmaterialNoList) {
|
||||
BomNewEbomUpdateDetailEntity changeDetailEnt = new BomNewEbomUpdateDetailEntity();
|
||||
changeDetailEnt.setRowId(IdWorker.getId());
|
||||
changeDetailEnt.setVirtualPackageMaterialNo(vNo);
|
||||
changeDetailEnt.setParentMaterialNo(parent.getMaterialNo());
|
||||
changeDetailEnt.setCurrentVersion(parent.getCurrentVersion());
|
||||
changeDetailEnt.setChildMaterialNo(vo.getMaterialNo());
|
||||
changeDetailEnt.setNum(vo.getNum());
|
||||
changeDetailEnt.setProjectType(vo.getProjectType());
|
||||
changeDetailEnt.setUpdatedTime(LocalDateTime.now());
|
||||
changeDetailEnt.setEbomSourceRowId(vo.getRowId());
|
||||
this.upgradeChangeDetailResult.add(changeDetailEnt);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void buildUpgradeChange(List<BomNewEbomVirtualPackageCompositionEntity> changeList, BomNewEbomParentVO parent) {
|
||||
List<String> vmaterialNoList = changeList.stream().map(u -> u.getVirtualPackageMaterialNo()).distinct().collect(Collectors.toList());
|
||||
for (String vmaterialNo : vmaterialNoList) {
|
||||
String key = StrUtil.join("-", vmaterialNo, parent.getMaterialNo());
|
||||
if (hasBuildVNo.contains(key)) {
|
||||
continue;
|
||||
}
|
||||
BomNewEbomUpgradeChangeEntity changeEntity = new BomNewEbomUpgradeChangeEntity();
|
||||
changeEntity.setRowId(IdWorker.getId());
|
||||
changeEntity.setMaterialNo(vmaterialNo);
|
||||
changeEntity.setVersionOld(parent.getCurrentVersion());
|
||||
changeEntity.setVersionNew(VersionUtil.getNextVersionForSmallVersion(parent.getCurrentVersion()));
|
||||
changeEntity.setDeviseName(SessionUtil.getRealName());
|
||||
changeEntity.setDeptName(SessionUtil.getDepartName());
|
||||
changeEntity.setRelMaterialNo(parent.getMaterialNo());
|
||||
changeEntity.setRelMaterialDesc(parent.getMaterialDesc());
|
||||
changeEntity.setStatus(0);
|
||||
upgradeChangeResult.add(changeEntity);
|
||||
|
||||
hasBuildVNo.add(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提层汇总数量
|
||||
*
|
||||
* @param lastVirtualPackage 虚拟包
|
||||
* @param vo 提层项
|
||||
*/
|
||||
private void liftingLayerSummary(BomNewEbomParentVO lastVirtualPackage, BomNewEbomParentVO vo) {
|
||||
BigDecimal sum = vo.getNum();
|
||||
String parentLevelNo = BomLevelUtil.getParentLevelNo(vo.getLevelNo());
|
||||
List<BigDecimal> parentFullPathNum = new ArrayList<>();
|
||||
while (parentLevelNo.length() >= lastVirtualPackage.getLevelNo().length()) {
|
||||
String pNo = parentLevelNo;
|
||||
List<BomNewEbomParentVO> parentList = allBomDetail.stream().filter(u -> u.getLevelNo().equals(pNo)).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(parentList)) {
|
||||
sum = NumberUtil.mul(sum, parentList.get(0).getNum());
|
||||
parentFullPathNum.add(parentList.get(0).getNum());
|
||||
}
|
||||
// else {
|
||||
// parentFullPathNum.add(parentList.get(0).getNum());
|
||||
// }
|
||||
parentLevelNo = BomLevelUtil.getParentLevelNo(parentLevelNo);
|
||||
|
||||
}
|
||||
vo.setNum(sum);
|
||||
//构建虚拟包组成
|
||||
buildVirtualPackageComposition(lastVirtualPackage, vo, parentFullPathNum);
|
||||
|
||||
}
|
||||
|
||||
private void buildVirtualPackageComposition(BomNewEbomParentVO lastVirtualPackage, BomNewEbomParentVO vo, List<BigDecimal> parentFullPathNum) {
|
||||
|
||||
BomNewEbomVirtualPackageCompositionEntity packageCompositionEntity = new BomNewEbomVirtualPackageCompositionEntity();
|
||||
packageCompositionEntity.setRowId(IdWorker.getId());
|
||||
packageCompositionEntity.setVirtualPackageMaterialNo(lastVirtualPackage.getMaterialNo());
|
||||
List<BomNewEbomParentVO> voParent = allBomDetail.stream().filter(u -> u.getBomRowId().equals(vo.getParentRowId())).collect(Collectors.toList());
|
||||
VUtils.isTure(CollUtil.isEmpty(voParent)).throwMessage(vo.getMaterialNo() + " 未找到父级");
|
||||
packageCompositionEntity.setParentMaterialNo(voParent.get(0).getMaterialNo());
|
||||
packageCompositionEntity.setChildMaterialNo(vo.getMaterialNo());
|
||||
packageCompositionEntity.setParentFullPathNum(StrUtil.join(",", parentFullPathNum));
|
||||
packageCompositionEntity.setProjectType(vo.getProjectType());
|
||||
packageCompositionEntity.setUnitWeight(vo.getUnitWeight());
|
||||
packageCompositionEntity.setTotalWeight(vo.getTotalWeight());
|
||||
packageCompositionEntity.setUpdatedTime(LocalDateTime.now());
|
||||
this.virtualPackageCompositionResult.add(packageCompositionEntity);
|
||||
}
|
||||
|
||||
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 "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
private BomNewEbomParentVO getLastVirtualPackage(BomNewEbomParentVO vo, VirtualPackageTypeEnum virtualPackageTypeEnum) {
|
||||
List<BomNewEbomParentVO> zhiFaList = allBomDetail.stream().filter(u -> vo.getLevelNumber().compareTo(u.getLevelNumber()) > 0 && u.getMaterialName().contains(virtualPackageTypeEnum.getConMaterialName())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(zhiFaList)) {
|
||||
return Collections.max(zhiFaList, Comparator.comparing(BomNewEbomParentVO::getLevelNumber));
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private BomNewEbomParentVO getVirtualPackageByName(VirtualPackageTypeEnum virtualPackageTypeEnum) {
|
||||
List<BomNewEbomParentVO> list = allBomDetail.stream().filter(u -> u.getMaterialName().contains(virtualPackageTypeEnum.getConMaterialName())).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;
|
||||
|
||||
String preAssemblyPackageLevelNo = StrUtil.isNotBlank(parentDrawingNoRe) ? StrUtil.join("-", parentDrawingNoRe, "1") : "1";
|
||||
for (BomNewEbomParentVO firstLevelBom : firstLevelBoms) {
|
||||
|
||||
if (firstLevelBom.getMaterialName().contains(VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getConMaterialName()) || firstLevelBom.getMaterialName().contains(VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE.getConMaterialName())) {
|
||||
firstLevelBom.setLevelNumber(levelToNum(preAssemblyPackageLevelNo));
|
||||
firstLevelBom.setLevelNo(preAssemblyPackageLevelNo);
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,9 @@ package com.nflg.product.bomnew.service.domain.EBom;
|
|||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.nflg.product.bomnew.constant.EBomExceptionStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.ProjectTypeInputTypeEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewEbomParentMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.MaterialHistoryProjectTypeVO;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -17,7 +12,6 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 初始化项目类别
|
||||
|
|
|
|||
Loading…
Reference in New Issue