package com.jd.lightapplication.common.lang;

import lombok.Data;

import java.io.Serializable;

/**
 * 功能描述：封装结果数据
 *
 * @Author WaiterXiaoYY
 * @Date 2022/1/13 21:20
 * @Version 1.0
 */
@Data
public class R implements Serializable {

    private int code;
    private String msg;
    private Object data;

    public static R success() {
        return success(200, "操作成功", null);
    }

    public static R success(Object data) {
        return success(200, "操作成功", data);
    }

    public static R success(int code, String msg, Object data) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static R fail(String msg) {
        return fail(400, msg, null);
    }

    public static R fail(int code, String msg, Object data) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

}
