|
|
@@ -19,10 +19,10 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
|
public class SapCustomerClientImpl implements SapCustomerClient {
|
|
|
|
|
|
- @Value("${sap.customer-balance-url:}")
|
|
|
- private String customerBalanceUrl;
|
|
|
- @Value("${sap.customer-unlock-order-url:}")
|
|
|
- private String customerUnlockOrderUrl;
|
|
|
+ @Value("${sap.customer-inquiry-url:}")
|
|
|
+ private String customerInquiryUrl;
|
|
|
+ @Value("${sap.customer-inquiry-token:}")
|
|
|
+ private String customerInquiryToken;
|
|
|
|
|
|
/**
|
|
|
* Query customer balance.
|
|
|
@@ -34,7 +34,7 @@ public class SapCustomerClientImpl implements SapCustomerClient {
|
|
|
*/
|
|
|
@Override
|
|
|
public Map queryBalance(String requestId, String customerNumber) {
|
|
|
- return query(customerBalanceUrl, requestId, customerNumber);
|
|
|
+ return query("OTC002", requestId, customerNumber);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -47,20 +47,23 @@ public class SapCustomerClientImpl implements SapCustomerClient {
|
|
|
*/
|
|
|
@Override
|
|
|
public Map queryUnlockOrders(String requestId, String customerNumber) {
|
|
|
- return query(customerUnlockOrderUrl, requestId, customerNumber);
|
|
|
+ return query("OTC004", requestId, customerNumber);
|
|
|
}
|
|
|
|
|
|
- private Map query(String url, String requestId, String customerNumber) {
|
|
|
- if (StringUtils.isBlank(url)) {
|
|
|
+ private Map query(String interfaceNo, String requestId, String customerNumber) {
|
|
|
+ if (StringUtils.isBlank(customerInquiryUrl)) {
|
|
|
return null;
|
|
|
}
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("bearer_token", customerInquiryToken);
|
|
|
+ param.put("interface_no", interfaceNo);
|
|
|
param.put("requestID", requestId);
|
|
|
Map<String, Object> body = new HashMap<>();
|
|
|
body.put("CUSTOMER_NUMBER", customerNumber);
|
|
|
- log.info("SAP客户查询请求: endpoint={}, query={}, body={}", endpoint(url), param, body);
|
|
|
- String response = UtilHttp.doPost_S(url, null, param, body);
|
|
|
- log.info("SAP客户查询响应: endpoint={}, response={}", endpoint(url), response);
|
|
|
+ log.info("SAP客户查询请求: endpoint={}, query={}, body={}", endpoint(customerInquiryUrl), safeParam(param), body);
|
|
|
+ String response = UtilHttp.doPost_S(customerInquiryUrl, null, param, body);
|
|
|
+ log.info("SAP客户查询响应: endpoint={}, response={}", endpoint(customerInquiryUrl), response);
|
|
|
+ assertJsonResponse(response);
|
|
|
Object parsed = JSON.parse(response);
|
|
|
Map result;
|
|
|
if (parsed instanceof JSONArray) {
|
|
|
@@ -73,9 +76,38 @@ public class SapCustomerClientImpl implements SapCustomerClient {
|
|
|
throw new IllegalStateException("SAP客户查询接口返回为空");
|
|
|
}
|
|
|
result.remove("original");
|
|
|
+ assertSuccess(result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private void assertJsonResponse(String response) {
|
|
|
+ if (StringUtils.isBlank(response)) {
|
|
|
+ throw new IllegalStateException("SAP查询服务未返回数据");
|
|
|
+ }
|
|
|
+ String content = response.trim().toLowerCase();
|
|
|
+ if (content.startsWith("<") || content.contains("502 bad gateway") || content.contains("503 service unavailable")) {
|
|
|
+ throw new IllegalStateException("SAP查询服务暂时不可用,请稍后重试");
|
|
|
+ }
|
|
|
+ if (!content.startsWith("{") && !content.startsWith("[")) {
|
|
|
+ throw new IllegalStateException("SAP查询服务返回格式异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void assertSuccess(Map result) {
|
|
|
+ String status = result.get("STATUS") == null ? "" : String.valueOf(result.get("STATUS"));
|
|
|
+ if (!"S".equalsIgnoreCase(status) && StringUtils.isNotBlank(status)) {
|
|
|
+ String message = result.get("MESSAGE") == null ? "" : String.valueOf(result.get("MESSAGE"));
|
|
|
+ throw new IllegalStateException(StringUtils.isBlank(message)
|
|
|
+ ? "SAP客户查询失败,状态=" + status : message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> safeParam(Map<String, Object> param) {
|
|
|
+ Map<String, Object> safe = new HashMap<>(param);
|
|
|
+ safe.put("bearer_token", "***");
|
|
|
+ return safe;
|
|
|
+ }
|
|
|
+
|
|
|
private String endpoint(String url) {
|
|
|
int queryStart = url.indexOf('?');
|
|
|
return queryStart >= 0 ? url.substring(0, queryStart) : url;
|