BUG修复
This commit is contained in:
parent
87c322a4c7
commit
8ad11de234
|
|
@ -807,7 +807,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
List<String> noProductionFactoryCodeList = allChild.stream().filter(u -> StrUtil.isBlank(u.getProductionFactoryCode())).map(u -> u.getMaterialNo()).collect(Collectors.toList());
|
||||
VUtils.isTure(CollUtil.isNotEmpty(noProductionFactoryCodeList)).throwMessage(StrUtil.join(",", noProductionFactoryCodeList) + "物料暂未分工厂,请分完工厂再进行发布");
|
||||
ConvertToMBom convertToMBom = new ConvertToMBom(rootParent, allChild);
|
||||
convertToMBom.convertToMBom(false, true);
|
||||
convertToMBom.convertToMBomNew(false, true);
|
||||
if (CollUtil.isNotEmpty(convertToMBom.getMBomParentResult())) {
|
||||
mBomParentService.saveOrUpdateBatch(convertToMBom.getMBomParentResult());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,9 +48,7 @@ public class ConvertToMBom {
|
|||
|
||||
private List<ConvertToMBomDTO> allChild_1010;
|
||||
|
||||
private List<ConvertToMBomDTO> allChildTreeList_1020 = new ArrayList<>();
|
||||
|
||||
private List<ConvertToMBomDTO> allChildTreeList_1010 = new ArrayList();
|
||||
|
||||
|
||||
@Getter
|
||||
List<BomNewMbomParentEntity> mBomParentResult = new ArrayList<>();
|
||||
|
|
@ -87,305 +85,5 @@ public class ConvertToMBom {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化1020
|
||||
*/
|
||||
private void initFacAllChild_1020() {
|
||||
List<ConvertToMBomDTO> firstLevelNodes = allChild_1020.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList());
|
||||
for (ConvertToMBomDTO firstLevelNode : firstLevelNodes) {
|
||||
|
||||
firstLevelNode.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
|
||||
List<ConvertToMBomDTO> firstChildNodes = allChild_1020.stream().filter(u -> u.getParentRowId().equals(firstLevelNode.getBomRowId())).collect(Collectors.toList());
|
||||
|
||||
for (ConvertToMBomDTO itemChild : firstChildNodes) {
|
||||
|
||||
itemChild.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
}
|
||||
}
|
||||
|
||||
allChild_1020.forEach(k -> {
|
||||
setDel(k, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换MBom
|
||||
*/
|
||||
public void convertToMBom(Boolean convert1010, Boolean convert1020) {
|
||||
//handler1010();
|
||||
if (convert1020) {
|
||||
handler1020();
|
||||
buildMBomFor1020();
|
||||
}
|
||||
if (convert1010) {
|
||||
buildMBomFor1010();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建MBom明细
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
private void buildMBomFor1020() {
|
||||
BomNewMbomParentEntity mBomParent = buildMBomParent(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
//当10120 bom 内容为空时,不创建31 的Mbom
|
||||
|
||||
List<ConvertToMBomDTO> bomContent1020 = allChildTreeList_1020.stream().filter(u -> u.getDelIs().equals(0) && u.getVirtualPartType().equals(0)).collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(bomContent1020)) {
|
||||
return;
|
||||
}
|
||||
this.mBomParentResult.add(mBomParent);
|
||||
List<ConvertToMBomDTO> nodes1020 = allChildTreeList_1020.stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList());
|
||||
buildChildFor1020(EBomConstant.XIAN_TAO_FACTORY_CODE_1020, nodes1020, mBomParent.getRowId());
|
||||
}
|
||||
|
||||
private void buildMBomFor1010() {
|
||||
BomNewMbomParentEntity mBomParent = buildMBomParent(EBomConstant.MAIN_FACTORY_CODE_1010);
|
||||
this.mBomParentResult.add(mBomParent);
|
||||
allChild_1010.forEach(u -> {
|
||||
u.setRelParentRowId(u.getParentRowId());
|
||||
});
|
||||
buildChildFor1010(EBomConstant.MAIN_FACTORY_CODE_1010, allChild_1010, mBomParent.getRowId());
|
||||
}
|
||||
|
||||
private BomNewMbomParentEntity buildMBomParent(String facCode) {
|
||||
BomNewMbomParentEntity mBomParent = new BomNewMbomParentEntity();
|
||||
BeanUtil.copyProperties(parent, mBomParent);
|
||||
BomNewMbomParentEntity oldParent = SpringUtil.getBean(BomNewMbomParentService.class).lambdaQuery().eq(BomNewMbomParentEntity::getMaterialNo, parent.getMaterialNo())
|
||||
.eq(BomNewMbomParentEntity::getLastVersionIs, 1).eq(BomNewMbomParentEntity::getFacCode, facCode).one();
|
||||
if (Objects.nonNull(oldParent)) {
|
||||
if (MBomConstantEnum.MBomStatusEnum.PUB_SAP.equalsValue(oldParent.getStatus())) {
|
||||
|
||||
mBomParent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
|
||||
oldParent.setLastVersionIs(0);
|
||||
this.mBomParentResult.add(oldParent);
|
||||
} else {
|
||||
SpringUtil.getBean(BomNewMbomDetailService.class).getBaseMapper().deleteByMap(ImmutableMap.of("bom_row_id", oldParent.getRowId()));
|
||||
SpringUtil.getBean(BomNewMbomParentService.class).getBaseMapper().deleteById(oldParent.getRowId());
|
||||
mBomParent.setCurrentVersion(oldParent.getCurrentVersion());
|
||||
}
|
||||
} else {
|
||||
mBomParent.setCurrentVersion(VersionUtil.getNextVersion(""));
|
||||
}
|
||||
mBomParent.setRowId(IdWorker.getId());
|
||||
mBomParent.setFacCode(facCode);
|
||||
mBomParent.setCreatedBy(SessionUtil.getUserCode());
|
||||
mBomParent.setCreatedTime(LocalDateTime.now());
|
||||
mBomParent.setModifyTime(LocalDateTime.now());
|
||||
mBomParent.setSourceRowId(parent.getRowId());
|
||||
mBomParent.setLastVersionIs(1);
|
||||
mBomParent.setStatus(MBomConstantEnum.MBomStatusEnum.UNPUB_SAP.getValue());
|
||||
return mBomParent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建子级
|
||||
*
|
||||
* @param allChild
|
||||
*/
|
||||
private void buildChildFor1020(String facCode, List<ConvertToMBomDTO> allChild, Long bomRowId) {
|
||||
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
|
||||
for (ConvertToMBomDTO item : childBomTree) {
|
||||
//构建子级
|
||||
if (item.getDelIs().equals(0)) {
|
||||
buildMBomChildDo(facCode, item, 0L, bomRowId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buildChildFor1010(String facCode, List<ConvertToMBomDTO> allChild, Long bomRowId) {
|
||||
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
|
||||
|
||||
for (ConvertToMBomDTO item : childBomTree) {
|
||||
buildMBomChildDo(facCode, item, 0L, bomRowId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buildMBomChildDo(String facCode, ConvertToMBomDTO item, Long parentRowId, Long bomRowId) {
|
||||
if (item.getDelIs().equals(0)) {
|
||||
parentRowId = buildChildDo(facCode, item, bomRowId, parentRowId);
|
||||
}
|
||||
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
|
||||
buildMBomChildDo(facCode, itemChild, parentRowId, bomRowId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理制作下为空的虚拟包
|
||||
* 当制作下子级为空时--删除该发货,制作,和直发
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
private void handEmptyMakePackage(List<ConvertToMBomDTO> childBomTree) {
|
||||
|
||||
// List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChildTreeList_1020, ConvertToMBomDTO::getRelParentRowId, ConvertToMBomDTO::getBomRowId);
|
||||
for (ConvertToMBomDTO item : childBomTree) {
|
||||
if (VirtualPackageTypeEnum.DELIVERY_PACKAGE.equalsValue(item.getVirtualPartType())) {
|
||||
List<ConvertToMBomDTO> makeChild = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.MAKING_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList());
|
||||
List<ConvertToMBomDTO> zhifaChild = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList());
|
||||
|
||||
if ((CollUtil.isEmpty(makeChild) || CollUtil.isEmpty(makeChild.get(0).getChildNodes().stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList()))) &&
|
||||
(CollUtil.isEmpty(zhifaChild) || CollUtil.isEmpty(zhifaChild.get(0).getChildNodes().stream().filter(u -> u.getDelIs().equals(0)).collect(Collectors.toList())))) {
|
||||
item.setRelParentRowId(0L);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Long buildChildDo(String facCode, ConvertToMBomDTO dto, Long bomRowId, Long parentRowId) {
|
||||
BomNewMbomDetailEntity child = new BomNewMbomDetailEntity();
|
||||
BeanUtil.copyProperties(dto, child);
|
||||
child.setRowId(IdWorker.getId());
|
||||
child.setBomRowId(bomRowId);
|
||||
// child.setFacCode(dto.getProductionFactoryCode());
|
||||
child.setFacCode(facCode);
|
||||
child.setParentRowId(parentRowId);
|
||||
child.setCreatedBy(SessionUtil.getUserCode());
|
||||
child.setCreatedTime(LocalDateTime.now());
|
||||
child.setModifyTime(LocalDateTime.now());
|
||||
child.setSourceRowId(dto.getRowId());
|
||||
this.mBomDetailResult.add(child);
|
||||
return child.getRowId();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void handler1010() {
|
||||
|
||||
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1010, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId);
|
||||
for (ConvertToMBomDTO item : childBomTree) {
|
||||
//默认
|
||||
recursionHandlerChild1010(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void recursionHandlerChild1010(ConvertToMBomDTO item) {
|
||||
|
||||
item.setRelParentRowId(item.getParentRowId());
|
||||
setDel(item, EBomConstant.MAIN_FACTORY_CODE_1010);
|
||||
handlerMaterial(item, EBomConstant.MAIN_FACTORY_CODE_1010);
|
||||
|
||||
this.allChildTreeList_1010.add(item);
|
||||
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
|
||||
recursionHandlerChild1010(itemChild);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void handler1020() {
|
||||
List<ConvertToMBomDTO> childBomTree = ConvertToMbomUtil.toTree(parent.getRowId(), allChild_1020, ConvertToMBomDTO::getParentRowId, ConvertToMBomDTO::getBomRowId);
|
||||
//虚拟包名称加仙桃
|
||||
initFac1020Info(childBomTree);
|
||||
|
||||
for (ConvertToMBomDTO item : childBomTree) {
|
||||
|
||||
ConvertToMBomDTO directDeliveryPackage = item.getChildNodes().stream().filter(u -> VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(u.getVirtualPartType())).collect(Collectors.toList()).get(0);
|
||||
VUtils.isTure(Objects.isNull(directDeliveryPackage)).throwMessage("发货包下,没有直发包");
|
||||
|
||||
recursionHandlerChild1020(item, directDeliveryPackage);
|
||||
}
|
||||
//处理制作包无下级的情况
|
||||
handEmptyMakePackage(childBomTree);
|
||||
|
||||
}
|
||||
|
||||
private void recursionHandlerChild1020(ConvertToMBomDTO item, ConvertToMBomDTO directDeliveryPackage) {
|
||||
|
||||
|
||||
item.setRelParentRowId(item.getParentRowId());
|
||||
setDel(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
//非31下的直发包
|
||||
if (!item.getParentRowId().equals(parent.getRowId())) {
|
||||
ConvertToMBomDTO parentNode = getParent(item.getParentRowId(), EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
if (VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.equalsValue(parentNode.getVirtualPartType()) && parentNode.getRowId() != directDeliveryPackage.getRowId()) {
|
||||
handlerDirectDeliveryPackage(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020, directDeliveryPackage);
|
||||
} else {
|
||||
handlerMaterial(item, EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
}
|
||||
}
|
||||
this.allChildTreeList_1020.add(item);
|
||||
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
|
||||
recursionHandlerChild1020(itemChild, directDeliveryPackage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理直发包下的物料
|
||||
* 所有直发包,归到31下的直发包
|
||||
*/
|
||||
private void handlerDirectDeliveryPackage(ConvertToMBomDTO childItem, String facCode, ConvertToMBomDTO directDeliveryPackage) {
|
||||
if (!childItem.getParentRowId().equals(parent.getRowId())) {
|
||||
ConvertToMBomDTO relParent = getParent(childItem.getParentRowId(), facCode);
|
||||
while (Objects.nonNull(relParent) && !VirtualPackageTypeEnum.MAKING_PACKAGE.equalsValue(relParent.getVirtualPartType())) {
|
||||
childItem.setNum(NumberUtil.mul(childItem.getNum(), relParent.getNum()));
|
||||
relParent = getParent(relParent.getParentRowId(), facCode);
|
||||
}
|
||||
childItem.setRelParentRowId(directDeliveryPackage.getBomRowId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理一般材料(提层)
|
||||
*
|
||||
* @param childItem
|
||||
* @param facCode
|
||||
*/
|
||||
private void handlerMaterial(ConvertToMBomDTO childItem, String facCode) {
|
||||
if (!childItem.getParentRowId().equals(parent.getRowId())) {
|
||||
ConvertToMBomDTO relParent = getParent(childItem.getParentRowId(), facCode);
|
||||
while (Objects.nonNull(relParent) && relParent.getDelIs().equals(1)) {
|
||||
childItem.setNum(NumberUtil.mul(childItem.getNum(), relParent.getNum()));
|
||||
relParent = getParent(relParent.getParentRowId(), facCode);
|
||||
}
|
||||
childItem.setRelParentRowId(relParent.getBomRowId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setDel(ConvertToMBomDTO item, String facCode) {
|
||||
if (!item.getProductionFactoryCode().equals(facCode)) {
|
||||
item.setDelIs(1);
|
||||
}
|
||||
}
|
||||
|
||||
//获取父节点
|
||||
private ConvertToMBomDTO getParent(Long parentRowId, String facCode) {
|
||||
if (parentRowId <= 0) return null;
|
||||
List<ConvertToMBomDTO> data = EBomConstant.MAIN_FACTORY_CODE_1010.equals(facCode) ? allChild_1010 : allChild_1020;
|
||||
return data.stream().filter(u -> parentRowId.equals(u.getBomRowId())).collect(Collectors.toList()).get(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 1020-名称加仙桃
|
||||
*/
|
||||
private void initFac1020Info(List<ConvertToMBomDTO> childBomTree) {
|
||||
|
||||
for (ConvertToMBomDTO item : childBomTree) {
|
||||
item.setMaterialName(item.getMaterialName() + EBomConstant.XIAN_TAO_FACTORY_Name_1020);
|
||||
item.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
|
||||
item.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.DEFAULT.getValue());
|
||||
for (ConvertToMBomDTO itemChild : item.getChildNodes()) {
|
||||
itemChild.setMaterialName(itemChild.getMaterialName() + EBomConstant.XIAN_TAO_FACTORY_Name_1020);
|
||||
itemChild.setProductionFactoryCode(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
|
||||
|
||||
itemChild.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.DEFAULT.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue