This commit is contained in:
2023-03-04 16:29:55 +08:00
commit 397ba75479
1007 changed files with 109050 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package com.jsowell.common.exception;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import lombok.Data;
@Data
public class BusinessException extends RuntimeException{
private static final long serialVersionUID = 1L;
/**
* 错误码
*/
private String code;
/**
* 错误提示
*/
private String message;
public BusinessException(ReturnCodeEnum returnCodeEnum) {
this.code = returnCodeEnum.getValue();
this.message = returnCodeEnum.getLabel();
}
public BusinessException(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -0,0 +1,13 @@
package com.jsowell.common.exception;
/**
* 演示模式异常
*
* @author jsowell
*/
public class DemoModeException extends RuntimeException {
private static final long serialVersionUID = 1L;
public DemoModeException() {
}
}

View File

@@ -0,0 +1,51 @@
package com.jsowell.common.exception;
/**
* 全局异常
*
* @author jsowell
*/
public class GlobalException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* 错误提示
*/
private String message;
/**
* 错误明细,内部调试错误
* <p>
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
*/
private String detailMessage;
/**
* 空构造方法,避免反序列化问题
*/
public GlobalException() {
}
public GlobalException(String message) {
this.message = message;
}
public String getDetailMessage() {
return detailMessage;
}
public GlobalException setDetailMessage(String detailMessage) {
this.detailMessage = detailMessage;
return this;
}
@Override
public String getMessage() {
return message;
}
public GlobalException setMessage(String message) {
this.message = message;
return this;
}
}

View File

@@ -0,0 +1,65 @@
package com.jsowell.common.exception;
/**
* 业务异常
*
* @author jsowell
*/
public final class ServiceException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* 错误码
*/
private Integer code;
/**
* 错误提示
*/
private String message;
/**
* 错误明细,内部调试错误
* <p>
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
*/
private String detailMessage;
/**
* 空构造方法,避免反序列化问题
*/
public ServiceException() {
}
public ServiceException(String message) {
this.message = message;
}
public ServiceException(String message, Integer code) {
this.message = message;
this.code = code;
}
public String getDetailMessage() {
return detailMessage;
}
@Override
public String getMessage() {
return message;
}
public Integer getCode() {
return code;
}
public ServiceException setMessage(String message) {
this.message = message;
return this;
}
public ServiceException setDetailMessage(String detailMessage) {
this.detailMessage = detailMessage;
return this;
}
}

View File

@@ -0,0 +1,22 @@
package com.jsowell.common.exception;
/**
* 工具类异常
*
* @author jsowell
*/
public class UtilException extends RuntimeException {
private static final long serialVersionUID = 8247610319171014183L;
public UtilException(Throwable e) {
super(e.getMessage(), e);
}
public UtilException(String message) {
super(message);
}
public UtilException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@@ -0,0 +1,84 @@
package com.jsowell.common.exception.base;
import com.jsowell.common.util.MessageUtils;
import com.jsowell.common.util.StringUtils;
/**
* 基础异常
*
* @author jsowell
*/
public class BaseException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* 所属模块
*/
private String module;
/**
* 错误码
*/
private String code;
/**
* 错误码对应的参数
*/
private Object[] args;
/**
* 错误消息
*/
private String defaultMessage;
public BaseException(String module, String code, Object[] args, String defaultMessage) {
this.module = module;
this.code = code;
this.args = args;
this.defaultMessage = defaultMessage;
}
public BaseException(String module, String code, Object[] args) {
this(module, code, args, null);
}
public BaseException(String module, String defaultMessage) {
this(module, null, null, defaultMessage);
}
public BaseException(String code, Object[] args) {
this(null, code, args, null);
}
public BaseException(String defaultMessage) {
this(null, null, null, defaultMessage);
}
@Override
public String getMessage() {
String message = null;
if (!StringUtils.isEmpty(code)) {
message = MessageUtils.message(code, args);
}
if (message == null) {
message = defaultMessage;
}
return message;
}
public String getModule() {
return module;
}
public String getCode() {
return code;
}
public Object[] getArgs() {
return args;
}
public String getDefaultMessage() {
return defaultMessage;
}
}

View File

@@ -0,0 +1,17 @@
package com.jsowell.common.exception.file;
import com.jsowell.common.exception.base.BaseException;
/**
* 文件信息异常类
*
* @author jsowell
*/
public class FileException extends BaseException {
private static final long serialVersionUID = 1L;
public FileException(String code, Object[] args) {
super("file", code, args, null);
}
}

View File

