Bläddra i källkod

优化异常信息

RuoYi 4 år sedan
förälder
incheckning
1e4ed04a65
16 ändrade filer med 299 tillägg och 191 borttagningar
  1. 13 13
      ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
  2. 0 43
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/CustomException.java
  3. 58 0
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/GlobalException.java
  4. 73 0
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/ServiceException.java
  5. 79 79
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/BaseException.java
  6. 1 1
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileException.java
  7. 1 1
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/user/UserException.java
  8. 2 2
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sql/SqlUtil.java
  9. 48 28
      ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java
  10. 9 9
      ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java
  11. 2 2
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
  12. 2 2
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
  13. 2 2
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
  14. 2 2
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java
  15. 3 3
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
  16. 4 4
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

+ 13 - 13
ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java

@@ -7,7 +7,7 @@ import com.ruoyi.common.core.constant.SecurityConstants;
7 7
 import com.ruoyi.common.core.constant.UserConstants;
8 8
 import com.ruoyi.common.core.domain.R;
9 9
 import com.ruoyi.common.core.enums.UserStatus;
10
-import com.ruoyi.common.core.exception.BaseException;
10
+import com.ruoyi.common.core.exception.ServiceException;
11 11
 import com.ruoyi.common.core.utils.SecurityUtils;
12 12
 import com.ruoyi.common.core.utils.ServletUtils;
13 13
 import com.ruoyi.common.core.utils.StringUtils;
@@ -41,51 +41,51 @@ public class SysLoginService
41 41
         if (StringUtils.isAnyBlank(username, password))
42 42
         {
43 43
             recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
44
-            throw new BaseException("用户/密码必须填写");
44
+            throw new ServiceException("用户/密码必须填写");
45 45
         }
46 46
         // 密码如果不在指定范围内 错误
47 47
         if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
48 48
                 || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
49 49
         {
50 50
             recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
51
-            throw new BaseException("用户密码不在指定范围");
51
+            throw new ServiceException("用户密码不在指定范围");
52 52
         }
53 53
         // 用户名不在指定范围内 错误
54 54
         if (username.length() < UserConstants.USERNAME_MIN_LENGTH
55 55
                 || username.length() > UserConstants.USERNAME_MAX_LENGTH)
56 56
         {
57 57
             recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
58
-            throw new BaseException("用户名不在指定范围");
58
+            throw new ServiceException("用户名不在指定范围");
59 59
         }
60 60
         // 查询用户信息
61 61
         R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
62 62
 
63 63
         if (R.FAIL == userResult.getCode())
64 64
         {
65
-            throw new BaseException(userResult.getMsg());
65
+            throw new ServiceException(userResult.getMsg());
66 66
         }
67 67
 
68 68
         if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
69 69
         {
70 70
             recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
71
-            throw new BaseException("登录用户:" + username + " 不存在");
71
+            throw new ServiceException("登录用户:" + username + " 不存在");
72 72
         }
73 73
         LoginUser userInfo = userResult.getData();
74 74
         SysUser user = userResult.getData().getSysUser();
75 75
         if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
76 76
         {
77 77
             recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
78
-            throw new BaseException("对不起,您的账号:" + username + " 已被删除");
78
+            throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
79 79
         }
80 80
         if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
81 81
         {
82 82
             recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
83
-            throw new BaseException("对不起,您的账号:" + username + " 已停用");
83
+            throw new ServiceException("对不起,您的账号:" + username + " 已停用");
84 84
         }
85 85
         if (!SecurityUtils.matchesPassword(password, user.getPassword()))
86 86
         {
87 87
             recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
88
-            throw new BaseException("用户不存在/密码错误");
88
+            throw new ServiceException("用户不存在/密码错误");
89 89
         }
90 90
         recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
91 91
         return userInfo;
@@ -104,17 +104,17 @@ public class SysLoginService
104 104
         // 用户名或密码为空 错误
105 105
         if (StringUtils.isAnyBlank(username, password))
106 106
         {
107
-            throw new BaseException("用户/密码必须填写");
107
+            throw new ServiceException("用户/密码必须填写");
108 108
         }
109 109
         if (username.length() < UserConstants.USERNAME_MIN_LENGTH
110 110
                 || username.length() > UserConstants.USERNAME_MAX_LENGTH)
111 111
         {
112
-            throw new BaseException("账户长度必须在2到20个字符之间");
112
+            throw new ServiceException("账户长度必须在2到20个字符之间");
113 113
         }
114 114
         if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
