package com.diagbot.dto;

/**
 * @Description: 通用返回对象
 * @author: rengb
 * @time: 2021/1/5 18:27
 */
public class CommonResult<T> {

    private long code;
    private String message;
    private T data;

    protected CommonResult() {
    }

    protected CommonResult(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public long getCode() {
        return code;
    }

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

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

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

    public static <T> RespDTO<T> tranResp(CommonResult<T> commonResult) {
        RespDTO respDTO = new RespDTO();
        if (commonResult.code == 500l) {
            respDTO.code = "-1";
        } else if (commonResult.code == 200l) {
            respDTO.code = "0";
        } else {
            respDTO.code = commonResult.code + "";
        }
        respDTO.msg = commonResult.message;
        respDTO.data = commonResult.data;
        return respDTO;
    }

}