GITZYY 1 tydzień temu
rodzic
commit
882240c9ed

+ 4 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/config/client/HttpTemPlateClient.java

@@ -2,6 +2,10 @@ package com.hrsk.cloud.eg.infrastructure.config.client;
 
 import com.hrsk.cloud.eg.domain.api.HttpApi;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;

+ 33 - 28
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/exception/ExceptionAdvice.java

@@ -1,7 +1,8 @@
 package com.hrsk.cloud.eg.infrastructure.exception;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.hrsk.cloud.eg.domain.common.constant.ResultCode;
-import com.hrsk.cloud.eg.vo.response.DefaultResponseVo;
+import com.hrsk.pangu.dto.SingleResponse;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.context.properties.bind.BindException;
 import org.springframework.http.HttpStatus;
@@ -28,57 +29,61 @@ public class ExceptionAdvice {
      * @return
      */
     @ExceptionHandler(Exception.class)
-    public ResponseEntity<DefaultResponseVo> exception(Exception exception) {
-        DefaultResponseVo result = new DefaultResponseVo<>();
-        ResponseEntity<DefaultResponseVo> springResponse = handleSpringException(exception);
+    public ResponseEntity<SingleResponse> exception(Exception exception) {
+        SingleResponse result = new SingleResponse<>();
+        ResponseEntity<SingleResponse> springResponse = handleSpringException(exception);
         if (springResponse != null) {
             return springResponse;
         }
 
         if (exception instanceof IllegalArgumentException) {
-            result.setCode(ResultCode.GLOBAL_REQUEST_FAIL.getCode());
-            result.setMsg(exception.getMessage());
-            return ResponseEntity.ok(result);
+            return ResponseEntity.ok(fail(ResultCode.GLOBAL_REQUEST_FAIL.getCode(), exception.getMessage()));
         }
         if (exception instanceof BindException) {
-            result.setCode(ResultCode.GLOBAL_REQUEST_FAIL.getCode());
-            result.setMsg(exception.getMessage());
-            return ResponseEntity.ok(result);
+            return ResponseEntity.ok(fail(ResultCode.GLOBAL_REQUEST_FAIL.getCode(), exception.getMessage()));
         }
         if (exception instanceof ConstraintViolationException) {
-            result.setCode(ResultCode.GLOBAL_REQUEST_FAIL.getCode());
-            result.setMsg(exception.getMessage());
-            return ResponseEntity.ok(result);
+            return ResponseEntity.ok(fail(ResultCode.GLOBAL_REQUEST_FAIL.getCode(), exception.getMessage()));
         }
         if (exception instanceof BindException) {
-            BindException bizException = (BindException) exception;
-            result.setCode(ResultCode.GLOBAL_REQUEST_FAIL.getCode());
-            result.setMsg(ResultCode.GLOBAL_REQUEST_FAIL.getMsg());
-            result.setData(null);
-            return ResponseEntity.ok(result);
+//            BindException bizException = (BindException) exception;
+            return ResponseEntity.ok(fail(ResultCode.GLOBAL_REQUEST_FAIL.getCode(), ResultCode.GLOBAL_REQUEST_FAIL.getMsg()));
         }
         if (exception instanceof MethodArgumentNotValidException) {
             MethodArgumentNotValidException bindException = (MethodArgumentNotValidException) exception;
-            result.setCode(400);
-            result.setMsg(bindException.getBindingResult().getFieldError().getDefaultMessage());
-            result.setData(null);
-            return ResponseEntity.ok(result);
+            return ResponseEntity.ok(fail(400, bindException.getBindingResult().getFieldError().getDefaultMessage()));
         }
         log.error("全局未知异常,异常信息:{}", exception.getMessage(), exception);
-        result = DefaultResponseVo.fail(ResultCode.GLOBAL_REQUEST_FAIL.getMsg());
-        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
+        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(fail(500, exception.getMessage()));
     }
 
-    private ResponseEntity<DefaultResponseVo> handleSpringException(Exception exception) {
+    private ResponseEntity<SingleResponse> handleSpringException(Exception exception) {
         if (exception instanceof ServletRequestBindingException) {
-            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(DefaultResponseVo.fail(exception.getMessage()));
+            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(fail(404,exception.getMessage()));
         }
         if (exception instanceof HttpRequestMethodNotSupportedException) {
-            return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(DefaultResponseVo.fail(exception.getMessage()));
+            return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(fail(405,exception.getMessage()));
         }
         if (exception instanceof HttpMessageNotReadableException) {
-            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(DefaultResponseVo.fail(exception.getMessage()));
+            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(fail(406,exception.getMessage()));
         }
         return null;
     }
+
+    /** 
+     * @description:  简单的构建错误信息
+     * @param:  
+     * @return:  
+     * @author zhangyy
+     * @date: 2024/11/11 10:50
+     */ 
+    private SingleResponse fail(Integer code,String msg){
+            SingleResponse result = new SingleResponse<>();
+            result.setSuccess(false);
+            JSONObject data = new JSONObject();
+            data.put("code",code);
+            data.put("msg",msg);
+            result.setData(data);
+           return result;
+    }
 }

+ 0 - 16
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/repository/database/mapper/EgApiProductExtendMapper.java

@@ -1,16 +0,0 @@
-package com.hrsk.cloud.eg.infrastructure.repository.database.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Mapper;
-
-/**
- * 接出产品api扩展表
- * 
- * @author chenshun
- * @email sunlightcs@gmail.com
- * @date 2024-09-23 11:07:01
- */
-@Mapper
-public interface EgApiProductExtendMapper extends BaseMapper<EgApiProductExtendDo> {
-	
-}

+ 5 - 5
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/request/HttpRequestCheckIntoService.java

@@ -1,17 +1,17 @@
 package com.hrsk.cloud.eg.infrastructure.request;
 
 import com.alibaba.fastjson2.JSONObject;
+import com.hrsk.cloud.eg.clinet.dto.data.command.CheckIntoParamCmd;
+import com.hrsk.cloud.eg.clinet.vo.DataVo;
 import com.hrsk.cloud.eg.domain.api.Api;
 import com.hrsk.cloud.eg.domain.api.ApiFactory;
 import com.hrsk.cloud.eg.domain.api.HttpApi;
 import com.hrsk.cloud.eg.domain.api.HttpApiConfig;
-import com.hrsk.cloud.eg.dto.data.CheckIntoParamDto;
-import com.hrsk.cloud.eg.domain.config.client.HessianUtils;
-import com.hrsk.cloud.eg.domain.config.client.HttpTemPlateClient;
+import com.hrsk.cloud.eg.infrastructure.config.client.HessianUtils;
+import com.hrsk.cloud.eg.infrastructure.config.client.HttpTemPlateClient;
 import com.hrsk.cloud.eg.infrastructure.repository.database.entity.EgApiEndpointDo;
 import com.hrsk.cloud.eg.infrastructure.service.EgApiEndpointService;
 import com.hrsk.cloud.eg.infrastructure.service.EgApiService;
-import com.hrsk.cloud.eg.vo.response.DataVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -47,7 +47,7 @@ public class HttpRequestCheckIntoService {
      * @author zhangyy
      * @date: 2024/8/30 14:24
      */
-    public DataVo checkInto(CheckIntoParamDto paramDto){
+    public DataVo checkInto(CheckIntoParamCmd paramDto){
         EgApiEndpointDo eg = egApiEndpointService.getById(paramDto.getPlan().getApiId());
         try {
             HttpApiConfig httpApiConfig = (HttpApiConfig) HessianUtils.deserialize(eg.getRequestConfig());

+ 2 - 3
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/service/impl/EgApiServiceImpl.java

@@ -4,12 +4,11 @@ import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.hrsk.cloud.eg.constant.GlobalDataStatusEnum;
+import com.hrsk.cloud.eg.clinet.constant.GlobalDataStatusEnum;
 import com.hrsk.cloud.eg.infrastructure.repository.database.entity.*;
 import com.hrsk.cloud.eg.infrastructure.repository.database.mapper.EgApiEndpointMapper;
 import com.hrsk.cloud.eg.infrastructure.repository.database.mapper.EgApiLoanExtendMapper;
 import com.hrsk.cloud.eg.infrastructure.repository.database.mapper.EgApiMapper;
-import com.hrsk.cloud.eg.infrastructure.service.EgApiEndpointService;
 import com.hrsk.cloud.eg.infrastructure.service.EgApiService;
 import com.hrsk.cloud.eg.infrastructure.utils.RedisUtil;
 import org.apache.commons.lang3.StringUtils;
@@ -60,7 +59,7 @@ public class EgApiServiceImpl extends ServiceImpl<EgApiMapper, EgApiDo> implemen
         if (Objects.isNull(egApiEndpointDos)) {
             return egLoanApiConfigInfoDo;
         }
-        egLoanApiConfigInfoDo.setApiConfig(egApiEndpointDos.getRequestConfig());
+        egLoanApiConfigInfoDo.setRequestConfig(egApiEndpointDos.getRequestConfig());
 
         //查询扩展配置
         LambdaQueryWrapper<EgApiLoanExtendDo> extendDoLambdaQueryWrapper=new LambdaQueryWrapper<>();