From 47b9f7a2708a63bbd09d65552ae8fc6d77b80b4d Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期日, 01 十二月 2024 03:03:24 +0800
Subject: [PATCH] 优化代码

---
 service-api/src/main/java/com/java110/api/smo/impl/ApiServiceSMOImpl.java |  343 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 301 insertions(+), 42 deletions(-)

diff --git a/service-api/src/main/java/com/java110/api/smo/impl/ApiServiceSMOImpl.java b/service-api/src/main/java/com/java110/api/smo/impl/ApiServiceSMOImpl.java
index 0a39e00..8c4991b 100644
--- a/service-api/src/main/java/com/java110/api/smo/impl/ApiServiceSMOImpl.java
+++ b/service-api/src/main/java/com/java110/api/smo/impl/ApiServiceSMOImpl.java
@@ -2,43 +2,44 @@
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.aliyuncs.utils.StringUtils;
 import com.java110.api.smo.IApiServiceSMO;
-import com.java110.core.smo.ISaveTransactionLogSMO;
 import com.java110.core.client.RestTemplate;
 import com.java110.core.context.ApiDataFlow;
 import com.java110.core.context.DataFlow;
+import com.java110.core.context.Environment;
 import com.java110.core.event.service.api.ServiceDataFlowEventPublishing;
 import com.java110.core.factory.AuthenticationFactory;
 import com.java110.core.factory.DataFlowFactory;
 import com.java110.core.factory.GenerateCodeFactory;
-import com.java110.entity.center.AppRoute;
-import com.java110.entity.center.AppService;
-import com.java110.entity.center.DataFlowLinksCost;
-import com.java110.po.transactionLog.TransactionLogPo;
+import com.java110.core.log.LoggerFactory;
+import com.java110.core.smo.ISaveTransactionLogSMO;
+import com.java110.core.trace.Java110TraceLog;
+import com.java110.dto.order.OrderDto;
+import com.java110.dto.system.AppRoute;
+import com.java110.dto.system.AppService;
+import com.java110.dto.system.DataFlowLinksCost;
+import com.java110.po.log.TransactionLogPo;
 import com.java110.utils.cache.AppRouteCache;
 import com.java110.utils.cache.MappingCache;
 import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.KafkaConstant;
 import com.java110.utils.constant.MappingConstant;
 import com.java110.utils.constant.ResponseConstant;
-import com.java110.utils.constant.ServiceCodeConstant;
-import com.java110.utils.exception.BusinessException;
-import com.java110.utils.exception.DecryptException;
-import com.java110.utils.exception.InitConfigDataException;
-import com.java110.utils.exception.ListenerExecuteException;
-import com.java110.utils.exception.NoAuthorityException;
-import com.java110.utils.exception.SMOException;
+import com.java110.utils.exception.*;
+import com.java110.utils.factory.ApplicationContextFactory;
 import com.java110.utils.kafka.KafkaFactory;
 import com.java110.utils.log.LoggerEngine;
+import com.java110.utils.util.BootReplaceUtil;
 import com.java110.utils.util.DateUtil;
 import com.java110.utils.util.StringUtil;
+import com.java110.vo.ResultVo;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
+import org.springframework.http.*;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpStatusCodeException;
 
 import java.util.Date;
 import java.util.List;
@@ -74,6 +75,7 @@
      * @throws SMOException
      */
     @Override
