From e76b67db9ffde73650e7617a1404ba9222a8b6bc Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期一, 08 一月 2024 21:42:41 +0800
Subject: [PATCH] 加入mysql tt
---
service-api/src/main/java/com/java110/api/smo/impl/ApiServiceSMOImpl.java | 66 +++++++++++++++++---------------
1 files changed, 35 insertions(+), 31 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
old mode 100644
new mode 100755
index 0a39e00..efce49a
--- 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
@@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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;
@@ -11,30 +10,24 @@
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.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.constant.*;
+import com.java110.utils.exception.*;
import com.java110.utils.kafka.KafkaFactory;
import com.java110.utils.log.LoggerEngine;
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;
@@ -74,6 +67,7 @@
* @throws SMOException
*/
@Override
+ @Java110TraceLog
public ResponseEntity<String> service(String reqJson, Map<String, String> headers) throws SMOException {
ApiDataFlow dataFlow = null;
@@ -105,17 +99,20 @@
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 +129,8 @@
//娣诲姞鑰楁椂
saveLog(dataFlow, startDate, endDate, reqJson, responseEntity);
//杩欓噷淇濆瓨鑰楁椂锛屼互鍙婃棩蹇�
- return responseEntity;
-
}
-
+ return responseEntity;
}
/**
@@ -153,18 +148,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 +312,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, "绛惧悕澶辫触");
}
}
@@ -390,6 +386,14 @@
"鏈嶅姟銆�" + appService.getServiceCode() + "銆戣皟鐢ㄦ柟寮忎笉瀵硅妫�鏌�,褰撳墠璇锋眰鏂瑰紡涓猴細" + httpMethod);
}
dataFlow.setApiCurrentService(ServiceCodeConstant.SERVICE_CODE_SYSTEM_TRANSFER);
+ } else if ("CMD".equals(appService.getIsInstance())) {
+ //濡傛灉鏄�忎紶绫� 璇锋眰鏂瑰紡蹇呴』涓庢帴鍙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_CMD);
} else {
dataFlow.setApiCurrentService(dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE));
}
@@ -406,7 +410,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 +428,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