From 70d65268d77b91db6ee40159b0e3be63d8f8c7b9 Mon Sep 17 00:00:00 2001 From: jing's Date: Tue, 12 Mar 2024 14:15:43 +0800 Subject: [PATCH] =?UTF-8?q?mbom=20sap=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nflg/product/bomnew/api/user/MBomApi.java | 21 +++ .../service/BomNewMbomParentService.java | 134 +++++++++++++++++- .../bomnew/service/SapOpUtilService.java | 2 +- 3 files changed, 152 insertions(+), 5 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/MBomApi.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/MBomApi.java index 2196ebe2..159efe2f 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/MBomApi.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/MBomApi.java @@ -220,6 +220,27 @@ public class MBomApi extends BaseApi { } } + + @GetMapping("importSap") + @ApiOperation("导入sap") + @LogRecord(success = "Mbom-导入sap,操作结果:{{#_ret}}", bizNo = "", + extra = "{{#rowId}}" ,type = "Mbom-导入sap") + public ResultVO importSap(@ApiParam("行Id") @RequestParam("rowId") Long rowId) { + + if(Objects.isNull(rowId)){ + throw new NflgBusinessException(STATE.Error, "选择行操作" ); + + } + return bomNewMbomParentService.importSap(rowId) ; + + + } + + + + + + @Resource RedisService redisService; diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewMbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewMbomParentService.java index ca70c770..2c119351 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewMbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewMbomParentService.java @@ -1,25 +1,38 @@ package com.nflg.product.bomnew.service; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.ImmutableList; +import com.nflg.product.base.core.conmon.util.SessionUtil; +import com.nflg.product.bomnew.constant.BomConstant; import com.nflg.product.bomnew.constant.EBomConstant; import com.nflg.product.bomnew.constant.MBomConstantEnum; import com.nflg.product.bomnew.mapper.master.BomNewMbomParentMapper; import com.nflg.product.bomnew.pojo.dto.BomNewMBomChildDTO; +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.BomNewMbomParentEntity; import com.nflg.product.bomnew.pojo.query.BomNewMbomParentQuery; import com.nflg.product.bomnew.pojo.vo.BomNewMbomMiddleVO; +import com.nflg.product.bomnew.pojo.vo.ForwardReportVO; import com.nflg.product.bomnew.service.domain.MBom.IndexListTree; +import com.nflg.product.bomnew.util.VUtils; +import io.swagger.annotations.ApiParam; +import nflg.product.common.constant.STATE; +import nflg.product.common.vo.ResultVO; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import java.util.*; +import java.util.stream.Collectors; + +import static com.nflg.product.bomnew.constant.EBomConstant.MAIN_FACTORY_CODE_1010; /** @@ -134,4 +147,117 @@ public class BomNewMbomParentService extends ServiceImpl queryDetail( Long rowId, Long bomRowId) { + + + List rowIdList = new ArrayList<>( Arrays.asList(rowId) ); + List voList = new ArrayList<>(); + + while (!rowIdList.isEmpty()) { + List childList = SpringUtil.getBean(BomNewMbomParentService.class).getBaseMapper().getParentChild(rowIdList, bomRowId); + rowIdList.clear(); + if (CollUtil.isNotEmpty(childList)) { + for (BomNewMbomMiddleVO item: + childList) { + //Long bomRowIdTmp=item.getBomRowId(); + // item.setBomRowId(item.getBomVersionRowId()); + if (item.getParentRowId().longValue() == 0l) { + item.setParentRowId(bomRowId); + // item.setBomVersionRowId(item.getBomRowId()); + } + + } + + + voList.addAll(childList); + + List nextBomId = childList.stream().filter(u -> u.getBomVersionRowId() != null && u.getBomVersionRowId() > 0).map(BomNewMbomMiddleVO::getBomVersionRowId).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(nextBomId)) { + rowIdList.addAll(nextBomId); + } + + } + + } + + return voList; + } + + + + public ResultVO importSap(Long rowId){ + + + BomNewMbomMiddleVO parentVO= getParentById(rowId); + + VUtils.isTure(parentVO==null).throwMessage("选择顶层节点导入"); + parentVO.setParentRowId(0l); + parentVO.setBomRowId(parentVO.getRowId()); + parentVO.setBomExist(1); + + List list=queryDetail(0l,parentVO.getRowId()); + + list.add(0,parentVO); + ImportSapParamDTO result=new ImportSapParamDTO(); + result.setT1(new ArrayList<>()); + result.setZID(RandomUtil.randomNumbers(5)); + if(parentVO.getFacCode().equals(MAIN_FACTORY_CODE_1010)){ + result.setI_WERKS("1"); + }else{ + result.setI_WERKS("2"); + } + + result.setI_STLAN(BomConstant.SAP_MBOM); + String dateYMD= DateUtil.format(new Date(),"yyyyMMdd"); + + List parentList=list.stream().filter(u -> u.getBomExist().intValue()>0).collect(Collectors.toList()); + + + for (BomNewMbomMiddleVO parent: + parentList) { + List childList=list.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(childList)){ + continue; + } + for (BomNewMbomMiddleVO child: + childList) { + + T1DTO t1=new T1DTO(); + t1.setID(RandomUtil.randomNumbers(5)); + t1.setMATNR(parent.getMaterialNo()); + t1.setIDNRK(child.getMaterialNo()); + t1.setMEINS(child.getMaterialUnit()); + t1.setMENGE("1"); + t1.setPOSTP(child.getProjectType()); + t1.setDATUM(dateYMD); + t1.setMAKTX(parent.getMaterialDesc()); + t1.setMAKTX1(child.getMaterialDesc()); + result.getT1().add(t1); + } + + } + ResultVO resultVO= SpringUtil.getBean(SapOpUtilService.class).importToSapV2(result,null); + + //上传成功更新状态 + if(resultVO.getState().equals( STATE.Success.getState())){ + BomNewMbomParentEntity parentEntity=new BomNewMbomParentEntity(); + parentEntity.setRowId(parentVO.getRowId()); + parentEntity.setStatus(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue()); + parentEntity.setSysnSapUserName(SessionUtil.getUserName()); + parentEntity.setSysnSapTime(LocalDateTimeUtil.now()); + parentEntity.setModifyTime(LocalDateTimeUtil.now()); + this.updateById(parentEntity); + } + + return resultVO; + } + + + + + + + + } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/SapOpUtilService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/SapOpUtilService.java index 8744aec1..be0e1ab4 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/SapOpUtilService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/SapOpUtilService.java @@ -190,7 +190,7 @@ public class SapOpUtilService { list) { - if(CollectionUtil.isNotEmpty(backList)){ + if( backList !=null){ backList.add(item); } //"FLAG": "1" -- 0 失败;1 成功