java110
2022-02-20 8d62257c26dcba1f62e396e6aae30f164ec02b3b
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.core.log.LoggerFactory;
import com.java110.core.smo.ISaveTransactionLogSMO;
import com.java110.core.trace.Java110TraceLog;
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.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,16 @@
            responseEntity = dataFlow.getResponseEntity();
        } catch (DecryptException e) { //解密异常
            responseEntity = new ResponseEntity<String>("解密异常:" + e.getMessage(), HttpStatus.NON_AUTHORITATIVE_INFORMATION);
            responseEntity = ResultVo.error("解密异常:" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        } catch (BusinessException e) {
            responseEntity = new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
            responseEntity = ResultVo.error(e.getMessage(), HttpStatus.BAD_REQUEST);
        } catch (NoAuthorityException e) {
            responseEntity = new ResponseEntity<String>("鉴权失败:" + e.getMessage(), HttpStatus.UNAUTHORIZED);
            responseEntity = ResultVo.error("鉴权失败:" + e.getMessage(), HttpStatus.UNAUTHORIZED);
        } catch (InitConfigDataException e) {
            responseEntity = new ResponseEntity<String>("初始化失败:" + e.getMessage(), HttpStatus.BAD_REQUEST);
            responseEntity = ResultVo.error("初始化失败:" + e.getMessage(), HttpStatus.BAD_REQUEST);
        } 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(), HttpStatus.INTERNAL_SERVER_ERROR);
        } finally {
            Date endDate = DateUtil.getCurrentDate();
            if (dataFlow != null) {
@@ -158,6 +151,7 @@
                || "/transactionLog/queryTransactionLogMessage".equals(serviceCode)
                || "file.getFile".equals(serviceCode)
                || "file.getFileByObjId".equals(serviceCode)
                || "/machine/heartbeat".equals(serviceCode) // 心跳也不记录
        ) {
            return;
        }
@@ -388,6 +382,14 @@
                        "服务【" + appService.getServiceCode() + "】调用方式不对请检查,当前请求方式为:" + httpMethod);
            }
            dataFlow.setApiCurrentService(ServiceCodeConstant.SERVICE_CODE_SYSTEM_TRANSFER);
        } else if ("CMD".equals(appService.getIsInstance())) {
            //如果是透传类 请求方式必须与接口提供方调用方式一致
            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));
        }