fix(pbom): 修复导入到sap时,只导入了第一层的问题

This commit is contained in:
曹鹏飞 2024-05-30 08:42:33 +08:00
parent 23f3147edc
commit 3125800c3f
2 changed files with 64 additions and 58 deletions

View File

@ -331,7 +331,7 @@ public class PBomApi extends BaseApi {
/**
* 导入到SAP
* @param rootBomRowIds 顶级bom的rowId
* @param query 顶级bom的rowId
* @return
*/
@PostMapping("importToSAP")

View File

@ -5,15 +5,15 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.nflg.product.bomnew.constant.BomConstant;
import com.nflg.product.bomnew.constant.PBomStatusEnum;
import com.nflg.product.bomnew.constant.SapStatusEnum;
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.T1DTO;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
import com.nflg.product.bomnew.util.VUtils;
import nflg.product.common.constant.STATE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -52,7 +52,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
BomNewPbomParentEntity root = bomNewPbomParentService.getById(rootBomRowId);
is21 = root.getMaterialNo().startsWith("21");
List<BomNewPbomChildEntity> rcs = bomNewPbomChildService.lambdaQuery()
.eq(BomNewPbomChildEntity::getParentRowId, rootBomRowId)
.eq(BomNewPbomChildEntity::getParentRowId, root.getRowId())
.list();
if (root.getMaterialNo().startsWith("31")) {
List<BomNewPbomChildEntity> unVirtualParts = rcs.stream()
@ -65,26 +65,35 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
}
children.addAll(convert(rcs, root.getMaterialNo()));
rcs.forEach(it -> {
List<BomNewPbomParentEntity> cps = getParents(it);
cps.forEach(pt -> {
List<BomNewPbomChildEntity> cpsc = getChildren(pt);
children.addAll(convert(cpsc, pt.getMaterialNo()));
cpsc.forEach(cptt -> {
if (Objects.equals(cptt.getVirtualPartType(), VirtualPackageTypeEnum.DELIVERY_PACKAGE.getValue())) {
//选出发货包
cmap.put(cptt.getRowId(), new ArrayList<>());
LOGGER.debug("{} 发货包 rowId{},编号:{},描述:{}", TAG, cptt.getRowId(), cptt.getMaterialNo(), cptt.getMaterialDesc());
BomNewPbomParentEntity cp = getParent(it);
if (Objects.nonNull(cp)) {
Long ddpRowId = null;
//选出直发包
List<BomNewPbomChildEntity> cpsc = getChildren(cp);
if (CollUtil.isNotEmpty(cpsc)) {
for (BomNewPbomChildEntity cptt : cpsc) {
if (Objects.equals(cptt.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
BomNewPbomParentEntity cpttp = getParent(cptt);
VUtils.isTure(Objects.isNull(cpttp)).throwMessage("顶层直发包parent丢失");
ddpRowId = cpttp.getRowId();
cmap.put(ddpRowId, new ArrayList<>());
LOGGER.debug("{} 直发包 rowId{},编号:{},描述:{}", TAG, ddpRowId, cpttp.getMaterialNo(), cpttp.getMaterialDesc());
break;
}
}
List<BomNewPbomParentEntity> cpsfp = getParents(cptt);
cpsfp.forEach(ewfce -> {
buildChildrenForSap(Objects.equals(cptt.getVirtualPartType(), VirtualPackageTypeEnum.DELIVERY_PACKAGE.getValue()) ? cptt.getRowId() : null, ewfce, it);
});
});
});
}
buildChildrenForSap(ddpRowId, cp, it);
}
});
ImportSapParamDTO sapDto = new ImportSapParamDTO();
sapDto.setZID(RandomUtil.randomNumbers(5));
sapDto.setI_WERKS("1");
if (StrUtil.equals(root.getFacCode(), EBomConstant.MAIN_FACTORY_CODE_1010)) {
sapDto.setI_WERKS("1");
} else if (StrUtil.equals(root.getFacCode(), EBomConstant.XIAN_TAO_FACTORY_CODE_1020)) {
sapDto.setI_WERKS("2");
} else {
throw new NflgBusinessException(STATE.BusinessError, "无效的工厂编号:" + root.getFacCode());
}
sapDto.setI_STLAN("1");
sapDto.setI_EMPNO(root.getCreatedBy());
sapDto.setT1(children);
@ -140,51 +149,47 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
/**
* 构建child数据
* @param cRowId 当前的发货包rowId
* @param p parent
* @param cRowId 顶层的的直发包rowId
* @param p 父级节点的parent
* @param c 父级节点的child
* @return
*/
private void buildChildrenForSap(Long cRowId, BomNewPbomParentEntity p, BomNewPbomChildEntity c) {
List<BomNewPbomChildEntity> cc = getChildren(p);
if (is21 && !isForSale && Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
LOGGER.debug("{} 丢弃21编码非销售订单的直发包 编号:{}", TAG, c.getMaterialNo());
cc.forEach(cit -> {
LOGGER.debug("{} 丢弃21编码非销售订单的直发包下的物料 编号:{}", TAG, cit.getMaterialNo());
});
return;
}
for (BomNewPbomChildEntity it : cc) {
if (is21 && !isForSale && !Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
return;
}
if (Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue())) {
if (Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
if (Objects.isNull(cRowId)) {
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, c.getMaterialNo()));
if (Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
if (Objects.nonNull(cRowId)) {
T1DTO cct = cmap.get(cRowId).stream()
.filter(ct -> (StrUtil.equals(ct.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY, true) && StrUtil.equals(ct.getPOTX1(), it.getMaterialDesc()))
|| (!StrUtil.equals(ct.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY, true) && StrUtil.equals(ct.getIDNRK(), it.getMaterialNo())))
.findFirst()
.orElse(null);
if (Objects.isNull(cct)) {
LOGGER.debug("{} 物料提层到顶级发货包 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
cct = convert(it, p.getMaterialNo());
cmap.get(cRowId).add(cct);
children.add(cct);
} else {
T1DTO cct = cmap.get(cRowId).stream()
.filter(ct -> (StrUtil.equals(ct.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY, true) && StrUtil.equals(ct.getPOTX1(), it.getMaterialDesc()))
|| (!StrUtil.equals(ct.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY, true) && StrUtil.equals(ct.getIDNRK(), it.getMaterialNo())))
.findFirst()
.orElse(null);
if (Objects.isNull(cct)) {
LOGGER.debug("{} 物料提层到顶级发货包 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
cct = convert(it, c.getMaterialNo());
cmap.get(cRowId).add(cct);
children.add(cct);
} else {
//合并计算数量
cct.setMENGE(new BigDecimal(cct.getMENGE()).add(it.getNum()).toString());
LOGGER.debug("{} 物料提层到顶级发货包且合并 编号:{},父级编号:{},数量:{},合并后总数:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), cct.getMENGE(), it.getMaterialDesc());
}
//合并计算数量
cct.setMENGE(new BigDecimal(cct.getMENGE()).add(it.getNum()).toString());
LOGGER.debug("{} 物料提层到顶级发货包且合并 编号:{},父级编号:{},数量:{},合并后总数:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), cct.getMENGE(), it.getMaterialDesc());
}
} else {
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, c.getMaterialNo()));
}
} else if (!Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
} else {
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, c.getMaterialNo()));
}
List<BomNewPbomParentEntity> cp = getParents(it);
cp.forEach(cpt -> {
buildChildrenForSap(cRowId, cpt, it);
});
BomNewPbomParentEntity cp = getParent(it);
if (Objects.nonNull(cp)) {
buildChildrenForSap(cRowId, cp, it);
}
}
}
@ -194,11 +199,12 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
.list();
}
private List<BomNewPbomParentEntity> getParents(BomNewPbomChildEntity child) {
private BomNewPbomParentEntity getParent(BomNewPbomChildEntity child) {
return bomNewPbomParentService.lambdaQuery()
.eq(BomNewPbomParentEntity::getMaterialNo, child.getMaterialNo())
.eq(BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
.list();
.eq(BomNewPbomParentEntity::getStatus, PBomStatusEnum.FACTORY_CONFIRM.getValue())
.eq(BomNewPbomParentEntity::getFacCode, child.getFacCode())
.one();
}
// private List<BomNewPbomChildEntity> getChildren(List<BomNewPbomParentEntity> parents) {