package com.engine.htxc.common.dto;


import com.alibaba.fastjson.JSON;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810050
 * @version: 1.0
 * @CreateDate: 2022/8/2915:23
 * @Description:
 * @ModifyLog:
 **/
public class EcologyCommonResponseDTO<T> {
    public static final String SUCCESS_CODE = "0";
    public static final String FAIL_CODE = "-1";

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

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

    public static String  failJson(String msg){
        return JSON.toJSONString(new EcologyCommonResponseDTO(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 "EcologyCommonResponseDTO{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
