Browse Source

修复登录

java110 5 years ago
parent
commit
a0281b3da1

+ 41 - 6
service-api/src/main/java/com/java110/api/rest/RestApi.java

@@ -2,9 +2,10 @@ package com.java110.api.rest;
 
 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.utils.constant.CommonConstant;
+import com.java110.vo.ResultVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
@@ -33,6 +34,8 @@ import java.util.Map;
 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;
 
@@ -78,8 +81,9 @@ public class RestApi extends BaseController {
                                               @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 @@ public class RestApi extends BaseController {
             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 class RestApi extends BaseController {
     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);
@@ -121,6 +131,14 @@ public class RestApi extends BaseController {
         }
         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 @@ public class RestApi extends BaseController {
                                              @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 @@ public class RestApi extends BaseController {
             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 class RestApi extends BaseController {
     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 @@ public class RestApi extends BaseController {
         }
 
         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;
     }
 

+ 20 - 5
service-front/src/main/java/com/java110/front/controller/CallComponentController.java

@@ -1,19 +1,24 @@
 package com.java110.front.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.core.base.controller.BaseController;
+import com.java110.core.context.IPageData;
+import com.java110.core.context.PageData;
 import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.exception.SMOException;
 import com.java110.utils.factory.ApplicationContextFactory;
 import com.java110.utils.util.Assert;
-import com.java110.core.base.controller.BaseController;
-import com.java110.core.context.IPageData;
-import com.java110.core.context.PageData;
+import com.java110.utils.util.StringUtil;
+import com.java110.vo.ResultVo;
 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.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -31,7 +36,8 @@ import java.util.Map;
 public class CallComponentController extends BaseController {
 
     private final static Logger logger = LoggerFactory.getLogger(CallComponentController.class);
-
+    private static final String VERSION = "version";
+    private static final String VERSION_2 = "2.0";
     @Autowired
     private RestTemplate restTemplate;
 
@@ -40,6 +46,7 @@ public class CallComponentController extends BaseController {
      * 前台调用api方法
      * add by wuxw 2020-03-16
      * /callComponent/activities.listActivitiess
+     *
      * @return
      */
 
@@ -91,6 +98,14 @@ public class CallComponentController extends BaseController {
             responseEntity = new ResponseEntity<>(msg, HttpStatus.INTERNAL_SERVER_ERROR);
         } finally {
             logger.debug("api调用返回信息为{}", responseEntity);
+            if (responseEntity.getStatusCode() == HttpStatus.OK) {
+                return responseEntity;
+            }
+            String version = request.getParameter(VERSION);
+            //当 接口版本号为2.0时 返回错误处理
+            if (!StringUtil.isEmpty(version) && VERSION_2.equals(version)) {
+                return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, responseEntity.getBody());
+            }
             return responseEntity;
         }
     }