115 115
                 || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
116 116
         {
117
-            throw new BaseException("密码长度必须在5到20个字符之间");
117
+            throw new ServiceException("密码长度必须在5到20个字符之间");
118 118
         }
119 119
 
120 120
         // 注册用户信息
@@ -126,7 +126,7 @@ public class SysLoginService
126 126
 
127 127
         if (R.FAIL == registerResult.getCode())
128 128
         {
129
-            throw new BaseException(registerResult.getMsg());
129
+            throw new ServiceException(registerResult.getMsg());
130 130
         }
131 131
         recordLogininfor(username, Constants.REGISTER, "注册成功");
132 132
     }

+ 0 - 43
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/CustomException.java

@@ -1,43 +0,0 @@
1
-package com.ruoyi.common.core.exception;
2
-
3
-/**
4
- * 自定义异常
5
- * 
6
- * @author ruoyi
7
- */
8
-public class CustomException extends RuntimeException
9
-{
10
-    private static final long serialVersionUID = 1L;
11
-
12
-    private Integer code;
13
-
14
-    private String message;
15
-
16
-    public CustomException(String message)
17
-    {
18
-        this.message = message;
19
-    }
20
-
21
-    public CustomException(String message, Integer code)
22
-    {
23
-        this.message = message;
24
-        this.code = code;
25
-    }
26
-
27
-    public CustomException(String message, Throwable e)
28
-    {
29
-        super(message, e);
30
-        this.message = message;
31
-    }
32
-
33
-    @Override
34
-    public String getMessage()
35
-    {
36
-        return message;
37
-    }
38
-
39
-    public Integer getCode()
40
-    {
41
-        return code;
42
-    }
43
-}

+ 58 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/GlobalException.java

@@ -0,0 +1,58 @@
1
+package com.ruoyi.common.core.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
+}

+ 73 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/ServiceException.java

@@ -0,0 +1,73 @@
1
+package com.ruoyi.common.core.exception;
2
+
3
+/**
4
+ * 业务异常
5
+ * 
6
+ * @author ruoyi
7
+ */
8
+public final class ServiceException extends RuntimeException
9
+{
10
+    private static final long serialVersionUID = 1L;
11
+
12
+    /**
13
+     * 错误码
14
+     */
15
+    private Integer code;
16
+
17
+    /**
18
+     * 错误提示
19
+     */
20
+    private String message;
21
+
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)
37
+    {
38
+        this.message = message;
39
+    }
40
+
41
+    public ServiceException(String message, Integer code)
42
+    {
43
+        this.message = message;
44
+        this.code = code;
45
+    }
46
+
47
+    public String getDetailMessage()
48
+    {
49
+        return detailMessage;
50
+    }
51
+
52
+    public String getMessage()
53
+    {
54
+        return message;
55
+    }
56
+
57
+    public Integer getCode()
58
+    {
59
+        return code;
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
+    }
73
+}

+ 79 - 79
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/BaseException.java