+    @Java110TraceLog
     public ResponseEntity<String> service(String reqJson, Map<String, String> headers) throws SMOException {
 
         ApiDataFlow dataFlow = null;
@@ -85,37 +87,40 @@
         String resJson = "";
 
         try {
-            //鍦╬ost鍜� put 鏃舵墠瀛樺湪鎶ユ枃鍔犲瘑鐨勬儏鍐�
+            //todo 鍦╬ost鍜� put 鏃舵墠瀛樺湪鎶ユ枃鍔犲瘑鐨勬儏鍐�
             if ("POST,PUT".contains(headers.get(CommonConstant.HTTP_METHOD))) {
                 reqJson = decrypt(reqJson, headers);
             }
 
-            //1.0 鍒涘缓鏁版嵁娴� appId serviceCode
+            //todo 1.0 鍒涘缓鏁版嵁娴� appId serviceCode
             dataFlow = DataFlowFactory.newInstance(ApiDataFlow.class).builder(reqJson, headers);
 
-            //2.0 鍔犺浇閰嶇疆淇℃伅
+            //todo 2.0 鍔犺浇閰嶇疆淇℃伅
             initConfigData(dataFlow);
 
-            //3.0 鏍¢獙 APPID鏄惁鏈夋潈闄愭搷浣渟erviceCode
+            //todo 3.0 鏍¢獙 APPID鏄惁鏈夋潈闄愭搷浣渟erviceCode
             judgeAuthority(dataFlow);
 
-            //6.0 璋冪敤涓嬫父绯荤粺
+            //todo 6.0 璋冪敤涓嬫父绯荤粺
             invokeBusinessSystem(dataFlow);
 
             responseEntity = dataFlow.getResponseEntity();
 
         } catch (DecryptException e) { //瑙e瘑寮傚父
-            responseEntity = new ResponseEntity<String>("瑙e瘑寮傚父锛�" + e.getMessage(), HttpStatus.NON_AUTHORITATIVE_INFORMATION);
+            logger.error("鍐呴儴寮傚父锛�", e);
+            responseEntity = ResultVo.error("瑙e瘑寮傚父锛�" + e.getMessage());
         } catch (BusinessException e) {
-            responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
+            logger.error("鍐呴儴寮傚父锛�", e);
+            responseEntity = ResultVo.error(e.getMessage());
         } catch (NoAuthorityException e) {
-            responseEntity = new ResponseEntity<String>("閴存潈澶辫触锛�" + e.getMessage(), HttpStatus.UNAUTHORIZED);
+            logger.error("鍐呴儴寮傚父锛�", e);
+            responseEntity = ResultVo.error("閴存潈澶辫触锛�" + e.getMessage());
         } catch (InitConfigDataException e) {
-            responseEntity = new ResponseEntity<String>("鍒濆鍖栧け璐ワ細" + e.getMessage(), HttpStatus.BAD_REQUEST);
+            logger.error("鍐呴儴寮傚父锛�", e);
+            responseEntity = ResultVo.error("鍒濆鍖栧け璐ワ細" + e.getMessage());
         } catch (Exception e) {
             logger.error("鍐呴儴寮傚父锛�", e);
-            responseEntity = new ResponseEntity<String>("鍐呴儴寮傚父锛�" + e.getMessage() + e.getLocalizedMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
-
+            responseEntity = ResultVo.error("鍐呴儴寮傚父锛�" + e.getMessage() + e.getLocalizedMessage());
         } finally {
             Date endDate = DateUtil.getCurrentDate();
             if (dataFlow != null) {
@@ -132,10 +137,8 @@
             //娣诲姞鑰楁椂
             saveLog(dataFlow, startDate, endDate, reqJson, responseEntity);
             //杩欓噷淇濆瓨鑰楁椂锛屼互鍙婃棩蹇�
-            return responseEntity;
-
         }
-
+        return responseEntity;
     }
 
     /**
@@ -153,18 +156,19 @@
 
         String serviceCode = dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE);
 
-        String logServiceCode = MappingCache.getValue(MappingCache.LOG_SERVICE_CODE);
+        String logServiceCode = MappingCache.getValue(MappingConstant.DOMAIN_SYSTEM_SWITCH,MappingCache.LOG_SERVICE_CODE);
 
         //鏃ュ織鏌ヨ涓嶈褰�
         if ("/transactionLog/queryTransactionLog".equals(serviceCode)
                 || "/transactionLog/queryTransactionLogMessage".equals(serviceCode)
                 || "file.getFile".equals(serviceCode)
                 || "file.getFileByObjId".equals(serviceCode)
-        ) {
+                || "/machine/heartbeat".equals(serviceCode) // 蹇冭烦涔熶笉璁板綍
+                ) {
             return;
         }
 
-        if (StringUtil.isEmpty(logServiceCode)) {
+        if (StringUtil.isEmpty(logServiceCode) || "OFF".equals(logServiceCode.toUpperCase())) {
             return;
         }
         if (logServiceCode.contains("|")) {
@@ -316,7 +320,7 @@
 
         if (!StringUtil.isNullOrNone(dataFlow.getAppRoutes().get(0).getSecurityCode())) {
             String sign = AuthenticationFactory.apiDataFlowMd5(dataFlow);
-            if (!sign.equals(dataFlow.getReqSign().toLowerCase())) {
+            if (StringUtil.isEmpty(dataFlow.getReqSign()) || !sign.equals(dataFlow.getReqSign().toLowerCase())) {
                 throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "绛惧悕澶辫触");
             }
         }
@@ -326,13 +330,13 @@
             DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "閴存潈鑰楁椂", startDate);
             throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "requestTime 鏍煎紡涓嶅锛岄伒寰獃yyyMMddHHmmss鏍煎紡");
         }
-        //鐢ㄦ埛ID鏍¢獙
+        //todo 鐢ㄦ埛ID鏍¢獙
         if (StringUtil.isNullOrNone(dataFlow.getUserId())) {
             throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "USER_ID 涓嶈兘涓虹┖");
         }
 
 
-        //鍒ゆ柇 AppId 鏄惁鏈夋潈闄愭搷浣滅浉搴旂殑鏈嶅姟
+        //todo 鍒ゆ柇 AppId 鏄惁鏈夋潈闄愭搷浣滅浉搴旂殑鏈嶅姟
         AppService appService = DataFlowFactory.getService(dataFlow, dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE));
 
         //杩欓噷璋冪敤缂撳瓨 鏌ヨ缂撳瓨淇℃伅
@@ -371,9 +375,9 @@
      */
     private void invokeBusinessSystem(ApiDataFlow dataFlow) throws BusinessException {
         Date startDate = DateUtil.getCurrentDate();
-        //鎷垮埌褰撳墠鏈嶅姟
+        //todo 鎷垮埌褰撳墠鏈嶅姟
         AppService appService = DataFlowFactory.getService(dataFlow, dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE));
-        //杩欓噷瀵归�忎紶绫诲鐞�
+        //todo 杩欓噷瀵归�忎紶绫诲鐞�,鐩墠寰堝皯鐢ㄥ埌锛屽彲浠ヤ笉鐢ㄥ叧娉�
         if ("NT".equals(appService.getIsInstance())) {
             //濡傛灉鏄�忎紶绫� 璇锋眰鏂瑰紡蹇呴』涓庢帴鍙f彁渚涙柟璋冪敤鏂瑰紡涓�鑷�
             String httpMethod = dataFlow.getRequestCurrentHeaders().get(CommonConstant.HTTP_METHOD);
@@ -381,20 +385,275 @@
                 throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR,
                         "鏈嶅姟銆�" + appService.getServiceCode() + "銆戣皟鐢ㄦ柟寮忎笉瀵硅妫�鏌�,褰撳墠璇锋眰鏂瑰紡涓猴細" + httpMethod);
             }
-            dataFlow.setApiCurrentService(ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_TRANSFER);
-        } else if ("T".equals(appService.getIsInstance())) {
+            //dataFlow.setApiCurrentService(ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_TRANSFER);
+            doNT(appService, dataFlow, dataFlow.getReqJson());
+            return;
+        } else if ("T".equals(appService.getIsInstance())) { // todo 閫氳繃閫忎紶鏂瑰紡 璋冪敤 鐩墠寰堝皯鐢ㄥ埌锛屽彲浠ヤ笉鐢ㄥ叧娉�
+            //todo 濡傛灉鏄�忎紶绫� 璇锋眰鏂瑰紡蹇呴』涓庢帴鍙f彁渚涙柟璋冪敤鏂瑰紡涓�鑷�
+            String httpMethod = dataFlow.getRequestCurrentHeaders().get(CommonConstant.HTTP_METHOD);
+            if (!appService.getMethod().equals(httpMethod)) {
+                throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR,
+                        "鏈嶅姟銆�" + appService.getServiceCode() + "銆戣皟鐢ㄦ柟寮忎笉瀵硅妫�鏌�,褰撳墠璇锋眰鏂瑰紡涓猴細" + httpMethod);
+            }
+            doTransfer(appService, dataFlow, dataFlow.getReqJson());
+            return;
+        } else if ("CMD".equals(appService.getIsInstance())) { // todo 寰湇鍔¤皟鐢ㄦ柟寮忥紝鐩墠涓昏鐢ㄨ繖绉嶆柟寮忚皟搴﹀垎鍙� 鍒颁笉鍚岀殑寰湇鍔★紝杩欓噷鏄�氳繃c_service 涓厤缃� 璋冪敤鍒颁笉鍚岀殑寰湇鍔�
             //濡傛灉鏄�忎紶绫� 璇锋眰鏂瑰紡蹇呴』涓庢帴鍙f彁渚涙柟璋冪敤鏂瑰紡涓�鑷�
             String httpMethod = dataFlow.getRequestCurrentHeaders().get(CommonConstant.HTTP_METHOD);
             if (!appService.getMethod().equals(httpMethod)) {
                 throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR,
                         "鏈嶅姟銆�" + appService.getServiceCode() + "銆戣皟鐢ㄦ柟寮忎笉瀵硅妫�鏌�,褰撳墠璇锋眰鏂瑰紡涓猴細" + httpMethod);
             }
