ソースを参照

绑定直播间 feign

lyhzzz 3 年 前
コミット
40d3c41e7f

+ 3 - 1
platform-api/src/main/java/com/platform/api/ApiAddressController.java

@@ -3,9 +3,11 @@ package com.platform.api;
 import com.alibaba.fastjson.JSONObject;
 import com.platform.annotation.LoginUser;
 import com.platform.entity.AddressVo;
+import com.platform.entity.Result;
 import com.platform.entity.UserVo;
 import com.platform.service.ApiAddressService;
 import com.platform.util.ApiBaseAction;
+import com.platform.vos.ReturnDTO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -60,7 +62,7 @@ public class ApiAddressController extends ApiBaseAction {
         if (!entity.getUserId().equals(loginUser.getUserId())) {
             return toResponsObject(403, "您无权查看", "");
         }
-        return toResponsSuccess(entity);
+        return Result.success(entity);
     }
 
     /**

+ 10 - 22
platform-api/src/main/java/com/platform/util/ApiBaseAction.java

@@ -1,6 +1,7 @@
 package com.platform.util;
 
 import com.alibaba.fastjson.JSONObject;
+import com.platform.entity.Result;
 import com.platform.entity.TokenEntity;
 import com.platform.interceptor.AuthorizationInterceptor;
 import com.platform.service.TokenService;
@@ -56,7 +57,7 @@ public class ApiBaseAction {
      */
     @ExceptionHandler({BindException.class, MissingServletRequestParameterException.class, UnauthorizedException.class, TypeMismatchException.class})
     @ResponseBody
-    public Map<String, Object> bindException(Exception e) {
+    public Result bindException(Exception e) {
         if (e instanceof BindException) {
             return toResponsObject(1, "参数绑定异常", e.getMessage());
         } else if (e instanceof UnauthorizedException) {
@@ -75,33 +76,20 @@ public class ApiBaseAction {
      * @date 2016年9月2日
      * @author zhuliyun
      */
-    public Map<String, Object> toResponsObject(int requestCode, String msg, Object data) {
-        Map<String, Object> obj = new HashMap<String, Object>();
-        obj.put("errno", requestCode);
-        obj.put("errmsg", msg);
-        if (data != null)
-            obj.put("data", data);
-        return obj;
+    public Result toResponsObject(int requestCode, String msg, Object data) {
+        return Result.failure(requestCode,msg,data);
     }
 
-    public Map<String, Object> toResponsSuccess(Object data) {
-        Map<String, Object> rp = toResponsObject(0, "执行成功", data);
-        logger.info("response:{}",JSONObject.toJSONString(rp));
-        return rp;
+    public Result toResponsSuccess(Object data) {
+        return Result.success(data);
     }
 
-    public Map<String, Object> toResponsMsgSuccess(String msg) {
-        return toResponsObject(0, msg, "");
+    public Result toResponsMsgSuccess(String msg) {
+        return toResponsSuccess(msg);
     }
 
-    public Map<String, Object> toResponsSuccessForSelect(Object data) {
-        Map<String, Object> result = new HashMap<>(2);
-        result.put("list", data);
-        return toResponsObject(0, "执行成功", result);
-    }
-
-    public Map<String, Object> toResponsFail(String msg) {
-        return toResponsObject(1, msg, null);
+    public Result toResponsFail(String msg) {
+        return Result.failure(msg);
     }
 
     /**

+ 3 - 0
platform-common/src/main/java/com/platform/entity/Result.java

@@ -88,6 +88,9 @@ public class Result implements Serializable {
     public static Result failure(Integer code, String msg) {
         return new Result(code, msg, NOOP);
     }
+    public static Result failure(Integer code, String msg,Object data) {
+        return new Result(code, msg, data);
+    }
     /**
      * 处理失败
      *