package com.ruoyi.zzb.common.bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * 统一响应工具类
 */
public class RspResult {
    private int code;
    private String msg;
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public RspResult() {
    }

    public RspResult(int code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public RspResult(int code, String msg, Object data) {
        super();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }



    /**
     * 操作成功 - 无业务数据返回
     *
     * @return
     */
    public static JSONObject success() {
        return (JSONObject) JSON.toJSON(new RspResult(StateCodeEnum.SUCCESS.getCode(), StateCodeEnum.SUCCESS.getMsg()));
    }

    /**
     * 操作成功 - 有业务数据返回
     *
     * @return
     */
    public static JSONObject success(Object data) {
        return (JSONObject) JSON.toJSON(new RspResult(StateCodeEnum.SUCCESS.getCode(), StateCodeEnum.SUCCESS.getMsg(), data));
    }


    /**
     * 操作失败 - 无业务数据返回
     *
     * @return
     */
    public static JSONObject error() {
        return (JSONObject) JSON.toJSON(new RspResult(StateCodeEnum.ERROR.getCode(), StateCodeEnum.ERROR.getMsg()));
    }


    /**
     * 操作失败 - 有业务数据返回
     *
     * @return
     */
    public static JSONObject error(Object data) {
        return (JSONObject) JSON.toJSON(new RspResult(StateCodeEnum.ERROR.getCode(), StateCodeEnum.ERROR.getMsg(), data));
    }



}
