优化封装post提交asp
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.zt.plat.module.erp.common.conf;
|
package com.zt.plat.module.erp.common.conf;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@@ -144,50 +145,50 @@ public class ErpConfig {
|
|||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
|
ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
|
||||||
|
|
||||||
return postResult(response);
|
// 解析响应结果
|
||||||
|
String responseBody = response.getBody();
|
||||||
|
if (responseBody.isEmpty()) {
|
||||||
|
throw new RuntimeException("ERP接口返回结果为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject jsonResponse = JSON.parseObject(responseBody);
|
||||||
|
if (jsonResponse == null) {
|
||||||
|
throw new RuntimeException("ERP接口响应无法解析为JSON");
|
||||||
|
}
|
||||||
|
return postResult(jsonResponse);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("调用ERP RFC接口失败:" + e.getMessage(), e);
|
throw new RuntimeException("调用ERP RFC接口失败: " + e);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST请求处理
|
// POST请求处理
|
||||||
public HashMap<String, String> postResult(ResponseEntity<String> result) {
|
public HashMap<String, String> postResult(JSONObject result) {
|
||||||
HashMap<String, String> resMap = new HashMap<>();
|
HashMap<String, String> resMap = new HashMap<>();
|
||||||
String E_RSLT = null;
|
|
||||||
|
|
||||||
boolean succeed = result.getHeaders().containsKey("succeed");
|
boolean succeed = result.getBoolean("succeed");
|
||||||
// JSONObject data = result.getBody("data");
|
JSONObject data = result.getJSONObject("data");
|
||||||
// if (data == null) {
|
if (data == null) {
|
||||||
// throw new RuntimeException("SAP接口返回值为空," + result.getMsg());
|
throw new RuntimeException("SAP接口返回值为空," + result.getString("msg"));
|
||||||
// } else if (succeed && "S".equals(data.getString("E_FLAG"))) {
|
} else if (succeed && "S".equals(data.getString("E_FLAG"))) {
|
||||||
// String E_FLAG = data.getString("E_FLAG");
|
String flag = "S";
|
||||||
// String flag = "S";
|
String E_RESP = data.getString("E_RESP");
|
||||||
// String E_RESP = data.getString("E_RESP");
|
String E_MSG = data.getString("ET_MSG");
|
||||||
// String E_MSG = data.getString("ET_MSG");
|
resMap.put("E_RESP", E_RESP);
|
||||||
//// log.info("请求SAP成功 E_RESP:{}", E_RESP);
|
resMap.put("resStr", E_MSG);
|
||||||
//// log.info("请求SAP成功 E_MSG:{}", E_MSG);
|
resMap.put("flag", flag);
|
||||||
// resMap.put("E_RESP", E_RESP);
|
|
||||||
// resMap.put("resStr", E_MSG);
|
|
||||||
// resMap.put("flag", flag);
|
|
||||||
// return resMap;
|
|
||||||
// } else if (!succeed && "E".equals(data.getString("E_FLAG"))) {
|
|
||||||
// String E_FLAG = data.getString("E_FLAG");
|
|
||||||
// String flag = "E";
|
|
||||||
// String E_RESP = data.getString("E_DATA");
|
|
||||||
// String E_MSG = data.getString("ET_MSG");
|
|
||||||
// if (StrUtil.isBlank(E_MSG)) {
|
|
||||||
// E_MSG = result.getMsg();
|
|
||||||
// E_MSG = "[{\"MESSAGE\":\"" + result.getMsg() + "\"}]";
|
|
||||||
// }
|
|
||||||
// resMap.put("resStr", E_MSG);
|
|
||||||
// resMap.put("flag", flag);
|
|
||||||
//// log.info("请求SAP失败 E_MSG:{}", E_MSG);
|
|
||||||
// return resMap;
|
|
||||||
// } else {
|
|
||||||
// throw new RuntimeException("SAP接口异常," + result);
|
|
||||||
// }
|
|
||||||
return resMap;
|
return resMap;
|
||||||
|
} else if (!succeed && "E".equals(data.getString("E_FLAG"))) {
|
||||||
|
String flag = "E";
|
||||||
|
String E_MSG = data.getString("ET_MSG");
|
||||||
|
if (StrUtil.isBlank(E_MSG)) {
|
||||||
|
E_MSG = result.getString("msg");
|
||||||
|
}
|
||||||
|
resMap.put("resStr", E_MSG);
|
||||||
|
resMap.put("flag", flag);
|
||||||
|
return resMap;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("SAP接口异常," + result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user