optimize: 导入SAP优化

This commit is contained in:
曹鹏飞 2024-05-31 12:17:28 +08:00
parent 0f40fa7618
commit c58185771a
17 changed files with 252 additions and 170 deletions

View File

@ -166,7 +166,8 @@ public class EbomApi extends BaseApi {
//导入到sap
List<OperationErrorMsgVO> errorMsgVOS = new ArrayList<>();
paramDto.getBomRowIds().forEach(rootRowId -> {
errorMsgVOS.addAll(bomNewEbomParentService.importToSAP(rootRowId));
BomNewEbomExportToSAP exportToSAP = new BomNewEbomExportToSAP();
errorMsgVOS.addAll(exportToSAP.export(rootRowId));
});
return ResultVO.success(errorMsgVOS);

View File

@ -280,12 +280,13 @@ public class PBomApi extends BaseApi {
}
@GetMapping("realesePbom")
@PostMapping("realesePbom")
@ApiOperation("发布Pbom")
@LogRecord(success = "发布PBom物料编码{{#bom.materialNo}}-版本:{{#bom.currentVersion}} 操作结果:{{#_ret}}", bizNo = "{{#bomRowId}}",type = "发布PBom")
public ResultVO<Boolean> realesePbom(@RequestParam("bomRowId") Long bomRowId) {
return ResultVO.success(bomNewPbomParentService.realesePbom(bomRowId));
public ResultVO<Boolean> realesePbom(@Valid @RequestBody @NotNull PbomImportToSAPQuery query) {
bomNewPbomParentService.realesePbom(query.getRootBomRowId());
bomNewPbomParentService.importToSAP2(query);
return ResultVO.success();
}

View File

@ -11,7 +11,8 @@ public enum EBomSourceEnum implements ValueEnum<Integer> {
//来源1-原BOM转换 2-EXCE导入 3-MDM创建
FROM_BOM(1, "原始BOM转换"),
FROM_EXCE(2, "EXCE导入"),
FROM_MDM(3, "MDM创建");
FROM_MDM(3, "MDM创建"),
FROM_SAP(4, "从SAP导入");
private final Integer value;
private final String description;

View File

@ -7,55 +7,55 @@ import lombok.Data;
@Data
public class T1DTO {
@ApiModelProperty("客户端")
private String MANDT="";
// @ApiModelProperty("客户端")
// private String MANDT="";
@ApiModelProperty("流程标题")
private String ZLCBT="";
// @ApiModelProperty("流程标题")
// private String ZLCBT="";
@ApiModelProperty("--序号")
private String ID="";
protected String ID = "";
@ApiModelProperty("日期")
private String DATUM="99991231";
protected String DATUM = "99991231";
@ApiModelProperty("日期")
private String UZEIT="";
// @ApiModelProperty("日期")
// private String UZEIT="";
@ApiModelProperty("父级物料")
private String MATNR="";
protected String MATNR = "";
@ApiModelProperty("物料描述")
private String MAKTX="";
// @ApiModelProperty("物料描述")
// private String MAKTX="";
@ApiModelProperty("项目类别")
private String POSTP="";
protected String POSTP = "";
@ApiModelProperty("子级物料")
private String IDNRK;
protected String IDNRK;
@ApiModelProperty("子级物料描述")
private String MAKTX1;
// @ApiModelProperty("子级物料描述")
// private String MAKTX1;
@ApiModelProperty("组件数量")
private String MENGE;
protected String MENGE;
@ApiModelProperty("单位")
private String MEINS;
protected String MEINS;
@ApiModelProperty("bom项目文本")
private String POTX1="";
protected String POTX1 = "";
@ApiModelProperty("是否发货")
private String SFFH="";
// @ApiModelProperty("是否发货")
// private String SFFH="";
@ApiModelProperty("物料检查结果")
private String ZCHECK="";
// @ApiModelProperty("物料检查结果")
// private String ZCHECK="";
@ApiModelProperty("导入状态描述")
private String STATUS="";
// @ApiModelProperty("导入状态描述")
// private String STATUS="";
@ApiModelProperty("导入标志")
private String FLAG="";
// @ApiModelProperty("导入标志")
// private String FLAG="";
}

View File

@ -0,0 +1,38 @@
package com.nflg.product.bomnew.pojo.dto.sap.impart2;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author 曹鹏飞
* @date 2024/5/30 17:05:01
*/
@Data
public class T1ExtDTO {
@ApiModelProperty("--序号")
protected String ID = "";
@ApiModelProperty("日期")
protected String DATUM = "99991231";
@ApiModelProperty("父级物料")
protected String MATNR = "";
@ApiModelProperty("项目类别")
protected String POSTP = "";
@ApiModelProperty("子级物料")
protected String IDNRK;
@ApiModelProperty("组件数量")
protected String MENGE;
@ApiModelProperty("单位")
protected String MEINS;
@ApiModelProperty("bom项目文本")
protected String POTX1 = "";
private boolean ignore = false;
}

View File

@ -0,0 +1,18 @@
package com.nflg.product.bomnew.pojo.dto.sap.impart2;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author 曹鹏飞
* @date 2024/5/31 09:42:50
*/
@Data
public class T1ResultDTO extends T1DTO {
@ApiModelProperty("导入状态描述")
private String STATUS = "";
@ApiModelProperty("导入标志")
private String FLAG = "";
}

View File

@ -1,6 +1,7 @@
package com.nflg.product.bomnew.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
@ -8,12 +9,10 @@ import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.BomConstant;
import com.nflg.product.bomnew.constant.EBomStatusEnum;
import com.nflg.product.bomnew.constant.SapStatusEnum;
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
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.dto.sap.impart2.T1ExtDTO;
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewSapErrorMsgEntity;
@ -25,6 +24,7 @@ import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author 曹鹏飞
@ -35,8 +35,8 @@ public class BomNewEbomExportToSAP {
private final static String TAG = "Ebom导入到SAP";
private final String dateYMD = DateUtil.format(new Date(), "yyyyMMdd");
private final Map<Long, List<T1DTO>> cmap = new HashMap<>();
private final List<T1DTO> children = new ArrayList<>();
private final Map<Long, List<T1ExtDTO>> cmap = new HashMap<>();
private final List<T1ExtDTO> children = new ArrayList<>();
private final static Logger LOGGER = LoggerFactory.getLogger(BomNewEbomExportToSAP.class);
@ -55,15 +55,14 @@ public class BomNewEbomExportToSAP {
updateSapState(rootBomRowId, SapStatusEnum.PUB_RUNNING);
SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
try {
List<BomNewEbomChildEntity> children = getChildren(root);
children.forEach(it -> buildChildrenForSap(0L, root, it));
buildChildrenForSap(0L, root, null, false);
ImportSapParamDTO sapDto = new ImportSapParamDTO();
sapDto.setZID(RandomUtil.randomNumbers(5));
sapDto.setI_WERKS("1");
sapDto.setI_STLAN("2");
sapDto.setI_EMPNO(root.getCreatedBy());
sapDto.setT1(this.children);
sapDto.setT1(Convert.toList(T1DTO.class, this.children.stream().filter(c -> !c.isIgnore()).collect(Collectors.toList())));
liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
if (CollUtil.isEmpty(liErrMsg)) {
state = SapStatusEnum.PUB_SUCCESS;
@ -80,44 +79,44 @@ public class BomNewEbomExportToSAP {
/**
* 构建child数据
* @param cRowId 上层的直发包rowId
* @param p 级节点的parent
* @param c 级节点的child
* @param p 级节点的parent
* @param c 级节点的child
* @return 是否是空的直发包
*/
private boolean buildChildrenForSap(Long cRowId, BomNewEbomParentEntity p, BomNewEbomChildEntity c) {
private boolean buildChildrenForSap(Long cRowId, BomNewEbomParentEntity p, BomNewEbomChildEntity c, boolean ignore) {
List<BomNewEbomChildEntity> cc = getChildren(p);
if (CollUtil.isEmpty(cc)) {
return Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue());
}
boolean isEmpty = false;
for (BomNewEbomChildEntity it : cc) {
if (Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
if (Objects.nonNull(c) && Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
if (Objects.nonNull(cRowId)) {
if (cRowId == 0L) {
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, c.getMaterialNo()));
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, p.getMaterialNo(), false));
} else {
T1DTO cct = cmap.get(cRowId).stream()
T1ExtDTO 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());
LOGGER.debug("{} 物料提层到上级发货包 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
cct = convert(it, p.getMaterialNo(), false);
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());
LOGGER.debug("{} 物料提层到上级发货包且合并 编号:{},父级编号:{},数量:{},合并后总数:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), cct.getMENGE(), it.getMaterialDesc());
}
}
}
isEmpty = true;
} else if (!Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, c.getMaterialNo()));
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, p.getMaterialNo(), ignore));
}
if (it.getVirtualPartType() > VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue()
&& !Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DELIVERY_PACKAGE.getValue())) {
@ -139,14 +138,18 @@ public class BomNewEbomExportToSAP {
LOGGER.debug("{} 直发包 rowId{},编号:{},描述:{}", TAG, cRowId, zfc.getMaterialNo(), zfc.getMaterialDesc());
}
}
boolean b = buildChildrenForSap(cRowId, cp, it);
if (!ignore && cp.getUserRootIs() == 1) {
ignore = true;
}
boolean b = buildChildrenForSap(cRowId, cp, it, ignore);
if (!b && Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
//非空的直发包
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, c.getMaterialNo()));
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, p.getMaterialNo(), ignore));
}
}
}
LOGGER.debug("children数量" + children.size());
return isEmpty;
}
@ -165,8 +168,8 @@ public class BomNewEbomExportToSAP {
}
}
private T1DTO convert(BomNewEbomChildEntity child, String parentMaterialNo) {
T1DTO t = new T1DTO();
private T1ExtDTO convert(BomNewEbomChildEntity child, String parentMaterialNo, boolean ignore) {
T1ExtDTO t = new T1ExtDTO();
t.setID(RandomUtil.randomNumbers(5));
t.setMATNR(parentMaterialNo);
t.setMENGE(child.getNum().toString());
@ -174,6 +177,7 @@ public class BomNewEbomExportToSAP {
t.setDATUM(dateYMD);
t.setMEINS(child.getMaterialUnit());
t.setIDNRK(child.getMaterialNo());
t.setIgnore(ignore);
if (BomConstant.PROJECT_TYPE_TEMPORARY.equals(child.getProjectType())) {
t.setIDNRK("");
t.setPOTX1(child.getMaterialDesc());
@ -183,19 +187,25 @@ public class BomNewEbomExportToSAP {
private BomNewEbomParentEntity getParent(BomNewEbomChildEntity c) {
BomNewEbomParentEntity p = bomNewEbomParentService.lambdaQuery()
.select(BomNewEbomParentEntity::getRowId, BomNewEbomParentEntity::getMaterialNo
, BomNewEbomParentEntity::getMaterialDesc, BomNewEbomParentEntity::getUserRootIs)
.eq(BomNewEbomParentEntity::getMaterialNo, c.getMaterialNo())
.eq(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
.ne(BomNewEbomParentEntity::getSource, EBomSourceEnum.FROM_SAP.getValue())
.orderByDesc(BomNewEbomParentEntity::getCurrentVersion)
.last(" limit 1")
.one();
if (Objects.nonNull(p) && p.getUserRootIs() == 0) {
return p;
if (Objects.nonNull(p)) {
LOGGER.debug("BomNewEbomParentEntity" + JSON.toJSONString(p));
}
return null;
return p;
}
private List<BomNewEbomChildEntity> getChildren(BomNewEbomParentEntity parent) {
return bomNewEbomChildService.lambdaQuery()
.select(BomNewEbomChildEntity::getMaterialNo, BomNewEbomChildEntity::getNum
, BomNewEbomChildEntity::getMaterialUnit, BomNewEbomChildEntity::getMaterialDesc
, BomNewEbomChildEntity::getVirtualPartType, BomNewEbomChildEntity::getProjectType)
.eq(BomNewEbomChildEntity::getParentRowId, parent.getRowId())
.list();
}

View File

@ -7,6 +7,7 @@ import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.client.MaterialMainClient;
import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.pojo.dto.AddVirtrualMaterialDTO;
@ -20,11 +21,15 @@ import com.nflg.product.bomnew.pojo.vo.MaterialMainVO;
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
import com.nflg.product.bomnew.util.VUtils;
import com.nflg.product.bomnew.util.VersionUtil;
import nflg.product.common.constant.STATE;
import nflg.product.common.dto.LoginUserInfoDTO;
import nflg.product.common.vo.ResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@ -43,6 +48,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew
private final BomNewEbomChildService ebomChildService = SpringUtil.getBean(BomNewEbomChildService.class);
private final MaterialMainClient materialMainClient = SpringUtil.getBean(MaterialMainClient.class);
private final MaterialService materialService = SpringUtil.getBean(MaterialService.class);
private final PlatformTransactionManager transactionManager = SpringUtil.getBean(PlatformTransactionManager.class);
private final List<BomNewEbomChildEntity> childrenForAdd = Collections.synchronizedList(new ArrayList<>());
private final List<BomNewEbomChildEntity> childrenForUpdate = Collections.synchronizedList(new ArrayList<>());
@ -161,30 +167,38 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew
}
}
@Transactional(rollbackFor = Exception.class)
public void save() {
if (CollUtil.isNotEmpty(childRowIdsForDel)) {
ebomChildService.getBaseMapper().deleteBatchIds(childRowIdsForDel);
}
if (CollUtil.isNotEmpty(childrenForAdd)) {
LOGGER.debug("ebomChildService.saveBatch");
LOGGER.debug(JSON.toJSONString(childrenForAdd));
ebomChildService.saveBatch(childrenForAdd);
}
if (CollUtil.isNotEmpty(childrenForUpdate)) {
LOGGER.debug("ebomChildService.updateBatchById");
LOGGER.debug(JSON.toJSONString(childrenForUpdate));
ebomChildService.updateBatchById(childrenForUpdate);
}
if (CollUtil.isNotEmpty(parentsForAdd)) {
LOGGER.debug("ebomParentService.saveBatch");
LOGGER.debug(JSON.toJSONString(parentsForAdd));
ebomParentService.saveBatch(parentsForAdd);
}
if (CollUtil.isNotEmpty(parentsForUpdate)) {
LOGGER.debug("ebomParentService.updateBatchById");
LOGGER.debug(JSON.toJSONString(parentsForUpdate));
ebomParentService.updateBatchById(parentsForUpdate);
private void save() {
TransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
try {
if (CollUtil.isNotEmpty(childRowIdsForDel)) {
ebomChildService.getBaseMapper().deleteBatchIds(childRowIdsForDel);
}
if (CollUtil.isNotEmpty(childrenForAdd)) {
LOGGER.debug("ebomChildService.saveBatch");
LOGGER.debug(JSON.toJSONString(childrenForAdd));
ebomChildService.saveBatch(childrenForAdd);
}
if (CollUtil.isNotEmpty(childrenForUpdate)) {
LOGGER.debug("ebomChildService.updateBatchById");
LOGGER.debug(JSON.toJSONString(childrenForUpdate));
ebomChildService.updateBatchById(childrenForUpdate);
}
if (CollUtil.isNotEmpty(parentsForAdd)) {
LOGGER.debug("ebomParentService.saveBatch");
LOGGER.debug(JSON.toJSONString(parentsForAdd));
ebomParentService.saveBatch(parentsForAdd);
}
if (CollUtil.isNotEmpty(parentsForUpdate)) {
LOGGER.debug("ebomParentService.updateBatchById");
LOGGER.debug(JSON.toJSONString(parentsForUpdate));
ebomParentService.updateBatchById(parentsForUpdate);
}
transactionManager.commit(status);
} catch (Exception e) {
transactionManager.rollback(status);
LOGGER.error("生成虚拟包失败", e);
throw new NflgBusinessException(STATE.BusinessError, "生成虚拟包失败");
}
}
@ -475,6 +489,7 @@ public class BomNewEbomGenerateVirtualPackageServiceFor31Impl implements IBomNew
private BomNewEbomParentEntity buildParent(BomNewEbomParentEntity parent, BomNewEbomChildEntity child) {
BomNewEbomParentEntity p = Convert.convert(BomNewEbomParentEntity.class, child);
p.setCreatedBy(userInfo.getUserCode());
p.setDeptRowId(userInfo.getDepartRowId());
p.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
p.setVirtualPackageIs(1);
p.setRootIs(0);

View File

@ -414,9 +414,6 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
}
}
child.setChildBomRowId(child.getRowId());
BaseMaterialVO mvo = materialVOS.stream().filter(m -> StrUtil.equals(m.getMaterialNo(), child.getMaterialNo())).findFirst().orElse(null);
child.setSapOrderNum(BomUtil.generateSapOrderNum(child.getProjectType(), Objects.isNull(mvo) ? "" : mvo.getMaterialCategoryCode()
, "1010", child.getMaterialNo(), child.getBomExist()));
}
}
}
@ -945,10 +942,6 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
}
SpringUtil.getBean(BomNewEbomParentFormalService.class).copyEbomFormal(bomRowId);
CompletableFuture.runAsync(() -> {
importToSAP(bomRowId);
});
}
}

