|
|
@@ -1,8 +1,10 @@
|
|
|
package com.malk.taisen.service.sap.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.malk.taisen.service.sap.SapCustomerClient;
|
|
|
import com.malk.utils.UtilHttp;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
@@ -14,6 +16,7 @@ import java.util.Map;
|
|
|
* SAP customer information atomic HTTP client.
|
|
|
*/
|
|
|
@Component
|
|
|
+@Slf4j
|
|
|
public class SapCustomerClientImpl implements SapCustomerClient {
|
|
|
|
|
|
@Value("${sap.customer-balance-url:}")
|
|
|
@@ -24,38 +27,57 @@ public class SapCustomerClientImpl implements SapCustomerClient {
|
|
|
/**
|
|
|
* Query customer balance.
|
|
|
*
|
|
|
+ * @param requestId unique request identifier
|
|
|
* @param customerNumber SAP customer number
|
|
|
* @return raw SAP response
|
|
|
* @apiNote SAP interface URL pending confirmation
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map queryBalance(String customerNumber) {
|
|
|
- return query(customerBalanceUrl, customerNumber);
|
|
|
+ public Map queryBalance(String requestId, String customerNumber) {
|
|
|
+ return query(customerBalanceUrl, requestId, customerNumber);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Query customer payment-unlocked sales orders.
|
|
|
*
|
|
|
+ * @param requestId unique request identifier
|
|
|
* @param customerNumber SAP customer number
|
|
|
* @return raw SAP response
|
|
|
* @apiNote SAP interface URL pending confirmation
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map queryUnlockOrders(String customerNumber) {
|
|
|
- return query(customerUnlockOrderUrl, customerNumber);
|
|
|
+ public Map queryUnlockOrders(String requestId, String customerNumber) {
|
|
|
+ return query(customerUnlockOrderUrl, requestId, customerNumber);
|
|
|
}
|
|
|
|
|
|
- private Map query(String url, String customerNumber) {
|
|
|
+ private Map query(String url, String requestId, String customerNumber) {
|
|
|
if (StringUtils.isBlank(url)) {
|
|
|
return null;
|
|
|
}
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("requestID", requestId);
|
|
|
Map<String, Object> body = new HashMap<>();
|
|
|
body.put("CUSTOMER_NUMBER", customerNumber);
|
|
|
- String response = UtilHttp.doPost_S(url, null, null, body);
|
|
|
- Map result = JSON.parseObject(response, Map.class);
|
|
|
+ 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);
|
|
|
+ Object parsed = JSON.parse(response);
|
|
|
+ Map result;
|
|
|
+ if (parsed instanceof JSONArray) {
|
|
|
+ JSONArray items = (JSONArray) parsed;
|
|
|
+ result = items.isEmpty() ? null : items.getObject(0, Map.class);
|
|
|
+ } else {
|
|
|
+ result = JSON.parseObject(response, Map.class);
|
|
|
+ }
|
|
|
if (result == null) {
|
|
|
throw new IllegalStateException("SAP客户查询接口返回为空");
|
|
|
}
|
|
|
+ result.remove("original");
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ private String endpoint(String url) {
|
|
|
+ int queryStart = url.indexOf('?');
|
|
|
+ return queryStart >= 0 ? url.substring(0, queryStart) : url;
|
|
|
+ }
|
|
|
}
|