All Downloads are FREE. Search and download functionalities are using the official Maven repository.

k.e.book.common.model.Result Maven / Gradle / Ivy

package k.e.book.common.model;

import io.swagger.annotations.ApiModelProperty;
import k.e.book.common.enums.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public final class Result implements Serializable {

    public Result(ResultCodeEnum codeEnum, T data, Long count, String detail) {
        this.code = codeEnum.getCode();
        this.data = data;
        this.count = count;
        this.message = codeEnum.getMessage();
        this.detail = detail;
    }

    public Result(int code, T data, Long count, String detail, String message) {
        this.code = code;
        this.data = data;
        this.count = count;
        this.message = message;
        this.detail = detail;
    }

    /**
     * 状态编码
     */
    @ApiModelProperty("状态编码")
    private Integer code;

    /**
     * 状态含义
     */
    private String message;

    /**
     * 返回结果集
     */
    private T data;

    /**
     * 返回总数
     */
    @ApiModelProperty("总的数量")
    private Long count;

    /**
     * 详细信息
     */
    private String detail;

    public static Result fail(String msg){
        return new Result(ResultCodeEnum.ERROR,null,null,msg);
    }

    public static Result fail(){
        return new Result(ResultCodeEnum.ERROR,null,null,"系统异常");
    }

    public static  Result success() {
        return success(null);
    }

    public static  Result success(T data) {
        return success( data, (Long) null);
    }

    public static  Result success(T data, Long count) {
        return new Result(ResultCodeEnum.SUCCESS, data, count, "请求成功!");
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy