1、EBOM转PBOM逻辑调整
This commit is contained in:
parent
faf0071638
commit
bc423b6cd6
|
|
@ -18,6 +18,7 @@ import com.nflg.product.bomnew.pojo.vo.*;
|
|||
import com.nflg.product.bomnew.service.*;
|
||||
import com.nflg.product.bomnew.util.EecExcelUtil;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import com.nflg.product.bomnew.util.VersionUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import nflg.product.common.constant.STATE;
|
||||
|
|
@ -152,13 +153,9 @@ public class EbomApi extends BaseApi {
|
|||
public ResultVO<List<OperationErrorMsgVO>> convertToPBom(@RequestBody EBomToPBomParamDTO paramDto) throws ExecutionException, InterruptedException {
|
||||
VUtils.isTure(CollUtil.isEmpty(paramDto.getBomRowIds())).throwMessage("请选择要转换的物料");
|
||||
VUtils.isTure(CollUtil.isEmpty(paramDto.getFacCodes())).throwMessage("请选择要转换的工厂");
|
||||
VUtils.isTure(Objects.isNull(paramDto.getConvertMode())).throwMessage("转换模式不能为空");
|
||||
bomNewEbomParentService.convertToPBom(paramDto);
|
||||
|
||||
//更新PBomUse 数据
|
||||
// CompletableFuture.runAsync(()->{
|
||||
// bomNewPbomParentService.getBaseMapper().updatePBomMaterialUse();
|
||||
// });
|
||||
|
||||
//导入到sap
|
||||
List<OperationErrorMsgVO> errorMsgVOS = new ArrayList<>();
|
||||
paramDto.getBomRowIds().forEach(rootRowId -> {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.nflg.product.bomnew.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Ebom转Pbom 转换模式
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ConvertToPBomModelEnum implements ValueEnum<Integer>{
|
||||
// 转换模式:0-常规 1-覆盖
|
||||
NORMAL(0, "常规"),
|
||||
OVERRIDE(1, "覆盖");
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -27,4 +27,6 @@ public interface BomNewEbomChildMapper extends BaseMapper<BomNewEbomChildEntity>
|
|||
List<ChildMaxExceptionStateVO> getChildMaxExceptionState(@Param("bomRowIds") List<Long> bomRowIds);
|
||||
|
||||
Integer shouldSetRootIs(String materialNo);
|
||||
|
||||
void delBomChild(@Param("bomRowIds") List<Long> bomRowIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.nflg.product.bomnew.pojo.dto;
|
|||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -14,6 +15,10 @@ public class EBomToPBomParamDTO {
|
|||
@ApiModelProperty("物料bom行ID")
|
||||
private List<Long> bomRowIds;
|
||||
|
||||
@ApiModelProperty("转换模式:0-常规 1-覆盖")
|
||||
@NotBlank( message = "转换模式:0-常规 1-覆盖 不能为空")
|
||||
private Integer convertMode;
|
||||
|
||||
@ApiModelProperty("工厂编码列表")
|
||||
private List<String> facCodes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -341,6 +341,12 @@ public class BomNewEbomParentVO extends BaseMaterialVO implements Serializable {
|
|||
@ApiModelProperty(value = "导入SAP状态")
|
||||
private Integer sapState;
|
||||
|
||||
@ApiModelProperty("无需转PBom-和正式版BOM一致")
|
||||
private Integer noConvertToPBomIs=0;
|
||||
|
||||
@ApiModelProperty("是否发生了变更 0:不变 1:删除-和正式版一致 2-版本发版变化")
|
||||
private Integer hasChangeState=0;
|
||||
|
||||
private List<BomNewEbomParentVO> childNodes = Collections.emptyList();
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -842,11 +842,6 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
//31 码 须有虚拟包
|
||||
List<BomNewEbomParentEntity> parents = this.getBaseMapper().selectBatchIds(paramDto.getBomRowIds());
|
||||
|
||||
// VUtils.isTure(paramDto.getFacCodes().contains("1020") && parents.stream().anyMatch(u -> u.getMaterialNo().startsWith("31")))
|
||||
// .throwMessage("31码不能生成仙桃(1020)的pbom");
|
||||
|
||||
// VUtils.isTure(parents.stream().anyMatch(u -> u.getMaterialNo().startsWith("31") && u.getVirtrualPackageEnum() <= 0))
|
||||
// .throwMessage("31码须有虚拟包");
|
||||
parents.forEach(p -> {
|
||||
if (p.getMaterialNo().startsWith("31")) {
|
||||
List<String> errors = new ArrayList<>();
|
||||
|
|
@ -879,7 +874,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
parent.setChildBomRowId(parent.getRowId());
|
||||
parent.setParentRowId(0L);
|
||||
bomTree.add(parent);
|
||||
EBomToPbomBase eBomToPBom =parent.getMaterialNo().startsWith("31")? new EBomToPBomFor31(parent, bomTree, paramDto.getFacCodes(), 0L):new EBomToPBom(parent, bomTree, paramDto.getFacCodes(), 0L);
|
||||
EBomToPbomBase eBomToPBom =parent.getMaterialNo().startsWith("31")? new EBomToPBomFor31(parent, bomTree, paramDto.getFacCodes(), 0L,EnumUtils.getValueEnum(ConvertToPBomModelEnum.class,paramDto.getConvertMode())):new EBomToPBom(parent, bomTree, paramDto.getFacCodes(), 0L,EnumUtils.getValueEnum(ConvertToPBomModelEnum.class,paramDto.getConvertMode()));
|
||||
eBomToPBom.convert();
|
||||
|
||||
if (CollUtil.isNotEmpty(eBomToPBom.getPBomParentResult())) {
|
||||
|
|
@ -889,43 +884,36 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
if (CollUtil.isNotEmpty(eBomToPBom.getPBomChildResult())) {
|
||||
pBomChildService.saveOrUpdateBatch(eBomToPBom.getPBomChildResult());
|
||||
}
|
||||
|
||||
//删除EBOM中和正式表BOM一致的数据
|
||||
List<BomNewEbomParentVO> delEBomParents = bomTree.stream().filter(u -> u.getHasChangeState().equals(1)).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(delEBomParents)){
|
||||
List<Long> delParentBom = delEBomParents.stream().filter(u -> u.getBomRowId() > 0).map(BomNewEbomParentVO::getBomRowId).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(delParentBom)){
|
||||
this.getBaseMapper().delBatch(delParentBom);
|
||||
ebomChildService.getBaseMapper().delBomChild(delParentBom);
|
||||
}
|
||||
}
|
||||
//需修改正式版版本的BOM
|
||||
List<BomNewEbomParentVO> upVersionEBomParents = bomTree.stream().filter(u -> u.getHasChangeState().equals(2)).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(upVersionEBomParents)){
|
||||
List<BomNewEbomParentEntity> upVersionList=new ArrayList<>();
|
||||
for (BomNewEbomParentVO upVersionEBomParent : upVersionEBomParents) {
|
||||
BomNewEbomParentEntity upVersion = new BomNewEbomParentEntity();
|
||||
upVersion.setRowId(upVersionEBomParent.getBomRowId());
|
||||
upVersion.setCurrentVersion(upVersionEBomParent.getCurrentVersion());
|
||||
upVersionList.add(upVersion);
|
||||
}
|
||||
if(CollUtil.isNotEmpty(upVersionList)){
|
||||
this.saveOrUpdateBatch(upVersionList);
|
||||
}
|
||||
}
|
||||
|
||||
//标记PBom未发布跟节点
|
||||
Set<String> materialNos = bomTree.stream().map(u -> u.getMaterialNo()).collect(Collectors.toSet());
|
||||
if(CollUtil.isNotEmpty(materialNos)){
|
||||
pBomParentService.getBaseMapper().updateWaitPublicRootState(materialNos);
|
||||
}
|
||||
//标记跟节点
|
||||
// upRootMark(parent);
|
||||
// if (CollUtil.isNotEmpty(eBomToPBom.getVirtualPackageCompositionResult())) {
|
||||
// //先删除
|
||||
// Set<String> delSet = eBomToPBom.getVirtualPackageCompositionResult().stream().map(u -> StrUtil.join("-", u.getVirtualPackageMaterialNo(), u.getParentMaterialNo())).collect(Collectors.toSet());
|
||||
// for (String s : delSet) {
|
||||
// String[] split = StrUtil.split(s, "-");
|
||||
// virtualPackageCompositionService.getBaseMapper().delByVnoAndParentNo(split[0], split[1]);
|
||||
// }
|
||||
// virtualPackageCompositionService.saveOrUpdateBatch(eBomToPBom.getVirtualPackageCompositionResult());
|
||||
// }
|
||||
// else {
|
||||
// //记录变更影响
|
||||
// if (CollUtil.isNotEmpty(eBomToPBom.getUpgradeChangeResult())) {
|
||||
//
|
||||
// List<String> vNos = eBomToPBom.getUpgradeChangeResult().stream().map(u -> StrUtil.join(u.getMaterialNo(), u.getRelMaterialNo())).collect(Collectors.toList());
|
||||
// if (CollUtil.isNotEmpty(vNos)) {
|
||||
// upgradeChangeService.getBaseMapper().delByVNo(vNos);
|
||||
// }
|
||||
// upgradeChangeService.saveOrUpdateBatch(eBomToPBom.getUpgradeChangeResult());
|
||||
// }
|
||||
// if (CollUtil.isNotEmpty(eBomToPBom.getUpgradeChangeDetailResult())) {
|
||||
//
|
||||
// //先删除
|
||||
// Set<String> delSet = eBomToPBom.getUpgradeChangeDetailResult().stream().map(u -> StrUtil.join("-", u.getVirtualPackageMaterialNo(), u.getParentMaterialNo())).collect(Collectors.toSet());
|
||||
// for (String s : delSet) {
|
||||
// String[] split = StrUtil.split(s, "-");
|
||||
// updateDetailService.getBaseMapper().delByVnoAndParentNo(split[0], split[1]);
|
||||
// }
|
||||
// updateDetailService.saveOrUpdateBatch(eBomToPBom.getUpgradeChangeDetailResult());
|
||||
// }
|
||||
// }
|
||||
List<Long> bomRowIds = bomTree.stream().filter(u -> u.getBomRowId() > 0).map(u -> u.getBomRowId()).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(bomRowIds)) {
|
||||
this.getBaseMapper().updateStateBatchByRowIds(EBomStatusEnum.PUBLISHED.getValue(), bomRowIds);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ 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.StrUtil;
|
||||
import com.alibaba.excel.enums.BooleanEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.bomnew.constant.ConvertToPBomModelEnum;
|
||||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
|
||||
|
|
@ -14,6 +16,7 @@ import lombok.NoArgsConstructor;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -25,11 +28,13 @@ public class EBomToPBom extends EBomToPbomBase {
|
|||
|
||||
|
||||
|
||||
public EBomToPBom(BomNewEbomParentVO inParent, List<BomNewEbomParentVO> inAllBomDetail, List<String> inFacCodes, Long parentRowId) {
|
||||
public EBomToPBom(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, "");
|
||||
initEBomVersion();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -54,9 +59,14 @@ public class EBomToPBom extends EBomToPbomBase {
|
|||
continue;
|
||||
}
|
||||
hasConvert.add(hasConvertKey);
|
||||
|
||||
//无需转换bom
|
||||
if(BooleanEnum.TRUE.equals(vo.getNoConvertToPBomIs()) ){
|
||||
continue;
|
||||
}
|
||||
//构建变更明细
|
||||
buildUpgradeChangeDetail(vo, VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE);
|
||||
buildUpgradeChangeDetail(vo, VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE);
|
||||
// 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());
|
||||
|
|
@ -65,7 +75,10 @@ public class EBomToPBom extends EBomToPbomBase {
|
|||
continue;
|
||||
}
|
||||
|
||||
BomNewPbomParentEntity parentEnt = buildPBomParent(vo, facCode);
|
||||
BomNewPbomParentEntity parentEnt = buildPBomParent(vo, facCode,parentList);
|
||||
if(Objects.isNull(parentEnt)){
|
||||
continue;
|
||||
}
|
||||
//子级
|
||||
if (CollUtil.isNotEmpty(child)) {
|
||||
//合并子级
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ 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.alibaba.excel.enums.BooleanEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.bomnew.constant.ConvertToPBomModelEnum;
|
||||
import com.nflg.product.bomnew.constant.EBomConstant;
|
||||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
|
||||
|
|
@ -14,10 +16,7 @@ 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.*;
|
||||
import java.util.stream.Collectors;
|
||||
import com.nflg.product.bomnew.util.ListCommonUtil;
|
||||
|
||||
|
|
@ -32,11 +31,14 @@ 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) {
|
||||
public EBomToPBomFor31(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, "");
|
||||
//初始化Ebom版本
|
||||
initEBomVersion();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -87,13 +89,19 @@ public class EBomToPBomFor31 extends EBomToPbomBase {
|
|||
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);
|
||||
List<BomNewEbomParentVO> parentList = ListCommonUtil.toDistinct(facBomDataMp.get(facCode).stream().filter(u -> u.getBomRowId() > 0)
|
||||
.sorted(Comparator.comparing(BomNewEbomParentVO::getLevelNumber))
|
||||
.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);
|
||||
//无需转换bom
|
||||
if(BooleanEnum.TRUE.equals(vo.getNoConvertToPBomIs()) ){
|
||||
continue;
|
||||
}
|
||||
//构建变更明细
|
||||
// buildUpgradeChangeDetail(vo, VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE);
|
||||
// buildUpgradeChangeDetail(vo, VirtualPackageTypeEnum.PRE_ASSEMBLY_PACKAGE);
|
||||
|
|
@ -104,8 +112,10 @@ public class EBomToPBomFor31 extends EBomToPbomBase {
|
|||
if( compareContentIsSame(vo, mergeChild, facCode)){
|
||||
continue;
|
||||
}
|
||||
|
||||
BomNewPbomParentEntity parentEnt = buildPBomParent(vo, facCode);
|
||||
BomNewPbomParentEntity parentEnt = buildPBomParent(vo, facCode,parentList);
|
||||
if(Objects.isNull(parentEnt)){
|
||||
continue;
|
||||
}
|
||||
//子级
|
||||
if (CollUtil.isNotEmpty(child)) {
|
||||
//合并子级
|
||||
|
|
@ -118,8 +128,6 @@ public class EBomToPBomFor31 extends EBomToPbomBase {
|
|||
childEnt.setIdentityNo(StrUtil.join("-", parentEnt.getMaterialNo(), eb.getMaterialNo()));
|
||||
this.pBomChildResult.add(childEnt);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ 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.alibaba.excel.enums.BooleanEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
|
|
@ -13,14 +14,14 @@ 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.service.*;
|
||||
import com.nflg.product.bomnew.util.BomLevelUtil;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import com.nflg.product.bomnew.util.VersionUtil;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
|
@ -30,6 +31,9 @@ public abstract class EBomToPbomBase {
|
|||
|
||||
protected BomNewEbomParentVO parent;
|
||||
|
||||
@ApiModelProperty("转换模式:0-常规 1-覆盖")
|
||||
protected ConvertToPBomModelEnum convertMode;
|
||||
|
||||
//工厂编码列表
|
||||
protected List<String> facCodes;
|
||||
|
||||
|
|
@ -56,7 +60,7 @@ public abstract class EBomToPbomBase {
|
|||
|
||||
protected Set<String> hasBuildVNo = Sets.newHashSet();
|
||||
|
||||
public abstract void convert();
|
||||
public abstract void convert();
|
||||
|
||||
/**
|
||||
* BOM 明细对比,如只有T项变化则,不升级直接修改
|
||||
|
|
@ -71,24 +75,24 @@ public abstract class EBomToPbomBase {
|
|||
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;
|
||||
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;
|
||||
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)){
|
||||
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)) {
|
||||
if (CollUtil.isNotEmpty(newBomT)) {
|
||||
for (BomNewEbomParentVO netT : newBomT) {
|
||||
BomNewPbomChildEntity childEnt = new BomNewPbomChildEntity();
|
||||
BeanUtil.copyProperties(netT, childEnt);
|
||||
|
|
@ -111,12 +115,12 @@ public abstract class EBomToPbomBase {
|
|||
|
||||
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));
|
||||
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().filter(u->Objects.nonNull(u.getNum())).map(aa -> aa.getNum()).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
ent.setNum(voList.stream().filter(u -> Objects.nonNull(u.getNum())).map(aa -> aa.getNum()).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
result.add(ent);
|
||||
}
|
||||
return result;
|
||||
|
|
@ -142,44 +146,68 @@ public abstract class EBomToPbomBase {
|
|||
* @param parentVo
|
||||
* @return Pair<Integer, BomNewPbomParentEntity> key, 0-旧 1-新 value:pBomParent
|
||||
*/
|
||||
protected BomNewPbomParentEntity buildPBomParent(BomNewEbomParentVO parentVo, String facCode) {
|
||||
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();
|
||||
|
||||
// this.hasConvertEBomRowIds.add(parentVo.getRowId());
|
||||
if (Objects.nonNull(oldParent) && oldParent.getStatus()< EBomStatusEnum.PUBLISHED.getValue()) {
|
||||
SpringUtil.getBean(BomNewPbomChildService.class).getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldParent.getRowId()));
|
||||
oldParent.setCurrentVersion(parentVo.getCurrentVersion());
|
||||
oldParent.setSourceRowId(parentVo.getRowId());
|
||||
this.pBomParentResult.add(oldParent);
|
||||
return oldParent;
|
||||
} else {
|
||||
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.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);
|
||||
|
||||
if(Objects.isNull(oldParent)){
|
||||
buildParentEntity(parentVo,facCode,oldParent,parentVo.getCurrentVersion());
|
||||
}
|
||||
//pbom 处于工作表
|
||||
if (Objects.nonNull(oldParent) && oldParent.getStatus() < EBomStatusEnum.PUBLISHED.getValue()) {
|
||||
if (oldParent.getCreatedBy() == parentVo.getCreatedBy()) {
|
||||
if (ConvertToPBomModelEnum.OVERRIDE.equals(convertMode.getValue())) {
|
||||
SpringUtil.getBean(BomNewPbomChildService.class).getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldParent.getRowId()));
|
||||
oldParent.setCurrentVersion(parentVo.getCurrentVersion());
|
||||
oldParent.setSourceRowId(parentVo.getRowId());
|
||||
this.pBomParentResult.add(oldParent);
|
||||
return oldParent;
|
||||
}
|
||||
|
||||
} else {
|
||||
// 降parentVo 及其子节点标记为不转换
|
||||
markNoConvert(parentVo, parentList);
|
||||
}
|
||||
this.pBomParentResult.add(pBomParent);
|
||||
return pBomParent;
|
||||
return null;
|
||||
|
||||
} else { //pbom-处于正式表
|
||||
String bomVersion= VersionUtil.compare(parentVo.getCurrentVersion(),oldParent.getCurrentVersion())>=0?parentVo.getCurrentVersion():VersionUtil.getNextVersion(oldParent.getCurrentVersion());
|
||||
return buildParentEntity(parentVo, facCode, oldParent,bomVersion));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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());
|
||||
//版本=EBom版本
|
||||
pBomParent.setCurrentVersion(bomVersion);
|
||||
pBomParent.setEditStatus(PBomEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
if (Objects.nonNull(oldParent)) {
|
||||
oldParent.setExpireEndTime(LocalDateTime.now());
|
||||
oldParent.setLastVersionIs(0);
|
||||
}
|
||||
this.pBomParentResult.add(pBomParent);
|
||||
return pBomParent;
|
||||
}
|
||||
|
||||
public void markNoConvert(BomNewEbomParentVO parentVo, List<BomNewEbomParentVO> parentList) {
|
||||
List<BomNewEbomParentVO> subVos = parentList.stream().filter(u -> u.getLevelNumber().compareTo(parentVo.getLevelNumber()) >= 0 && u.getLevelNumber().compareTo(NumberUtil.add(parentVo.getLevelNumber(), BigDecimal.valueOf(0.01))) < 0).collect(Collectors.toList());
|
||||
for (BomNewEbomParentVO vo : subVos) {
|
||||
vo.setNoConvertToPBomIs(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 31提层
|
||||
*
|
||||
|
|
@ -350,7 +378,7 @@ public abstract class EBomToPbomBase {
|
|||
|
||||
|
||||
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());
|
||||
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));
|
||||
}
|
||||
|
|
@ -360,7 +388,7 @@ public abstract class EBomToPbomBase {
|
|||
|
||||
|
||||
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());
|
||||
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);
|
||||
}
|
||||
|
|
@ -426,4 +454,80 @@ public abstract class EBomToPbomBase {
|
|||
}
|
||||
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.getChildBomRowId() > 0).collect(Collectors.toList());
|
||||
for (BomNewEbomParentVO parentBom : parentBoms) {
|
||||
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();
|
||||
|
||||
List<BomNewEbomParentVO> newParentChild = allBomDetail.stream().filter(u -> u.getParentRowId().equals(parentBom.getBomRowId())).collect(Collectors.toList());
|
||||
//一样则无需转换
|
||||
if (isSameEBomV2(oldParentChild, newParentChild)) {
|
||||
parentBom.setNoConvertToPBomIs(1);
|
||||
parentBom.setHasChangeState(1);
|
||||
//只变化项目类别-则使用小版本
|
||||
} else if (isSameEBomV2FormMaterialNoAndNum(oldParentChild, newParentChild)) {
|
||||
parentBom.setCurrentVersion(VersionUtil.getNextVersionForSmallVersion(oldEBom.getCurrentVersion()));
|
||||
parentBom.setHasChangeState(2);
|
||||
} else {
|
||||
parentBom.setCurrentVersion(VersionUtil.getNextVersion(oldEBom.getCurrentVersion()));
|
||||
parentBom.setHasChangeState(2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
|
|||
BomNewEbomParentEntity oldEBom = ebomParentService.lambdaQuery().eq(BomNewEbomParentEntity::getMaterialNo, parentEnt.getMaterialNo()).last(" order by current_version desc limit 1").one();
|
||||
//无Ebom时
|
||||
if (Objects.isNull(oldEBom)) {
|
||||
Long parentRowId = buildEBomParent(parentEnt, "V00");
|
||||
Long parentRowId = buildEBomParent(parentEnt, VersionUtil.getNextVersion(""));
|
||||
parentEnt.setEBomRowId(parentRowId);
|
||||
handlerChild(parentEnt, parentChild);
|
||||
return;
|
||||
|
|
@ -246,13 +246,13 @@ public class OriginalBomToEBomV2Convert extends BaseConvert {
|
|||
List<BomNewEbomChildEntity> oldParenChild = SpringUtil.getBean(BomNewEbomChildMapper.class).getChildByMaterialNo(parentEntity.getMaterialNo());
|
||||
//不存在EBom 时
|
||||
if (Objects.isNull(oldEBom)) {
|
||||
buildCommonMaterialChildBom(childVo, materialBaseInfo, "V00");
|
||||
buildCommonMaterialChildBom(childVo, materialBaseInfo, VersionUtil.getNextVersion(""));
|
||||
|
||||
} else {
|
||||
if (!EBomStatusEnum.PUBLISHED.equalsValue(oldEBom.getStatus())) {
|
||||
BomNewEbomChildEntity newChild = buildCommonEbomChildEntity(materialBaseInfo, parentEntity);
|
||||
//结构是否相同 且为同一个人
|
||||
if (!isSameEBom(oldParenChild, ImmutableList.of(newChild)) && oldEBom.getCreatedBy().equals(parentEntity.getCreatedBy())) {
|
||||
if ( oldEBom.getCreatedBy().equals(parentEntity.getCreatedBy())) {
|
||||
ebomParentService.getBaseMapper().deleteById(oldEBom.getRowId());
|
||||
ebomChildService.getBaseMapper().deleteByMap(ImmutableMap.of("parent_row_id", oldEBom.getRowId()));
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import static org.apache.naming.SelectorContext.prefix;
|
|||
*/
|
||||
public class VersionUtil {
|
||||
|
||||
static final String versionPrefix = "A";
|
||||
public static final String versionPrefix = "A";
|
||||
|
||||
static final String mBomVersionPrefix = "B";
|
||||
|
||||
|
|
@ -92,12 +92,34 @@ public class VersionUtil {
|
|||
* @param version2
|
||||
* @return version1>version2 返回>0,version1<version2返回 <0,version1=version2返回0
|
||||
*/
|
||||
public static int compare(String version1, String version2) {
|
||||
version1=StrUtil.replace(version1,versionPrefix,"");
|
||||
version1=StrUtil.replace(version2,versionPrefix,"");
|
||||
Version v1 = Version.parse(version1);
|
||||
Version v2 = Version.parse(version2);
|
||||
return v1.compareTo(v2);
|
||||
|
||||
|
||||
|
||||
public static int compare(String s1, String s2) {
|
||||
// 分割字符串为字母部分和数字部分
|
||||
String[] split1 = s1.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
|
||||
String[] split2 = s2.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
|
||||
|
||||
// 遍历每个部分进行比较
|
||||
for (int i = 0; i < Math.min(split1.length, split2.length); i++) {
|
||||
if (split1[i].matches("\\d+\\.\\d+") && split2[i].matches("\\d+\\.\\d+")) {
|
||||
// 如果都是小数,则转为浮点数比较
|
||||
double num1 = Double.parseDouble(split1[i]);
|
||||
double num2 = Double.parseDouble(split2[i]);
|
||||
if (num1 != num2) {
|
||||
return Double.compare(num1, num2);
|
||||
}
|
||||
} else {
|
||||
// 否则按字符串比较
|
||||
int result = split1[i].compareTo(split2[i]);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 长度不同的情况下,长度较长的字符串视为较大
|
||||
return Integer.compare(split1.length, split2.length);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,4 +94,11 @@
|
|||
ELSE 0
|
||||
END AS result;
|
||||
</select>
|
||||
|
||||
<delete id="delBomChild">
|
||||
delete from t_bom_new_ebom_child where parent_row_id in
|
||||
<foreach collection="bomRowIds" item="item" open="(" close=")" separator=",">
|
||||
#{item}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue