From 4db93360932dcee2efddae48152a4ba1f9d7f28b Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 19 一月 2021 12:02:20 +0800
Subject: [PATCH] 优化业主查询报错问题

---
 service-api/src/main/java/com/java110/api/rest/RestApi.java |  134 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 126 insertions(+), 8 deletions(-)

diff --git a/service-api/src/main/java/com/java110/api/rest/RestApi.java b/service-api/src/main/java/com/java110/api/rest/RestApi.java
index 9a81498..dc0647a 100644
--- a/service-api/src/main/java/com/java110/api/rest/RestApi.java
+++ b/service-api/src/main/java/com/java110/api/rest/RestApi.java
@@ -2,9 +2,10 @@
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.api.smo.IApiServiceSMO;
-import com.java110.utils.constant.CommonConstant;
 import com.java110.core.base.controller.BaseController;
-import com.java110.core.smo.user.IUserInnerServiceSMO;
+import com.java110.intf.user.IUserInnerServiceSMO;
+import com.java110.utils.constant.CommonConstant;
+import com.java110.vo.ResultVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
@@ -33,11 +34,14 @@
 public class RestApi extends BaseController {
 
     private static Logger logger = LoggerFactory.getLogger(RestApi.class);
+    private static final String VERSION = "version";
+    private static final String VERSION_2 = "2.0";
     @Autowired
     private IApiServiceSMO apiServiceSMOImpl;
 
     @Autowired
     private IUserInnerServiceSMO userInnerServiceSMOImpl;
+
 
     /**
      * 鍋ュ悍妫�鏌� 鏈嶅姟
@@ -70,7 +74,6 @@
      * @param request  璇锋眰瀵硅薄 鏌ヨ澶翠俊鎭� url绛変俊鎭�
      * @return http status 200 鎴愬姛 鍏朵粬澶辫触
      */
-
     @RequestMapping(path = "/{service:.+}", method = RequestMethod.POST)
     @ApiOperation(value = "璧勬簮post璇锋眰", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
     @ApiImplicitParam(paramType = "query", name = "service", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "String")
@@ -78,8 +81,9 @@
                                               @RequestBody String postInfo,
                                               HttpServletRequest request) {
         ResponseEntity<String> responseEntity = null;
+        Map<String, String> headers = new HashMap<String, String>();
         try {
-            Map<String, String> headers = new HashMap<String, String>();
+
             this.getRequestInfo(request, headers);
             headers.put(CommonConstant.HTTP_SERVICE, service);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_POST);
@@ -90,7 +94,13 @@
             responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
         }
         logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", service, responseEntity);
-
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            return responseEntity;
+        }
+        //褰� 鎺ュ彛鐗堟湰鍙蜂负2.0鏃� 杩斿洖閿欒澶勭悊
+        if (headers.containsKey(VERSION) && VERSION_2.equals(headers.get(VERSION))) {
+            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, responseEntity.getBody());
+        }
         return responseEntity;
     }
 
@@ -108,8 +118,8 @@
     public ResponseEntity<String> serviceGet(@PathVariable String service,
                                              HttpServletRequest request) {
         ResponseEntity<String> responseEntity = null;
+        Map<String, String> headers = new HashMap<String, String>();
         try {
-            Map<String, String> headers = new HashMap<String, String>();
             this.getRequestInfo(request, headers);
             headers.put(CommonConstant.HTTP_SERVICE, service);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_GET);
@@ -120,6 +130,14 @@
             responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
         }
         logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", service, responseEntity);
+
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            return responseEntity;
+        }
+        //褰� 鎺ュ彛鐗堟湰鍙蜂负2.0鏃� 杩斿洖閿欒澶勭悊
+        if (headers.containsKey(VERSION) && VERSION_2.equals(headers.get(VERSION))) {
+            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, responseEntity.getBody());
+        }
 
         return responseEntity;
     }
@@ -140,8 +158,9 @@
                                              @RequestBody String postInfo,
                                              HttpServletRequest request) {
         ResponseEntity<String> responseEntity = null;
+        Map<String, String> headers = new HashMap<String, String>();
         try {
-            Map<String, String> headers = new HashMap<String, String>();
+
             this.getRequestInfo(request, headers);
             headers.put(CommonConstant.HTTP_SERVICE, service);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_PUT);
@@ -152,6 +171,14 @@
             responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
         }
         logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", service, responseEntity);
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            return responseEntity;
+        }
+        //褰� 鎺ュ彛鐗堟湰鍙蜂负2.0鏃� 杩斿洖閿欒澶勭悊
+        if (headers.containsKey(VERSION) && VERSION_2.equals(headers.get(VERSION))) {
+            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, responseEntity.getBody());
+        }
+
         return responseEntity;
     }
 
@@ -169,8 +196,9 @@
     public ResponseEntity<String> serviceDelete(@PathVariable String service,
                                                 HttpServletRequest request) {
         ResponseEntity<String> responseEntity = null;
+        Map<String, String> headers = new HashMap<String, String>();
         try {
-            Map<String, String> headers = new HashMap<String, String>();
+
             this.getRequestInfo(request, headers);
             headers.put(CommonConstant.HTTP_SERVICE, service);
             headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_DELETE);
@@ -183,6 +211,13 @@
         }
 
         logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", service, responseEntity);
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            return responseEntity;
+        }
+        //褰� 鎺ュ彛鐗堟湰鍙蜂负2.0鏃� 杩斿洖閿欒澶勭悊
+        if (headers.containsKey(VERSION) && VERSION_2.equals(headers.get(VERSION))) {
+            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, responseEntity.getBody());
+        }
         return responseEntity;
     }
 
@@ -205,6 +240,89 @@
     }
 
 
+    /**
+     * 璧勬簮璇锋眰 post鏂瑰紡
+     *
+     * @param resource 璇锋眰鎺ュ彛鏂瑰紡
+     * @param postInfo post鍐呭
+     * @param request  璇锋眰瀵硅薄 鏌ヨ澶翠俊鎭� url绛変俊鎭�
+     * @return http status 200 鎴愬姛 鍏朵粬澶辫触
+     */
+    @RequestMapping(path = "/{resource}/{action}", method = RequestMethod.POST)
+    @ApiOperation(value = "璧勬簮post璇锋眰", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
+    @ApiImplicitParam(paramType = "query", name = "subServicePost", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "String")
+    public ResponseEntity<String> subServicePost(
+            @PathVariable String resource,
+            @PathVariable String action,
+            @RequestBody String postInfo,
+            HttpServletRequest request) {
+        ResponseEntity<String> responseEntity = null;
+        Map<String, String> headers = new HashMap<String, String>();
+        try {
+            this.getRequestInfo(request, headers);
+            headers.put(CommonConstant.HTTP_SERVICE, "/" + resource + "/" + action);
+            headers.put(CommonConstant.HTTP_RESOURCE, resource);
+            headers.put(CommonConstant.HTTP_ACTION, action);
+            headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_POST);
+            logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", action, postInfo, headers);
+            responseEntity = apiServiceSMOImpl.service(postInfo, headers);
+        } catch (Throwable e) {
+            logger.error("璇锋眰post 鏂规硶[" + action + "]澶辫触锛�" + postInfo, e);
+            responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+        logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", action, responseEntity);
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            return responseEntity;
+        }
+        //褰� 鎺ュ彛鐗堟湰鍙蜂负2.0鏃� 杩斿洖閿欒澶勭悊
+        if (headers.containsKey(VERSION) && VERSION_2.equals(headers.get(VERSION))) {
+            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, responseEntity.getBody());
+        }
+        return responseEntity;
+    }
+
+    /**
+     * 璧勬簮璇锋眰 get鏂瑰紡
+     *
+     * @param request 璇锋眰瀵硅薄 鏌ヨ澶翠俊鎭� url绛変俊鎭�
+     * @return http status 200 鎴愬姛 鍏朵粬澶辫触
+     */
+
+    @RequestMapping(path = "/{resource}/{action}", method = RequestMethod.GET)
+    @ApiOperation(value = "璧勬簮get璇锋眰", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
+    @ApiImplicitParam(paramType = "query", name = "subServiceGet", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "String")
+    public ResponseEntity<String> subServiceGet(
+            @PathVariable String resource,
+            @PathVariable String action,
+            HttpServletRequest request) {
+        ResponseEntity<String> responseEntity = null;
+        Map<String, String> headers = new HashMap<String, String>();
+        try {
+            this.getRequestInfo(request, headers);
+            headers.put(CommonConstant.HTTP_SERVICE, "/" + resource + "/" + action);
+            headers.put(CommonConstant.HTTP_RESOURCE, resource);
+            headers.put(CommonConstant.HTTP_ACTION, action);
+            headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_GET);
+            logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", "", headers);
+            responseEntity = apiServiceSMOImpl.service(JSONObject.toJSONString(getParameterStringMap(request)), headers);
+        } catch (Throwable e) {
+            logger.error("璇锋眰get 鏂规硶[" + action + "]澶辫触锛�", e);
+            responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+        logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", action, responseEntity);
+
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            return responseEntity;
+        }
+        //褰� 鎺ュ彛鐗堟湰鍙蜂负2.0鏃� 杩斿洖閿欒澶勭悊
+        if (headers.containsKey(VERSION) && VERSION_2.equals(headers.get(VERSION))) {
+            return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, responseEntity.getBody());
+        }
+
+        return responseEntity;
+    }
+
+
     public IApiServiceSMO getApiServiceSMOImpl() {
         return apiServiceSMOImpl;
     }

--
Gitblit v1.8.0