package cn.fiona.pet.account.facade;

import cn.fiona.pet.account.entity.RestResultEnum;
import cn.fiona.pet.account.exception.ApiException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiResponse;

import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

/**
 * rest result
 *
 * @author baiqw
 */
@XmlRootElement
@ApiModel("返回结果")
public class RestResult<T> implements Serializable {
    @ApiModelProperty("错误码:0 无错误信息;404 未找到资源; 500 服务器错误;")
    RestResultEnum resultEnum = RestResultEnum.OK;

    public RestResult(RestResultEnum resultEnum) {
        this.resultEnum = resultEnum;
    }

    public static <T> RestResult<T> REST_RESULT(RestResultEnum resultEnum, T data){
        RestResult restResult = new RestResult(resultEnum);
        restResult.setData(data);
        return restResult;
    }

    public static <T> RestResult<T> NOT_FOND(){
        RestResult<T> restResult = new RestResult<T>(RestResultEnum.NOT_FONT);
        return restResult;
    }

    public static <T> RestResult<T> OK(T data){
        RestResult restResult = new RestResult(RestResultEnum.OK);
        restResult.setData(data);
        return restResult;
    }

    @ApiModelProperty("数据信息")
    private T data;

    public int getCode() {
        return resultEnum.getCode();
    }

    public String getMessage() {
        return resultEnum.getDesc();
    }

    public T getData() {
        return data;
    }

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

    public static <T> RestResult<T> ERROR(String message) {
        RestResult restResult = new RestResult(RestResultEnum.SERVER_ERROR);
        restResult.setData(message);
        return restResult;
    }

    public static RestResult<String> REST_RESULT(ApiException apiE) {
        RestResult restResult = new RestResult(RestResultEnum.SERVER_ERROR);
        restResult.setData(apiE.getMessage());
        return restResult;
    }
}

@@ -534,24 +534,32 @@
 %E5%8A%A1%E5%99%A8%E9%94%99%E8%AF%AF;%22)%0A    
+private 
 RestResultEn
@@ -594,16 +594,50 @@
 um.OK;%0A%0A
+    public RestResult() %7B%0A%0A    %7D%0A%0A
     publ
@@ -1471,32 +1471,208 @@
 tDesc();%0A    %7D%0A%0A
+    public void setCode(int code) %7B%0A        this.resultEnum.setCode(code);%0A    %7D%0A%0A    public void setMessage(String message) %7B%0A        this.resultEnum.setDesc(message);%0A    %7D%0A%0A
     public T get

modify restresult