From e57e32fc43da31917912eebb4e47d4e50df1a9e9 Mon Sep 17 00:00:00 2001
From: shiyj1101 <1098226878@qq.com>
Date: 星期四, 05 八月 2021 22:56:15 +0800
Subject: [PATCH] 完善格式化功能

---
 java110-bean/src/main/java/com/java110/vo/ResultVo.java |  131 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 127 insertions(+), 4 deletions(-)

diff --git a/java110-bean/src/main/java/com/java110/vo/ResultVo.java b/java110-bean/src/main/java/com/java110/vo/ResultVo.java
old mode 100644
new mode 100755
index 3616a19..ee7ea09
--- a/java110-bean/src/main/java/com/java110/vo/ResultVo.java
+++ b/java110-bean/src/main/java/com/java110/vo/ResultVo.java
@@ -1,6 +1,7 @@
 package com.java110.vo;
 
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -19,7 +20,7 @@
 
     public static final int CODE_ERROR = 404;// 鏈煡寮傚父
 
-    public static final int CODE_OK = 200; // 鎴愬姛
+    public static final int CODE_OK = 0; // 鎴愬姛
 
     public static final int CODE_MACHINE_OK = 0; // 鎴愬姛
 
@@ -27,6 +28,7 @@
 
     public static final int CODE_UNAUTHORIZED = 401; //璁よ瘉澶辫触
     public static final int CODE_WECHAT_UNAUTHORIZED = 1401; //璁よ瘉澶辫触
+    public static final int CODE_BUSINESS_VERIFICATION = 5010; //涓氬姟鏍¢獙鏈�氳繃
 
     public static final int ORDER_ERROR = 500; //璁㈠崟璋冨害寮傚父
 
@@ -36,6 +38,9 @@
     public static final String MSG_OK = "鎴愬姛"; // 鎴愬姛
 
     public static final String MSG_UNAUTHORIZED = "璁よ瘉澶辫触"; //璁よ瘉澶辫触
+
+    public static final int DEFAULT_RECORD = 1;
+    public static final int DEFAULT_TOTAL = 1;
 
     // 鍒嗛〉椤垫暟
     private int page;
@@ -48,7 +53,7 @@
     // 鎬昏褰曟暟
     private int total;
 
-    //鐘舵�佸槢
+    //鐘舵��
     private int code;
 
     //閿欒鎻愮ず
@@ -56,6 +61,12 @@
 
     //鏁版嵁瀵硅薄
     private Object data;
+
+    //鐢ㄦ潵瀛樻斁澶ц銆佸皬璁¢噾棰�
+    private Object sumTotal;
+
+    //鎵�闇�鏁版嵁
+    private Object rep;
 
     public ResultVo() {
     }
@@ -77,6 +88,25 @@
         this.records = records;
         this.total = total;
         this.data = data;
+    }
+
+    public ResultVo(int records, int total, Object data, Object sumTotal) {
+        this.code = CODE_OK;
+        this.msg = MSG_OK;
+        this.records = records;
+        this.total = total;
+        this.data = data;
+        this.sumTotal = sumTotal;
+    }
+
+    public ResultVo(int records, int total, Object data, Object sumTotal, Object rep) {
+        this.code = CODE_OK;
+        this.msg = MSG_OK;
+        this.records = records;
+        this.total = total;
+        this.data = data;
+        this.sumTotal = sumTotal;
+        this.rep = rep;
     }
 
     public ResultVo(int code, String msg, Object data) {
@@ -149,9 +179,71 @@
         this.data = data;
     }
 
+    public Object getSumTotal() {
+        return sumTotal;
+    }
+
+    public void setSumTotal(Object sumTotal) {
+        this.sumTotal = sumTotal;
+    }
+
+    public Object getRep() {
+        return rep;
+    }
+
+    public void setRep(Object rep) {
+        this.rep = rep;
+    }
+
     @Override
     public String toString() {
-        return JSONObject.toJSONString(this);
+        return JSONObject.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat);
+    }
+
+
+    /**
+     * 鍒涘缓ResponseEntity瀵硅薄
+     *
+     * @param data 鏁版嵁瀵硅薄
+     * @return
+     */
+    public static ResponseEntity<String> createResponseEntity(Object data) {
+        ResultVo resultVo = new ResultVo(DEFAULT_RECORD, DEFAULT_TOTAL, data);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
+    /**
+     * 鍒涘缓ResponseEntity瀵硅薄
+     *
+     * @param resultVo 鏁版嵁瀵硅薄
+     * @return
+     */
+    public static ResponseEntity<String> createResponseEntity(ResultVo resultVo) {
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
+    /**
+     * 鎴愬姛閫氱敤鍥炲
+     *
+     * @return
+     */
+    public static ResponseEntity<String> success() {
+        ResultVo resultVo = new ResultVo(CODE_OK, MSG_OK);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
+    /**
+     * 鎴愬姛閫氱敤鍥炲
+     *
+     * @return
+     */
+    public static ResponseEntity<String> error(String msg) {
+        ResultVo resultVo = new ResultVo(CODE_ERROR, msg);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
     }
 
     /**
@@ -169,14 +261,30 @@
     }
 
     /**
+     * 鍒涘缓ResponseEntity瀵硅薄
+     *
+     * @param records
+     * @param total
+     * @param data
+     * @param sumTotal
+     * @return
+     */
+    public static ResponseEntity<String> createResponseEntity(int records, int total, Object data, Object sumTotal) {
+        ResultVo resultVo = new ResultVo(records, total, data, sumTotal);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
+    /**
      * 椤甸潰璺宠浆
+     *
      * @param url
      * @return
      */
     public static ResponseEntity<String> redirectPage(String url) {
         HttpHeaders headers = new HttpHeaders();
         headers.add(HttpHeaders.LOCATION, url);
-        ResponseEntity<String> responseEntity = new ResponseEntity<String>("123123", headers, HttpStatus.BAD_REQUEST);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>("", headers, HttpStatus.FOUND);
         return responseEntity;
     }
 
@@ -197,6 +305,19 @@
     /**
      * 鍒涘缓ResponseEntity瀵硅薄
      *
+     * @param code 鐘舵�佸槢
+     * @param msg  杩斿洖淇℃伅
+     * @return
+     */
+    public static ResponseEntity<String> createResponseEntity(int code, String msg) {
+        ResultVo resultVo = new ResultVo(code, msg);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
+    /**
+     * 鍒涘缓ResponseEntity瀵硅薄
+     *
      * @param records 椤垫暟
      * @param total   鎬昏褰曟暟
      * @param code    鐘舵�佸槢
@@ -209,4 +330,6 @@
         ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
         return responseEntity;
     }
+
+
 }

--
Gitblit v1.8.0