update - SAP接口

master
yinq 12 months ago
parent 8390b3d1b9
commit 6a7e8d3222

@ -1,5 +1,6 @@
package com.aucma.api.controller;
import com.aucma.api.domain.dto.SAPBOMPortDto;
import com.aucma.api.domain.dto.SAPPortDto;
import com.aucma.api.domain.dto.WERKSDto;
import com.aucma.api.service.ISAPPortService;
@ -92,7 +93,7 @@ public class SAPPortController extends BaseController {
*/
@PostMapping("/getBaseBomInfo")
public AjaxResult getBaseBomInfo(@RequestBody Map paramMap) {
SAPPortDto sapPortDto = new SAPPortDto();
SAPBOMPortDto sapPortDto = new SAPBOMPortDto();
sapPortDto.setStartDate(String.valueOf(paramMap.get("NDATE")));
sapPortDto.setEndDate(String.valueOf(paramMap.get("EDATE")));
HashMap<String,List<HashMap<String,String>>> werksMap = (HashMap<String,List<HashMap<String,String>>>)paramMap.get("WERKS");

@ -0,0 +1,68 @@
package com.aucma.api.domain.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @Author YinQ
* @create 2023-09-26 14:46
*/
public class SAPBOMPortDto {
private static final long serialVersionUID = 1L;
/**
*
*/
@JsonProperty(value = "NDATE")
private String startDate;
/**
*
*/
@JsonProperty(value = "EDATE")
private String endDate;
/**
*
*/
@JsonProperty(value = "XTYPE")
private String type;
/**
*
*/
@JsonProperty(value = "WERKS")
private WERKSDto factoryCodes;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public WERKSDto getFactoryCodes() {
return factoryCodes;
}
public void setFactoryCodes(WERKSDto factoryCodes) {
this.factoryCodes = factoryCodes;
}
}

@ -18,7 +18,7 @@ public class SAPResultVo {
private HashMap<String, List<HashMap<String, String>>> O_TAB;
@JsonProperty(value = "WERKS")
private String WERKS;
private WERKSDto WERKS;
@JsonProperty(value = "O_RETURN")
private WERKSDto O_RETURN;
@ -31,11 +31,11 @@ public class SAPResultVo {
O_TAB = o_TAB;
}
public String getWERKS() {
public WERKSDto getWERKS() {
return WERKS;
}
public void setWERKS(String WERKS) {
public void setWERKS(WERKSDto WERKS) {
this.WERKS = WERKS;
}
@ -47,6 +47,9 @@ public class SAPResultVo {
O_RETURN = o_RETURN;
}
public SAPResultVo() {
}
@Override
public String toString() {
return "SAPResultVo{" +

@ -1,5 +1,6 @@
package com.aucma.api.service;
import com.aucma.api.domain.dto.SAPBOMPortDto;
import com.aucma.api.domain.dto.SAPPortDto;
import com.aucma.base.domain.BaseDeviceLedger;
import com.aucma.base.domain.BaseMaterialInfo;
@ -44,6 +45,6 @@ public interface ISAPPortService {
* @param sapPortDto
* @return
*/
List<OrderBomInfo> getSapOrderBomInfo(SAPPortDto sapPortDto);
List<OrderBomInfo> getSapOrderBomInfo(SAPBOMPortDto sapPortDto);
}

@ -1,9 +1,9 @@
package com.aucma.api.service.impl;
import com.aucma.api.domain.dto.SAPBOMPortDto;
import com.aucma.api.domain.dto.SAPPortDto;
import com.aucma.api.domain.dto.WERKSDto;
import com.aucma.api.domain.vo.SAPResultBomVo;
import com.aucma.api.domain.vo.SAPResultOrderInfoVo;
import com.aucma.api.domain.vo.SAPResultVo;
import com.aucma.api.service.ISAPPortService;
@ -16,7 +16,6 @@ import com.aucma.base.domain.BaseOrderInfo;
import com.aucma.base.domain.OrderBomInfo;
import com.aucma.common.exception.base.BaseException;
import com.aucma.common.utils.StringUtils;
import com.aucma.common.utils.http.HttpUtils;
import com.aucma.system.utils.PortLogUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
@ -62,24 +61,19 @@ public class SAPPortServiceImpl implements ISAPPortService {
requestParam = objectMapper.writeValueAsString(sapPortDto);
result = ApiUtils.sendSAPHttpPost(SAPConstants.SAP_PREFIX_URL + SAPConstants.MATERIAL_URL, requestParam);
// 处理接口返回消息
// result = "{\"O_TAB\":{\"item\":[{\"MAKTX\":\"压缩机,GP14TG,R134a,ACC\",\"WERKS\":\"2004\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000125\"},{\"MAKTX\":\"压缩机,GP14TG,R134a,ACC\",\"WERKS\":\"2006\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000125\"},{\"MAKTX\":\"压缩机,NL7CLX,R404a,丹佛斯\",\"WERKS\":\"2004\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000126\"},{\"MAKTX\":\"压缩机,NL7CLX,R404a,丹佛斯\",\"WERKS\":\"2006\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000126\"},{\"MAKTX\":\"压缩机,HVY57AA,R600a,奥地利ACC\",\"WERKS\":\"2004\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000127\"},{\"MAKTX\":\"压缩机,HVY57AA,R600a,奥地利ACC\",\"WERKS\":\"2006\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000127\"},{\"MAKTX\":\"压缩机,HVY67AA,R600a,奥地利ACC\",\"WERKS\":\"2004\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000128\"},{\"MAKTX\":\"压缩机,HVY67AA,R600a,奥地利ACC\",\"WERKS\":\"2006\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000128\"},{\"MAKTX\":\"压缩机,MR22FB,R404a,ACC\",\"WERKS\":\"2004\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000129\"},{\"MAKTX\":\"压缩机,MR22FB,R404a,ACC\",\"WERKS\":\"2006\",\"MTART\":\"ROH\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-21\",\"MATNR\":\"000000003000000129\"},{\"MAKTX\":\"盖后加固体,BC/BD-127FA\",\"WERKS\":\"2004\",\"MTART\":\"HALB\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-06\",\"MATNR\":\"000000008106000102\"},{\"MAKTX\":\"SC-246,YZXGWB乳品\",\"WERKS\":\"2006\",\"MTART\":\"FERT\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-22\",\"MATNR\":\"000000009002003478\"},{\"MAKTX\":\"SD-460,YZXGW蒙牛冰品\",\"WERKS\":\"2004\",\"MTART\":\"FERT\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-22\",\"MATNR\":\"000000009000004735\"},{\"MAKTX\":\"BC-100E,特需\",\"WERKS\":\"2006\",\"MTART\":\"FERT\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-02\",\"MATNR\":\"000000009001002406\"},{\"MAKTX\":\"BD(C)-310T,特需\",\"WERKS\":\"2004\",\"MTART\":\"FERT\",\"MEINS\":\"EA\",\"UDATE\":\"2019-08-20\",\"MATNR\":\"000000009000000225\"}]},\"WERKS\":null,\"O_RETURN\":{\"item\":[{\"MESSAGE\":\"查询成功1\",\"ID\":\" 0\",\"TYPE\":\"S\"}]}}";
ObjectMapper resultMapper = new ObjectMapper();
// 将 JSON 字符串 转换为 Java 对象
SAPResultVo resultVo = resultMapper.readValue(result, SAPResultVo.class);
//判断返回数据是否正确
if (StringUtils.isNull(resultVo.getO_RETURN()) || !" 0".equals(resultVo.getO_RETURN().getItem().get(0).get("ID"))){
Integer integer = Integer.valueOf(resultVo.getO_RETURN().getItem().get(0).get("ID"));
if (integer!=0){
if (StringUtils.isNull(resultVo.getO_RETURN()) || !resultVo.getO_RETURN().getItem().get(0).get("ID").contains("0")){
throw new BaseException("处理接口返回消息错误ID不为0或O_RETURN为空");
}
}
//转物料实体类 保存数据
materialVos = storageService.insertSAPMaterialInfo(resultVo);
//保存接口日志
PortLogUtils.savePortLog(werks.getItem().get(0).get("WERKS"), "获取SAP物料主数据" + intervalDate, "getSAPMaterialData", requestParam, result, null);
} catch (Exception e) {
//保存接口日志
System.out.println(e.getMessage());
PortLogUtils.savePortLog(werks.getItem().get(0).get("WERKS"), "获取SAP物料主数据" + intervalDate, "getSAPMaterialData", requestParam, result, e.toString());
}
return materialVos;
@ -114,13 +108,9 @@ public class SAPPortServiceImpl implements ISAPPortService {
SAPResultOrderInfoVo resultVo = resultMapper.readValue(result, SAPResultOrderInfoVo.class);
//判断返回数据是否正确
if (StringUtils.isNull(resultVo.getO_RETURN()) || !" 0".equals(resultVo.getO_RETURN().getItem().get(0).get("ID"))){
String id = resultVo.getO_RETURN().getItem().get(0).get("ID");
Integer integer = Integer.valueOf(id);
if (integer!=0&&integer!=null){
if (StringUtils.isNull(resultVo.getO_RETURN()) || !resultVo.getO_RETURN().getItem().get(0).get("ID").contains("0")){
throw new BaseException("处理接口返回消息错误ID不为0或O_RETURN为空");
}
}
//转物料实体类 保存数据
baseOrderInfoVos = storageService.insertSAPBaseOrderInfo(resultVo);
//保存接口日志
@ -161,7 +151,7 @@ public class SAPPortServiceImpl implements ISAPPortService {
// 将 JSON 字符串转换为 Java 对象
SAPResultOrderInfoVo resultVo = resultMapper.readValue(result, SAPResultOrderInfoVo.class);
//判断返回数据是否正确
if (StringUtils.isNull(resultVo.getO_RETURN()) || !" 0".equals(resultVo.getO_RETURN().getItem().get(0).get("ID"))){
if (StringUtils.isNull(resultVo.getO_RETURN()) || !resultVo.getO_RETURN().getItem().get(0).get("ID").contains("0")){
throw new BaseException("处理接口返回消息错误ID不为0或O_RETURN为空");
}
//转物料实体类 保存数据
@ -182,10 +172,11 @@ public class SAPPortServiceImpl implements ISAPPortService {
* @return
*/
@Override
public List<OrderBomInfo> getSapOrderBomInfo(SAPPortDto sapPortDto) {
public List<OrderBomInfo> getSapOrderBomInfo(SAPBOMPortDto sapPortDto) {
String startDate = sapPortDto.getStartDate();
String endDate = sapPortDto.getEndDate();
WERKSDto werks = sapPortDto.getFactoryCodes();
sapPortDto.setType("S");
String intervalDate = "(" + startDate + "——" + endDate + ")";
if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate) || StringUtils.isNull(werks)) {
return null;
@ -205,21 +196,15 @@ public class SAPPortServiceImpl implements ISAPPortService {
// 将 JSON 字符串转换为 Java 对象
SAPResultOrderInfoVo resultVo = resultMapper.readValue(result, SAPResultOrderInfoVo.class);
//判断返回数据是否正确
if (StringUtils.isNull(resultVo.getO_RETURN()) || !" 0".equals(resultVo.getO_RETURN().getItem().get(0).get("ID"))){
String id = resultVo.getO_RETURN().getItem().get(0).get("ID");
String s = id.replaceAll(" ", "");
if (0!=Long.valueOf(s)){
if (StringUtils.isNull(resultVo.getO_RETURN()) || !resultVo.getO_RETURN().getItem().get(0).get("ID").contains("0")){
throw new BaseException("处理接口返回消息错误ID不为0或O_RETURN为空");
}
}
//转物料实体类 保存数据
orderBomInfosVos = storageService.insertSAPOrderBomInfo(resultVo);
//保存接口日志
PortLogUtils.savePortLog(werks.getItem().get(0).get("WERKS"), "获取产品bom数据" + intervalDate, "getSapBaseBomInfo", requestParam, result, null);
} catch (Exception e) {
//保存接口日志
System.out.println(e.getMessage());
PortLogUtils.savePortLog(werks.getItem().get(0).get("WERKS"), "获取产品bom数据" + intervalDate, "getSapBaseBomInfo", requestParam, result, e.toString());
}
return orderBomInfosVos;

@ -3,6 +3,7 @@ package com.aucma.api.service.impl;
import com.aucma.api.domain.vo.SAPResultOrderInfoVo;
import com.aucma.api.domain.vo.SAPResultVo;
import com.aucma.api.service.ISAPPutStorageService;
import com.aucma.api.utils.SAPConstants;
import com.aucma.base.domain.BaseDeviceLedger;
import com.aucma.base.domain.BaseMaterialInfo;
import com.aucma.base.domain.BaseOrderInfo;
@ -12,6 +13,7 @@ import com.aucma.base.service.IBaseMaterialInfoService;
import com.aucma.base.service.IBaseOrderInfoService;
import com.aucma.base.service.IOrderBomInfoService;
import com.aucma.common.utils.DateUtils;
import com.aucma.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -53,6 +55,9 @@ public class SAPPutStorageServiceImpl implements ISAPPutStorageService {
ArrayList<BaseMaterialInfo> baseMaterialInfoArrayList = new ArrayList<>();
List<HashMap<String, String>> itemList = resultVo.getO_TAB().get("item");
for (HashMap<String, String> map : itemList) {
if (StringUtils.isEmpty(map.get("WERKS")) || !map.get("WERKS").equals(SAPConstants.FACTORY_CODE)){
continue;
}
BaseMaterialInfo baseMaterialInfo = new BaseMaterialInfo();
baseMaterialInfo.setPlantCode(map.get("WERKS"));
baseMaterialInfo.setMaterialCode(map.get("MATNR"));
@ -64,6 +69,8 @@ public class SAPPutStorageServiceImpl implements ISAPPutStorageService {
materialInfo.setMaterialType(map.get("MTART"));
materialInfo.setPlantCode(map.get("WERKS"));
materialInfo.setMaterialUnit(map.get("MEINS"));
materialInfo.setMaterialMatkl(map.get("MATKL"));
materialInfo.setIncrementDate(DateUtils.dateTime(DateUtils.YYYY_MM_DD,map.get("UDATE")));
baseMaterialInfoService.insertBaseMaterialInfo(materialInfo);
baseMaterialInfoArrayList.add(materialInfo);
}
@ -79,6 +86,9 @@ public class SAPPutStorageServiceImpl implements ISAPPutStorageService {
ArrayList<BaseOrderInfo> baseOrderInfoList = new ArrayList<>();
List<HashMap<String, String>> itemList = resultVo.getO_TAB().get("item");
for (HashMap<String, String> map : itemList) {
if (StringUtils.isEmpty(map.get("WERKS")) || !map.get("WERKS").equals(SAPConstants.FACTORY_CODE)){
continue;
}
BaseOrderInfo boInfo = new BaseOrderInfo();
boInfo.setOrderCode(map.get("AUFNR"));
boInfo.setMaterialCode(map.get("MATNR"));
@ -98,7 +108,7 @@ public class SAPPutStorageServiceImpl implements ISAPPutStorageService {
baseOrderInfo.setOrderType(map.get("AUART"));
baseOrderInfo.setBeginDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("GLTRP")));
baseOrderInfo.setEndDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("GSTRP")));
baseOrderInfo.setCreatedTime(DateUtils.getNowDate());
baseOrderInfoService.insertBaseOrderInfo(baseOrderInfo);
baseOrderInfoList.add(baseOrderInfo);
}
@ -120,6 +130,9 @@ public class SAPPutStorageServiceImpl implements ISAPPutStorageService {
ArrayList<BaseDeviceLedger> baseDeviceLedgerArrayList = new ArrayList<>();
List<HashMap<String, String>> itemList = resultVo.getO_TAB().get("item");
for (HashMap<String, String> map : itemList) {
if (StringUtils.isEmpty(map.get("WERKS")) || !map.get("WERKS").equals(SAPConstants.FACTORY_CODE)){
continue;
}
BaseDeviceLedger device = new BaseDeviceLedger();
device.setCostCenter(map.get("KOSTL"));;
device.setDeviceCode(map.get("EQUNR"));
@ -151,8 +164,10 @@ public class SAPPutStorageServiceImpl implements ISAPPutStorageService {
public ArrayList<OrderBomInfo> insertSAPOrderBomInfo(SAPResultOrderInfoVo resultVo) throws ParseException {
ArrayList<OrderBomInfo> orderBomInfoList = new ArrayList<>();
List<HashMap<String, String>> itemList = resultVo.getO_TAB().get("item");
for (HashMap<String, String> map : itemList) {
if (StringUtils.isEmpty(map.get("WERKS")) || !map.get("WERKS").equals(SAPConstants.FACTORY_CODE)){
continue;
}
OrderBomInfo bomInfo = new OrderBomInfo();
bomInfo.setMaterialCode(map.get("IDNRK"));
bomInfo.setParentId(map.get("MATNR"));

@ -1,5 +1,6 @@
package com.aucma.api.task;
import com.aucma.api.domain.dto.SAPBOMPortDto;
import com.aucma.api.domain.dto.SAPPortDto;
import com.aucma.api.domain.dto.WERKSDto;
import com.aucma.api.service.ISAPPortService;
@ -57,7 +58,11 @@ public class SAPTask {
*/
public void SAPBaseBomInfoDataTask(String factoryCode, Long days) {
SAPPortDto sapPortDto = this.SAPRequestDataAssembly(factoryCode, days);
portService.getSapOrderBomInfo(sapPortDto);
SAPBOMPortDto sapbomPortDto = new SAPBOMPortDto();
sapbomPortDto.setStartDate(sapPortDto.getStartDate());
sapbomPortDto.setEndDate(sapPortDto.getEndDate());
sapbomPortDto.setFactoryCodes(sapPortDto.getFactoryCodes());
portService.getSapOrderBomInfo(sapbomPortDto);
}

@ -25,7 +25,9 @@ public class ApiUtils {
.header("Authorization", "Basic " + Base64.getUrlEncoder().
encodeToString((SAPConstants.USER_NAME + ":" + SAPConstants.PASS_WORD).getBytes()))
.body(jsonData) // 设置JSON格式的请求体
.contentType("application/json"); // 设置Content-Type为application/json
.contentType("application/json") // 设置Content-Type为application/json
.setConnectionTimeout(1000 * 10) // 设置请求连接超时时间
;
// 发送POST请求
HttpResponse httpResponse = request.execute();

@ -46,6 +46,11 @@ public class SAPConstants {
*/
public static final String PRODUCTS_BOM_URL = "/SdGetSB/SdSapGetBomToMesSvcRSProxy/merge";
/**
*
*/
public static final String FACTORY_CODE = "1301";
@Value("${sap.prefix}")
public void setPrefix(String value) {

@ -116,7 +116,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
// 开放SAP接口调试
// .antMatchers(HttpMethod.POST, "/sap/port/**").permitAll()
.antMatchers(HttpMethod.POST, "/sap/port/**").permitAll()
// 开放看板接口
.antMatchers(HttpMethod.POST, "/boardReport/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证

Loading…
Cancel
Save