wuxw
2022-01-15 e3aed650aa4e232f4583a00fc3de088276a2188b
java110-bean/src/main/java/com/java110/vo/ResultVo.java
old mode 100644 new mode 100755
@@ -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; //订单调度异常
@@ -37,6 +39,13 @@
    public static final String MSG_UNAUTHORIZED = "认证失败"; //认证失败
    public static final int DEFAULT_RECORD = 1;
    public static final int DEFAULT_TOTAL = 1;
    public static final int CODE_WAIT_PAY = 41;// 支付未完成
    public static final String EMPTY_ARRAY = "[]";
    // 分页页数
    private int page;
    // 行数
@@ -46,9 +55,9 @@
    private int records;
    // 总记录数
    private int total;
    private long total;
    //状态嘛
    //状态
    private int code;
    //错误提示
@@ -56,6 +65,12 @@
    //数据对象
    private Object data;
    //用来存放大计、小计金额
    private Object sumTotal;
    //所需数据
    private Object rep;
    public ResultVo() {
    }
@@ -77,6 +92,33 @@
        this.records = records;
        this.total = total;
        this.data = data;
    }
    public ResultVo(int records, long total, Object data) {
        this.code = CODE_OK;
        this.msg = MSG_OK;
        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) {
@@ -117,7 +159,7 @@
        this.records = records;
    }
    public int getTotal() {
    public long getTotal() {
        return total;
    }
@@ -149,9 +191,93 @@
        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,HttpStatus status) {
        ResultVo resultVo = new ResultVo(CODE_ERROR, msg);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), status);
        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;
    }
    /**
     * 成功通用回复
     *
     * @return
     */
    public static ResponseEntity<String> error(String msg,Object data) {
        ResultVo resultVo = new ResultVo(CODE_ERROR, msg,data);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
    /**
@@ -169,7 +295,23 @@
    }
    /**
     * 创建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
     */
@@ -197,6 +339,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 +364,6 @@
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
}