-            dataFlow.setApiCurrentService(ServiceCodeConstant.SERVICE_CODE_SYSTEM_TRANSFER);
+            // todo 鏍规嵁鎺ュ彛缂栫爜鎵惧埌 appService 涔熷氨鏄痗_service 琛ㄤ腑鐨勫唴瀹�
+            dealCmd(appService, dataFlow, dataFlow.getReqJson());
+            return;
         } else {
             dataFlow.setApiCurrentService(dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE));
         }
         ServiceDataFlowEventPublishing.multicastEvent(dataFlow, appService);
         DataFlowFactory.addCostTime(dataFlow, "invokeBusinessSystem", "璋冪敤涓嬫父绯荤粺鑰楁椂", startDate);
+    }
+
+    private void doNT(AppService service, ApiDataFlow dataFlow, JSONObject reqJson) {
+
+
+        HttpHeaders header = new HttpHeaders();
+        for (String key : dataFlow.getRequestCurrentHeaders().keySet()) {
+            header.add(key, dataFlow.getRequestCurrentHeaders().get(key));
+        }
+        HttpEntity<String> httpEntity = new HttpEntity<String>(reqJson.toJSONString(), header);
+        //http://user-service/test/sayHello
+
+        ResponseEntity responseEntity = null;
+        //閰嶇疆c_service 鏃惰娉ㄦ剰 濡傛灉鏄互out 寮�澶寸殑璋冪敤澶栭儴鐨勫湴鍧�
+        RestTemplate restTemplate ;
+        if (Environment.isStartBootWay()) {
+            restTemplate = ApplicationContextFactory.getBean("outRestTemplate", RestTemplate.class);
+        } else {
+            restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class);
+        }
+
+        try {
+            if (CommonConstant.HTTP_METHOD_GET.equals(service.getMethod())) {
+                String requestUrl = dataFlow.getRequestHeaders().get("REQUEST_URL");
+                if (!StringUtil.isNullOrNone(requestUrl)) {
+                    String param = requestUrl.contains("?") ? requestUrl.substring(requestUrl.indexOf("?") + 1, requestUrl.length()) : "";
+                    if (service.getUrl().contains("?")) {
+                        requestUrl = service.getUrl() + "&" + param;
+                    } else {
+                        requestUrl = service.getUrl() + "?" + param;
+                    }
+                }
+
+                requestUrl = BootReplaceUtil.replaceServiceName(requestUrl);
+
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.GET, httpEntity, String.class);
+            } else if (CommonConstant.HTTP_METHOD_PUT.equals(service.getMethod())) {
+                responseEntity = restTemplate.exchange(service.getUrl(), HttpMethod.PUT, httpEntity, String.class);
+            } else if (CommonConstant.HTTP_METHOD_DELETE.equals(service.getMethod())) {
+                String requestUrl = dataFlow.getRequestHeaders().get("REQUEST_URL");
+                if (!StringUtil.isNullOrNone(requestUrl)) {
+                    String param = requestUrl.contains("?") ? requestUrl.substring(requestUrl.indexOf("?"), requestUrl.length()) : "";
+                    if (service.getUrl().contains("?")) {
+                        requestUrl = service.getUrl() + "&" + param;
+                    } else {
+                        requestUrl = service.getUrl() + "?" + param;
+                    }
+                }
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.DELETE, httpEntity, String.class);
+            } else {
+
+                String requestUrl = BootReplaceUtil.replaceServiceName(service.getUrl());
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.POST, httpEntity, String.class);
+            }
+        } catch (HttpStatusCodeException e) { //杩欓噷spring 妗嗘灦 鍦�4XX 鎴� 5XX 鏃舵姏鍑� HttpServerErrorException 寮傚父锛岄渶瑕侀噸鏂板皝瑁呬竴涓�
+            responseEntity = new ResponseEntity<String>(e.getResponseBodyAsString(), e.getStatusCode());
+        }
+
+        logger.debug("API 鏈嶅姟璋冪敤涓嬫父鏈嶅姟璇锋眰锛歿}锛岃繑鍥炰负锛歿}", httpEntity, responseEntity);
+
+        dataFlow.setResponseEntity(responseEntity);
+    }
+
+    private void doTransfer(AppService appService, ApiDataFlow dataFlow, JSONObject reqJson) {
+
+        Map<String, String> reqHeader = dataFlow.getRequestCurrentHeaders();
+        HttpHeaders header = new HttpHeaders();
+        for (String key : dataFlow.getRequestCurrentHeaders().keySet()) {
+            header.add(key, reqHeader.get(key));
+        }
+        HttpEntity<String> httpEntity = new HttpEntity<String>(reqJson.toJSONString(), header);
+        String orgRequestUrl = dataFlow.getRequestHeaders().get("REQUEST_URL");
+
+        //String serviceCode = "/" + reqHeader.get(CommonConstant.HTTP_RESOURCE) + "/" + reqHeader.get(CommonConstant.HTTP_ACTION);
+        String serviceCode = appService.getServiceCode();
+        serviceCode = serviceCode.startsWith("/") ? serviceCode : ("/" + serviceCode);
+
+        //String requestUrl = "http://127.0.0.1:8008" + serviceCode;
+        String requestUrl = serviceCode;
+        RestTemplate restTemplate ;
+        if (Environment.isStartBootWay()) {
+            requestUrl = Environment.BOOT_PATH + requestUrl;
+            restTemplate = ApplicationContextFactory.getBean("outRestTemplate", RestTemplate.class);
+        } else {
+            requestUrl = appService.getUrl() + requestUrl;
+            restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class);
+        }
+
+        ResponseEntity responseEntity = null;
+        if (!StringUtil.isNullOrNone(orgRequestUrl)) {
+            String param = orgRequestUrl.contains("?") ? orgRequestUrl.substring(orgRequestUrl.indexOf("?") + 1, orgRequestUrl.length()) : "";
+            requestUrl += ("?" + param);
+        }
+        try {
+            if (CommonConstant.HTTP_METHOD_GET.equals(appService.getMethod())) {
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.GET, httpEntity, String.class);
+            } else if (CommonConstant.HTTP_METHOD_PUT.equals(appService.getMethod())) {
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.PUT, httpEntity, String.class);
+            } else if (CommonConstant.HTTP_METHOD_DELETE.equals(appService.getMethod())) {
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.DELETE, httpEntity, String.class);
+            } else {
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.POST, httpEntity, String.class);
+            }
+            HttpHeaders headers = responseEntity.getHeaders();
+            String oId = "-1";
+            if (headers.containsKey(OrderDto.O_ID)) {
+                oId = headers.get(OrderDto.O_ID).get(0);
+            }
+
+//            //杩涘叆databus
+//            if (!CommonConstant.HTTP_METHOD_GET.equals(appService.getMethod())) {
+//
+//                // dealDatabus(serviceCode, reqJson, oId);
+//            }
+
+
+        } catch (HttpStatusCodeException e) { //杩欓噷spring 妗嗘灦 鍦�4XX 鎴� 5XX 鏃舵姏鍑� HttpServerErrorException 寮傚父锛岄渶瑕侀噸鏂板皝瑁呬竴涓�
+            logger.error("璇锋眰涓嬫父鏈嶅姟銆�" + requestUrl + "銆戝紓甯革紝鍙傛暟涓�" + httpEntity + e.getResponseBodyAsString(), e);
+            String body = e.getResponseBodyAsString();
+
+            if (StringUtil.isJsonObject(body)) {
+                JSONObject bodyObj = JSONObject.parseObject(body);
+                if (bodyObj.containsKey("message") && !StringUtil.isEmpty(bodyObj.getString("message"))) {
+                    body = bodyObj.getString("message");
+                }
+            }
+            responseEntity = new ResponseEntity<String>(body, e.getStatusCode());
+        }
+
+        logger.debug("API 鏈嶅姟璋冪敤涓嬫父鏈嶅姟璇锋眰锛歿}锛岃繑鍥炰负锛歿}", httpEntity, responseEntity);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            responseEntity = ResultVo.createResponseEntity(ResultVo.CODE_ERROR, String.valueOf(responseEntity.getBody()));
+            dataFlow.setResponseEntity(responseEntity);
+
+            return;
+        }
+        if (StringUtils.isEmpty(responseEntity.getBody() + "")) {
+            responseEntity = ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "澶勭悊澶辫触");
+            dataFlow.setResponseEntity(responseEntity);
+            return;
+        }
+        JSONObject resParam = JSONObject.parseObject(responseEntity.getBody() + "");
+        if (resParam.containsKey("code") && resParam.containsKey("msg")) { // 璇存槑寰湇鍔¤繑鍥炵殑鏄� resultVo 瀵硅薄鐩存帴杩斿洖灏卞彲浠�
+            dataFlow.setResponseEntity(responseEntity);
+            return;
+        }
+        responseEntity = ResultVo.createResponseEntity(resParam);
+        dataFlow.setResponseEntity(responseEntity);
+    }
+
+    /**
+     * 寮�濮嬭皟搴﹀井鏈嶅姟
+     * @param appService
+     * @param dataFlow
+     * @param reqJson
+     */
+    private void dealCmd(AppService appService, ApiDataFlow dataFlow, JSONObject reqJson) {
+        Map<String, String> reqHeader = dataFlow.getRequestCurrentHeaders();
+        HttpHeaders header = new HttpHeaders();
+        //todo 瀵瑰ご淇℃伅閲嶆柊鍖呰
+        for (String key : dataFlow.getRequestCurrentHeaders().keySet()) {
+            if("userName".equals(key) || "user-name".equals(key)){
+                header.add(key, "-");
+                continue;
+            }
+            header.add(key, reqHeader.get(key));
+        }
+        //todo 鐢ㄦ埛淇℃伅鍐嶆鍖呰
+        if (reqHeader.containsKey(CommonConstant.USER_ID)
+                && (!reqJson.containsKey("userId") || StringUtil.isEmpty(reqJson.getString("userId")))) {
+            reqJson.put("userId", reqHeader.get(CommonConstant.USER_ID));
+        }
+        if (reqHeader.containsKey(CommonConstant.USER_ID)
+                && (!reqJson.containsKey("loginUserId") || StringUtil.isEmpty(reqJson.getString("loginUserId")))) {
+            reqJson.put("loginUserId", reqHeader.get(CommonConstant.LOGIN_U_ID));
+        }
+        if (reqHeader.containsKey(CommonConstant.STORE_ID)
+                && (!reqJson.containsKey("storeId") || StringUtil.isEmpty(reqJson.getString("storeId")))) {
+            reqJson.put("storeId", reqHeader.get(CommonConstant.STORE_ID));
+        }
+        HttpEntity<String> httpEntity = new HttpEntity<String>(reqJson.toJSONString(), header);
+        String orgRequestUrl = dataFlow.getRequestHeaders().get("REQUEST_URL");
+
+        String serviceCode = appService.getServiceCode();
+
+        serviceCode = serviceCode.startsWith("/") ? serviceCode : ("/" + serviceCode);
+
+        //todo 缁勮璋冪敤寰湇鍔$殑鍦板潃
+        //String requestUrl = "http://127.0.0.1:8008/cmd" + serviceCode;
+        String requestUrl = "/cmd" + serviceCode;
+        //
+        ResponseEntity responseEntity = null;
+        //todo url 甯︿簡鍦板潃杩欓噷 鎷兼帴
+        if (!StringUtil.isNullOrNone(orgRequestUrl)) {
+            String param = orgRequestUrl.contains("?") ? orgRequestUrl.substring(orgRequestUrl.indexOf("?") + 1, orgRequestUrl.length()) : "";
+            requestUrl += ("?" + param);
+        }
+        try {
+            //todo http鐨勬柟寮忚皟鐢ㄥ井鏈嶅姟锛岀浉搴旂殑java绫诲彲浠ュ埌鐩稿簲寰湇鍔′笅鐨刢md涓嬫牴鎹畇erviceCode 鐨勫鎵�
+            //todo 杩欓噷浼氳皟鐢ㄥ埌 java110-service 妯″潡涓嬬殑 CmdApi 绫伙紝杩欎釜绫诲悇涓井鏈嶅姟閮戒細闆嗘垚
+            if (Environment.isStartBootWay()) {
+                requestUrl = Environment.BOOT_PATH + requestUrl;
+                restTemplate = ApplicationContextFactory.getBean("outRestTemplate", RestTemplate.class);
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.POST, httpEntity, String.class);
+            } else {
+                requestUrl = appService.getUrl() + requestUrl;
+                restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class);
+                responseEntity = restTemplate.exchange(requestUrl, HttpMethod.POST, httpEntity, String.class);
+            }
+            HttpHeaders headers = responseEntity.getHeaders();
+            String oId = "-1";
+            if (headers.containsKey(OrderDto.O_ID)) {
+                oId = headers.get(OrderDto.O_ID).get(0);
+            }
+
+        } catch (HttpStatusCodeException e) { //todo 杩欓噷spring 妗嗘灦 鍦�4XX 鎴� 5XX 鏃舵姏鍑� HttpServerErrorException 寮傚父锛岄渶瑕侀噸鏂板皝瑁呬竴涓�
+            logger.error("璇锋眰涓嬫父鏈嶅姟銆�" + requestUrl + "銆戝紓甯革紝鍙傛暟涓�" + httpEntity + e.getResponseBodyAsString(), e);
+            String body = e.getResponseBodyAsString();
+
+            if (StringUtil.isJsonObject(body)) {
+                JSONObject bodyObj = JSONObject.parseObject(body);
+                if (bodyObj != null && bodyObj.containsKey("message") && !StringUtil.isEmpty(bodyObj.getString("message"))) {
+                    body = bodyObj.getString("message");
+                }
+            }
+            responseEntity = new ResponseEntity<String>(body, e.getStatusCode());
+        }
+
+        logger.debug("API 鏈嶅姟璋冪敤涓嬫父鏈嶅姟璇锋眰锛歿}锛岃繑鍥炰负锛歿}", httpEntity, responseEntity);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            responseEntity = ResultVo.createResponseEntity(ResultVo.CODE_ERROR, String.valueOf(responseEntity.getBody()));
+            dataFlow.setResponseEntity(responseEntity);
+            return;
+        }
+        if (StringUtils.isEmpty(responseEntity.getBody() + "")) {
+            responseEntity = ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "澶勭悊澶辫触");
+            dataFlow.setResponseEntity(responseEntity);
+            return;
+        }
+        dataFlow.setResponseEntity(responseEntity);
     }
 
 
@@ -406,7 +665,7 @@
     private void saveLogMessage(String requestJson, String responseJson) {
 
         try {
-            if (MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_LOG_ON_OFF))) {
+            if (MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.DOMAIN_SYSTEM_SWITCH,MappingConstant.KEY_LOG_ON_OFF))) {
                 JSONObject log = new JSONObject();
                 log.put("request", requestJson);
                 log.put("response", responseJson);
@@ -424,7 +683,7 @@
      */
     private void saveCostTimeLogMessage(DataFlow dataFlow) {
         try {
-            if (MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_COST_TIME_ON_OFF))) {
+            if (MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.DOMAIN_SYSTEM_SWITCH,MappingConstant.KEY_COST_TIME_ON_OFF))) {
                 List<DataFlowLinksCost> dataFlowLinksCosts = dataFlow.getLinksCostDates();
                 JSONObject costDate = new JSONObject();
                 JSONArray costDates = new JSONArray();

--
Gitblit v1.8.0