正在显示
18 个修改的文件
包含
176 行增加
和
91 行删除
| 1 | +package com.ruoyi.common.exception; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 全局异常 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public class GlobalException extends RuntimeException | ||
| 9 | +{ | ||
| 10 | + | ||
| 11 | + private static final long serialVersionUID = 1L; | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 错误提示 | ||
| 15 | + */ | ||
| 16 | + private String message; | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 错误明细,内部调试错误 | ||
| 20 | + * | ||
| 21 | + * 和 {@link CommonResult#getDetailMessage()} 一致的设计 | ||
| 22 | + */ | ||
| 23 | + private String detailMessage; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 空构造方法,避免反序列化问题 | ||
| 27 | + */ | ||
| 28 | + public GlobalException() | ||
| 29 | + { | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public GlobalException(String message) | ||
| 33 | + { | ||
| 34 | + this.message = message; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getDetailMessage() | ||
| 38 | + { | ||
| 39 | + return detailMessage; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public GlobalException setDetailMessage(String detailMessage) | ||
| 43 | + { | ||
| 44 | + this.detailMessage = detailMessage; | ||
| 45 | + return this; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public String getMessage() | ||
| 49 | + { | ||
| 50 | + return message; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public GlobalException setMessage(String message) | ||
| 54 | + { | ||
| 55 | + this.message = message; | ||
| 56 | + return this; | ||
| 57 | + } | ||
| 58 | +} |
| 1 | package com.ruoyi.common.exception; | 1 | package com.ruoyi.common.exception; |
| 2 | 2 | ||
| 3 | /** | 3 | /** |
| 4 | - * 自定义异常 | 4 | + * 业务异常 |
| 5 | * | 5 | * |
| 6 | * @author ruoyi | 6 | * @author ruoyi |
| 7 | */ | 7 | */ |
| 8 | -public class CustomException extends RuntimeException | 8 | +public final class ServiceException extends RuntimeException |
| 9 | { | 9 | { |
| 10 | private static final long serialVersionUID = 1L; | 10 | private static final long serialVersionUID = 1L; |
| 11 | 11 | ||
| 12 | + /** | ||
| 13 | + * 错误码 | ||
| 14 | + */ | ||
| 12 | private Integer code; | 15 | private Integer code; |
| 13 | 16 | ||
| 17 | + /** | ||
| 18 | + * 错误提示 | ||
| 19 | + */ | ||
| 14 | private String message; | 20 | private String message; |
| 15 | 21 | ||
| 16 | - public CustomException(String message) | 22 | + /** |
| 23 | + * 错误明细,内部调试错误 | ||
| 24 | + * | ||
| 25 | + * 和 {@link CommonResult#getDetailMessage()} 一致的设计 | ||
| 26 | + */ | ||
| 27 | + private String detailMessage; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 空构造方法,避免反序列化问题 | ||
| 31 | + */ | ||
| 32 | + public ServiceException() | ||
| 33 | + { | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public ServiceException(String message) | ||
| 17 | { | 37 | { |
| 18 | this.message = message; | 38 | this.message = message; |
| 19 | } | 39 | } |
| 20 | 40 | ||
| 21 | - public CustomException(String message, Integer code) | 41 | + public ServiceException(String message, Integer code) |
| 22 | { | 42 | { |
| 23 | this.message = message; | 43 | this.message = message; |
| 24 | this.code = code; | 44 | this.code = code; |
| 25 | } | 45 | } |
| 26 | 46 | ||
| 27 | - public CustomException(String message, Throwable e) | 47 | + public String getDetailMessage() |
| 28 | { | 48 | { |
| 29 | - super(message, e); | ||
| 30 | - this.message = message; | 49 | + return detailMessage; |
| 31 | } | 50 | } |
| 32 | 51 | ||
| 33 | - @Override | ||
| 34 | public String getMessage() | 52 | public String getMessage() |
| 35 | { | 53 | { |
| 36 | return message; | 54 | return message; |
| @@ -40,4 +58,16 @@ public class CustomException extends RuntimeException | @@ -40,4 +58,16 @@ public class CustomException extends RuntimeException | ||
| 40 | { | 58 | { |
| 41 | return code; | 59 | return code; |
| 42 | } | 60 | } |
| 61 | + | ||
| 62 | + public ServiceException setMessage(String message) | ||
| 63 | + { | ||
| 64 | + this.message = message; | ||
| 65 | + return this; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public ServiceException setDetailMessage(String detailMessage) | ||
| 69 | + { | ||
| 70 | + this.detailMessage = detailMessage; | ||
| 71 | + return this; | ||
| 72 | + } | ||
| 43 | } | 73 | } |
| @@ -5,7 +5,7 @@ import org.springframework.security.core.context.SecurityContextHolder; | @@ -5,7 +5,7 @@ import org.springframework.security.core.context.SecurityContextHolder; | ||
| 5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | 5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| 6 | import com.ruoyi.common.constant.HttpStatus; | 6 | import com.ruoyi.common.constant.HttpStatus; |
| 7 | import com.ruoyi.common.core.domain.model.LoginUser; | 7 | import com.ruoyi.common.core.domain.model.LoginUser; |
| 8 | -import com.ruoyi.common.exception.CustomException; | 8 | +import com.ruoyi.common.exception.ServiceException; |
| 9 | 9 | ||
| 10 | /** | 10 | /** |
| 11 | * 安全服务工具类 | 11 | * 安全服务工具类 |
| @@ -25,7 +25,7 @@ public class SecurityUtils | @@ -25,7 +25,7 @@ public class SecurityUtils | ||
| 25 | } | 25 | } |
| 26 | catch (Exception e) | 26 | catch (Exception e) |
| 27 | { | 27 | { |
| 28 | - throw new CustomException("获取用户ID异常", HttpStatus.UNAUTHORIZED); | 28 | + throw new ServiceException("获取用户ID异常", HttpStatus.UNAUTHORIZED); |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 31 | 31 | ||
| @@ -40,7 +40,7 @@ public class SecurityUtils | @@ -40,7 +40,7 @@ public class SecurityUtils | ||
| 40 | } | 40 | } |
| 41 | catch (Exception e) | 41 | catch (Exception e) |
| 42 | { | 42 | { |
| 43 | - throw new CustomException("获取部门ID异常", HttpStatus.UNAUTHORIZED); | 43 | + throw new ServiceException("获取部门ID异常", HttpStatus.UNAUTHORIZED); |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | 46 | ||
| @@ -55,7 +55,7 @@ public class SecurityUtils | @@ -55,7 +55,7 @@ public class SecurityUtils | ||
| 55 | } | 55 | } |
| 56 | catch (Exception e) | 56 | catch (Exception e) |
| 57 | { | 57 | { |
| 58 | - throw new CustomException("获取用户账户异常", HttpStatus.UNAUTHORIZED); | 58 | + throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED); |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 | ||
| @@ -70,7 +70,7 @@ public class SecurityUtils | @@ -70,7 +70,7 @@ public class SecurityUtils | ||
| 70 | } | 70 | } |
| 71 | catch (Exception e) | 71 | catch (Exception e) |
| 72 | { | 72 | { |
| 73 | - throw new CustomException("获取用户信息异常", HttpStatus.UNAUTHORIZED); | 73 | + throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED); |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | 76 |
| @@ -66,7 +66,7 @@ import com.ruoyi.common.annotation.Excels; | @@ -66,7 +66,7 @@ import com.ruoyi.common.annotation.Excels; | ||
| 66 | import com.ruoyi.common.config.RuoYiConfig; | 66 | import com.ruoyi.common.config.RuoYiConfig; |
| 67 | import com.ruoyi.common.core.domain.AjaxResult; | 67 | import com.ruoyi.common.core.domain.AjaxResult; |
| 68 | import com.ruoyi.common.core.text.Convert; | 68 | import com.ruoyi.common.core.text.Convert; |
| 69 | -import com.ruoyi.common.exception.CustomException; | 69 | +import com.ruoyi.common.exception.UtilException; |
| 70 | import com.ruoyi.common.utils.DateUtils; | 70 | import com.ruoyi.common.utils.DateUtils; |
| 71 | import com.ruoyi.common.utils.DictUtils; | 71 | import com.ruoyi.common.utils.DictUtils; |
| 72 | import com.ruoyi.common.utils.StringUtils; | 72 | import com.ruoyi.common.utils.StringUtils; |
| @@ -450,7 +450,7 @@ public class ExcelUtil<T> | @@ -450,7 +450,7 @@ public class ExcelUtil<T> | ||
| 450 | catch (Exception e) | 450 | catch (Exception e) |
| 451 | { | 451 | { |
| 452 | log.error("导出Excel异常{}", e.getMessage()); | 452 | log.error("导出Excel异常{}", e.getMessage()); |
| 453 | - throw new CustomException("导出Excel失败,请联系网站管理员!"); | 453 | + throw new UtilException("导出Excel失败,请联系网站管理员!"); |
| 454 | } | 454 | } |
| 455 | finally | 455 | finally |
| 456 | { | 456 | { |
| 1 | package com.ruoyi.common.utils.sql; | 1 | package com.ruoyi.common.utils.sql; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.exception.BaseException; | 3 | +import com.ruoyi.common.exception.UtilException; |
| 4 | import com.ruoyi.common.utils.StringUtils; | 4 | import com.ruoyi.common.utils.StringUtils; |
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| @@ -22,7 +22,7 @@ public class SqlUtil | @@ -22,7 +22,7 @@ public class SqlUtil | ||
| 22 | { | 22 | { |
| 23 | if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) | 23 | if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) |
| 24 | { | 24 | { |
| 25 | - throw new BaseException("参数不符合规范,不能进行查询"); | 25 | + throw new UtilException("参数不符合规范,不能进行查询"); |
| 26 | } | 26 | } |
| 27 | return value; | 27 | return value; |
| 28 | } | 28 | } |
| 1 | package com.ruoyi.framework.web.exception; | 1 | package com.ruoyi.framework.web.exception; |
| 2 | 2 | ||
| 3 | +import javax.servlet.http.HttpServletRequest; | ||
| 3 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
| 4 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
| 5 | import org.springframework.security.access.AccessDeniedException; | 6 | import org.springframework.security.access.AccessDeniedException; |
| 6 | -import org.springframework.security.authentication.AccountExpiredException; | ||
| 7 | -import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
| 8 | import org.springframework.validation.BindException; | 7 | import org.springframework.validation.BindException; |
| 8 | +import org.springframework.web.HttpRequestMethodNotSupportedException; | ||
| 9 | import org.springframework.web.bind.MethodArgumentNotValidException; | 9 | import org.springframework.web.bind.MethodArgumentNotValidException; |
| 10 | import org.springframework.web.bind.annotation.ExceptionHandler; | 10 | import org.springframework.web.bind.annotation.ExceptionHandler; |
| 11 | import org.springframework.web.bind.annotation.RestControllerAdvice; | 11 | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| 12 | -import org.springframework.web.servlet.NoHandlerFoundException; | ||
| 13 | import com.ruoyi.common.constant.HttpStatus; | 12 | import com.ruoyi.common.constant.HttpStatus; |
| 14 | import com.ruoyi.common.core.domain.AjaxResult; | 13 | import com.ruoyi.common.core.domain.AjaxResult; |
| 15 | -import com.ruoyi.common.exception.BaseException; | ||
| 16 | -import com.ruoyi.common.exception.CustomException; | ||
| 17 | import com.ruoyi.common.exception.DemoModeException; | 14 | import com.ruoyi.common.exception.DemoModeException; |
| 15 | +import com.ruoyi.common.exception.ServiceException; | ||
| 18 | import com.ruoyi.common.utils.StringUtils; | 16 | import com.ruoyi.common.utils.StringUtils; |
| 19 | 17 | ||
| 20 | /** | 18 | /** |
| @@ -28,59 +26,58 @@ public class GlobalExceptionHandler | @@ -28,59 +26,58 @@ public class GlobalExceptionHandler | ||
| 28 | private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); | 26 | private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); |
| 29 | 27 | ||
| 30 | /** | 28 | /** |
| 31 | - * 基础异常 | 29 | + * 权限校验异常 |
| 32 | */ | 30 | */ |
| 33 | - @ExceptionHandler(BaseException.class) | ||
| 34 | - public AjaxResult baseException(BaseException e) | 31 | + @ExceptionHandler(AccessDeniedException.class) |
| 32 | + public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) | ||
| 35 | { | 33 | { |
| 36 | - return AjaxResult.error(e.getMessage()); | 34 | + String requestURI = request.getRequestURI(); |
| 35 | + log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage()); | ||
| 36 | + return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权"); | ||
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| 40 | - * 业务异常 | 40 | + * 请求方式不支持 |
| 41 | */ | 41 | */ |
| 42 | - @ExceptionHandler(CustomException.class) | ||
| 43 | - public AjaxResult businessException(CustomException e) | ||
| 44 | - { | ||
| 45 | - if (StringUtils.isNull(e.getCode())) | 42 | + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) |
| 43 | + public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, | ||
| 44 | + HttpServletRequest request) | ||
| 46 | { | 45 | { |
| 46 | + String requestURI = request.getRequestURI(); | ||
| 47 | + log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod()); | ||
| 47 | return AjaxResult.error(e.getMessage()); | 48 | return AjaxResult.error(e.getMessage()); |
| 48 | } | 49 | } |
| 49 | - return AjaxResult.error(e.getCode(), e.getMessage()); | ||
| 50 | - } | ||
| 51 | 50 | ||
| 52 | - @ExceptionHandler(NoHandlerFoundException.class) | ||
| 53 | - public AjaxResult handlerNoFoundException(Exception e) | ||
| 54 | - { | ||
| 55 | - log.error(e.getMessage(), e); | ||
| 56 | - return AjaxResult.error(HttpStatus.NOT_FOUND, "路径不存在,请检查路径是否正确"); | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - @ExceptionHandler(AccessDeniedException.class) | ||
| 60 | - public AjaxResult handleAuthorizationException(AccessDeniedException e) | ||
| 61 | - { | ||
| 62 | - log.error(e.getMessage()); | ||
| 63 | - return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权"); | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - @ExceptionHandler(AccountExpiredException.class) | ||
| 67 | - public AjaxResult handleAccountExpiredException(AccountExpiredException e) | 51 | + /** |
| 52 | + * 业务异常 | ||
| 53 | + */ | ||
| 54 | + @ExceptionHandler(ServiceException.class) | ||
| 55 | + public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) | ||
| 68 | { | 56 | { |
| 69 | log.error(e.getMessage(), e); | 57 | log.error(e.getMessage(), e); |
| 70 | - return AjaxResult.error(e.getMessage()); | 58 | + Integer code = e.getCode(); |
| 59 | + return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage()); | ||
| 71 | } | 60 | } |
| 72 | 61 | ||
| 73 | - @ExceptionHandler(UsernameNotFoundException.class) | ||
| 74 | - public AjaxResult handleUsernameNotFoundException(UsernameNotFoundException e) | 62 | + /** |
| 63 | + * 拦截未知的运行时异常 | ||
| 64 | + */ | ||
| 65 | + @ExceptionHandler(RuntimeException.class) | ||
| 66 | + public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) | ||
| 75 | { | 67 | { |
| 76 | - log.error(e.getMessage(), e); | 68 | + String requestURI = request.getRequestURI(); |
| 69 | + log.error("请求地址'{}',发生未知异常.", requestURI, e); | ||
| 77 | return AjaxResult.error(e.getMessage()); | 70 | return AjaxResult.error(e.getMessage()); |
| 78 | } | 71 | } |
| 79 | 72 | ||
| 73 | + /** | ||
| 74 | + * 系统异常 | ||
| 75 | + */ | ||
| 80 | @ExceptionHandler(Exception.class) | 76 | @ExceptionHandler(Exception.class) |
| 81 | - public AjaxResult handleException(Exception e) | 77 | + public AjaxResult handleException(Exception e, HttpServletRequest request) |
| 82 | { | 78 | { |
| 83 | - log.error(e.getMessage(), e); | 79 | + String requestURI = request.getRequestURI(); |
| 80 | + log.error("请求地址'{}',发生系统异常.", requestURI, e); | ||
| 84 | return AjaxResult.error(e.getMessage()); | 81 | return AjaxResult.error(e.getMessage()); |
| 85 | } | 82 | } |
| 86 | 83 | ||
| @@ -88,7 +85,7 @@ public class GlobalExceptionHandler | @@ -88,7 +85,7 @@ public class GlobalExceptionHandler | ||
| 88 | * 自定义验证异常 | 85 | * 自定义验证异常 |
| 89 | */ | 86 | */ |
| 90 | @ExceptionHandler(BindException.class) | 87 | @ExceptionHandler(BindException.class) |
| 91 | - public AjaxResult validatedBindException(BindException e) | 88 | + public AjaxResult handleBindException(BindException e) |
| 92 | { | 89 | { |
| 93 | log.error(e.getMessage(), e); | 90 | log.error(e.getMessage(), e); |
| 94 | String message = e.getAllErrors().get(0).getDefaultMessage(); | 91 | String message = e.getAllErrors().get(0).getDefaultMessage(); |
| @@ -99,7 +96,7 @@ public class GlobalExceptionHandler | @@ -99,7 +96,7 @@ public class GlobalExceptionHandler | ||
| 99 | * 自定义验证异常 | 96 | * 自定义验证异常 |
| 100 | */ | 97 | */ |
| 101 | @ExceptionHandler(MethodArgumentNotValidException.class) | 98 | @ExceptionHandler(MethodArgumentNotValidException.class) |
| 102 | - public Object validExceptionHandler(MethodArgumentNotValidException e) | 99 | + public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) |
| 103 | { | 100 | { |
| 104 | log.error(e.getMessage(), e); | 101 | log.error(e.getMessage(), e); |
| 105 | String message = e.getBindingResult().getFieldError().getDefaultMessage(); | 102 | String message = e.getBindingResult().getFieldError().getDefaultMessage(); |
| @@ -110,7 +107,7 @@ public class GlobalExceptionHandler | @@ -110,7 +107,7 @@ public class GlobalExceptionHandler | ||
| 110 | * 演示模式异常 | 107 | * 演示模式异常 |
| 111 | */ | 108 | */ |
| 112 | @ExceptionHandler(DemoModeException.class) | 109 | @ExceptionHandler(DemoModeException.class) |
| 113 | - public AjaxResult demoModeException(DemoModeException e) | 110 | + public AjaxResult handleDemoModeException(DemoModeException e) |
| 114 | { | 111 | { |
| 115 | return AjaxResult.error("演示模式,不允许操作"); | 112 | return AjaxResult.error("演示模式,不允许操作"); |
| 116 | } | 113 | } |
| @@ -11,7 +11,7 @@ import com.ruoyi.common.constant.Constants; | @@ -11,7 +11,7 @@ import com.ruoyi.common.constant.Constants; | ||
| 11 | import com.ruoyi.common.core.domain.entity.SysUser; | 11 | import com.ruoyi.common.core.domain.entity.SysUser; |
| 12 | import com.ruoyi.common.core.domain.model.LoginUser; | 12 | import com.ruoyi.common.core.domain.model.LoginUser; |
| 13 | import com.ruoyi.common.core.redis.RedisCache; | 13 | import com.ruoyi.common.core.redis.RedisCache; |
| 14 | -import com.ruoyi.common.exception.CustomException; | 14 | +import com.ruoyi.common.exception.ServiceException; |
| 15 | import com.ruoyi.common.exception.user.CaptchaException; | 15 | import com.ruoyi.common.exception.user.CaptchaException; |
| 16 | import com.ruoyi.common.exception.user.CaptchaExpireException; | 16 | import com.ruoyi.common.exception.user.CaptchaExpireException; |
| 17 | import com.ruoyi.common.exception.user.UserPasswordNotMatchException; | 17 | import com.ruoyi.common.exception.user.UserPasswordNotMatchException; |
| @@ -82,7 +82,7 @@ public class SysLoginService | @@ -82,7 +82,7 @@ public class SysLoginService | ||
| 82 | else | 82 | else |
| 83 | { | 83 | { |
| 84 | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); | 84 | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); |
| 85 | - throw new CustomException(e.getMessage()); | 85 | + throw new ServiceException(e.getMessage()); |
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); | 88 | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); |
| @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service; | @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service; | ||
| 10 | import com.ruoyi.common.core.domain.entity.SysUser; | 10 | import com.ruoyi.common.core.domain.entity.SysUser; |
| 11 | import com.ruoyi.common.core.domain.model.LoginUser; | 11 | import com.ruoyi.common.core.domain.model.LoginUser; |
| 12 | import com.ruoyi.common.enums.UserStatus; | 12 | import com.ruoyi.common.enums.UserStatus; |
| 13 | -import com.ruoyi.common.exception.BaseException; | 13 | +import com.ruoyi.common.exception.ServiceException; |
| 14 | import com.ruoyi.common.utils.StringUtils; | 14 | import com.ruoyi.common.utils.StringUtils; |
| 15 | import com.ruoyi.system.service.ISysUserService; | 15 | import com.ruoyi.system.service.ISysUserService; |
| 16 | 16 | ||
| @@ -37,17 +37,17 @@ public class UserDetailsServiceImpl implements UserDetailsService | @@ -37,17 +37,17 @@ public class UserDetailsServiceImpl implements UserDetailsService | ||
| 37 | if (StringUtils.isNull(user)) | 37 | if (StringUtils.isNull(user)) |
| 38 | { | 38 | { |
| 39 | log.info("登录用户:{} 不存在.", username); | 39 | log.info("登录用户:{} 不存在.", username); |
| 40 | - throw new UsernameNotFoundException("登录用户:" + username + " 不存在"); | 40 | + throw new ServiceException("登录用户:" + username + " 不存在"); |
| 41 | } | 41 | } |
| 42 | else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) | 42 | else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) |
| 43 | { | 43 | { |
| 44 | log.info("登录用户:{} 已被删除.", username); | 44 | log.info("登录用户:{} 已被删除.", username); |
| 45 | - throw new BaseException("对不起,您的账号:" + username + " 已被删除"); | 45 | + throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); |
| 46 | } | 46 | } |
| 47 | else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) | 47 | else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) |
| 48 | { | 48 | { |
| 49 | log.info("登录用户:{} 已被停用.", username); | 49 | log.info("登录用户:{} 已被停用.", username); |
| 50 | - throw new BaseException("对不起,您的账号:" + username + " 已停用"); | 50 | + throw new ServiceException("对不起,您的账号:" + username + " 已停用"); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | return createLoginUser(user); | 53 | return createLoginUser(user); |
| @@ -25,7 +25,7 @@ import com.alibaba.fastjson.JSONObject; | @@ -25,7 +25,7 @@ import com.alibaba.fastjson.JSONObject; | ||
| 25 | import com.ruoyi.common.constant.Constants; | 25 | import com.ruoyi.common.constant.Constants; |
| 26 | import com.ruoyi.common.constant.GenConstants; | 26 | import com.ruoyi.common.constant.GenConstants; |
| 27 | import com.ruoyi.common.core.text.CharsetKit; | 27 | import com.ruoyi.common.core.text.CharsetKit; |
| 28 | -import com.ruoyi.common.exception.CustomException; | 28 | +import com.ruoyi.common.exception.ServiceException; |
| 29 | import com.ruoyi.common.utils.SecurityUtils; | 29 | import com.ruoyi.common.utils.SecurityUtils; |
| 30 | import com.ruoyi.common.utils.StringUtils; | 30 | import com.ruoyi.common.utils.StringUtils; |
| 31 | import com.ruoyi.generator.domain.GenTable; | 31 | import com.ruoyi.generator.domain.GenTable; |
| @@ -180,7 +180,7 @@ public class GenTableServiceImpl implements IGenTableService | @@ -180,7 +180,7 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 180 | } | 180 | } |
| 181 | catch (Exception e) | 181 | catch (Exception e) |
| 182 | { | 182 | { |
| 183 | - throw new CustomException("导入失败:" + e.getMessage()); | 183 | + throw new ServiceException("导入失败:" + e.getMessage()); |
| 184 | } | 184 | } |
| 185 | } | 185 | } |
| 186 | 186 | ||
| @@ -269,7 +269,7 @@ public class GenTableServiceImpl implements IGenTableService | @@ -269,7 +269,7 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 269 | } | 269 | } |
| 270 | catch (IOException e) | 270 | catch (IOException e) |
| 271 | { | 271 | { |
| 272 | - throw new CustomException("渲染模板失败,表名:" + table.getTableName()); | 272 | + throw new ServiceException("渲染模板失败,表名:" + table.getTableName()); |
| 273 | } | 273 | } |
| 274 | } | 274 | } |
| 275 | } | 275 | } |
| @@ -291,7 +291,7 @@ public class GenTableServiceImpl implements IGenTableService | @@ -291,7 +291,7 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 291 | List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); | 291 | List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); |
| 292 | if (StringUtils.isEmpty(dbTableColumns)) | 292 | if (StringUtils.isEmpty(dbTableColumns)) |
| 293 | { | 293 | { |
| 294 | - throw new CustomException("同步数据失败,原表结构不存在"); | 294 | + throw new ServiceException("同步数据失败,原表结构不存在"); |
| 295 | } | 295 | } |
| 296 | List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); | 296 | List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); |
| 297 | 297 | ||
| @@ -383,25 +383,25 @@ public class GenTableServiceImpl implements IGenTableService | @@ -383,25 +383,25 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 383 | JSONObject paramsObj = JSONObject.parseObject(options); | 383 | JSONObject paramsObj = JSONObject.parseObject(options); |
| 384 | if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) | 384 | if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) |
| 385 | { | 385 | { |
| 386 | - throw new CustomException("树编码字段不能为空"); | 386 | + throw new ServiceException("树编码字段不能为空"); |
| 387 | } | 387 | } |
| 388 | else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) | 388 | else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) |
| 389 | { | 389 | { |
| 390 | - throw new CustomException("树父编码字段不能为空"); | 390 | + throw new ServiceException("树父编码字段不能为空"); |
| 391 | } | 391 | } |
| 392 | else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) | 392 | else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) |
| 393 | { | 393 | { |
| 394 | - throw new CustomException("树名称字段不能为空"); | 394 | + throw new ServiceException("树名称字段不能为空"); |
| 395 | } | 395 | } |
| 396 | else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) | 396 | else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) |
| 397 | { | 397 | { |
| 398 | if (StringUtils.isEmpty(genTable.getSubTableName())) | 398 | if (StringUtils.isEmpty(genTable.getSubTableName())) |
| 399 | { | 399 | { |
| 400 | - throw new CustomException("关联子表的表名不能为空"); | 400 | + throw new ServiceException("关联子表的表名不能为空"); |
| 401 | } | 401 | } |
| 402 | else if (StringUtils.isEmpty(genTable.getSubTableFkName())) | 402 | else if (StringUtils.isEmpty(genTable.getSubTableFkName())) |
| 403 | { | 403 | { |
| 404 | - throw new CustomException("子表关联的外键名不能为空"); | 404 | + throw new ServiceException("子表关联的外键名不能为空"); |
| 405 | } | 405 | } |
| 406 | } | 406 | } |
| 407 | } | 407 | } |
| @@ -6,7 +6,7 @@ import com.ruoyi.common.constant.UserConstants; | @@ -6,7 +6,7 @@ import com.ruoyi.common.constant.UserConstants; | ||
| 6 | import com.ruoyi.common.core.redis.RedisCache; | 6 | import com.ruoyi.common.core.redis.RedisCache; |
| 7 | import com.ruoyi.common.core.text.Convert; | 7 | import com.ruoyi.common.core.text.Convert; |
| 8 | import com.ruoyi.common.enums.DataSourceType; | 8 | import com.ruoyi.common.enums.DataSourceType; |
| 9 | -import com.ruoyi.common.exception.CustomException; | 9 | +import com.ruoyi.common.exception.ServiceException; |
| 10 | import com.ruoyi.common.utils.StringUtils; | 10 | import com.ruoyi.common.utils.StringUtils; |
| 11 | import com.ruoyi.system.domain.SysConfig; | 11 | import com.ruoyi.system.domain.SysConfig; |
| 12 | import com.ruoyi.system.mapper.SysConfigMapper; | 12 | import com.ruoyi.system.mapper.SysConfigMapper; |
| @@ -156,7 +156,7 @@ public class SysConfigServiceImpl implements ISysConfigService | @@ -156,7 +156,7 @@ public class SysConfigServiceImpl implements ISysConfigService | ||
| 156 | SysConfig config = selectConfigById(configId); | 156 | SysConfig config = selectConfigById(configId); |
| 157 | if (StringUtils.equals(UserConstants.YES, config.getConfigType())) | 157 | if (StringUtils.equals(UserConstants.YES, config.getConfigType())) |
| 158 | { | 158 | { |
| 159 | - throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); | 159 | + throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); |
| 160 | } | 160 | } |
| 161 | configMapper.deleteConfigById(configId); | 161 | configMapper.deleteConfigById(configId); |
| 162 | redisCache.deleteObject(getCacheKey(config.getConfigKey())); | 162 | redisCache.deleteObject(getCacheKey(config.getConfigKey())); |
| @@ -12,7 +12,7 @@ import com.ruoyi.common.core.domain.TreeSelect; | @@ -12,7 +12,7 @@ import com.ruoyi.common.core.domain.TreeSelect; | ||
| 12 | import com.ruoyi.common.core.domain.entity.SysDept; | 12 | import com.ruoyi.common.core.domain.entity.SysDept; |
| 13 | import com.ruoyi.common.core.domain.entity.SysRole; | 13 | import com.ruoyi.common.core.domain.entity.SysRole; |
| 14 | import com.ruoyi.common.core.text.Convert; | 14 | import com.ruoyi.common.core.text.Convert; |
| 15 | -import com.ruoyi.common.exception.CustomException; | 15 | +import com.ruoyi.common.exception.ServiceException; |
| 16 | import com.ruoyi.common.utils.StringUtils; | 16 | import com.ruoyi.common.utils.StringUtils; |
| 17 | import com.ruoyi.system.mapper.SysDeptMapper; | 17 | import com.ruoyi.system.mapper.SysDeptMapper; |
| 18 | import com.ruoyi.system.mapper.SysRoleMapper; | 18 | import com.ruoyi.system.mapper.SysRoleMapper; |
| @@ -184,7 +184,7 @@ public class SysDeptServiceImpl implements ISysDeptService | @@ -184,7 +184,7 @@ public class SysDeptServiceImpl implements ISysDeptService | ||
| 184 | // 如果父节点不为正常状态,则不允许新增子节点 | 184 | // 如果父节点不为正常状态,则不允许新增子节点 |
| 185 | if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) | 185 | if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) |
| 186 | { | 186 | { |
| 187 | - throw new CustomException("部门停用,不允许新增"); | 187 | + throw new ServiceException("部门停用,不允许新增"); |
| 188 | } | 188 | } |
| 189 | dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); | 189 | dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); |
| 190 | return deptMapper.insertDept(dept); | 190 | return deptMapper.insertDept(dept); |
| @@ -3,7 +3,7 @@ package com.ruoyi.system.service.impl; | @@ -3,7 +3,7 @@ package com.ruoyi.system.service.impl; | ||
| 3 | import com.ruoyi.common.constant.UserConstants; | 3 | import com.ruoyi.common.constant.UserConstants; |
| 4 | import com.ruoyi.common.core.domain.entity.SysDictData; | 4 | import com.ruoyi.common.core.domain.entity.SysDictData; |
| 5 | import com.ruoyi.common.core.domain.entity.SysDictType; | 5 | import com.ruoyi.common.core.domain.entity.SysDictType; |
| 6 | -import com.ruoyi.common.exception.CustomException; | 6 | +import com.ruoyi.common.exception.ServiceException; |
| 7 | import com.ruoyi.common.utils.DictUtils; | 7 | import com.ruoyi.common.utils.DictUtils; |
| 8 | import com.ruoyi.common.utils.StringUtils; | 8 | import com.ruoyi.common.utils.StringUtils; |
| 9 | import com.ruoyi.system.mapper.SysDictDataMapper; | 9 | import com.ruoyi.system.mapper.SysDictDataMapper; |
| @@ -122,7 +122,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService | @@ -122,7 +122,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService | ||
| 122 | SysDictType dictType = selectDictTypeById(dictId); | 122 | SysDictType dictType = selectDictTypeById(dictId); |
| 123 | if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) | 123 | if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) |
| 124 | { | 124 | { |
| 125 | - throw new CustomException(String.format("%1$s已分配,不能删除", dictType.getDictName())); | 125 | + throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName())); |
| 126 | } | 126 | } |
| 127 | dictTypeMapper.deleteDictTypeById(dictId); | 127 | dictTypeMapper.deleteDictTypeById(dictId); |
| 128 | DictUtils.removeDictCache(dictType.getDictType()); | 128 | DictUtils.removeDictCache(dictType.getDictType()); |
| @@ -4,7 +4,7 @@ import java.util.List; | @@ -4,7 +4,7 @@ import java.util.List; | ||
| 4 | import org.springframework.beans.factory.annotation.Autowired; | 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 5 | import org.springframework.stereotype.Service; | 5 | import org.springframework.stereotype.Service; |
| 6 | import com.ruoyi.common.constant.UserConstants; | 6 | import com.ruoyi.common.constant.UserConstants; |
| 7 | -import com.ruoyi.common.exception.CustomException; | 7 | +import com.ruoyi.common.exception.ServiceException; |
| 8 | import com.ruoyi.common.utils.StringUtils; | 8 | import com.ruoyi.common.utils.StringUtils; |
| 9 | import com.ruoyi.system.domain.SysPost; | 9 | import com.ruoyi.system.domain.SysPost; |
| 10 | import com.ruoyi.system.mapper.SysPostMapper; | 10 | import com.ruoyi.system.mapper.SysPostMapper; |
| @@ -147,7 +147,7 @@ public class SysPostServiceImpl implements ISysPostService | @@ -147,7 +147,7 @@ public class SysPostServiceImpl implements ISysPostService | ||
| 147 | SysPost post = selectPostById(postId); | 147 | SysPost post = selectPostById(postId); |
| 148 | if (countUserPostById(postId) > 0) | 148 | if (countUserPostById(postId) > 0) |
| 149 | { | 149 | { |
| 150 | - throw new CustomException(String.format("%1$s已分配,不能删除", post.getPostName())); | 150 | + throw new ServiceException(String.format("%1$s已分配,不能删除", post.getPostName())); |
| 151 | } | 151 | } |
| 152 | } | 152 | } |
| 153 | return postMapper.deletePostByIds(postIds); | 153 | return postMapper.deletePostByIds(postIds); |
| @@ -11,7 +11,7 @@ import org.springframework.transaction.annotation.Transactional; | @@ -11,7 +11,7 @@ import org.springframework.transaction.annotation.Transactional; | ||
| 11 | import com.ruoyi.common.annotation.DataScope; | 11 | import com.ruoyi.common.annotation.DataScope; |
| 12 | import com.ruoyi.common.constant.UserConstants; | 12 | import com.ruoyi.common.constant.UserConstants; |
| 13 | import com.ruoyi.common.core.domain.entity.SysRole; | 13 | import com.ruoyi.common.core.domain.entity.SysRole; |
| 14 | -import com.ruoyi.common.exception.CustomException; | 14 | +import com.ruoyi.common.exception.ServiceException; |
| 15 | import com.ruoyi.common.utils.StringUtils; | 15 | import com.ruoyi.common.utils.StringUtils; |
| 16 | import com.ruoyi.common.utils.spring.SpringUtils; | 16 | import com.ruoyi.common.utils.spring.SpringUtils; |
| 17 | import com.ruoyi.system.domain.SysRoleDept; | 17 | import com.ruoyi.system.domain.SysRoleDept; |
| @@ -183,7 +183,7 @@ public class SysRoleServiceImpl implements ISysRoleService | @@ -183,7 +183,7 @@ public class SysRoleServiceImpl implements ISysRoleService | ||
| 183 | { | 183 | { |
| 184 | if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) | 184 | if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) |
| 185 | { | 185 | { |
| 186 | - throw new CustomException("不允许操作超级管理员角色"); | 186 | + throw new ServiceException("不允许操作超级管理员角色"); |
| 187 | } | 187 | } |
| 188 | } | 188 | } |
| 189 | 189 | ||
| @@ -342,7 +342,7 @@ public class SysRoleServiceImpl implements ISysRoleService | @@ -342,7 +342,7 @@ public class SysRoleServiceImpl implements ISysRoleService | ||
| 342 | SysRole role = selectRoleById(roleId); | 342 | SysRole role = selectRoleById(roleId); |
| 343 | if (countUserRoleByRoleId(roleId) > 0) | 343 | if (countUserRoleByRoleId(roleId) > 0) |
| 344 | { | 344 | { |
| 345 | - throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName())); | 345 | + throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName())); |
| 346 | } | 346 | } |
| 347 | } | 347 | } |
| 348 | // 删除角色与菜单关联 | 348 | // 删除角色与菜单关联 |
| @@ -11,7 +11,7 @@ import com.ruoyi.common.annotation.DataScope; | @@ -11,7 +11,7 @@ import com.ruoyi.common.annotation.DataScope; | ||
| 11 | import com.ruoyi.common.constant.UserConstants; | 11 | import com.ruoyi.common.constant.UserConstants; |
| 12 | import com.ruoyi.common.core.domain.entity.SysRole; | 12 | import com.ruoyi.common.core.domain.entity.SysRole; |
| 13 | import com.ruoyi.common.core.domain.entity.SysUser; | 13 | import com.ruoyi.common.core.domain.entity.SysUser; |
| 14 | -import com.ruoyi.common.exception.CustomException; | 14 | +import com.ruoyi.common.exception.ServiceException; |
| 15 | import com.ruoyi.common.utils.SecurityUtils; | 15 | import com.ruoyi.common.utils.SecurityUtils; |
| 16 | import com.ruoyi.common.utils.StringUtils; | 16 | import com.ruoyi.common.utils.StringUtils; |
| 17 | import com.ruoyi.system.domain.SysPost; | 17 | import com.ruoyi.system.domain.SysPost; |
| @@ -223,7 +223,7 @@ public class SysUserServiceImpl implements ISysUserService | @@ -223,7 +223,7 @@ public class SysUserServiceImpl implements ISysUserService | ||
| 223 | { | 223 | { |
| 224 | if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) | 224 | if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) |
| 225 | { | 225 | { |
| 226 | - throw new CustomException("不允许操作超级管理员用户"); | 226 | + throw new ServiceException("不允许操作超级管理员用户"); |
| 227 | } | 227 | } |
| 228 | } | 228 | } |
| 229 | 229 | ||
| @@ -485,7 +485,7 @@ public class SysUserServiceImpl implements ISysUserService | @@ -485,7 +485,7 @@ public class SysUserServiceImpl implements ISysUserService | ||
| 485 | { | 485 | { |
| 486 | if (StringUtils.isNull(userList) || userList.size() == 0) | 486 | if (StringUtils.isNull(userList) || userList.size() == 0) |
| 487 | { | 487 | { |
| 488 | - throw new CustomException("导入用户数据不能为空!"); | 488 | + throw new ServiceException("导入用户数据不能为空!"); |
| 489 | } | 489 | } |
| 490 | int successNum = 0; | 490 | int successNum = 0; |
| 491 | int failureNum = 0; | 491 | int failureNum = 0; |
| @@ -530,7 +530,7 @@ public class SysUserServiceImpl implements ISysUserService | @@ -530,7 +530,7 @@ public class SysUserServiceImpl implements ISysUserService | ||
| 530 | if (failureNum > 0) | 530 | if (failureNum > 0) |
| 531 | { | 531 | { |
| 532 | failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); | 532 | failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); |
| 533 | - throw new CustomException(failureMsg.toString()); | 533 | + throw new ServiceException(failureMsg.toString()); |
| 534 | } | 534 | } |
| 535 | else | 535 | else |
| 536 | { | 536 | { |
-
请 注册 或 登录 后发表评论