From 10e77091bdc0a2c0ea6b5d0b7b9d6771fd9d6e26 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 11 十一月 2021 15:27:27 +0800
Subject: [PATCH] 優化代碼

---
 service-api/src/main/java/com/java110/api/smo/payment/adapt/wechatPay/WechatOweFeeToNotifyAdapt.java |   47 ++++++++++++++---------------------------------
 1 files changed, 14 insertions(+), 33 deletions(-)

diff --git a/service-api/src/main/java/com/java110/api/smo/payment/adapt/wechatPay/WechatOweFeeToNotifyAdapt.java b/service-api/src/main/java/com/java110/api/smo/payment/adapt/wechatPay/WechatOweFeeToNotifyAdapt.java
index fd11b4d..a6d3a53 100644
--- a/service-api/src/main/java/com/java110/api/smo/payment/adapt/wechatPay/WechatOweFeeToNotifyAdapt.java
+++ b/service-api/src/main/java/com/java110/api/smo/payment/adapt/wechatPay/WechatOweFeeToNotifyAdapt.java
@@ -17,6 +17,7 @@
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.java110.api.smo.DefaultAbstractComponentSMO;
 import com.java110.core.factory.WechatFactory;
 import com.java110.dto.fee.FeeDto;
 import com.java110.dto.smallWeChat.SmallWeChatDto;
@@ -47,7 +48,7 @@
  */
 
 @Component(value = "wechatOweFeeToNotifyAdapt")
-public class WechatOweFeeToNotifyAdapt implements IOweFeeToNotifyAdapt {
+public class WechatOweFeeToNotifyAdapt extends DefaultAbstractComponentSMO implements IOweFeeToNotifyAdapt {
 
     private static final Logger logger = LoggerFactory.getLogger(WechatOweFeeToNotifyAdapt.class);
 
@@ -140,8 +141,8 @@
         JSONObject paramIn = JSONObject.parseObject(order);
         paramIn.put("oId", orderId);
         freshFees(paramIn);
-        String url = ServiceConstant.SERVICE_API_URL + "/api/fee.payOweFee";
-        responseEntity = this.callCenterService(restTemplate, "-1", paramIn.toJSONString(), url, HttpMethod.POST);
+        String url = "fee.payOweFee";
+        responseEntity = this.callCenterService(getHeaders("-1"), paramIn.toJSONString(), url, HttpMethod.POST);
 
         if (responseEntity.getStatusCode() != HttpStatus.OK) {
             return 0;
@@ -168,43 +169,23 @@
     }
 
 
-    /**
-     * 璋冪敤涓績鏈嶅姟
-     *
-     * @return
-     */
-    protected ResponseEntity<String> callCenterService(RestTemplate restTemplate, String userId, String param, String url, HttpMethod httpMethod) {
 
-        ResponseEntity<String> responseEntity = null;
-        HttpHeaders header = new HttpHeaders();
-        header.add(CommonConstant.HTTP_APP_ID.toLowerCase(), APP_ID);
-        header.add(CommonConstant.HTTP_USER_ID.toLowerCase(), userId);
-        header.add(CommonConstant.HTTP_TRANSACTION_ID.toLowerCase(), UUID.randomUUID().toString());
-        header.add(CommonConstant.HTTP_REQ_TIME.toLowerCase(), DateUtil.getDefaultFormateTimeString(new Date()));
-        header.add(CommonConstant.HTTP_SIGN.toLowerCase(), "");
-        header.add("Content-Type", "application/json");
-        HttpEntity<String> httpEntity = new HttpEntity<String>(param, header);
-        //logger.debug("璇锋眰涓績鏈嶅姟淇℃伅锛寋}", httpEntity);
-        try {
-            responseEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class);
-        } catch (HttpStatusCodeException e) { //杩欓噷spring 妗嗘灦 鍦�4XX 鎴� 5XX 鏃舵姏鍑� HttpServerErrorException 寮傚父锛岄渶瑕侀噸鏂板皝瑁呬竴涓�
-            responseEntity = new ResponseEntity<String>(e.getResponseBodyAsString(), e.getStatusCode());
-        } catch (Exception e) {
-            responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
-        } finally {
-            logger.debug("璇锋眰鍦板潃涓�,{} 璇锋眰涓績鏈嶅姟淇℃伅锛寋},涓績鏈嶅姟杩斿洖淇℃伅锛寋}", url, httpEntity, responseEntity);
-        }
-
-        return responseEntity;
+    private Map<String, String> getHeaders(String userId) {
+        Map<String, String> headers = new HashMap<>();
+        headers.put(CommonConstant.HTTP_APP_ID.toLowerCase(), APP_ID);
+        headers.put(CommonConstant.HTTP_USER_ID.toLowerCase(), userId);
+        headers.put(CommonConstant.HTTP_TRANSACTION_ID.toLowerCase(), UUID.randomUUID().toString());
+        headers.put(CommonConstant.HTTP_REQ_TIME.toLowerCase(), DateUtil.getDefaultFormateTimeString(new Date()));
+        headers.put(CommonConstant.HTTP_SIGN.toLowerCase(), "");
+        return headers;
     }
-
 
     private SmallWeChatDto getSmallWechat(String appId) {
 
         ResponseEntity responseEntity = null;
 
-        responseEntity = this.callCenterService(restTemplate, "-1", "",
-                ServiceConstant.SERVICE_API_URL + "/api/smallWeChat.listSmallWeChats?appId="
+        responseEntity = this.callCenterService(getHeaders("-1"), "",
+                "smallWeChat.listSmallWeChats?appId="
                         + appId + "&page=1&row=1", HttpMethod.GET);
 
         if (responseEntity.getStatusCode() != HttpStatus.OK) {

--
Gitblit v1.8.0