Merge remote-tracking branch 'origin/master-hlq20241009batch'

# Conflicts:
#	nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomExportToSAP.java
This commit is contained in:
10001392 2024-10-31 17:18:33 +08:00
commit 25cb146344
7 changed files with 49 additions and 12 deletions

View File

@ -3,7 +3,10 @@ package com.nflg.product.bomnew.api.user;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.nflg.product.base.core.api.BaseApi; import com.nflg.product.base.core.api.BaseApi;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.EBomConstant;
import com.nflg.product.bomnew.pojo.query.BatchBomQuery; import com.nflg.product.bomnew.pojo.query.BatchBomQuery;
import com.nflg.product.bomnew.pojo.query.PbomImportToSAPQuery; import com.nflg.product.bomnew.pojo.query.PbomImportToSAPQuery;
import com.nflg.product.bomnew.pojo.vo.*; import com.nflg.product.bomnew.pojo.vo.*;
@ -69,7 +72,7 @@ public class BatchBomApi extends BaseApi {
if (CollUtil.isNotEmpty(addRowIds)) { if (CollUtil.isNotEmpty(addRowIds)) {
addRowIds.forEach(rootRowId -> { addRowIds.forEach(rootRowId -> {
BomNewEbomExportToSAP exportToSAP = new BomNewEbomExportToSAP(); BomNewEbomExportToSAP exportToSAP = new BomNewEbomExportToSAP();
errorMsgVOS.addAll(exportToSAP.export(rootRowId)); errorMsgVOS.addAll(exportToSAP.export(rootRowId, true));
}); });
} }
return ResultVO.success(errorMsgVOS); return ResultVO.success(errorMsgVOS);
@ -86,7 +89,7 @@ public class BatchBomApi extends BaseApi {
PbomImportToSAPQuery query = new PbomImportToSAPQuery(); PbomImportToSAPQuery query = new PbomImportToSAPQuery();
query.setRootBomRowId(rootRowId); query.setRootBomRowId(rootRowId);
query.setIsForSale(false); query.setIsForSale(false);
errorMsgVOS.addAll(bomNewPbomParentService.importToSAP2(query)); errorMsgVOS.addAll(bomNewPbomParentService.importToSAP2(query, true));
}); });
} }
return ResultVO.success(errorMsgVOS); return ResultVO.success(errorMsgVOS);
@ -98,4 +101,14 @@ public class BatchBomApi extends BaseApi {
EecExcelUtil.setResponseExcelHeader(response, "批量替代" + query.getMaterialNo() + "_" + new Date().getTime()); EecExcelUtil.setResponseExcelHeader(response, "批量替代" + query.getMaterialNo() + "_" + new Date().getTime());
batchBomService.getExportExcelWork(query).writeTo(response.getOutputStream()); batchBomService.getExportExcelWork(query).writeTo(response.getOutputStream());
} }
@GetMapping("getUserFactory")
@ApiOperation("获取登录用户所在工厂")
public ResultVO<String> getUserFactory() {
String dptCde = materialMainService.getBaseMapper().getUserDepartmentDptCode(SessionUtil.getDepartRowId());
if (StrUtil.isNotBlank(dptCde) && dptCde.contains("仙桃公司")) {
return ResultVO.success(EBomConstant.XIAN_TAO_FACTORY_CODE_1020);
}
return ResultVO.success(EBomConstant.MAIN_FACTORY_CODE_1010);
}
} }

View File