@@ -1,79 +1,79 @@
1
-package com.ruoyi.common.core.exception;
2
-
3
-/**
4
- * 基础异常
5
- * 
6
- * @author ruoyi
7
- */
8
-public class BaseException extends RuntimeException
9
-{
10
-    private static final long serialVersionUID = 1L;
11
-
12
-    /**
13
-     * 所属模块
14
-     */
15
-    private String module;
16
-
17
-    /**
18
-     * 错误码
19
-     */
20
-    private String code;
21
-
22
-    /**
23
-     * 错误码对应的参数
24
-     */
25
-    private Object[] args;
26
-
27
-    /**
28
-     * 错误消息
29
-     */
30
-    private String defaultMessage;
31
-
32
-    public BaseException(String module, String code, Object[] args, String defaultMessage)
33
-    {
34
-        this.module = module;
35
-        this.code = code;
36
-        this.args = args;
37
-        this.defaultMessage = defaultMessage;
38
-    }
39
-
40
-    public BaseException(String module, String code, Object[] args)
41
-    {
42
-        this(module, code, args, null);
43
-    }
44
-
45
-    public BaseException(String module, String defaultMessage)
46
-    {
47
-        this(module, null, null, defaultMessage);
48
-    }
49
-
50
-    public BaseException(String code, Object[] args)
51
-    {
52
-        this(null, code, args, null);
53
-    }
54
-
55
-    public BaseException(String defaultMessage)
56
-    {
57
-        this(null, null, null, defaultMessage);
58
-    }
59
-
60
-    public String getModule()
61
-    {
62
-        return module;
63
-    }
64
-
65
-    public String getCode()
66
-    {
67
-        return code;
68
-    }
69
-
70
-    public Object[] getArgs()
71
-    {
72
-        return args;
73
-    }
74
-
75
-    public String getDefaultMessage()
76
-    {
77
-        return defaultMessage;
78
-    }
79
-}
1
+package com.ruoyi.common.core.exception.base;
2
+
3
+/**
4
+ * 基础异常
5
+ * 
6
+ * @author ruoyi
7
+ */
8
+public class BaseException extends RuntimeException
9
+{
10
+    private static final long serialVersionUID = 1L;
11
+
12
+    /**
13
+     * 所属模块
14
+     */
15
+    private String module;
16
+
17
+    /**
18
+     * 错误码
19
+     */
20
+    private String code;
21
+
22
+    /**
23
+     * 错误码对应的参数
24
+     */
25
+    private Object[] args;
26
+
27
+    /**
28
+     * 错误消息
29
+     */
30
+    private String defaultMessage;
31
+
32
+    public BaseException(String module, String code, Object[] args, String defaultMessage)
33
+    {
34
+        this.module = module;
35
+        this.code = code;
36
+        this.args = args;
37
+        this.defaultMessage = defaultMessage;
38
+    }
39
+
40
+    public BaseException(String module, String code, Object[] args)
41
+    {
42
+        this(module, code, args, null);
43
+    }
44
+
45
+    public BaseException(String module, String defaultMessage)
46
+    {
47
+        this(module, null, null, defaultMessage);
48
+    }
49
+
50
+    public BaseException(String code, Object[] args)
51
+    {
52
+        this(null, code, args, null);
53
+    }
54
+
55
+    public BaseException(String defaultMessage)
56
+    {
57
+        this(null, null, null, defaultMessage);
58
+    }
59
+
60
+    public String getModule()
61
+    {
62
+        return module;
63
+    }
64
+
65
+    public String getCode()
66
+    {
67
+        return code;
68
+    }
69
+
70
+    public Object[] getArgs()
71
+    {
72
+        return args;
73
+    }
74
+
75
+    public String getDefaultMessage()
76
+    {
77
+        return defaultMessage;
78
+    }
79
+}

+ 1 - 1
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileException.java

@@ -1,6 +1,6 @@
1 1
 package com.ruoyi.common.core.exception.file;
2 2
 
3
-import com.ruoyi.common.core.exception.BaseException;
3
+import com.ruoyi.common.core.exception.base.BaseException;
4 4
 
5 5
 /**
6 6
  * 文件信息异常类

+ 1 - 1
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/user/UserException.java

@@ -1,6 +1,6 @@
1 1
 package com.ruoyi.common.core.exception.user;
2 2
 
3
-import com.ruoyi.common.core.exception.BaseException;
3
+import com.ruoyi.common.core.exception.base.BaseException;
4 4
 
5 5
 /**
6 6
  * 用户信息异常类

+ 2 - 2
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sql/SqlUtil.java

@@ -1,6 +1,6 @@
1 1
 package com.ruoyi.common.core.utils.sql;
2 2
 
3
-import com.ruoyi.common.core.exception.BaseException;
3
+import com.ruoyi.common.core.exception.UtilException;
4 4
 import com.ruoyi.common.core.utils.StringUtils;
5 5
 
6 6
 /**
@@ -22,7 +22,7 @@ public class SqlUtil
22 22
     {
23 23
         if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value))
24 24
         {
25
-            throw new BaseException("参数不符合规范,不能进行查询");
25
+            throw new UtilException("参数不符合规范,不能进行查询");
26 26
         }
27 27
         return value;
28 28
     }

+ 48 - 28
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java

@@ -1,16 +1,18 @@
1 1
 package com.ruoyi.common.security.handler;
2 2
 
3
+import javax.servlet.http.HttpServletRequest;
3 4
 import org.slf4j.Logger;
4 5
 import org.slf4j.LoggerFactory;
5 6
 import org.springframework.validation.BindException;
7
+import org.springframework.web.HttpRequestMethodNotSupportedException;
6 8
 import org.springframework.web.bind.MethodArgumentNotValidException;
7 9
 import org.springframework.web.bind.annotation.ExceptionHandler;
8 10
 import org.springframework.web.bind.annotation.RestControllerAdvice;
9
-import com.ruoyi.common.core.exception.BaseException;
10
-import com.ruoyi.common.core.exception.CustomException;
11
+import com.ruoyi.common.core.constant.HttpStatus;
11 12
 import com.ruoyi.common.core.exception.DemoModeException;
12 13
 import com.ruoyi.common.core.exception.InnerAuthException;
13 14
 import com.ruoyi.common.core.exception.PreAuthorizeException;
15
+import com.ruoyi.common.core.exception.ServiceException;
14 16
 import com.ruoyi.common.core.utils.StringUtils;
15 17
 import com.ruoyi.common.core.web.domain.AjaxResult;
16 18
 
@@ -25,31 +27,58 @@ public class GlobalExceptionHandler
25 27
     private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
26 28
 
27 29
     /**
28
-     * 基础异常
30
+     * 权限异常
29 31
      */