View File

@ -294,8 +294,8 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
t1.setMENGE("1");
t1.setPOSTP(child.getProjectType());
t1.setDATUM(dateYMD);
t1.setMAKTX(parent.getMaterialDesc());
t1.setMAKTX1(child.getMaterialDesc());
// t1.setMAKTX(parent.getMaterialDesc());
// t1.setMAKTX1(child.getMaterialDesc());
result.getT1().add(t1);
}

View File

@ -1,6 +1,7 @@
package com.nflg.product.bomnew.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
@ -9,6 +10,7 @@ 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.dto.sap.impart2.T1ExtDTO;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
@ -35,8 +37,8 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
private boolean is21 = false;
private final String dateYMD = DateUtil.format(new Date(), "yyyyMMdd");
private final Map<Long, List<T1DTO>> cmap = new HashMap<>();
private final List<T1DTO> children = new ArrayList<>();
private final Map<Long, List<T1ExtDTO>> cmap = new HashMap<>();
private final List<T1ExtDTO> children = new ArrayList<>();
private final static Logger LOGGER = LoggerFactory.getLogger(BomNewPbomExportToSAPImpl.class);
@ -54,53 +56,53 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
List<BomNewPbomChildEntity> rcs = bomNewPbomChildService.lambdaQuery()
.eq(BomNewPbomChildEntity::getParentRowId, root.getRowId())
.list();
if (root.getMaterialNo().startsWith("31")) {
List<BomNewPbomChildEntity> unVirtualParts = rcs.stream()
.filter(c -> Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue())
&& !StrUtil.equals(BomConstant.PROJECT_TYPE_TEMPORARY, c.getProjectType(), true))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(unVirtualParts)) {
return unVirtualParts.stream().map(c -> OperationErrorMsgVO.create(c.getMaterialNo(), "未生成发货包")).collect(Collectors.toList());
}
}
children.addAll(convert(rcs, root.getMaterialNo()));
rcs.forEach(it -> {
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(StrUtil.format("顶层直发包({})对应的parent丢失", cptt.getMaterialNo()));
ddpRowId = cpttp.getRowId();
cmap.put(ddpRowId, new ArrayList<>());
LOGGER.debug("{} 直发包 rowId{},编号:{},描述:{}", TAG, ddpRowId, cpttp.getMaterialNo(), cpttp.getMaterialDesc());
break;
}
}
}
buildChildrenForSap(ddpRowId, cp, it);
}
});
ImportSapParamDTO sapDto = new ImportSapParamDTO();
sapDto.setZID(RandomUtil.randomNumbers(5));
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);
// if (root.getMaterialNo().startsWith("31")) {
// List<BomNewPbomChildEntity> unVirtualParts = rcs.stream()
// .filter(c -> Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.UN_VIRTUAL_PACKAGE.getValue())
// && !StrUtil.equals(BomConstant.PROJECT_TYPE_TEMPORARY, c.getProjectType(), true))
// .collect(Collectors.toList());
// if (CollUtil.isNotEmpty(unVirtualParts)) {
// return unVirtualParts.stream().map(c -> OperationErrorMsgVO.create(c.getMaterialNo(), "未生成发货包")).collect(Collectors.toList());
// }
// }
updateSapState(rootBomRowId, SapStatusEnum.PUB_RUNNING);
SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
List<OperationErrorMsgVO> liErrMsg = null;
try {
updateSapState(rootBomRowId, SapStatusEnum.PUB_RUNNING);
children.addAll(convert(rcs, root.getMaterialNo(), false));
rcs.forEach(it -> {
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(StrUtil.format("顶层直发包({})对应的parent丢失", cptt.getMaterialNo()));
ddpRowId = cpttp.getRowId();
cmap.put(ddpRowId, new ArrayList<>());
LOGGER.debug("{} 直发包 rowId{},编号:{},描述:{}", TAG, ddpRowId, cpttp.getMaterialNo(), cpttp.getMaterialDesc());
break;
}
}
}
buildChildrenForSap(ddpRowId, cp, it, false);
}
});
ImportSapParamDTO sapDto = new ImportSapParamDTO();
sapDto.setZID(RandomUtil.randomNumbers(5));
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(Convert.toList(T1DTO.class, this.children.stream().filter(c -> !c.isIgnore()).collect(Collectors.toList())));
liErrMsg = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
LOGGER.debug("本次导入到sap数量共{}个,其中{}个有错误", sapDto.getT1().size(), liErrMsg.size());
if (CollUtil.isEmpty(liErrMsg)) {
@ -122,8 +124,8 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
.update();
}
private T1DTO convert(BomNewPbomChildEntity child, String parentMaterialNo) {
T1DTO t = new T1DTO();
private T1ExtDTO convert(BomNewPbomChildEntity child, String parentMaterialNo, boolean ignore) {
T1ExtDTO t = new T1ExtDTO();
t.setID(RandomUtil.randomNumbers(5));
t.setMATNR(parentMaterialNo);
t.setMENGE(child.getNum().toString());
@ -131,6 +133,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
t.setDATUM(dateYMD);
t.setMEINS(child.getMaterialUnit());
t.setIDNRK(child.getMaterialNo());
t.setIgnore(ignore);
if (BomConstant.PROJECT_TYPE_TEMPORARY.equals(child.getProjectType())) {
t.setIDNRK("");
t.setPOTX1(child.getMaterialDesc());
@ -138,8 +141,8 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
return t;
}
private List<T1DTO> convert(List<BomNewPbomChildEntity> children, String parentMaterialNo) {
return children.stream().map(c -> convert(c, parentMaterialNo)).collect(Collectors.toList());
private List<T1ExtDTO> convert(List<BomNewPbomChildEntity> children, String parentMaterialNo, boolean ignore) {
return children.stream().map(c -> convert(c, parentMaterialNo, ignore)).collect(Collectors.toList());
}
/**
@ -149,7 +152,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
* @param c 父级节点的child
* @return
*/
private void buildChildrenForSap(Long cRowId, BomNewPbomParentEntity p, BomNewPbomChildEntity c) {
private void buildChildrenForSap(Long cRowId, BomNewPbomParentEntity p, BomNewPbomChildEntity c, boolean ignore) {
List<BomNewPbomChildEntity> cc = getChildren(p);
if (is21 && !isForSale && Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
LOGGER.debug("{} 丢弃21编码非销售订单的直发包 编号:{}", TAG, c.getMaterialNo());
@ -161,51 +164,54 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
for (BomNewPbomChildEntity it : cc) {
if (Objects.equals(c.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
if (Objects.nonNull(cRowId)) {
T1DTO cct = cmap.get(cRowId).stream()
T1ExtDTO 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());
LOGGER.debug("{} 物料提层到顶级发货包 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
cct = convert(it, p.getMaterialNo(), false);
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());
LOGGER.debug("{} 物料提层到顶级发货包且合并 编号:{},父级编号:{},数量:{},合并后总数:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), cct.getMENGE(), it.getMaterialDesc());
}
}
} else if (!Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), c.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, c.getMaterialNo()));
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
children.add(convert(it, p.getMaterialNo(), ignore));
}
BomNewPbomParentEntity cp = getParent(it);
if (!ignore && cp.getUserRootIs() == 1) {
ignore = true;
}
if (Objects.nonNull(cp)) {
buildChildrenForSap(cRowId, cp, it);
buildChildrenForSap(cRowId, cp, it, ignore);
}
}
}
private List<BomNewPbomChildEntity> getChildren(BomNewPbomParentEntity parent) {
return bomNewPbomChildService.lambdaQuery()
.select(BomNewPbomChildEntity::getMaterialNo, BomNewPbomChildEntity::getNum
, BomNewPbomChildEntity::getMaterialUnit, BomNewPbomChildEntity::getMaterialDesc
, BomNewPbomChildEntity::getVirtualPartType, BomNewPbomChildEntity::getProjectType)
.eq(BomNewPbomChildEntity::getParentRowId, parent.getRowId())
.list();
}
private BomNewPbomParentEntity getParent(BomNewPbomChildEntity child) {
BomNewPbomParentEntity p = bomNewPbomParentService.lambdaQuery()
return bomNewPbomParentService.lambdaQuery()
.eq(BomNewPbomParentEntity::getMaterialNo, child.getMaterialNo())
.eq(BomNewPbomParentEntity::getStatus, PBomStatusEnum.FACTORY_CONFIRM.getValue())
.eq(BomNewPbomParentEntity::getFacCode, child.getFacCode())
.ne(BomNewPbomParentEntity::getCreatedBy, "admin")
.orderByDesc(BomNewPbomParentEntity::getCurrentVersion)
.last(" limit 1")
.one();
if (Objects.nonNull(p) && p.getUserRootIs() == 0) {
return p;
}
return null;
}
// private List<BomNewPbomChildEntity> getChildren(List<BomNewPbomParentEntity> parents) {

View File

@ -44,7 +44,6 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
@ -1041,10 +1040,6 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
pBomToFormal(bomRowIds, parentMaterialNos,parent.getFacCode());
// SpringUtil.getBean(BomNewPbomParentFormalService.class).copyPbomFormal(bomRowId);
CompletableFuture.runAsync(() -> {
importToSAP(bomRowId);
});
} catch (Exception ex) {
throw new NflgBusinessException(STATE.BusinessError, "发布Pbom失败" + ex.getMessage());
}

View File

@ -155,8 +155,8 @@ public class OptionalMbomMaterialService extends ServiceImpl<OptionalMbomMateria
t1.setMENGE(child.getExistStatus().toString());
t1.setPOSTP("L");
t1.setDATUM(dateYMD);
t1.setMAKTX(parent.getMaterialDesc());
t1.setMAKTX1(child.getMaterialDesc());
// t1.setMAKTX(parent.getMaterialDesc());
// t1.setMAKTX1(child.getMaterialDesc());
result.getT1().add(t1);
}

View File

@ -14,6 +14,7 @@ import com.nflg.product.bomnew.pojo.dto.sap.SapResult;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParam2DTO;
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.T1ResultDTO;
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
import com.nflg.product.bomnew.util.VUtils;
import lombok.extern.slf4j.Slf4j;
@ -180,9 +181,9 @@ public class SapOpUtilService {
Map<String, List<Map<String, Object>>> outTablesMap = sapResult.getOutTablesMap();
log.info("导入到SAP--返回值:" + JSON.toJSONString(outTablesMap));
List<Map<String, Object>> tOut = outTablesMap.get("T1");
List<T1DTO> list = null;
List<T1ResultDTO> list = null;
if (!CollectionUtils.isEmpty(tOut)) {
list = Convert.convert(new TypeReference<List<T1DTO>>() {
list = Convert.convert(new TypeReference<List<T1ResultDTO>>() {
}, tOut);
}
if (CollUtil.isEmpty(list)) {

View File

@ -167,6 +167,9 @@ public abstract class EBomToPbomBase {
//版本=EBom版本
pBomParent.setCurrentVersion(parentVo.getCurrentVersion());
pBomParent.setEditStatus(PBomEditStatusEnum.HANDLER_CREATED.getValue());
pBomParent.setDeptName(SessionUtil.getDepartName());
pBomParent.setDeptRowId(SessionUtil.getDepartRowId());
pBomParent.setCreatedBy(SessionUtil.getUserCode());
if (Objects.nonNull(oldParent)) {
// pBomParent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
oldParent.setExpireEndTime(LocalDateTime.now());

View File

@ -286,6 +286,7 @@ public abstract class VirtualPackageBase {
parent.setDeviseName(SessionUtil.getRealName());
parent.setCreatedBy(SessionUtil.getUserCode());
parent.setDeptName(SessionUtil.getDepartName());
parent.setDeptRowId(SessionUtil.getDepartRowId());
parent.setSource(EBomSourceEnum.FROM_MDM.getValue());
//parent.setModifyTime(LocalDateTime.now());
parent.setStatus(p.getStatus());

View File

@ -7,7 +7,6 @@ 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.BomNewPbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
import org.apache.http.util.Args;
import java.util.ArrayList;
import java.util.List;
@ -48,8 +47,8 @@ public class Sap {
t1.setMEINS(child.getMaterialUnit());
t1.setMENGE(child.getNum().toString());
t1.setPOSTP(child.getProjectType());
t1.setMAKTX(parentBom.getMaterialDesc());
t1.setMAKTX1(child.getMaterialDesc());
// t1.setMAKTX(parentBom.getMaterialDesc());
// t1.setMAKTX1(child.getMaterialDesc());
result.getT1().add(t1);
}
}