package com.engine.htxc.common;

import com.alibaba.fastjson.JSON;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810039
 * @version: 1.0
 * @CreateDate: 2022-09-21 17:51
 * @Description: 统一返回类
 * @ModifyLog:
 **/
public class EcologyResponseDTO<T> {
    public static final String SUCCESS_CODE = "0";
    public static final String FAIL_CODE = "-1";

    public EcologyResponseDTO(String code, String msg, T data){
        this.code=code;
        this.msg=msg;
        this.data=data;
    }

    public static <T> EcologyResponseDTO<T> success(T data){
        return new EcologyResponseDTO(SUCCESS_CODE,"success",data);
    }
    public static String  successJson(Object data){
        return JSON.toJSONString(new EcologyResponseDTO(SUCCESS_CODE,"success",data));
    }

    public static String  failJson(String msg){
        return JSON.toJSONString(new EcologyResponseDTO(FAIL_CODE,msg,null));
    }

    private String code;
    private String msg;
    private T data;

    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;
    }

    @Override
    public String toString() {
        return "EcologyResponseDTO{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}