30
-    @ExceptionHandler(BaseException.class)
31
-    public AjaxResult baseException(BaseException e)
32
+    @ExceptionHandler(PreAuthorizeException.class)
33
+    public AjaxResult handlePreAuthorizeException(PreAuthorizeException e, HttpServletRequest request)
32 34
     {
33
-        return AjaxResult.error(e.getDefaultMessage());
35
+        String requestURI = request.getRequestURI();
36
+        log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage());
37
+        return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权");
38
+    }
39
+
40
+    /**
41
+     * 请求方式不支持
42
+     */
43
+    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
44
+    public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
45
+            HttpServletRequest request)
46
+    {
47
+        String requestURI = request.getRequestURI();
48
+        log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
49
+        return AjaxResult.error(e.getMessage());
34 50
     }
35 51
 
36 52
     /**
37 53
      * 业务异常
38 54
      */
39
-    @ExceptionHandler(CustomException.class)
40
-    public AjaxResult businessException(CustomException e)
55
+    @ExceptionHandler(ServiceException.class)
56
+    public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request)
41 57
     {
42
-        if (StringUtils.isNull(e.getCode()))
43
-        {
44
-            return AjaxResult.error(e.getMessage());
45
-        }
46
-        return AjaxResult.error(e.getCode(), e.getMessage());
58
+        log.error(e.getMessage(), e);
59
+        Integer code = e.getCode();
60
+        return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
47 61
     }
48 62
 
63
+    /**
64
+     * 拦截未知的运行时异常
65
+     */
66
+    @ExceptionHandler(RuntimeException.class)
67
+    public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request)
68
+    {
69
+        String requestURI = request.getRequestURI();
70
+        log.error("请求地址'{}',发生未知异常.", requestURI, e);
71
+        return AjaxResult.error(e.getMessage());
72
+    }
73
+
74
+    /**
75
+     * 系统异常
76
+     */
49 77
     @ExceptionHandler(Exception.class)
50
-    public AjaxResult handleException(Exception e)
78
+    public AjaxResult handleException(Exception e, HttpServletRequest request)
51 79
     {
52
-        log.error(e.getMessage(), e);
80
+        String requestURI = request.getRequestURI();
81
+        log.error("请求地址'{}',发生系统异常.", requestURI, e);
53 82
         return AjaxResult.error(e.getMessage());
54 83
     }
55 84
 
@@ -57,7 +86,7 @@ public class GlobalExceptionHandler
57 86
      * 自定义验证异常
58 87
      */
59 88
     @ExceptionHandler(BindException.class)
60
-    public AjaxResult validatedBindException(BindException e)
89
+    public AjaxResult handleBindException(BindException e)
61 90
     {
62 91
         log.error(e.getMessage(), e);
63 92
         String message = e.getAllErrors().get(0).getDefaultMessage();
@@ -68,7 +97,7 @@ public class GlobalExceptionHandler
68 97
      * 自定义验证异常
69 98
      */
70 99
     @ExceptionHandler(MethodArgumentNotValidException.class)
71
-    public Object validExceptionHandler(MethodArgumentNotValidException e)
100
+    public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e)
72 101
     {
73 102
         log.error(e.getMessage(), e);
74 103
         String message = e.getBindingResult().getFieldError().getDefaultMessage();
@@ -76,19 +105,10 @@ public class GlobalExceptionHandler
76 105
     }
77 106
 
78 107
     /**
79
-     * 权限异常
80
-     */
81
-    @ExceptionHandler(PreAuthorizeException.class)
82
-    public AjaxResult preAuthorizeException(PreAuthorizeException e)
83
-    {
84
-        return AjaxResult.error("没有权限,请联系管理员授权");
85
-    }
86
-
87
-    /**
88 108
      * 内部认证异常
89 109
      */
