Commit 84617814 by henry

添加枚举类

1 parent 564a1152
package org.arch;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.arch.enums.ExceptionEnum;
/**
* 返回结果
*
* @param <T>
*/
@Data
@ApiModel(value = "返回结果", description = "返回结果")
@Accessors(chain = true)
public class Result<T> {
/**
* 默认成功编码
*/
public static final int SUCCEDD_CODE = 200;
/**
* 默认失败编码
*/
public static final int FAILE_CODE = 500;
/**
* 默认成功返回信息
*/
public static final String SUCCEDD_MSG = "操作成功!";
/**
* 默认失败返回信息
*/
public static final String FAILE_MSG = "系统数据有误,请确认数据信息!";
/**
* 请求结果编码
*/
@ApiModelProperty(value = "返回消息", required = true, notes = ",默认成功返回200,失败返回500,其他错误码根据实际情况返回")
private int code;
/**
* 请求结果消息
*/
@ApiModelProperty(value = "返回消息")
private String msg;
/**
* 请求返回数据
*/
@ApiModelProperty(value = "返回数据")
private T data;
public Result() {
}
public Result(int code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
/**
* 默认成功返回
*
* @return 请求结果
*/
public static Result success() {
return new Result<>(Result.SUCCEDD_CODE, Result.SUCCEDD_MSG, null);
}
/**
* 成功结果
*
* @param msg 返回消息
* @param <T> 数据类型
* @return 请求结果
*/
public static <T> Result success(String msg) {
return new Result<T>(Result.SUCCEDD_CODE, msg, null);
}
/**
* 返回结果
*
* @param data 数据
* @param <T> 数据类型
* @return 请求结果
*/
public static <T> Result success(T data) {
return new Result<T>(Result.SUCCEDD_CODE, Result.SUCCEDD_MSG, data);
}
/**
* 返回结果
*
* @param msg 消息
* @param data 数据
* @param <T> 数据类型
* @return 请求结果
*/
public static <T> Result success(String msg, T data) {
return new Result<T>(Result.SUCCEDD_CODE, msg, data);
}
/**
* 默认成功返回
*
* @return 请求结果
*/
public static Result error() {
return new Result<>(Result.FAILE_CODE, Result.FAILE_MSG, null);
}
/**
* 成功结果
*
* @param msg 返回消息
* @param <T> 数据类型
* @return 请求结
*/
public static <T> Result error(String msg) {
return new Result<T>(Result.FAILE_CODE, msg, null);
}
/**
* 返回结果
*
* @param data 数据
* @param <T> 数据类型
* @return 请求结果
*/
public static <T> Result error(T data) {
return new Result<T>(Result.FAILE_CODE, Result.FAILE_MSG, data);
}
/**
* 返回结果
*
* @param msg 消息
* @param data 数据
* @param <T> 数据类型
* @return 请求结果
*/
public static <T> Result error(String msg, T data) {
return new Result<T>(Result.FAILE_CODE, msg, data);
}
/**
* 请求结果
*
* @param code 请求状态编码
* @param msg 返回消息
* @param <T> 数据类型
* @return 请求结果
*/
public static <T> Result error(int code, String msg) {
return new Result<T>(code, msg, null);
}
/**
* 错误信息
*
* @param exceptionEnum 错误枚举
* @param <T> 数据
* @return 错误信息
*/
public static <T> Result error(ExceptionEnum exceptionEnum) {
return new Result<T>(exceptionEnum.getCode(), exceptionEnum.getMsg(), null);
}
public Boolean isFailed() {
return this.code != 200;
}
}
package org.arch.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ExceptionEnum {
USER_NO_LOGIN(501,"用户未登录!"),
USER_ACCOUNT_NOT_EXIST(502,"账户信息不存在!"),
USER_ACCOUNT_NOT_ACTIVATE(503,"账户未激活!"),
//用户登录
USER_LOGIN_USERNAME_EMPTY(500,"登录用户名为空"),
USER_LOGIN_PASSWORD_EMPTY(500,"登录密码名为空"),
USER_LOGIN_USERNAME_PASSWORD_ERROR(500,"登录用户名或者密码名错误"),
//登录模块异常
NOT_LOGIN (501, "当前用户没有登录,请先进行登录!"),
ACCESS_TOKEN_NOT_BLANK (502,"accessToken为空,请先登录!"),
TOKEN_VALIDATE_CHECK_FAIL (504,"accessToken验证失败,请重新登录!"),
ACCESS_TOKEN_INVALIDATE (506,"无效的accessToken,请重新登录!"),
ACCESS_TOKEN_NOT_EXISTS_REDIS (507,"accessToken不存在或已经过期,请重新登录!"),
LOGIN_FAIL (508,"登录失败!"),
CURR_USER_HAS_NOT_PERMISSION (509,"当前用户没有权限访问该资源或者操作!"),
;
/**
* 错误码
*/
private int code;
/**
* 错误信息
*/
private String msg;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!