新增:erp、erp-spi
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package com.zsw.exception;
|
||||
|
||||
/**
|
||||
* 运行期异常基类
|
||||
*
|
||||
* @author 云久
|
||||
* @version 1.0
|
||||
* @see Exception
|
||||
*/
|
||||
public abstract class BaseCheckedException extends Exception implements BaseException {
|
||||
|
||||
private static final long serialVersionUID = 2706069899924648586L;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
protected String message;
|
||||
|
||||
/**
|
||||
* 具体异常码
|
||||
*/
|
||||
protected int code;
|
||||
|
||||
public BaseCheckedException(int code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BaseCheckedException(int code, String format, Object... args) {
|
||||
super(String.format(format, args));
|
||||
this.code = code;
|
||||
this.message = String.format(format, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.zsw.exception;
|
||||
|
||||
/**
|
||||
* 异常接口类
|
||||
*
|
||||
* @author 云久
|
||||
* @version 1.0,
|
||||
*/
|
||||
public interface BaseException {
|
||||
|
||||
/**
|
||||
* 统一参数验证异常码
|
||||
*/
|
||||
int BASE_VALID_PARAM = -9;
|
||||
|
||||
/**
|
||||
* 返回异常信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
/**
|
||||
* 返回异常编码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getCode();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.zsw.exception;
|
||||
|
||||
/**
|
||||
* 非运行期异常基类,所有自定义非运行时异常继承该类
|
||||
*
|
||||
* @author 云久
|
||||
* @version 1.0,
|
||||
* @see RuntimeException
|
||||
*/
|
||||
public class BaseUncheckedException extends RuntimeException implements BaseException {
|
||||
|
||||
private static final long serialVersionUID = -778887391066124051L;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
protected String message;
|
||||
|
||||
/**
|
||||
* 具体异常码
|
||||
*/
|
||||
protected int code;
|
||||
|
||||
public BaseUncheckedException(int code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BaseUncheckedException(int code, String format, Object... args) {
|
||||
super(String.format(format, args));
|
||||
this.code = code;
|
||||
this.message = String.format(format, args);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.zsw.exception;
|
||||
|
||||
import com.zsw.exception.code.BaseExceptionCode;
|
||||
|
||||
/**
|
||||
* 业务异常
|
||||
* 用于在处理业务逻辑时,进行抛出的异常。
|
||||
*
|
||||
* @author 云久
|
||||
* @version 1.0,
|
||||
* @see Exception
|
||||
*/
|
||||
public class BizException extends BaseUncheckedException {
|
||||
|
||||
private static final long serialVersionUID = -3843907364558373817L;
|
||||
|
||||
public BizException(String message) {
|
||||
super(-1, message);
|
||||
}
|
||||
|
||||
public BizException(int code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
|
||||
public BizException(int code, String message, Object... args) {
|
||||
super(code, message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化异常
|
||||
*
|
||||
* @param code 自定义异常编码
|
||||
* @param message 自定义异常消息
|
||||
* @param args 已定义异常参数
|
||||
* @return
|
||||
*/
|
||||
public static BizException wrap(int code, String message, Object... args) {
|
||||
return new BizException(code, message, args);
|
||||
}
|
||||
|
||||
public static BizException wrap(String message, Object... args) {
|
||||
return new BizException(-1, message, args);
|
||||
}
|
||||
|
||||
public static BizException validFail(String message, Object... args) {
|
||||
return new BizException(-9, message, args);
|
||||
}
|
||||
|
||||
public static BizException wrap(BaseExceptionCode ex) {
|
||||
return new BizException(ex.getCode(), ex.getMsg());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BizException [message=" + message + ", code=" + code + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.zsw.exception;
|
||||
|
||||
/**
|
||||
* 非业务异常
|
||||
* 用于在处理非业务逻辑时,进行抛出的异常。
|
||||
*
|
||||
* @author 云久
|
||||
* @version 1.0
|
||||
* @see Exception
|
||||
*/
|
||||
public class CommonException extends BaseCheckedException {
|
||||
|
||||
|
||||
public CommonException(int code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
|
||||
public CommonException(int code, String format, Object... args) {
|
||||
super(code, String.format(format, args));
|
||||
this.code = code;
|
||||
this.message = String.format(format, args);
|
||||
}
|
||||
|
||||
public CommonException wrap(int code, String format, Object... args) {
|
||||
return new CommonException(code, format, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BizException [message=" + message + ", code=" + code + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.zsw.exception.code;
|
||||
|
||||
|
||||
public interface BaseExceptionCode {
|
||||
/**
|
||||
* 异常编码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getCode();
|
||||
|
||||
/**
|
||||
* 异常消息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getMsg();
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.zsw.exception.code;
|
||||
|
||||
|
||||
/**
|
||||
* 全局错误码 10000-15000
|
||||
* <p>
|
||||
* 预警异常编码 范围: 30000~34999
|
||||
* 标准服务异常编码 范围:35000~39999
|
||||
* 邮件服务异常编码 范围:40000~44999
|
||||
* 短信服务异常编码 范围:45000~49999
|
||||
* 权限服务异常编码 范围:50000-59999
|
||||
* 文件服务异常编码 范围:60000~64999
|
||||
* 日志服务异常编码 范围:65000~69999
|
||||
* 消息服务异常编码 范围:70000~74999
|
||||
* 开发者平台异常编码 范围:75000~79999
|
||||
* 搜索服务异常编码 范围:80000-84999
|
||||
* 共享交换异常编码 范围:85000-89999
|
||||
* 移动终端平台 异常码 范围:90000-94999
|
||||
* <p>
|
||||
* 安全保障平台 范围: 95000-99999
|
||||
* 软硬件平台 异常编码 范围: 100000-104999
|
||||
* 运维服务平台 异常编码 范围: 105000-109999
|
||||
* 统一监管平台异常 编码 范围: 110000-114999
|
||||
* 认证方面的异常编码 范围:115000-115999
|
||||
*
|
||||
* @author 云久
|
||||
* @createTime 2017-12-13 16:22
|
||||
*/
|
||||
public enum ExceptionCode implements BaseExceptionCode {
|
||||
|
||||
//系统相关 start
|
||||
SUCCESS(0, "成功"),
|
||||
SYSTEM_BUSY(-1, "系统繁忙~请稍后再试~"),
|
||||
SYSTEM_TIMEOUT(-2, "系统维护中~请稍后再试~"),
|
||||
PARAM_EX(-3, "参数类型解析异常"),
|
||||
SQL_EX(-4, "运行SQL出现异常"),
|
||||
NULL_POINT_EX(-5, "空指针异常"),
|
||||
ILLEGALA_ARGUMENT_EX(-6, "无效参数异常"),
|
||||
MEDIA_TYPE_EX(-7, "请求类型异常"),
|
||||
LOAD_RESOURCES_ERROR(-8, "加载资源出错"),
|
||||
BASE_VALID_PARAM(-9, "统一验证参数异常"),
|
||||
OPERATION_EX(-10, "操作异常"),
|
||||
SERVICE_MAPPER_ERROR(-11, "Mapper类转换异常"),
|
||||
CAPTCHA_ERROR(-12, "验证码校验失败"),
|
||||
DuplicateKey(-13,"数据重复"),
|
||||
|
||||
OK(200, "OK"),
|
||||
BAD_REQUEST(400, "错误的请求"),
|
||||
/**
|
||||
* {@code 401 Unauthorized}.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc7235#section-3.1">HTTP/1.1: Authentication, section 3.1</a>
|
||||
*/
|
||||
UNAUTHORIZED(401, "未经授权"),
|
||||
/**
|
||||
* {@code 404 Not Found}.
|
||||
*
|
||||
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.4">HTTP/1.1: Semantics and Content, section 6.5.4</a>
|
||||
*/
|
||||
NOT_FOUND(404, "没有找到资源"),
|
||||
METHOD_NOT_ALLOWED(405, "不支持当前请求类型"),
|
||||
|
||||
TOO_MANY_REQUESTS(429, "请求超过次数限制"),
|
||||
INTERNAL_SERVER_ERROR(500, "内部服务错误"),
|
||||
BAD_GATEWAY(502, "网关错误"),
|
||||
GATEWAY_TIMEOUT(504, "网关超时"),
|
||||
//系统相关 end
|
||||
|
||||
REQUIRED_FILE_PARAM_EX(1001, "请求中必须至少包含一个有效文件"),
|
||||
|
||||
DATA_SAVE_ERROR(2000, "新增数据失败"),
|
||||
DATA_UPDATE_ERROR(2001, "修改数据失败"),
|
||||
TOO_MUCH_DATA_ERROR(2002, "批量新增数据过多"),
|
||||
//jwt token 相关 start
|
||||
|
||||
JWT_BASIC_INVALID(40000, "无效的基本身份验证令牌"),
|
||||
JWT_TOKEN_EXPIRED(40001, "会话超时,请重新登录"),
|
||||
JWT_SIGNATURE(40002, "不合法的token,请认真比对 token 的签名"),
|
||||
JWT_ILLEGAL_ARGUMENT(40003, "缺少token参数"),
|
||||
JWT_GEN_TOKEN_FAIL(40004, "生成token失败"),
|
||||
JWT_PARSER_TOKEN_FAIL(40005, "解析用户身份错误,请重新登录!"),
|
||||
JWT_USER_INVALID(40006, "用户名或密码错误"),
|
||||
JWT_USER_ENABLED(40007, "用户已经被禁用!"),
|
||||
JWT_OFFLINE(40008, "您已在另一个设备登录!"),
|
||||
USER_NOT_BIND_PLATFORM(40030,"您没有注册平台会员,暂不支持本操作"),
|
||||
//jwt token 相关 end
|
||||
|
||||
;
|
||||
|
||||
private int code;
|
||||
private String msg;
|
||||
|
||||
ExceptionCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
public ExceptionCode build(String msg, Object... param) {
|
||||
this.msg = String.format(msg, param);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExceptionCode param(Object... param) {
|
||||
msg = String.format(msg, param);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user