@@ -0,0 +1,14 @@
package com.jsowell.common.exception.file;
/**
* 文件名称超长限制异常类
*
* @author jsowell
*/
public class FileNameLengthLimitExceededException extends FileException {
private static final long serialVersionUID = 1L;
public FileNameLengthLimitExceededException(int defaultFileNameLength) {
super("upload.filename.exceed.length", new Object[]{defaultFileNameLength});
}
}

View File

@@ -0,0 +1,14 @@
package com.jsowell.common.exception.file;
/**
* 文件名大小限制异常类
*
* @author jsowell
*/
public class FileSizeLimitExceededException extends FileException {
private static final long serialVersionUID = 1L;
public FileSizeLimitExceededException(long defaultMaxSize) {
super("upload.exceed.maxSize", new Object[]{defaultMaxSize});
}
}

View File

@@ -0,0 +1,69 @@
package com.jsowell.common.exception.file;
import org.apache.commons.fileupload.FileUploadException;
import java.util.Arrays;
/**
* 文件上传 误异常类
*
* @author jsowell
*/
public class InvalidExtensionException extends FileUploadException {
private static final long serialVersionUID = 1L;
private String[] allowedExtension;
private String extension;
private String filename;
public InvalidExtensionException(String[] allowedExtension, String extension, String filename) {
super("文件[" + filename + "]后缀[" + extension + "]不正确,请上传" + Arrays.toString(allowedExtension) + "格式");
this.allowedExtension = allowedExtension;
this.extension = extension;
this.filename = filename;
}
public String[] getAllowedExtension() {
return allowedExtension;
}
public String getExtension() {
return extension;
}
public String getFilename() {
return filename;
}
public static class InvalidImageExtensionException extends InvalidExtensionException {
private static final long serialVersionUID = 1L;
public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename) {
super(allowedExtension, extension, filename);
}
}
public static class InvalidFlashExtensionException extends InvalidExtensionException {
private static final long serialVersionUID = 1L;
public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename) {
super(allowedExtension, extension, filename);
}
}
public static class InvalidMediaExtensionException extends InvalidExtensionException {
private static final long serialVersionUID = 1L;
public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename) {
super(allowedExtension, extension, filename);
}
}
public static class InvalidVideoExtensionException extends InvalidExtensionException {
private static final long serialVersionUID = 1L;
public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename) {
super(allowedExtension, extension, filename);
}
}
}

View File

@@ -0,0 +1,29 @@
package com.jsowell.common.exception.job;
/**
* 计划策略异常
*
* @author jsowell
*/
public class TaskException extends Exception {
private static final long serialVersionUID = 1L;
private Code code;
public TaskException(String msg, Code code) {
this(msg, code, null);
}
public TaskException(String msg, Code code, Exception nestedEx) {
super(msg, nestedEx);
this.code = code;
}
public Code getCode() {
return code;
}
public enum Code {
TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE
}
}

View File

@@ -0,0 +1,14 @@
package com.jsowell.common.exception.user;
/**
* 验证码错误异常类
*
* @author jsowell
*/
public class CaptchaException extends UserException {
private static final long serialVersionUID = 1L;
public CaptchaException() {
super("user.jcaptcha.error", null);
}
}

View File

@@ -0,0 +1,14 @@
package com.jsowell.common.exception.user;
/**
* 验证码失效异常类
*
* @author jsowell
*/
public class CaptchaExpireException extends UserException {
private static final long serialVersionUID = 1L;
public CaptchaExpireException() {
super("user.jcaptcha.expire", null);
}
}

View File

@@ -0,0 +1,16 @@
package com.jsowell.common.exception.user;
import com.jsowell.common.exception.base.BaseException;
/**
* 用户信息异常类
*
* @author jsowell
*/
public class UserException extends BaseException {
private static final long serialVersionUID = 1L;
public UserException(String code, Object[] args) {
super("user", code, args, null);
}
}

View File

@@ -0,0 +1,14 @@
package com.jsowell.common.exception.user;
/**
* 用户密码不正确或不符合规范异常类
*
* @author jsowell
*/
public class UserPasswordNotMatchException extends UserException {
private static final long serialVersionUID = 1L;
public UserPasswordNotMatchException() {
super("user.password.not.match", null);
}
}

View File

@@ -0,0 +1,14 @@
package com.jsowell.common.exception.user;
/**
* 用户错误最大次数异常类
*
* @author jsowell
*/
public class UserPasswordRetryLimitExceedException extends UserException {
private static final long serialVersionUID = 1L;
public UserPasswordRetryLimitExceedException(int retryLimitCount, int lockTime) {
super("user.password.retry.limit.exceed", new Object[]{retryLimitCount, lockTime});
}
}