同步sap
This commit is contained in:
parent
5fc1a33109
commit
9893678ea2
|
|
@ -8,6 +8,7 @@ import com.nflg.product.bomnew.constant.PBomEditStatusEnum;
|
|||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
||||
import com.nflg.product.bomnew.pojo.dto.*;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewTechnologyPackageTypeEntity;
|
||||
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
|
||||
|
|
@ -245,8 +246,8 @@ public class PBomApi extends BaseApi {
|
|||
|
||||
@PostMapping("sysnSapTest")
|
||||
@ApiOperation("同步sap测试")
|
||||
public ResultVO<Boolean> sysnSapTest(@RequestBody List<ImportToSapDTO> parems) {
|
||||
ResultVO<Boolean> result = sapOpUtilService.importPBomToSap(parems);
|
||||
public ResultVO<Boolean> sysnSapTest(@RequestBody ImportSapParamDTO param) {
|
||||
ResultVO<Boolean> result = sapOpUtilService.importToSap(param);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.nflg.product.bomnew.constant;
|
||||
|
||||
|
||||
public class BomConstant {
|
||||
|
||||
public static final String SAP_EBOM="2";
|
||||
public static final String SAP_PBOM="P";
|
||||
public static final String SAP_MBOM="1";
|
||||
|
||||
public static final String SAP_YDBOM="1";
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.nflg.product.bomnew.pojo.dto.sap.impart2;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class ImportSapParam2DTO {
|
||||
|
||||
@ApiModelProperty("流程标题,默认“主数据平台")
|
||||
private String I_LCBT = "主数据平台";
|
||||
|
||||
@ApiModelProperty("默认X")
|
||||
private String I_ACT = "X";
|
||||
|
||||
private String ZID = "";
|
||||
|
||||
@ApiModelProperty("分工厂")
|
||||
private String I_WERKS;
|
||||
|
||||
@ApiModelProperty(" EBOM: 2;PBOM: P;MBOM: 1;移动破: 1")
|
||||
private String I_STLAN;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.nflg.product.bomnew.pojo.dto.sap.impart2;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class ImportSapParamDTO {
|
||||
|
||||
@ApiModelProperty("流程标题,默认“主数据平台")
|
||||
private String I_LCBT="主数据平台";
|
||||
|
||||
@ApiModelProperty("默认X")
|
||||
private String I_ACT="X";
|
||||
|
||||
private String ZID="";
|
||||
|
||||
@ApiModelProperty("分工厂")
|
||||
private String I_WERKS;
|
||||
|
||||
@ApiModelProperty(" EBOM: 2;PBOM: P;MBOM: 1;移动破: 1")
|
||||
private String I_STLAN;
|
||||
|
||||
|
||||
@ApiModelProperty("详情")
|
||||
private List<T1DTO> T1;
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package com.nflg.product.bomnew.pojo.dto.sap.impart2;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class T1DTO {
|
||||
|
||||
@ApiModelProperty("客户端")
|
||||
private String MANDT="";
|
||||
|
||||
@ApiModelProperty("流程标题")
|
||||
private String ZLCBT="";
|
||||
|
||||
@ApiModelProperty("--序号")
|
||||
private String ID="";
|
||||
|
||||
@ApiModelProperty("日期")
|
||||
private String DATUM="";
|
||||
|
||||
@ApiModelProperty("日期")
|
||||
private String UZEIT="";
|
||||
|
||||
@ApiModelProperty("父级物料")
|
||||
private String MATNR="";
|
||||
|
||||
@ApiModelProperty("物料描述")
|
||||
private String MAKTX="";
|
||||
|
||||
@ApiModelProperty("项目类别")
|
||||
private String POSTP="";
|
||||
|
||||
@ApiModelProperty("子级物料")
|
||||
private String IDNRK;
|
||||
|
||||
@ApiModelProperty("子级物料描述")
|
||||
private String MAKTX1;
|
||||
|
||||
@ApiModelProperty("组件数量")
|
||||
private String MENGE;
|
||||
|
||||
@ApiModelProperty("单位")
|
||||
private String MEINS;
|
||||
|
||||
@ApiModelProperty("bom项目文本")
|
||||
private String POTX1="";
|
||||
|
||||
@ApiModelProperty("是否发货")
|
||||
private String SFFH="";
|
||||
|
||||
@ApiModelProperty("物料检查结果")
|
||||
private String ZCHECK="";
|
||||
|
||||
@ApiModelProperty("导入状态描述")
|
||||
private String STATUS="";
|
||||
|
||||
@ApiModelProperty("导入标志")
|
||||
private String FLAG="";
|
||||
}
|
||||
|
||||
|
|
@ -20,10 +20,12 @@ import com.nflg.product.bomnew.pojo.dto.*;
|
|||
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapChildDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapParentDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
|
||||
import com.nflg.product.bomnew.pojo.entity.*;
|
||||
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.*;
|
||||
import com.nflg.product.bomnew.service.domain.PBom.*;
|
||||
import com.nflg.product.bomnew.service.domain.Sap;
|
||||
import com.nflg.product.bomnew.util.*;
|
||||
import com.nflg.product.bomnew.util.LevelNumUtil;
|
||||
import nflg.product.common.constant.STATE;
|
||||
|
|
@ -616,12 +618,12 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
}
|
||||
}
|
||||
//非Q
|
||||
// List<BomNewPbomParentVO> noQList = childrenVO.stream().filter(u -> !u.getProjectType().equals("Q")).collect(Collectors.toList());
|
||||
// {
|
||||
// for (BomNewPbomParentVO noQVo : noQList) {
|
||||
// intiNotQFac(noQVo, childrenVO);
|
||||
// }
|
||||
// }
|
||||
List<BomNewPbomParentVO> noQList = childrenVO.stream().filter(u -> !u.getProjectType().equals("Q")).collect(Collectors.toList());
|
||||
{
|
||||
for (BomNewPbomParentVO noQVo : noQList) {
|
||||
intiNotQFac(noQVo, childrenVO);
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(result)) {
|
||||
pbomChildService.saveOrUpdateBatch(result);
|
||||
}
|
||||
|
|
@ -649,7 +651,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
//父级
|
||||
setParentFac(parentVO, child, EBomConstant.MAIN_FACTORY_CODE_1010);
|
||||
//子级
|
||||
setSubNodeFac(parentVO, child, EBomConstant.MAIN_FACTORY_CODE_1010);
|
||||
setSubNodeFacExcludeHasFac(parentVO, child, EBomConstant.MAIN_FACTORY_CODE_1010);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -678,6 +680,19 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
}
|
||||
}
|
||||
|
||||
private void setSubNodeFacExcludeHasFac(BomNewPbomParentVO parentVO, List<BomNewPbomParentVO> child, String facCode) {
|
||||
String[] numSplit = parentVO.getLevelNumber().toString().split(".");
|
||||
String zero = "1" + StrUtil.padAfter("0", (numSplit.length > 1 ? numSplit[1].length() : 0), "0");
|
||||
BigDecimal bNodeLevel = NumberUtil.add(parentVO.getLevelNumber(), (NumberUtil.div(new BigDecimal(1), new BigDecimal(zero))));
|
||||
List<BomNewPbomParentVO> subNodes = child.stream().filter(u -> u.getLevelNumber().compareTo(parentVO.getLevelNumber()) > 0 && u.getLevelNumber().compareTo(bNodeLevel) < 0).collect(Collectors.toList());
|
||||
for (BomNewPbomParentVO node : subNodes) {
|
||||
if(StrUtil.isBlank(node.getProductionFactoryCode())) {
|
||||
node.setProductionFactoryCode(facCode);
|
||||
node.setProductionFactoryCodeInputType(ProductionFactoryCodeInputTypeEnum.RULE_MATCH.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void reConvertToMBom(Long bomRowId, List<Long> backRowId) {
|
||||
|
||||
|
|
@ -789,84 +804,21 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
|
||||
}
|
||||
|
||||
private void saySyncDEMO() {
|
||||
ImportToSapDTO result = new ImportToSapDTO();
|
||||
SimpleDateFormat spt = new SimpleDateFormat("yyyy-MM-dd");
|
||||
ImportToSapParentDTO sapParent = new ImportToSapParentDTO();
|
||||
sapParent.setWERKS("1010");
|
||||
sapParent.setMATNR("2100564157");
|
||||
sapParent.setSTLAN("2");
|
||||
sapParent.setBMENG("1");
|
||||
sapParent.setBMEIN("PC");
|
||||
sapParent.setSTLST("3");
|
||||
sapParent.setDATUV("20240116");
|
||||
|
||||
result.setParent(sapParent);
|
||||
List<ImportToSapChildDTO> childResult = new ArrayList<>();
|
||||
ImportToSapChildDTO childEnt = new ImportToSapChildDTO();
|
||||
childEnt.setIDNRK("1100021745");
|
||||
childEnt.setPOSNR("045");
|
||||
childEnt.setPOSTP("F");
|
||||
childEnt.setMENGE("6");
|
||||
childEnt.setMEINS("PC");
|
||||
childResult.add(childEnt);
|
||||
|
||||
result.setChildList(childResult);
|
||||
|
||||
|
||||
List<ImportToSapDTO> sapParams = new ArrayList<>();
|
||||
|
||||
sapParams.add(result);
|
||||
ResultVO<Boolean> syncResult = sapOpUtilService.importPBomToSap(sapParams);
|
||||
VUtils.isTure(!syncResult.getState().equals(STATE.Success)).throwMessage("同步SAP失败:" + syncResult.getMsg());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void importSap(BomNewPbomParentEntity parent, List<BomNewPbomParentVO> children) {
|
||||
|
||||
List<BomNewPbomParentVO> pbom = children.stream().filter(u -> u.getBomRowId() > 0).collect(Collectors.toList());
|
||||
List<BomNewPbomParentVO> parentChild = children.stream().filter(u -> u.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList());
|
||||
List<ImportToSapDTO> sapParams = new ArrayList<>();
|
||||
sapParams.add(buildSapBom(Convert.convert(BomNewPbomParentVO.class, parent), parentChild));
|
||||
|
||||
for (BomNewPbomParentVO pt : pbom) {
|
||||
List<BomNewPbomParentVO> pChild = children.stream().filter(u -> u.getParentRowId().equals(pt.getBomRowId())).collect(Collectors.toList());
|
||||
sapParams.add(buildSapBom(Convert.convert(BomNewPbomParentVO.class, parent), pChild));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(sapParams)) {
|
||||
ResultVO<Boolean> booleanResultVO = sapOpUtilService.importPBomToSap(sapParams);
|
||||
Sap sap=new Sap(parent,children);
|
||||
ImportSapParamDTO importParm = sap.buildSyncSapParam();
|
||||
if (CollUtil.isNotEmpty(importParm.getT1())) {
|
||||
ResultVO<Boolean> booleanResultVO = sapOpUtilService.importToSap(importParm);
|
||||
VUtils.isTure(!booleanResultVO.getState().equals(STATE.Success)).throwMessage("同步SAP失败:" + booleanResultVO.getMsg());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ImportToSapDTO buildSapBom(BomNewPbomParentVO parentVO, List<BomNewPbomParentVO> children) {
|
||||
|
||||
ImportToSapDTO result = new ImportToSapDTO();
|
||||
ImportToSapParentDTO sapParent = new ImportToSapParentDTO();
|
||||
DateTimeFormatter ymd = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
sapParent.setWERKS(parentVO.getFacCode());
|
||||
sapParent.setMATNR(parentVO.getMaterialNo());
|
||||
sapParent.setSTLAN("2");
|
||||
sapParent.setBMENG(parentVO.getNum().toString());
|
||||
sapParent.setBMEIN(parentVO.getMaterialUnit());
|
||||
sapParent.setSTLST("3");
|
||||
sapParent.setDATUV(parentVO.getCreatedTime().format(ymd));
|
||||
|
||||
List<ImportToSapChildDTO> childResult = new ArrayList<>();
|
||||
for (BomNewPbomParentVO child : children) {
|
||||
ImportToSapChildDTO childEnt = new ImportToSapChildDTO();
|
||||
childEnt.setIDNRK(child.getMaterialNo());
|
||||
childEnt.setPOSNR(child.getOrderNumber());
|
||||
childEnt.setPOSTP(child.getProjectType());
|
||||
childEnt.setMENGE(child.getNum().toString());
|
||||
childEnt.setMEINS(child.getMaterialUnit());
|
||||
childResult.add(childEnt);
|
||||
}
|
||||
|
||||
result.setParent(sapParent);
|
||||
result.setChildList(childResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.nflg.product.bomnew.pojo.dto.sap.ImportToSapDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.sap.SapReqParams;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
|
|
@ -27,7 +29,13 @@ public class SapOpUtilService {
|
|||
SapService sapService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* sap 创建
|
||||
*
|
||||
* @param sapList
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public ResultVO<Boolean> importPBomToSap(List<ImportToSapDTO> sapList) {
|
||||
if (CollUtil.isEmpty(sapList)) {
|
||||
return null;
|
||||
|
|
@ -68,6 +76,58 @@ public class SapOpUtilService {
|
|||
}
|
||||
}
|
||||
|
||||
return ResultVO.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 覆盖
|
||||
*
|
||||
* @param impartSapParamDTO
|
||||
* @return
|
||||
*/
|
||||
public ResultVO<Boolean> importToSap(ImportSapParamDTO impartSapParamDTO) {
|
||||
if (CollUtil.isEmpty(impartSapParamDTO.getT1())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
SapReqParams params = new SapReqParams();
|
||||
// 接口名
|
||||
params.setFunName("ZRFC_PP_003");
|
||||
|
||||
Map<String, Map<String, Object>> inputStructure = new HashMap<>();
|
||||
|
||||
ImportSapParam2DTO pp=Convert.convert(ImportSapParam2DTO.class ,impartSapParamDTO);
|
||||
Map<String, Object> parentMap = Convert.convert(new TypeReference<Map<String, Object>>() {
|
||||
}, pp);
|
||||
inputStructure.put("I_STKO", parentMap);
|
||||
params.setInputParams(parentMap);
|
||||
|
||||
Map<String, List<Map<String, String>>> inputTables = new HashMap<>();
|
||||
List<Map<String, String>> childMapList = Convert.convert(new TypeReference<List<Map<String, String>>>() {
|
||||
}, impartSapParamDTO.getT1());
|
||||
inputTables.put("T1", childMapList);
|
||||
params.setInputTables(inputTables);
|
||||
|
||||
try {
|
||||
log.info("PBOM导入到SAP--参数:" + JSON.toJSONString(params));
|
||||
SapResult sapResult = sapService.doSapFun(params);
|
||||
Map<String, Object> exportMap = sapResult.getExportMap();
|
||||
if (!sapResult.isSuccess()) {
|
||||
return ResultVO.error(STATE.Error, "接口连接失败"+sapResult.getMsg());
|
||||
}
|
||||
|
||||
log.info("PBOM导入到SAP--返回值:" + JSON.toJSONString(exportMap));
|
||||
String eErrmsg = String.valueOf(exportMap.get("E_ERRMSG"));
|
||||
if (StrUtil.isNotEmpty(eErrmsg) && eErrmsg!="null") {
|
||||
return ResultVO.error(STATE.Error, eErrmsg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return ResultVO.error(STATE.Error, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
return ResultVO.success();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package com.nflg.product.bomnew.service.domain;
|
||||
|
||||
import com.nflg.product.bomnew.constant.BomConstant;
|
||||
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;
|
||||
|
||||
public class Sap {
|
||||
|
||||
|
||||
private BomNewPbomParentEntity parent;
|
||||
|
||||
private List<BomNewPbomParentVO> children;
|
||||
|
||||
public Sap(BomNewPbomParentEntity parent, List<BomNewPbomParentVO> children){
|
||||
|
||||
this.parent=parent;
|
||||
this.children=children;
|
||||
}
|
||||
|
||||
public ImportSapParamDTO buildSyncSapParam(){
|
||||
ImportSapParamDTO result=new ImportSapParamDTO();
|
||||
result.setZID(parent.getRowId().toString());
|
||||
result.setI_WERKS(parent.getFacCode());
|
||||
result.setI_STLAN(BomConstant.SAP_PBOM);
|
||||
|
||||
result.setT1(new ArrayList<>());
|
||||
|
||||
for (BomNewPbomParentVO child : children){
|
||||
T1DTO t1=new T1DTO();
|
||||
t1.setID(child.getOrderNumber());
|
||||
t1.setMATNR(parent.getMaterialNo());
|
||||
t1.setIDNRK(child.getMaterialNo());
|
||||
t1.setMEINS(child.getMaterialUnit());
|
||||
t1.setMENGE(child.getNum().toString());
|
||||
t1.setPOSTP(child.getProjectType());
|
||||
t1.setMAKTX(parent.getMaterialDesc());
|
||||
t1.setMAKTX1(child.getMaterialDesc());
|
||||
result.getT1().add(t1);
|
||||
}
|
||||
return result;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue