JsonResult.java 4.31 KB
package com.qgutech.common;

/**
 * @author xxx
 * @date 2024/12/19 9:58
 * @description
 */
public class JsonResult<T> {
    private boolean success = true;
    private T data;
    private String msg;
    private String errCode;

    public JsonResult() {
    }

    public JsonResult(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }

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

    public JsonResult(boolean success, String errCode, String msg, T data) {
        this.success = success;
        this.errCode = errCode;
        this.msg = msg;
        this.data = data;
    }

    public static JsonResult ok() {
        return new JsonResult();
    }

    public static JsonResult ok(String msg) {
        return new JsonResult(true, msg);
    }

    public static <T> JsonResult ok(String msg, T data) {
        return new JsonResult(true, msg, data);
    }

    public static JsonResult error() {
        return new JsonResult(false, (String)null);
    }

    public static JsonResult error(String msg) {
        return new JsonResult(false, msg);
    }

    public static <T> JsonResult error(String errCode, String msg) {
        return new JsonResult(false, errCode, msg);
    }

    public boolean isSuccess() {
        return this.success;
    }

    public T getData() {
        return this.data;
    }

    public String getMsg() {
        return this.msg;
    }

    public String getErrCode() {
        return this.errCode;
    }

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

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

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

    public void setErrCode(final String errCode) {
        this.errCode = errCode;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof JsonResult)) {
            return false;
        } else {
            JsonResult<?> other = (JsonResult)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.isSuccess() != other.isSuccess()) {
                return false;
            } else {
                label49: {
                    Object this$data = this.getData();
                    Object other$data = other.getData();
                    if (this$data == null) {
                        if (other$data == null) {
                            break label49;
                        }
                    } else if (this$data.equals(other$data)) {
                        break label49;
                    }

                    return false;
                }

                Object this$msg = this.getMsg();
                Object other$msg = other.getMsg();
                if (this$msg == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$msg.equals(other$msg)) {
                    return false;
                }

                Object this$errCode = this.getErrCode();
                Object other$errCode = other.getErrCode();
                if (this$errCode == null) {
                    if (other$errCode != null) {
                        return false;
                    }
                } else if (!this$errCode.equals(other$errCode)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof JsonResult;
    }

    public int hashCode() {
        int result = 1;
        result = result * 59 + (this.isSuccess() ? 79 : 97);
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        Object $msg = this.getMsg();
        result = result * 59 + ($msg == null ? 43 : $msg.hashCode());
        Object $errCode = this.getErrCode();
        result = result * 59 + ($errCode == null ? 43 : $errCode.hashCode());
        return result;
    }

    public String toString() {
        return "JsonResult(success=" + this.isSuccess() + ", data=" + this.getData() + ", msg=" + this.getMsg() + ", errCode=" + this.getErrCode() + ")";
    }
}