From 6ebeb26432d16745315326f4f54c6520492a29de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Thu, 27 Jun 2024 15:48:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=B9=E6=8D=AE=E7=9B=B4=E5=8F=91?= =?UTF-8?q?=E5=8C=85=E7=BC=96=E5=8F=B7=E5=AF=BC=E5=85=A5=E4=B8=8A=E7=BA=A7?= =?UTF-8?q?=E7=89=A9=E6=96=99=E5=88=B0SAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/BomNewPbomExportToSAPImpl.java | 96 +++++++++++++------ .../service/IBomNewPbomExportToSAP.java | 6 ++ 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomExportToSAPImpl.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomExportToSAPImpl.java index 5258e4f0..c3335930 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomExportToSAPImpl.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomExportToSAPImpl.java @@ -75,28 +75,25 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP { SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL; List liErrMsg = null; try { - rcs.forEach(it -> { + Long ddpRowId = null; + if (is21) { + //选出直发包 + ddpRowId = getZFBBomRowId(rcs); + } + for (BomNewPbomChildEntity it : rcs) { BomNewPbomParentEntity cp = getParent(it); children.add(convert(cp, it, root.getMaterialNo(), false)); if (Objects.nonNull(cp)) { - Long ddpRowId = null; - //选出直发包 - List 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(StrUtil.format("顶层直发包({})对应的parent丢失", cptt.getMaterialNo())); - ddpRowId = cpttp.getRowId(); - cmap.put(ddpRowId, new ArrayList<>()); - LOGGER.debug("{} 直发包 rowId:{},编号:{},描述:{}", TAG, ddpRowId, cpttp.getMaterialNo(), cpttp.getMaterialDesc()); - break; - } - } + if (is21) { + buildChildrenForSap(ddpRowId, cp, it, false); + } else { + //选出直发包 + List cpsc = getChildren(cp); + ddpRowId = getZFBBomRowId(cpsc); + buildChildrenForSap(ddpRowId, cp, it, false); } - buildChildrenForSap(ddpRowId, cp, it, false); } - }); + } ImportSapParamDTO sapDto = new ImportSapParamDTO(); sapDto.setZID(RandomUtil.randomNumbers(5)); if (StrUtil.equals(root.getFacCode(), EBomConstant.MAIN_FACTORY_CODE_1010)) { @@ -129,6 +126,22 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP { return liErrMsg; } + private Long getZFBBomRowId(List children) { + Long ddpRowId = null; + BomNewPbomChildEntity czfb = children.stream() + .filter(c -> Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) + .findFirst() + .orElse(null); + if (Objects.nonNull(czfb)) { + BomNewPbomParentEntity cpttp = getParent(czfb); + VUtils.isTure(Objects.isNull(cpttp)).throwMessage(StrUtil.format("顶层直发包({})对应的parent丢失", czfb.getMaterialNo())); + ddpRowId = cpttp.getRowId(); + cmap.put(ddpRowId, new ArrayList<>()); + LOGGER.debug("{} 直发包 rowId:{},编号:{},描述:{}", TAG, ddpRowId, cpttp.getMaterialNo(), cpttp.getMaterialDesc()); + } + return ddpRowId; + } + private void saveSapErrorMsg(Long rootBomRowId, List liErrMsg) { bomNewSapErrorMsgService.getBaseMapper().delete(Wrappers.lambdaQuery(BomNewSapErrorMsgEntity.class) .eq(BomNewSapErrorMsgEntity::getTargetRowId, rootBomRowId)); @@ -255,16 +268,43 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP { .one(); } - // private List getChildren(List parents) { - // return bomNewPbomChildService.lambdaQuery() - // .in(BomNewPbomChildEntity::getParentRowId, parents.stream().map(BomNewPbomParentEntity::getRowId).collect(Collectors.toSet())) - // .list(); - // } + /** + * 根据直发包编号导入上级物料到SAP + * @param materialNo 直发包编号 + */ + @Override + public void exportFromZFB(String materialNo) { + List pfhbs = bomNewPbomParentService.lambdaQuery() + .eq(BomNewPbomParentEntity::getMaterialNo, materialNo) + .ge(BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue()) + .list(); + VUtils.isTure(Objects.isNull(pfhbs)).throwMessage("没有需要导入的数据"); - // private List getParents(List children) { - // return bomNewPbomParentService.lambdaQuery() - // .in(BomNewPbomParentEntity::getMaterialNo, children.stream().map(BomNewPbomChildEntity::getMaterialNo).collect(Collectors.toSet())) - // .eq(BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue()) - // .list(); - // } + pfhbs.forEach(pfhb -> { + List errorMsgVOS = export(pfhb.getRowId()); + if (CollUtil.isNotEmpty(errorMsgVOS)) { + //如果导入SAP出错了,得将该bom提升为用户根节点,以便用户手动尝试导入到SAP去 + pfhb.setUserRootIs(1); + pfhb.setModifyTime(LocalDateTime.now()); + } + }); + + pfhbs.removeIf(p -> Objects.equals(p.getLastVersionIs(), 0)); + if (CollUtil.isNotEmpty(pfhbs)) { + bomNewPbomParentService.updateBatchById(pfhbs); + } + } + + private void buildChildrenForSap1(BomNewPbomParentEntity p) { + List cc = getChildren(p); + for (BomNewPbomChildEntity it : cc) { + BomNewPbomParentEntity cp = getParent(it); + children.add(convert(cp, it, p.getMaterialNo(), false)); + if (Objects.nonNull(cp)) { + if (cp.getUserRootIs() == 0) { + buildChildrenForSap1(cp); + } + } + } + } } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/IBomNewPbomExportToSAP.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/IBomNewPbomExportToSAP.java index 8d2ad928..13fb5c7f 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/IBomNewPbomExportToSAP.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/IBomNewPbomExportToSAP.java @@ -22,4 +22,10 @@ public interface IBomNewPbomExportToSAP { // String dateYMD = DateUtil.format(new Date(), "yyyyMMdd"); List export(Long rootBomRowId); + + /** + * 根据直发包编号导入上级物料到SAP + * @param materialNo 直发包编号 + */ + void exportFromZFB(String materialNo); }