From 5f804115139dfdeeb2ce950a0f584b30f94b285c Mon Sep 17 00:00:00 2001
From: 44323 <443237572@qq.com>
Date: 星期六, 23 九月 2023 17:57:27 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/PlayPai

---
 cloud-server-course/src/main/java/com/dsh/course/util/ResultUtil.java |  108 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 57 insertions(+), 51 deletions(-)

diff --git a/cloud-server-course/src/main/java/com/dsh/course/util/ResultUtil.java b/cloud-server-course/src/main/java/com/dsh/course/util/ResultUtil.java
index 45a64c6..52cf2de 100644
--- a/cloud-server-course/src/main/java/com/dsh/course/util/ResultUtil.java
+++ b/cloud-server-course/src/main/java/com/dsh/course/util/ResultUtil.java
@@ -1,13 +1,8 @@
 package com.dsh.course.util;
 
-import com.alibaba.fastjson.JSONObject;
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
 /**
  * 定义统一返回对象
  */
-@ApiModel(value = "统一返回结果集")
 public class ResultUtil<T> {
 
     public static final Integer SUCCESS = 200;
@@ -18,24 +13,22 @@
 
     public static final Integer ERROR = 500;
 
-    public static final Integer TOKEN_ERROR = 600;
+    public static final String Token = "Token失效";
 
-    public static final Integer SIGN_ERROR = 700;
+    private Integer status;//状态码
 
-    public static final String Token = "TOKEN_INVALID";
-
-    public static final String SIGN = "SIGN_INVALID";
-
-    @ApiModelProperty(name = "code", value = "业务状态码 200:成功,300:参数错误,400:运行异常,500:其他异常, 600:token无效,需重新登录,700:签名无效")
     private Integer code;//备用状态码
 
-    @ApiModelProperty(name = "msg", value = "返回结果说明")
     private String msg;//返回说明
 
-    @ApiModelProperty(name = "data", value = "返回结果值")
     private T data;//返回数据
 
+    private String str;//存储单个字符串值
 
+
+    public Integer getStatus() {
+        return status;
+    }
 
     public String getMsg() {
         return msg;
@@ -45,29 +38,53 @@
         return data;
     }
 
+    public String getStr() {
+        return str;
+    }
 
     public Integer getCode() {
         return code;
     }
 
-    private ResultUtil(Integer code, String msg) {
+    public ResultUtil(Integer status, Integer code, String msg) {
+        this.status = status;
         this.code = code;
         this.msg = msg;
     }
 
-    private ResultUtil(Integer code, String msg, T data) {
+    private ResultUtil(Integer status, Integer code, String msg, T data) {
+        this.status = status;
         this.code = code;
         this.msg = msg;
         this.data = data;
     }
 
-
-    public static <T> ResultUtil<T> getResult(Integer code, String msg){
-        return new ResultUtil<>(code, msg);
+    public ResultUtil(Integer status, Integer code, String msg, T data, String str) {
+        this.status = status;
+        this.code = code;
+        this.msg = msg;
+        this.data = data;
+        this.str = str;
     }
 
-    public static <T> ResultUtil<T> getResult(Integer code, String msg, T data){
-        return new ResultUtil<>(code, msg, data);
+    private ResultUtil(Integer status, Integer code, String msg, String str) {
+        this.status = status;
+        this.code = code;
+        this.msg = msg;
+        this.str = str;
+    }
+
+
+    public static <T> ResultUtil<T> getResult(Integer status, Integer code, String msg){
+        return new ResultUtil<>(status, code, msg);
+    }
+
+    public static <T> ResultUtil<T> getResult(Integer status, Integer code, String msg, T data){
+        return new ResultUtil<>(status, code, msg, data);
+    }
+
+    public static <T> ResultUtil<T> getResult(Integer status, Integer code, String msg, T data, String str){
+        return new ResultUtil<>(status, code, msg, data, str);
     }
 
     /**
@@ -75,7 +92,7 @@
      * @return
      */
     public static ResultUtil error(String mag){
-        return ResultUtil.getResult(ResultUtil.ERROR, mag, new JSONObject());
+        return ResultUtil.getResult(ResultUtil.ERROR, ResultUtil.ERROR, mag);
     }
 
     /**
@@ -83,7 +100,7 @@
      * @return
      */
     public static <T> ResultUtil <T> error(String mag, T obj){
-        return ResultUtil.getResult(ResultUtil.ERROR, mag, obj);
+        return ResultUtil.getResult(ResultUtil.ERROR, ResultUtil.ERROR, mag, obj);
     }
 
     /**
@@ -91,7 +108,7 @@
      * @return
      */
     public static ResultUtil tokenErr(){
-        return ResultUtil.getResult(ResultUtil.TOKEN_ERROR, ResultUtil.Token, new JSONObject());
+        return ResultUtil.getResult(ResultUtil.ERROR, ResultUtil.ERROR, ResultUtil.Token);
     }
 
     /**
@@ -99,15 +116,15 @@
      * @return
      */
     public static ResultUtil tokenErr(String msg){
-        return ResultUtil.getResult(ResultUtil.TOKEN_ERROR, msg, new JSONObject());
+        return ResultUtil.getResult(ResultUtil.ERROR, ResultUtil.ERROR, msg);
     }
 
     /**
      * 参数异常
      * @return
      */
-    public static  ResultUtil paranErr(String ages){
-        return ResultUtil.getResult(ResultUtil.PARAM_ERROR, "【" + ages + "】参数异常", new JSONObject());
+    public static  ResultUtil paranErr(){
+        return ResultUtil.getResult(ResultUtil.PARAM_ERROR, ResultUtil.PARAM_ERROR, "参数异常");
     }
 
     /**
@@ -115,16 +132,15 @@
      * @return
      */
     public static <T> ResultUtil<T> paranErr(T data){
-        return ResultUtil.getResult(ResultUtil.PARAM_ERROR, "PARAM_ERROR", data);
+        return ResultUtil.getResult(ResultUtil.PARAM_ERROR, ResultUtil.PARAM_ERROR, "参数异常", data);
     }
-
 
     /**
      * 运行异常
      * @return
      */
     public static ResultUtil runErr(){
-        return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, "SYSTEM_RUN_ERROR", new JSONObject());
+        return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, ResultUtil.RUNTIME_ERROR, "服务器运行异常");
     }
 
 
@@ -133,15 +149,7 @@
      * @return
      */
     public static <T>ResultUtil<T> runErr(T data){
-        return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, "SYSTEM_RUN_ERROR", data);
-    }
-
-    /**
-     * 运行异常
-     * @return
-     */
-    public static <T>ResultUtil<T> runErr(T data, String msg){
-        return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, msg, data);
+        return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, ResultUtil.RUNTIME_ERROR, "服务器运行异常", data);
     }
 
 
@@ -151,7 +159,7 @@
      * @return
      */
     public static ResultUtil success(){
-        return ResultUtil.getResult(ResultUtil.SUCCESS, "SUCCESS", new JSONObject());
+        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, "成功");
     }
 
 
@@ -162,28 +170,26 @@
      * @return
      */
     public static <T> ResultUtil<T> success(T data){
-        return ResultUtil.getResult(ResultUtil.SUCCESS, "SUCCESS", data);
+        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, "成功", data);
     }
 
     /**
      * 返回成功
-     * @param msg
      * @param data
+     * @param str
      * @param <T>
      * @return
      */
-    public static <T> ResultUtil<T> success(String msg, T data){
-        return ResultUtil.getResult(ResultUtil.SUCCESS, msg, data);
+    public static <T> ResultUtil<T> success(T data, String str){
+        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, "成功", data, str);
     }
 
+    public static <T> ResultUtil<T> success(String msg, T data){
+        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, msg, data);
+    }
 
-    /**
-     * 签名无效
-     * @param <T>
-     * @return
-     */
-    public static <T> ResultUtil<T> sign(){
-        return ResultUtil.getResult(ResultUtil.SIGN_ERROR, SIGN);
+    public static <T> ResultUtil<T> success(String msg, T data, String str){
+        return ResultUtil.getResult(ResultUtil.SUCCESS, ResultUtil.SUCCESS, msg, data, str);
     }
 
 }

--
Gitblit v1.7.1