@ -189,7 +189,7 @@ public class EbomApi extends BaseApi {
errorMsgVOS.addAll(bomNewEbomParentService.convertToPBom(paramDto)); errorMsgVOS.addAll(bomNewEbomParentService.convertToPBom(paramDto));
paramDto.getBomRowIds().forEach(rootRowId -> { paramDto.getBomRowIds().forEach(rootRowId -> {
BomNewEbomExportToSAP exportToSAP = new BomNewEbomExportToSAP(); BomNewEbomExportToSAP exportToSAP = new BomNewEbomExportToSAP();
errorMsgVOS.addAll(exportToSAP.export(rootRowId)); errorMsgVOS.addAll(exportToSAP.export(rootRowId, false));
}); });
return ResultVO.success(errorMsgVOS); return ResultVO.success(errorMsgVOS);
@ -483,7 +483,7 @@ public class EbomApi extends BaseApi {
VUtils.isTure(rootBomRowIds.size() > 1).throwMessage("每次只能导入1条"); VUtils.isTure(rootBomRowIds.size() > 1).throwMessage("每次只能导入1条");
// return ResultVO.success(bomNewEbomParentService.importToSAP(rootBomRowIds.get(0))); // return ResultVO.success(bomNewEbomParentService.importToSAP(rootBomRowIds.get(0)));
BomNewEbomExportToSAP exportToSAP = new BomNewEbomExportToSAP(); BomNewEbomExportToSAP exportToSAP = new BomNewEbomExportToSAP();
return ResultVO.success(exportToSAP.export(rootBomRowIds.get(0))); return ResultVO.success(exportToSAP.export(rootBomRowIds.get(0), false));
} }
/** /**

View File

@ -337,7 +337,7 @@ public class PBomApi extends BaseApi {
.last(" order by current_version desc limit 1").one(); .last(" order by current_version desc limit 1").one();
query.setRootBomRowId(parentEnt.getRowId()); query.setRootBomRowId(parentEnt.getRowId());
} }
return ResultVO.success(bomNewPbomParentService.importToSAP2(query)); return ResultVO.success(bomNewPbomParentService.importToSAP2(query, false));
} }
@ -399,7 +399,7 @@ public class PBomApi extends BaseApi {
@PostMapping("importToSAP") @PostMapping("importToSAP")
@ApiOperation("导入到SAP") @ApiOperation("导入到SAP")
public ResultVO<List<OperationErrorMsgVO>> importToSAP(@Valid @RequestBody @NotNull PbomImportToSAPQuery query) { public ResultVO<List<OperationErrorMsgVO>> importToSAP(@Valid @RequestBody @NotNull PbomImportToSAPQuery query) {
return ResultVO.success(bomNewPbomParentService.importToSAP2(query)); return ResultVO.success(bomNewPbomParentService.importToSAP2(query, false));
} }
/** /**

View File

@ -52,7 +52,7 @@ public class BomNewEbomExportToSAP {
private final BomNewSapErrorMsgService bomNewSapErrorMsgService = SpringUtil.getBean(BomNewSapErrorMsgService.class); private final BomNewSapErrorMsgService bomNewSapErrorMsgService = SpringUtil.getBean(BomNewSapErrorMsgService.class);
private final SapErrorMsgUtil sapErrorMsgUtil = SpringUtil.getBean(SapErrorMsgUtil.class); private final SapErrorMsgUtil sapErrorMsgUtil = SpringUtil.getBean(SapErrorMsgUtil.class);
public List<OperationErrorMsgVO> export(Long rootBomRowId) { public List<OperationErrorMsgVO> export(Long rootBomRowId, boolean singleLevel) {
BomNewEbomParentEntity root = bomNewEbomParentService.getById(rootBomRowId); BomNewEbomParentEntity root = bomNewEbomParentService.getById(rootBomRowId);
// VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在"); // VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
if (Objects.isNull(root)) return Collections.emptyList(); if (Objects.isNull(root)) return Collections.emptyList();
@ -80,6 +80,9 @@ public class BomNewEbomExportToSAP {
sapDto.setI_STLAN("2"); sapDto.setI_STLAN("2");
sapDto.setI_EMPNO(root.getCreatedBy()); sapDto.setI_EMPNO(root.getCreatedBy());
sapDto.setT1(Convert.toList(T1DTO.class, this.children.stream().filter(c -> !c.isIgnore()).collect(Collectors.toList()))); sapDto.setT1(Convert.toList(T1DTO.class, this.children.stream().filter(c -> !c.isIgnore()).collect(Collectors.toList())));
if (singleLevel) {
filterSingleLevelData(root.getMaterialNo(), sapDto);
}
//BOM的子表仅有一行BOM删除项目类别为K的数据 by 10002327 241017 //BOM的子表仅有一行BOM删除项目类别为K的数据 by 10002327 241017
// Map<String,List<T1ExtDTO>> t1Map = this.children.stream().collect(Collectors.groupingBy(T1ExtDTO::getMATNR)); // Map<String,List<T1ExtDTO>> t1Map = this.children.stream().collect(Collectors.groupingBy(T1ExtDTO::getMATNR));
// List<T3DTO> t3List = Lists.newArrayList(); // List<T3DTO> t3List = Lists.newArrayList();
@ -120,6 +123,15 @@ public class BomNewEbomExportToSAP {
return liErrMsg; return liErrMsg;
} }
/**
* 单层导入过滤出指定父级物料号的子级即可
* @param materialNo 父级物料号
*/
private void filterSingleLevelData(String materialNo, ImportSapParamDTO sapDto) {
List<T1DTO> t1 = sapDto.getT1();
sapDto.setT1(t1.stream().filter(item -> item.getMATNR().equals(materialNo)).collect(Collectors.toList()));
}
/** /**
* 构建child数据发包编号 * 构建child数据发包编号
* @param p 上级节点的parent * @param p 上级节点的parent

View File

@ -62,7 +62,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
} }
@Override @Override
public List<OperationErrorMsgVO> export(Long rootBomRowId) { public List<OperationErrorMsgVO> export(Long rootBomRowId, boolean singleLevel) {
BomNewPbomParentEntity root = bomNewPbomParentService.getById(rootBomRowId); BomNewPbomParentEntity root = bomNewPbomParentService.getById(rootBomRowId);
is21 = root.getMaterialNo().startsWith("21"); is21 = root.getMaterialNo().startsWith("21");
is31 = root.getMaterialNo().startsWith("31"); is31 = root.getMaterialNo().startsWith("31");
@ -114,6 +114,9 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
sapDto.setI_STLAN("1"); sapDto.setI_STLAN("1");
sapDto.setI_EMPNO(root.getCreatedBy()); sapDto.setI_EMPNO(root.getCreatedBy());
sapDto.setT1(Convert.toList(T1DTO.class, this.children.stream().filter(c -> !c.isIgnore()).collect(Collectors.toList()))); sapDto.setT1(Convert.toList(T1DTO.class, this.children.stream().filter(c -> !c.isIgnore()).collect(Collectors.toList())));
if (singleLevel) {
filterSingleLevelData(root.getMaterialNo(), sapDto);
}
liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null); liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
LOGGER.debug("本次导入到sap数量共{}个,其中{}个有错误", sapDto.getT1().size(), liErrMsg.size()); LOGGER.debug("本次导入到sap数量共{}个,其中{}个有错误", sapDto.getT1().size(), liErrMsg.size());
if (CollUtil.isEmpty(liErrMsg)) { if (CollUtil.isEmpty(liErrMsg)) {
@ -139,6 +142,15 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
return liErrMsg; return liErrMsg;
} }
/**
* 单层导入过滤出指定父级物料号的子级即可
* @param materialNo 父级物料号
*/
private void filterSingleLevelData(String materialNo, ImportSapParamDTO sapDto) {
List<T1DTO> t1 = sapDto.getT1();
sapDto.setT1(t1.stream().filter(item -> item.getMATNR().equals(materialNo)).collect(Collectors.toList()));
}
private Long getZFBBomRowId(List<BomNewPbomChildEntity> children) { private Long getZFBBomRowId(List<BomNewPbomChildEntity> children) {
Long ddpRowId = null; Long ddpRowId = null;
//电控系统的无须增加 直发包parent记录 by 10002327 240918 //电控系统的无须增加 直发包parent记录 by 10002327 240918
@ -382,7 +394,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
.one(); .one();
VUtils.isTure(Objects.isNull(pfhb)).throwMessage("没有需要导入的数据"); VUtils.isTure(Objects.isNull(pfhb)).throwMessage("没有需要导入的数据");
List<OperationErrorMsgVO> errorMsgVOS = export(pfhb.getRowId()); List<OperationErrorMsgVO> errorMsgVOS = export(pfhb.getRowId(), false);
if (CollUtil.isNotEmpty(errorMsgVOS)) { if (CollUtil.isNotEmpty(errorMsgVOS)) {
//如果导入SAP出错了得将该bom提升为用户根节点以便用户手动尝试导入到SAP去 //如果导入SAP出错了得将该bom提升为用户根节点以便用户手动尝试导入到SAP去
pfhb.setUserRootIs(1); pfhb.setUserRootIs(1);

View File

@ -1667,13 +1667,13 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
} }
} }
public List<OperationErrorMsgVO> importToSAP2(PbomImportToSAPQuery query) { public List<OperationErrorMsgVO> importToSAP2(PbomImportToSAPQuery query, boolean singleLevel) {
BomNewPbomParentEntity root = getById(query.getRootBomRowId()); BomNewPbomParentEntity root = getById(query.getRootBomRowId());
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在"); VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
// VUtils.isTure(root.getUserRootIs() != 1 && root.getRootIs() != 1).throwMessage("请选择根节点"); // VUtils.isTure(root.getUserRootIs() != 1 && root.getRootIs() != 1).throwMessage("请选择根节点");
IBomNewPbomExportToSAP service = new BomNewPbomExportToSAPImpl(query.getIsForSale()); IBomNewPbomExportToSAP service = new BomNewPbomExportToSAPImpl(query.getIsForSale());
return service.export(root.getRowId()); return service.export(root.getRowId(), singleLevel);
} }
/** /**

View File

@ -21,7 +21,7 @@ public interface IBomNewPbomExportToSAP {
// //
// String dateYMD = DateUtil.format(new Date(), "yyyyMMdd"); // String dateYMD = DateUtil.format(new Date(), "yyyyMMdd");
List<OperationErrorMsgVO> export(Long rootBomRowId); List<OperationErrorMsgVO> export(Long rootBomRowId, boolean singleLevel);
/** /**
* 根据直发包编号导入上级物料到SAP * 根据直发包编号导入上级物料到SAP