90 110
     @ExceptionHandler(InnerAuthException.class)
91
-    public AjaxResult InnerAuthException(InnerAuthException e)
111
+    public AjaxResult handleInnerAuthException(InnerAuthException e)
92 112
     {
93 113
         return AjaxResult.error(e.getMessage());
94 114
     }
@@ -97,7 +117,7 @@ public class GlobalExceptionHandler
97 117
      * 演示模式异常
98 118
      */
99 119
     @ExceptionHandler(DemoModeException.class)
100
-    public AjaxResult demoModeException(DemoModeException e)
120
+    public AjaxResult handleDemoModeException(DemoModeException e)
101 121
     {
102 122
         return AjaxResult.error("演示模式,不允许操作");
103 123
     }

+ 9 - 9
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java

@@ -24,7 +24,7 @@ import com.alibaba.fastjson.JSON;
24 24
 import com.alibaba.fastjson.JSONObject;
25 25
 import com.ruoyi.common.core.constant.Constants;
26 26
 import com.ruoyi.common.core.constant.GenConstants;
27
-import com.ruoyi.common.core.exception.CustomException;
27
+import com.ruoyi.common.core.exception.ServiceException;
28 28
 import com.ruoyi.common.core.text.CharsetKit;
29 29
 import com.ruoyi.common.core.utils.SecurityUtils;
30 30
 import com.ruoyi.common.core.utils.StringUtils;
@@ -180,7 +180,7 @@ public class GenTableServiceImpl implements IGenTableService
180 180
         }
181 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 269
                 }
270 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 291
         List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
292 292
         if (StringUtils.isEmpty(dbTableColumns))
293 293
         {
294
-            throw new CustomException("同步数据失败,原表结构不存在");
294
+            throw new ServiceException("同步数据失败,原表结构不存在");
295 295
         }
296 296
         List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
297 297
 
@@ -383,25 +383,25 @@ public class GenTableServiceImpl implements IGenTableService
383 383
             JSONObject paramsObj = JSONObject.parseObject(options);
384 384
             if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
385 385
             {
386
-                throw new CustomException("树编码字段不能为空");
386
+                throw new ServiceException("树编码字段不能为空");
387 387
             }
388 388
             else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
389 389
             {
390
-                throw new CustomException("树父编码字段不能为空");
390
+                throw new ServiceException("树父编码字段不能为空");
391 391
             }
392 392
             else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
393 393
             {
394
-                throw new CustomException("树名称字段不能为空");
394
+                throw new ServiceException("树名称字段不能为空");
395 395
             }
396 396
             else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
397 397
             {
398 398
                 if (StringUtils.isEmpty(genTable.getSubTableName()))
399 399
                 {
400
-                    throw new CustomException("关联子表的表名不能为空");
400
+                    throw new ServiceException("关联子表的表名不能为空");
401 401
                 }
402 402
                 else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
403 403
                 {
404
-                    throw new CustomException("子表关联的外键名不能为空");
404
+                    throw new ServiceException("子表关联的外键名不能为空");
405 405
                 }
406 406
             }
407 407
         }

+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java

@@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
7 7
 import org.springframework.stereotype.Service;
8 8
 import com.ruoyi.common.core.constant.Constants;
9 9
 import com.ruoyi.common.core.constant.UserConstants;
10
-import com.ruoyi.common.core.exception.CustomException;
10
+import com.ruoyi.common.core.exception.ServiceException;
11 11
 import com.ruoyi.common.core.text.Convert;
12 12
 import com.ruoyi.common.core.utils.StringUtils;
13 13
 import com.ruoyi.common.redis.service.RedisService;
@@ -137,7 +137,7 @@ public class SysConfigServiceImpl implements ISysConfigService
137 137
             SysConfig config = selectConfigById(configId);
138 138
             if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
139 139
             {
140
-                throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
140
+                throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
141 141
             }
142 142
             configMapper.deleteConfigById(configId);
143 143
             redisService.deleteObject(getCacheKey(config.getConfigKey()));

+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -7,7 +7,7 @@ import java.util.stream.Collectors;
7 7
 import org.springframework.beans.factory.annotation.Autowired;
8 8
 import org.springframework.stereotype.Service;
9 9
 import com.ruoyi.common.core.constant.UserConstants;
10
-import com.ruoyi.common.core.exception.CustomException;
10
+import com.ruoyi.common.core.exception.ServiceException;
11 11
 import com.ruoyi.common.core.text.Convert;
