fix(pbom): 修复导入到sap时,只导入了第一层的问题
This commit is contained in:
parent
23f3147edc
commit
3125800c3f
|
|
@ -331,7 +331,7 @@ public class PBomApi extends BaseApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入到SAP
|
* 导入到SAP
|
||||||
* @param rootBomRowIds 顶级bom的rowId
|
* @param query 顶级bom的rowId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("importToSAP")
|
@PostMapping("importToSAP")
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,15 @@ import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.nflg.product.bomnew.constant.BomConstant;
|
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
import com.nflg.product.bomnew.constant.*;
|
||||||
import com.nflg.product.bomnew.constant.SapStatusEnum;
|
|
||||||
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
|
|
||||||
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
|
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.dto.sap.impart2.T1DTO;
|
||||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
|
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
|
||||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
||||||
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
||||||
BomNewPbomParentEntity root = bomNewPbomParentService.getById(rootBomRowId);
|
BomNewPbomParentEntity root = bomNewPbomParentService.getById(rootBomRowId);
|
||||||
is21 = root.getMaterialNo().startsWith("21");
|
is21 = root.getMaterialNo().startsWith("21");
|
||||||
List<BomNewPbomChildEntity> rcs = bomNewPbomChildService.lambdaQuery()
|
List<BomNewPbomChildEntity> rcs = bomNewPbomChildService.lambdaQuery()
|
||||||
.eq(BomNewPbomChildEntity::getParentRowId, rootBomRowId)
|
.eq(BomNewPbomChildEntity::getParentRowId, root.getRowId())
|
||||||
.list();
|
.list();
|
||||||
if (root.getMaterialNo().startsWith("31")) {
|
if (root.getMaterialNo().startsWith("31")) {
|
||||||
List<BomNewPbomChildEntity> unVirtualParts = rcs.stream()
|
List<BomNewPbomChildEntity> unVirtualParts = rcs.stream()
|
||||||
|
|
@ -65,26 +65,35 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
||||||
}
|
}
|
||||||
children.addAll(convert(rcs, root.getMaterialNo()));
|
children.addAll(convert(rcs, root.getMaterialNo()));
|
||||||
rcs.forEach(it -> {
|
rcs.forEach(it -> {
|
||||||
List<BomNewPbomParentEntity> cps = getParents(it);
|
BomNewPbomParentEntity cp = getParent(it);
|
||||||
cps.forEach(pt -> {
|
if (Objects.nonNull(cp)) {
|
||||||
List<BomNewPbomChildEntity> cpsc = getChildren(pt);
|
Long ddpRowId = null;
|
||||||
children.addAll(convert(cpsc, pt.getMaterialNo()));
|
//选出直发包
|
||||||
cpsc.forEach(cptt -> {
|
List<BomNewPbomChildEntity> cpsc = getChildren(cp);
|
||||||
if (Objects.equals(cptt.getVirtualPartType(), VirtualPackageTypeEnum.DELIVERY_PACKAGE.getValue())) {
|
if (CollUtil.isNotEmpty(cpsc)) {
|
||||||
//选出发货包
|
for (BomNewPbomChildEntity cptt : cpsc) {
|
||||||
cmap.put(cptt.getRowId(), new ArrayList<>());
|
if (Objects.equals(cptt.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
|
||||||
LOGGER.debug("{} 发货包 rowId:{},编号:{},描述:{}", TAG, cptt.getRowId(), cptt.getMaterialNo(), cptt.getMaterialDesc());
|
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(ddpRowId, cp, it);
|
||||||
buildChildrenForSap(Objects.equals(cptt.getVirtualPartType(), VirtualPackageTypeEnum.DELIVERY_PACKAGE.getValue()) ? cptt.getRowId() : null, ewfce, it);
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
ImportSapParamDTO sapDto = new ImportSapParamDTO();
|
ImportSapParamDTO sapDto = new ImportSapParamDTO();
|
||||||
sapDto.setZID(RandomUtil.randomNumbers(5));
|
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_STLAN("1");
|
||||||
sapDto.setI_EMPNO(root.getCreatedBy());
|
sapDto.setI_EMPNO(root.getCreatedBy());
|
||||||
sapDto.setT1(children);
|
sapDto.setT1(children);
|
||||||
|
|
@ -140,51 +149,47 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建child数据
|
* 构建child数据
|
||||||
* @param cRowId 当前的发货包rowId
|
* @param cRowId 顶层的的直发包rowId
|
||||||
* @param p parent
|
* @param p 父级节点的parent
|
||||||
* @param c 父级节点的child
|
* @param c 父级节点的child
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private void buildChildrenForSap(Long cRowId, BomNewPbomParentEntity p, BomNewPbomChildEntity c) {
|
private void buildChildrenForSap(Long cRowId, BomNewPbomParentEntity p, BomNewPbomChildEntity c) {
|
||||||
List<BomNewPbomChildEntity> cc = getChildren(p);
|
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) {
|
for (BomNewPbomChildEntity it : cc) {
|
||||||
if (is21 && !isForSale && !Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
|
if (Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
|
||||||
return;
|
if (Objects.nonNull(cRowId)) {
|
||||||
}
|
T1DTO cct = cmap.get(cRowId).stream()
|
||||||
if (Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue())) {
|
.filter(ct -> (StrUtil.equals(ct.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY, true) && StrUtil.equals(ct.getPOTX1(), it.getMaterialDesc()))
|
||||||
if (Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
|
|| (!StrUtil.equals(ct.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY, true) && StrUtil.equals(ct.getIDNRK(), it.getMaterialNo())))
|
||||||
if (Objects.isNull(cRowId)) {
|
.findFirst()
|
||||||
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
|
.orElse(null);
|
||||||
children.add(convert(it, c.getMaterialNo()));
|
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 {
|
} else {
|
||||||
T1DTO cct = cmap.get(cRowId).stream()
|
//合并计算数量
|
||||||
.filter(ct -> (StrUtil.equals(ct.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY, true) && StrUtil.equals(ct.getPOTX1(), it.getMaterialDesc()))
|
cct.setMENGE(new BigDecimal(cct.getMENGE()).add(it.getNum()).toString());
|
||||||
|| (!StrUtil.equals(ct.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY, true) && StrUtil.equals(ct.getIDNRK(), it.getMaterialNo())))
|
LOGGER.debug("{} 物料提层到顶级发货包且合并 编号:{},父级编号:{},数量:{},合并后总数:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), cct.getMENGE(), it.getMaterialDesc());
|
||||||
.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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} 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());
|
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
|
||||||
children.add(convert(it, c.getMaterialNo()));
|
children.add(convert(it, c.getMaterialNo()));
|
||||||
}
|
}
|
||||||
List<BomNewPbomParentEntity> cp = getParents(it);
|
BomNewPbomParentEntity cp = getParent(it);
|
||||||
cp.forEach(cpt -> {
|
if (Objects.nonNull(cp)) {
|
||||||
buildChildrenForSap(cRowId, cpt, it);
|
buildChildrenForSap(cRowId, cp, it);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,11 +199,12 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
||||||
.list();
|
.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BomNewPbomParentEntity> getParents(BomNewPbomChildEntity child) {
|
private BomNewPbomParentEntity getParent(BomNewPbomChildEntity child) {
|
||||||
return bomNewPbomParentService.lambdaQuery()
|
return bomNewPbomParentService.lambdaQuery()
|
||||||
.eq(BomNewPbomParentEntity::getMaterialNo, child.getMaterialNo())
|
.eq(BomNewPbomParentEntity::getMaterialNo, child.getMaterialNo())
|
||||||
.eq(BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
|
.eq(BomNewPbomParentEntity::getStatus, PBomStatusEnum.FACTORY_CONFIRM.getValue())
|
||||||
.list();
|
.eq(BomNewPbomParentEntity::getFacCode, child.getFacCode())
|
||||||
|
.one();
|
||||||
}
|
}
|
||||||
|
|
||||||
// private List<BomNewPbomChildEntity> getChildren(List<BomNewPbomParentEntity> parents) {
|
// private List<BomNewPbomChildEntity> getChildren(List<BomNewPbomParentEntity> parents) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue