optimize: 优化导入SAP
This commit is contained in:
parent
bbd13241ed
commit
6423a67ebe
|
|
@ -4,6 +4,7 @@ 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;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
|
@ -78,12 +79,17 @@ public class BomNewEbomExportToSAP {
|
|||
state = SapStatusEnum.PUB_ERROR;
|
||||
}
|
||||
saveSapErrorMsg(rootBomRowId, liErrMsg);
|
||||
} catch (NflgBusinessException ex) {
|
||||
liErrMsg = new ArrayList<>();
|
||||
liErrMsg.add(OperationErrorMsgVO.create("", ex.getMessage()));
|
||||
saveSapErrorMsg(rootBomRowId, liErrMsg);
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("导入SAP失败", ex);
|
||||
liErrMsg = new ArrayList<>();
|
||||
liErrMsg.add(OperationErrorMsgVO.create("", "未知异常,请联系管理员"));
|
||||
liErrMsg.add(OperationErrorMsgVO.create("", ex.getMessage()));
|
||||
saveSapErrorMsg(rootBomRowId, liErrMsg);
|
||||
throw new NflgBusinessException(STATE.BusinessError, "导入SAP失败,请联系管理员");
|
||||
throw new NflgBusinessException(STATE.BusinessError, "导入SAP失败," + ex.getMessage());
|
||||
} finally {
|
||||
updateSapState(rootBomRowId, state);
|
||||
}
|
||||
|
|
@ -99,12 +105,12 @@ public class BomNewEbomExportToSAP {
|
|||
for (BomNewEbomChildEntity it : cc) {
|
||||
handlerItem(it, p);
|
||||
}
|
||||
LOGGER.debug("children数量:" + children.size());
|
||||
// LOGGER.debug("children数量:" + children.size());
|
||||
}
|
||||
|
||||
private void handlerItem(BomNewEbomChildEntity it, BomNewEbomParentEntity p) {
|
||||
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
|
||||
children.add(convert(it, p.getMaterialNo(), Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())));
|
||||
addToT1(convert(it, p.getMaterialNo(), Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())));
|
||||
BomNewEbomParentEntity cp = getParent(it);
|
||||
if (Objects.nonNull(cp)) {
|
||||
buildChildrenForSap(cp);
|
||||
|
|
@ -126,6 +132,13 @@ public class BomNewEbomExportToSAP {
|
|||
}
|
||||
}
|
||||
|
||||
private void addToT1(T1ExtDTO dto) {
|
||||
if (StrUtil.equals(dto.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY)
|
||||
|| children.stream().noneMatch(c -> StrUtil.equals(c.getIDNRK(), dto.getIDNRK()) && StrUtil.equals(c.getMATNR(), dto.getMATNR()))) {
|
||||
children.add(dto);
|
||||
}
|
||||
}
|
||||
|
||||
private T1ExtDTO convert(BomNewEbomChildEntity child, String parentMaterialNo, boolean isZFB) {
|
||||
T1ExtDTO t = new T1ExtDTO();
|
||||
t.setID(RandomUtil.randomNumbers(5));
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
|||
}
|
||||
for (BomNewPbomChildEntity it : rcs) {
|
||||
BomNewPbomParentEntity cp = getParent(it);
|
||||
children.add(convert(cp, it, root.getMaterialNo(), false));
|
||||
addToT1(convert(cp, it, root.getMaterialNo(), false));
|
||||
if (Objects.nonNull(cp)) {
|
||||
if (is21) {
|
||||
buildChildrenForSap(ddpRowId, cp, it, false);
|
||||
|
|
@ -114,12 +114,17 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
|||
state = SapStatusEnum.PUB_ERROR;
|
||||
}
|
||||
saveSapErrorMsg(rootBomRowId, liErrMsg);
|
||||
} catch (NflgBusinessException ex) {
|
||||
liErrMsg = new ArrayList<>();
|
||||
liErrMsg.add(OperationErrorMsgVO.create("", ex.getMessage()));
|
||||
saveSapErrorMsg(rootBomRowId, liErrMsg);
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("导入SAP失败", ex);
|
||||
liErrMsg = new ArrayList<>();
|
||||
liErrMsg.add(OperationErrorMsgVO.create("", "未知异常,请联系管理员"));
|
||||
liErrMsg.add(OperationErrorMsgVO.create("", ex.getMessage()));
|
||||
saveSapErrorMsg(rootBomRowId, liErrMsg);
|
||||
throw new NflgBusinessException(STATE.BusinessError, "导入SAP失败,请联系管理员");
|
||||
throw new NflgBusinessException(STATE.BusinessError, "导入SAP失败," + ex.getMessage());
|
||||
} finally {
|
||||
updateSapState(rootBomRowId, state);
|
||||
}
|
||||
|
|
@ -226,7 +231,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
|||
LOGGER.debug("{} 物料提层到顶级发货包 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
|
||||
cct = convert(cp, it, p.getMaterialNo(), false);
|
||||
cmap.get(cRowId).add(cct);
|
||||
children.add(cct);
|
||||
addToT1(cct);
|
||||
} else {
|
||||
//合并计算数量
|
||||
cct.setMENGE(new BigDecimal(cct.getMENGE()).add(it.getNum()).toString());
|
||||
|
|
@ -236,7 +241,7 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
|||
// } else if (!Objects.equals(it.getVirtualPartType(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE.getValue())) {
|
||||
} else {
|
||||
LOGGER.debug("{} 添加物料 编号:{},父级编号:{},数量:{},描述:{}", TAG, it.getMaterialNo(), p.getMaterialNo(), it.getNum().toString(), it.getMaterialDesc());
|
||||
children.add(convert(cp, it, p.getMaterialNo(), ignore));
|
||||
addToT1(convert(cp, it, p.getMaterialNo(), ignore));
|
||||
}
|
||||
if (Objects.nonNull(cp)) {
|
||||
if (!ignore && cp.getUserRootIs() == 1) {
|
||||
|
|
@ -246,6 +251,13 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
|||
}
|
||||
}
|
||||
|
||||
private void addToT1(T1ExtDTO dto) {
|
||||
if (StrUtil.equals(dto.getPOSTP(), BomConstant.PROJECT_TYPE_TEMPORARY)
|
||||
|| children.stream().noneMatch(c -> StrUtil.equals(c.getIDNRK(), dto.getIDNRK()) && StrUtil.equals(c.getMATNR(), dto.getMATNR()))) {
|
||||
children.add(dto);
|
||||
}
|
||||
}
|
||||
|
||||
private List<BomNewPbomChildEntity> getChildren(BomNewPbomParentEntity parent) {
|
||||
return bomNewPbomChildService.lambdaQuery()
|
||||
.select(BomNewPbomChildEntity::getMaterialNo, BomNewPbomChildEntity::getNum
|
||||
|
|
@ -260,10 +272,8 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
|||
private BomNewPbomParentEntity getParent(BomNewPbomChildEntity child) {
|
||||
return bomNewPbomParentService.lambdaQuery()
|
||||
.eq(BomNewPbomParentEntity::getMaterialNo, child.getMaterialNo())
|
||||
.eq(!is21, BomNewPbomParentEntity::getStatus, PBomStatusEnum.FACTORY_CONFIRM.getValue())
|
||||
.ge(is21, BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
|
||||
.ge(BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
|
||||
.eq(BomNewPbomParentEntity::getFacCode, child.getFacCode())
|
||||
.ne(BomNewPbomParentEntity::getCreatedBy, "admin")
|
||||
.orderByDesc(BomNewPbomParentEntity::getCurrentVersion)
|
||||
.last(" limit 1")
|
||||
.one();
|
||||
|
|
@ -292,17 +302,4 @@ public class BomNewPbomExportToSAPImpl implements IBomNewPbomExportToSAP {
|
|||
bomNewPbomParentService.updateById(pfhb);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildChildrenForSap1(BomNewPbomParentEntity p) {
|
||||
List<BomNewPbomChildEntity> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -406,26 +406,29 @@ public class DQBomService {
|
|||
List<T1DTO> t1s = new ArrayList<>();
|
||||
String dateYMD = DateUtil.format(new Date(), "yyyyMMdd");
|
||||
datas.forEach(d -> {
|
||||
T1DTO t1 = new T1DTO();
|
||||
t1.setID(RandomUtil.randomNumbers(5));
|
||||
t1.setMATNR(d.getParentMaterialNo());
|
||||
t1.setMENGE(d.getNum().toString());
|
||||
t1.setPOSTP(d.getProjectType());
|
||||
t1.setDATUM(dateYMD);
|
||||
if (StrUtil.equals(BomConstant.PROJECT_TYPE_TEMPORARY, d.getProjectType())
|
||||
|| t1s.stream().noneMatch(c -> StrUtil.equals(c.getIDNRK(), d.getMaterialNo()) && StrUtil.equals(c.getMATNR(), d.getParentMaterialNo()))) {
|
||||
T1DTO t1 = new T1DTO();
|
||||
t1.setID(RandomUtil.randomNumbers(5));
|
||||
t1.setMATNR(d.getParentMaterialNo());
|
||||
t1.setMENGE(d.getNum().toString());
|
||||
t1.setPOSTP(d.getProjectType());
|
||||
t1.setDATUM(dateYMD);
|
||||
|
||||
t1.setMEINS(d.getMaterialUnit());
|
||||
if (BomConstant.PROJECT_TYPE_TEMPORARY.equals(d.getProjectType())) {
|
||||
t1.setIDNRK("");
|
||||
t1.setPOTX1(d.getMaterialDesc());
|
||||
} else {
|
||||
t1.setIDNRK(d.getMaterialNo());
|
||||
BaseMaterialVO bm = materialBaseInfos.stream().filter(m -> m.getMaterialNo().equals(d.getMaterialNo())).findFirst().orElse(null);
|
||||
if (!Objects.isNull(bm)) {
|
||||
t1.setMEINS(bm.getMaterialUnit());
|
||||
t1.setMEINS(d.getMaterialUnit());
|
||||
if (BomConstant.PROJECT_TYPE_TEMPORARY.equals(d.getProjectType())) {
|
||||
t1.setIDNRK("");
|
||||
t1.setPOTX1(d.getMaterialDesc());
|
||||
} else {
|
||||
t1.setIDNRK(d.getMaterialNo());
|
||||
BaseMaterialVO bm = materialBaseInfos.stream().filter(m -> m.getMaterialNo().equals(d.getMaterialNo())).findFirst().orElse(null);
|
||||
if (!Objects.isNull(bm)) {
|
||||
t1.setMEINS(bm.getMaterialUnit());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t1s.add(t1);
|
||||
t1s.add(t1);
|
||||
}
|
||||
});
|
||||
sapDto.setT1(t1s);
|
||||
SapStatusEnum state = SapStatusEnum.PUB_ERROR_ALL;
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ public class SapOpUtilService {
|
|||
log.info("导入到SAP--参数:" + JSON.toJSONString(params));
|
||||
SapResult sapResult = sapService.doSapFun(params);
|
||||
if (!sapResult.isSuccess()) {
|
||||
throw new NflgBusinessException(STATE.ServiceConnectRefused, "接口连接失败," + sapResult.getMsg());
|
||||
throw new NflgBusinessException(STATE.RouteServiceError, sapResult.getMsg());
|
||||
}
|
||||
Map<String, List<Map<String, Object>>> outTablesMap = sapResult.getOutTablesMap();
|
||||
log.info("导入到SAP--返回值:" + JSON.toJSONString(outTablesMap));
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ public class SapService implements ApplicationContextAware {
|
|||
res.setOutTablesMap(outTablesMap);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("导入SAP出错", e);
|
||||
log.error("导入SAP失败", e);
|
||||
res.setCode(500);
|
||||
res.setSuccess(false);
|
||||
res.setMsg(e.getMessage());
|
||||
|
|
|
|||
Loading…
Reference in New Issue