12 12
 import com.ruoyi.common.core.utils.StringUtils;
13 13
 import com.ruoyi.common.datascope.annotation.DataScope;
@@ -184,7 +184,7 @@ public class SysDeptServiceImpl implements ISysDeptService
184 184
         // 如果父节点不为正常状态,则不允许新增子节点
185 185
         if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
186 186
         {
187
-            throw new CustomException("部门停用,不允许新增");
187
+            throw new ServiceException("部门停用,不允许新增");
188 188
         }
189 189
         dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
190 190
         return deptMapper.insertDept(dept);

+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java

@@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.stereotype.Service;
7 7
 import org.springframework.transaction.annotation.Transactional;
8 8
 import com.ruoyi.common.core.constant.UserConstants;
9
-import com.ruoyi.common.core.exception.CustomException;
9
+import com.ruoyi.common.core.exception.ServiceException;
10 10
 import com.ruoyi.common.core.utils.StringUtils;
11 11
 import com.ruoyi.common.security.utils.DictUtils;
12 12
 import com.ruoyi.system.api.domain.SysDictData;
@@ -122,7 +122,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
122 122
             SysDictType dictType = selectDictTypeById(dictId);
123 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 127
             dictTypeMapper.deleteDictTypeById(dictId);
128 128
             DictUtils.removeDictCache(dictType.getDictType());

+ 2 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java

@@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.stereotype.Service;
7 7
 
8 8
 import com.ruoyi.common.core.constant.UserConstants;
9
-import com.ruoyi.common.core.exception.CustomException;
9
+import com.ruoyi.common.core.exception.ServiceException;
10 10
 import com.ruoyi.common.core.utils.StringUtils;
11 11
 import com.ruoyi.system.domain.SysPost;
12 12
 import com.ruoyi.system.mapper.SysPostMapper;
@@ -149,7 +149,7 @@ public class SysPostServiceImpl implements ISysPostService
149 149
             SysPost post = selectPostById(postId);
150 150
             if (countUserPostById(postId) > 0)
151 151
             {
152
-                throw new CustomException(String.format("%1$s已分配,不能删除", post.getPostName()));
152
+                throw new ServiceException(String.format("%1$s已分配,不能删除", post.getPostName()));
153 153
             }
154 154
         }
155 155
         return postMapper.deletePostByIds(postIds);

+ 3 - 3
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java

@@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
9 9
 import org.springframework.stereotype.Service;
10 10
 import org.springframework.transaction.annotation.Transactional;
11 11
 import com.ruoyi.common.core.constant.UserConstants;
12
-import com.ruoyi.common.core.exception.CustomException;
12
+import com.ruoyi.common.core.exception.ServiceException;
13 13
 import com.ruoyi.common.core.utils.SpringUtils;
14 14
 import com.ruoyi.common.core.utils.StringUtils;
15 15
 import com.ruoyi.common.datascope.annotation.DataScope;
@@ -183,7 +183,7 @@ public class SysRoleServiceImpl implements ISysRoleService
183 183
     {
184 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 342
             SysRole role = selectRoleById(roleId);
343 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
         // 删除角色与菜单关联

+ 4 - 4
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
8 8
 import org.springframework.stereotype.Service;
9 9
 import org.springframework.transaction.annotation.Transactional;
10 10
 import com.ruoyi.common.core.constant.UserConstants;
11
-import com.ruoyi.common.core.exception.CustomException;
11
+import com.ruoyi.common.core.exception.ServiceException;
12 12
 import com.ruoyi.common.core.utils.SecurityUtils;
13 13
 import com.ruoyi.common.core.utils.StringUtils;
14 14
 import com.ruoyi.common.datascope.annotation.DataScope;
@@ -223,7 +223,7 @@ public class SysUserServiceImpl implements ISysUserService
223 223
     {
224 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 485
     {
486 486
         if (StringUtils.isNull(userList) || userList.size() == 0)
487 487
         {
488
-            throw new CustomException("导入用户数据不能为空!");
488
+            throw new ServiceException("导入用户数据不能为空!");
489 489
         }
490 490
         int successNum = 0;
491 491
         int failureNum = 0;
@@ -530,7 +530,7 @@ public class SysUserServiceImpl implements ISysUserService
530 530
         if (failureNum > 0)
531 531
         {
532 532
             failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
533
-            throw new CustomException(failureMsg.toString());
533
+            throw new ServiceException(failureMsg.toString());
534 534
         }
535 535
         else
536 536
         {