/** * */ package com.poyee.dto; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; import java.io.Serializable; /** * 控制层统一返回数据格式 * * @author poyee * */ @Data @AllArgsConstructor @NoArgsConstructor @Accessors(chain = true) public class ResultDTO implements Serializable { /** 状态码 成功: 0 */ public static final int RESPCODE_SUCCESS = 0; /** 状态码 失败: 1 */ public static final int RESPCODE_FAILURE = 1; /** 权限不足 */ public static final int RESPCODE_NO_AUTH = -1; /**返回成功信息*/ public static final String MSG_SUCCESS = "OK"; /** 失败信息FAIL */ public static final String MSG_FAIL = "FAIL"; /**权限不足返回信息*/ public static final String MSG_NO_AUTH = "权限不足"; /** 返回码 */ private int code; /** 返回信息 */ private String msg; /** 返回数据 */ private Object data; /** 时间戳 */ private Long timestamp=System.currentTimeMillis(); public ResultDTO(int code, String msg, Object data) { this.code = code; this.msg = msg; this.data = data; } /** * 构造错误result * * @return */ public static ResultDTO buildErrorResult() { return new ResultDTO(RESPCODE_FAILURE, MSG_FAIL, null); } /** * 构造空result * * @return 200 ok */ public static ResultDTO buildEmptySuccess() { return new ResultDTO(RESPCODE_SUCCESS, MSG_SUCCESS, null); } /** * 构造错误result * * @return */ public static ResultDTO buildErrorResult(String msg) { return new ResultDTO(RESPCODE_FAILURE, msg, null); } public static ResultDTO buildErrorResult(int code,String msg) { return new ResultDTO(code, msg, null); } public static ResultDTO build500Error(String msg) { return new ResultDTO(500, msg, null); } public static ResultDTO buildSuccessResult(Object o) { return new ResultDTO(RESPCODE_SUCCESS, MSG_SUCCESS, o); } }