package com.prolog.eis.utils;

/**
 * @Author wangkang
 * @Description
 * @CreateTime 2021/12/27 13:50
 */
public class DpsResult<T> {

    /**
     * 是否成功
     */
    private boolean success;

    /**
     * 错误代码
     */
    private String code;

    /**
     * 返回消息
     */
    private String msg;

    /**
     * 返回内容
     */
    private T data;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

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

    public String getMsg() {
        return msg;
    }

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

    public T getData() {
        return data;
    }

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

    public DpsResult(boolean success, String code, String msg, T data) {
        super();
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public DpsResult(boolean success, String code, String msg) {
        super();
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public DpsResult() {

    }

    public static <T> DpsResult<T> getSuccessInstance(T data) {
        return new DpsResult<T>(true, "200", "调用成功", data);
    }

    public static <T> DpsResult<T> getFailInstance(Exception e) {
        return new DpsResult<T>(false, "100", "调用失败:" + ((e.getMessage() != null) ? e.getMessage() : "空指针"), null);
    }



    public static <T> DpsResult<T> newInstance(boolean success, String code, String msg, T data) {
        return new DpsResult<T>(success, code, msg, data);
    }

    public static <T> DpsResult<T> newInstance(boolean success, String code, String msg) {
        return new DpsResult<T>(success, code, msg);
    }

    @Override
    public String toString() {
        return "DpsResult [success=" + success + ", code=" + code + ", msg=" + msg + ", data=" + data + "]";
    }

}
