Преглед изворни кода

新增全局异常。日志输出配置

xusl пре 2 година
родитељ
комит
32a80b6396
22 измењених фајлова са 823 додато и 728 уклоњено
  1. 2 1
      backend/src/main/java/com/jiayue/ssi/aspectj/AgainVerifyAspect.java
  2. 29 0
      backend/src/main/java/com/jiayue/ssi/config/GlobalExceptionAdvice.java
  3. 3 2
      backend/src/main/java/com/jiayue/ssi/config/ResponseAdvice.java
  4. 21 0
      backend/src/main/java/com/jiayue/ssi/constant/CustomException.java
  5. 17 22
      backend/src/main/java/com/jiayue/ssi/controller/IpBlacklistController.java
  6. 14 6
      backend/src/main/java/com/jiayue/ssi/controller/ServerController.java
  7. 14 28
      backend/src/main/java/com/jiayue/ssi/controller/SysAlarmController.java
  8. 8 24
      backend/src/main/java/com/jiayue/ssi/controller/SysApproveController.java
  9. 35 42
      backend/src/main/java/com/jiayue/ssi/controller/SysLogininforController.java
  10. 118 121
      backend/src/main/java/com/jiayue/ssi/controller/SysMenuController.java
  11. 46 52
      backend/src/main/java/com/jiayue/ssi/controller/SysOperlogController.java
  12. 63 73
      backend/src/main/java/com/jiayue/ssi/controller/SysParameterController.java
  13. 61 65
      backend/src/main/java/com/jiayue/ssi/controller/SysPolicyController.java
  14. 25 29
      backend/src/main/java/com/jiayue/ssi/controller/SysRoleController.java
  15. 170 176
      backend/src/main/java/com/jiayue/ssi/controller/SysUserController.java
  16. 82 66
      backend/src/main/java/com/jiayue/ssi/controller/UserLoginController.java
  17. 2 0
      backend/src/main/java/com/jiayue/ssi/service/impl/UserServiceImpl.java
  18. 3 0
      backend/src/main/resources/application.yml
  19. 82 0
      backend/src/main/resources/logback-ssi.xml
  20. 1 2
      backend/src/test/java/com/jiayue/ssi/JasyptStringEncryptorDemo.java
  21. 23 16
      ui/src/utils/request.js
  22. 4 3
      ui/src/views/sysManager/userManager/index.vue

+ 2 - 1
backend/src/main/java/com/jiayue/ssi/aspectj/AgainVerifyAspect.java

@@ -50,7 +50,8 @@ public class AgainVerifyAspect {
         try {
             decryptPassword= SmUtil.sm3(againPwd).toUpperCase();
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error("鉴别操作加密密码失败",e);
+            return ResponseVO.fail("鉴别失败,不能操作");
         }
         if (!decryptPassword.equals(SecurityContextUtil.getSysUser().getPassword())) {
             log.error("鉴别失败,不能操作");

+ 29 - 0
backend/src/main/java/com/jiayue/ssi/config/GlobalExceptionAdvice.java

@@ -0,0 +1,29 @@
+package com.jiayue.ssi.config;
+
+import com.jiayue.ssi.constant.CustomException;
+import com.jiayue.ssi.util.IPUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * 全局异常处理
+ *
+ * @author xsl
+ * @since 2023/04/28
+ */
+@Slf4j
+@ControllerAdvice
+public class GlobalExceptionAdvice {
+    @ExceptionHandler(value = CustomException.class)
+    @ResponseStatus(HttpStatus.BAD_REQUEST)
+    @ResponseBody
+    public void handleException(HttpServletRequest request, Exception e) throws Exception {
+        String ipAddr = IPUtils.getIpAddr(request);
+        log.error("IP:"+ipAddr+"访问异常:", e);
+    }
+}

+ 3 - 2
backend/src/main/java/com/jiayue/ssi/config/ResponseAdvice.java

@@ -4,13 +4,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.jiayue.ssi.constant.SecretKeyConstants;
 import com.jiayue.ssi.util.SM2CryptUtils;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.core.MethodParameter;
 import org.springframework.http.MediaType;
 import org.springframework.http.converter.HttpMessageConverter;
 import org.springframework.http.server.ServerHttpRequest;
 import org.springframework.http.server.ServerHttpResponse;
-import org.springframework.web.bind.annotation.ControllerAdvice;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
 
 /**
@@ -20,6 +20,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
 * @since 2023/03/03
 */
 @ControllerAdvice(annotations = RestController.class)
+@Slf4j
 public class ResponseAdvice implements ResponseBodyAdvice<Object> {
     @Override
     public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {

+ 21 - 0
backend/src/main/java/com/jiayue/ssi/constant/CustomException.java

@@ -0,0 +1,21 @@
+package com.jiayue.ssi.constant;/**
+* 自定义异常
+*
+* @author xsl
+* @since 2023/04/28
+*/
+public class CustomException extends Exception{
+    private String message;
+    private Throwable cause;
+
+    public CustomException(String message,Exception e){
+        super(message,e);
+        this.message = message;
+        this.cause = e;
+    }
+
+    @Override
+    public String getMessage(){
+        return message;
+    }
+}

+ 17 - 22
backend/src/main/java/com/jiayue/ssi/controller/IpBlacklistController.java

@@ -2,11 +2,11 @@ package com.jiayue.ssi.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.jiayue.ssi.annotation.AgainVerify;
 import com.jiayue.ssi.annotation.OperateLog;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
 import com.jiayue.ssi.constant.CacheConstants;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.SysBlacklist;
 import com.jiayue.ssi.service.SysBlacklistService;
 import com.jiayue.ssi.util.*;
@@ -38,10 +38,10 @@ public class IpBlacklistController {
      */
     @GetMapping(value = "/getAll")
     @PreAuthorize("@ss.hasPermi('system:ipblacklist:list')")
-    public ResponseVO getAll(Integer currentPage, Integer pageSize, String ip) {
+    public ResponseVO getAll(Integer currentPage, Integer pageSize, String ip) throws CustomException {
         try {
             QueryWrapper<SysBlacklist> wrapper = new QueryWrapper<>();
-            if (StringUtils.isNotEmpty(ip)){
+            if (StringUtils.isNotEmpty(ip)) {
                 if (!IPUtils.isIP(ip)) {
                     return ResponseVO.fail("查询条件ip不合法!");
                 }
@@ -50,9 +50,7 @@ public class IpBlacklistController {
             Page<SysBlacklist> result = sysBlacklistService.page(new Page<>(currentPage, pageSize), wrapper);
             return ResponseVO.success(result);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取ip列表异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取ip列表异常", e);
         }
     }
 
@@ -62,7 +60,7 @@ public class IpBlacklistController {
     @PostMapping(value = "/addIp")
     @OperateLog(title = "黑名单管理", businessType = BusinessType.INSERT, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:ipblacklist:add')")
-    public ResponseVO addIp(String ip) {
+    public ResponseVO addIp(String ip) throws CustomException {
         if (!IPUtils.isIP(ip)) {
             return ResponseVO.fail("ip不合法,不能添加!");
         }
@@ -79,9 +77,7 @@ public class IpBlacklistController {
                 return ResponseVO.fail("添加ip失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("添加ip异常");
-            return ResponseVO.error(e);
+            throw new CustomException("添加ip异常", e);
         }
     }
 
@@ -91,16 +87,17 @@ public class IpBlacklistController {
     @PostMapping(value = "/delIp")
     @OperateLog(title = "黑名单管理", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:ipblacklist:remove')")
-    public ResponseVO delIp(String id) {
-        if (StringUtils.isEmpty(id)) {
-            return ResponseVO.fail("id不能为空!");
-        }
-        // id获取ip信息
-        SysBlacklist sysBlacklist = sysBlacklistService.getById(id);
-        if (sysBlacklist == null) {
-            return ResponseVO.fail("不能执行删除ip操作!");
-        }
+    public ResponseVO delIp(String id) throws CustomException {
         try {
+            if (StringUtils.isEmpty(id)) {
+                return ResponseVO.fail("id不能为空!");
+            }
+            // id获取ip信息
+            SysBlacklist sysBlacklist = sysBlacklistService.getById(id);
+            if (sysBlacklist == null) {
+                return ResponseVO.fail("不能执行删除ip操作!");
+            }
+
             boolean bo = sysBlacklistService.removeById(Integer.parseInt(id));
             if (bo) {
                 CacheConstants.blacklistMap.remove(sysBlacklist.getIp());
@@ -110,9 +107,7 @@ public class IpBlacklistController {
                 return ResponseVO.fail("删除ip失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("删除ip异常");
-            return ResponseVO.error(e);
+            throw new CustomException("删除ip异常", e);
         }
     }
 }

+ 14 - 6
backend/src/main/java/com/jiayue/ssi/controller/ServerController.java

@@ -1,25 +1,33 @@
 package com.jiayue.ssi.controller;
 
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.Server;
 import com.jiayue.ssi.util.ResponseVO;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * 服务监控
+ * 服务监控
  *
- * @author ruoyi
+ * @author xsl
+ * @since 2023/03/13
  */
 @RestController
 @RequestMapping("/monitor/server")
+@Slf4j
 public class ServerController {
     @PreAuthorize("@ss.hasPermi('monitor:server:list')")
     @GetMapping()
-    public ResponseVO getInfo() throws Exception {
-        Server server = new Server();
-        server.copyTo();
-        return ResponseVO.success(server);
+    public ResponseVO getInfo() throws CustomException {
+        try {
+            Server server = new Server();
+            server.copyTo();
+            return ResponseVO.success(server);
+        } catch (Exception e) {
+            throw new CustomException("获取服务监控异常", e);
+        }
     }
 }

+ 14 - 28
backend/src/main/java/com/jiayue/ssi/controller/SysAlarmController.java

@@ -1,22 +1,13 @@
 package com.jiayue.ssi.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.jiayue.ssi.annotation.OperateLog;
-import com.jiayue.ssi.backenum.ApproveStatusEnum;
-import com.jiayue.ssi.backenum.AuditType;
-import com.jiayue.ssi.backenum.BusinessType;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.SysAlarm;
-import com.jiayue.ssi.entity.SysApprove;
-import com.jiayue.ssi.entity.SysUser;
 import com.jiayue.ssi.service.SysAlarmService;
 import com.jiayue.ssi.util.*;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
-
 import java.util.*;
 
 /**
@@ -38,42 +29,37 @@ public class SysAlarmController {
      * @return
      */
     @GetMapping(value = "/getAll")
-    public ResponseVO getAll() {
+    public ResponseVO getAll() throws CustomException {
         try {
             QueryWrapper<SysAlarm> wrapper = new QueryWrapper<>();
-//            wrapper.eq("read_sign", "0");
             wrapper.orderByDesc("create_time");
             List<SysAlarm> sysAlarmLis = sysAlarmService.list(wrapper);
             return ResponseVO.success(sysAlarmLis);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取所有告警消息异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取所有告警消息异常", e);
         }
     }
+
     /**
      * 查收提交
      */
     @PostMapping(value = "/readDone")
-    public ResponseVO readDone(Long id) {
-        if (id==null) {
-            return ResponseVO.fail("id不能为空!");
-        }
+    public ResponseVO readDone(Long id) throws CustomException {
         try {
+            if (id == null) {
+                return ResponseVO.fail("id不能为空!");
+            }
             SysAlarm sysAlarm = new SysAlarm();
             sysAlarm.setId(id);
             boolean bo = sysAlarmService.removeById(sysAlarm);
-            if (bo){
-              return ResponseVO.success("查收成功");
-            }
-            else {
-                log.error("查收失败");
-                return ResponseVO.fail("查收失败");
+            if (bo) {
+                return ResponseVO.success("告警查收成功");
+            } else {
+                log.error("告警查收失败");
+                return ResponseVO.fail("告警查收失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("查收异常");
-            return ResponseVO.error(e);
+            throw new CustomException("告警查收异常", e);
         }
     }
 }

+ 8 - 24
backend/src/main/java/com/jiayue/ssi/controller/SysApproveController.java

@@ -1,23 +1,14 @@
 package com.jiayue.ssi.controller;
 
-import cn.hutool.core.lang.Validator;
-import cn.hutool.crypto.SmUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.jiayue.ssi.annotation.AgainVerify;
 import com.jiayue.ssi.annotation.OperateLog;
-import com.jiayue.ssi.backenum.ApproveResultEnum;
 import com.jiayue.ssi.backenum.ApproveStatusEnum;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
-import com.jiayue.ssi.config.SendMailUtil;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.SysApprove;
-import com.jiayue.ssi.entity.SysUser;
-import com.jiayue.ssi.entity.SysUserRole;
 import com.jiayue.ssi.service.SysApproveService;
-import com.jiayue.ssi.service.SysUserRoleService;
-import com.jiayue.ssi.service.SysUserService;
-import com.jiayue.ssi.service.impl.SysPermissionService;
 import com.jiayue.ssi.util.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -25,8 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.*;
-
 /**
  * 审批接口
  *
@@ -47,7 +36,7 @@ public class SysApproveController {
      */
     @GetMapping(value = "/getAll")
     @PreAuthorize("@ss.hasPermi('approveManager:approve:list')")
-    public ResponseVO getAll(Integer currentPage, Integer pageSize, String approveStatus, String approveResult) {
+    public ResponseVO getAll(Integer currentPage, Integer pageSize, String approveStatus, String approveResult) throws CustomException {
         try {
             QueryWrapper<SysApprove> wrapper = new QueryWrapper<>();
             if (StringUtils.isNotEmpty(approveStatus)) {
@@ -59,9 +48,7 @@ public class SysApproveController {
             Page<SysApprove> result = sysApproveService.page(new Page<>(currentPage, pageSize), wrapper);
             return ResponseVO.success(result);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取所有审批异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取所有审批异常", e);
         }
     }
 
@@ -71,11 +58,11 @@ public class SysApproveController {
     @PostMapping(value = "/submitApprove")
     @OperateLog(title = "审批管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('approveManager:approve:submitApprove')")
-    public ResponseVO submitApprove(@RequestBody SysApprove sysApprove) {
-        sysApprove.setApproveStatus(ApproveStatusEnum.YSP.getCode()+"");
+    public ResponseVO submitApprove(@RequestBody SysApprove sysApprove) throws CustomException {
         try {
+            sysApprove.setApproveStatus(ApproveStatusEnum.YSP.getCode() + "");
             boolean bo = sysApproveService.updateById(sysApprove);
-            if (bo){
+            if (bo) {
                 // 执行业务操作
                 boolean bizBo = sysApproveService.executeBizSql(sysApprove);
                 if (bizBo) {
@@ -84,15 +71,12 @@ public class SysApproveController {
                     log.error("审批提交失败");
                     return ResponseVO.fail("审批提交失败");
                 }
-            }
-            else {
+            } else {
                 log.error("审批提交失败");
                 return ResponseVO.fail("审批提交失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("审批提交异常");
-            return ResponseVO.error(e);
+            throw new CustomException("审批提交异常", e);
         }
     }
 }

+ 35 - 42
backend/src/main/java/com/jiayue/ssi/controller/SysLogininforController.java

@@ -3,10 +3,10 @@ package com.jiayue.ssi.controller;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.jiayue.ssi.annotation.InterfaceLimit;
 import com.jiayue.ssi.annotation.OperateLog;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.SysLogininfor;
 import com.jiayue.ssi.service.SysLogininforService;
 import com.jiayue.ssi.util.DateUtils;
@@ -40,7 +40,7 @@ public class SysLogininforController {
     @GetMapping(value = "/getAll")
     @PreAuthorize("@ss.hasPermi('auditManager:logininfor:list')")
     public ResponseVO getAll(Integer currentPage, Integer pageSize, String ipaddr, String userName,
-                             String status,String startLoginTime,String endLoginTime,String sortOrder) {
+                             String status, String startLoginTime, String endLoginTime, String sortOrder) throws CustomException {
         try {
             if (StringUtils.isNotEmpty(ipaddr)) {
                 if (ipaddr.length() > 128) {
@@ -69,19 +69,18 @@ public class SysLogininforController {
                 wrapper.le("login_time", DateUtils.getDayLastTime(DateUtil.parseDate(endLoginTime)));
             }
 
-            if (StringUtils.isNotEmpty(sortOrder)){
+            if (StringUtils.isNotEmpty(sortOrder)) {
                 String[] orders = sortOrder.split("&");
                 String sortDbField = "";
-                if ("loginTime".equals(orders[0])){
+                if ("loginTime".equals(orders[0])) {
                     sortDbField = "login_time";
-                } else if ("userName".equals(orders[0])){
+                } else if ("userName".equals(orders[0])) {
                     sortDbField = "user_name";
                 }
 
-                if ("asc".equals(orders[1])){
+                if ("asc".equals(orders[1])) {
                     wrapper.orderByAsc(sortDbField);
-                }
-                else{
+                } else {
                     wrapper.orderByDesc(sortDbField);
                 }
             }
@@ -89,9 +88,7 @@ public class SysLogininforController {
             Page<SysLogininfor> result = sysLogininforService.page(new Page<>(currentPage, pageSize), wrapper);
             return ResponseVO.success(result);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取登录日志列表异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取登录日志列表异常", e);
         }
     }
 
@@ -99,13 +96,14 @@ public class SysLogininforController {
      * 删除登录信息
      */
     @PostMapping(value = "/delLoginInfo")
-    @OperateLog(title = "登录日志", businessType = BusinessType.DELETE,auditType = AuditType.SYS)
+    @OperateLog(title = "登录日志", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('auditManager:logininfor:remove')")
-    public ResponseVO delLoginInfo(String infoId) {
-        if (StringUtils.isEmpty(infoId)) {
-            return ResponseVO.fail("id不能为空!");
-        }
+    public ResponseVO delLoginInfo(String infoId) throws CustomException {
         try {
+            if (StringUtils.isEmpty(infoId)) {
+                return ResponseVO.fail("id不能为空!");
+            }
+
             boolean bo = sysLogininforService.removeLoginInfoById(Long.parseLong(infoId));
             if (bo) {
                 return ResponseVO.success("删除登录信息成功");
@@ -114,30 +112,27 @@ public class SysLogininforController {
                 return ResponseVO.fail("删除登录信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("删除登录信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("删除登录信息异常", e);
         }
     }
+
     /**
      * 清空登录信息
      */
     @PostMapping("/cleanLogininfor")
-    @OperateLog(title = "登录日志", businessType = BusinessType.CLEAN,auditType = AuditType.SYS)
+    @OperateLog(title = "登录日志", businessType = BusinessType.CLEAN, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('auditManager:logininfor:remove')")
-    public ResponseVO cleanLogininfor() {
+    public ResponseVO cleanLogininfor() throws CustomException {
         try {
             boolean bo = sysLogininforService.cleanLogininfor();
             if (bo) {
-                return ResponseVO.success("清空成功");
+                return ResponseVO.success("登录日志清空成功");
             } else {
-                log.error("清空失败");
-                return ResponseVO.fail("清空失败");
+                log.error("登录日志清空失败");
+                return ResponseVO.fail("登录日志清空失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("清空异常");
-            return ResponseVO.error(e);
+            throw new CustomException("登录日志清空异常", e);
         }
     }
 
@@ -148,7 +143,7 @@ public class SysLogininforController {
      */
     @GetMapping(value = "/logininforTotal")
     @PreAuthorize("@ss.hasPermi('auditManager:logininforTotal:list')")
-    public ResponseVO logininforTotal(String startLoginTime,String endLoginTime) {
+    public ResponseVO logininforTotal(String startLoginTime, String endLoginTime) throws CustomException {
         try {
             QueryWrapper<SysLogininfor> wrapper = new QueryWrapper<>();
             if (StringUtils.isNotEmpty(startLoginTime)) {
@@ -158,22 +153,22 @@ public class SysLogininforController {
                 wrapper.le("login_time", DateUtils.getDayLastTime(DateUtil.parseDate(endLoginTime)));
             }
             List<SysLogininfor> sysLogininforList = sysLogininforService.list(wrapper);
-            Map<String,List<SysLogininfor>> map = sysLogininforList.stream().collect(Collectors.groupingBy(item->DateUtil.format(item.getLoginTime(),"yyyy-MM-dd")));
-            List<Map<String,String>> resultList = new ArrayList<>();
-            map.forEach((key,value)->{
+            Map<String, List<SysLogininfor>> map = sysLogininforList.stream().collect(Collectors.groupingBy(item -> DateUtil.format(item.getLoginTime(), "yyyy-MM-dd")));
+            List<Map<String, String>> resultList = new ArrayList<>();
+            map.forEach((key, value) -> {
                 List<SysLogininfor> list = value;
-                Map<String,String> recordMap = new HashMap<>();
-                recordMap.put("day",key);
-                recordMap.put("count",list.size()+"");
+                Map<String, String> recordMap = new HashMap<>();
+                recordMap.put("day", key);
+                recordMap.put("count", list.size() + "");
                 // 登录成功统计
-                List<SysLogininfor> successList = list.stream().filter(sysLogininfor->"0".equals(sysLogininfor.getStatus())).collect(Collectors.toList());
-                recordMap.put("success",successList.size()+"");
+                List<SysLogininfor> successList = list.stream().filter(sysLogininfor -> "0".equals(sysLogininfor.getStatus())).collect(Collectors.toList());
+                recordMap.put("success", successList.size() + "");
                 // 登录失败统计
-                List<SysLogininfor> failList = list.stream().filter(sysLogininfor->"1".equals(sysLogininfor.getStatus())).collect(Collectors.toList());
-                recordMap.put("fail",failList.size()+"");
+                List<SysLogininfor> failList = list.stream().filter(sysLogininfor -> "1".equals(sysLogininfor.getStatus())).collect(Collectors.toList());
+                recordMap.put("fail", failList.size() + "");
                 // 登录ip个数统计
                 int ips = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(s -> s.getIpaddr()))), ArrayList::new)).size();
-                recordMap.put("ips",ips+"");
+                recordMap.put("ips", ips + "");
                 resultList.add(recordMap);
             });
             Collections.sort(resultList, new Comparator<Map<String, String>>() {
@@ -184,9 +179,7 @@ public class SysLogininforController {
             });
             return ResponseVO.success(resultList);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取登录日志统计列表异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取登录日志统计列表异常", e);
         }
     }
 }

+ 118 - 121
backend/src/main/java/com/jiayue/ssi/controller/SysMenuController.java

@@ -8,6 +8,7 @@ import cn.hutool.core.util.NumberUtil;
 import com.jiayue.ssi.annotation.OperateLog;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.constant.UserConstants;
 import com.jiayue.ssi.entity.SysMenu;
 import com.jiayue.ssi.service.SysMenuService;
@@ -16,7 +17,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
-import com.jiayue.ssi.annotation.InterfaceLimit;
 import com.jiayue.ssi.util.ResponseVO;
 import com.jiayue.ssi.util.SecurityContextUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -40,7 +40,7 @@ public class SysMenuController {
      */
     @GetMapping("/list")
     @PreAuthorize("@ss.hasPermi('system:menu:list')")
-    public ResponseVO list(SysMenu menu) {
+    public ResponseVO list(SysMenu menu) throws CustomException {
         try {
             if (StringUtils.isNotEmpty(menu.getMenuName())) {
                 if (menu.getMenuName().length() > 50) {
@@ -50,9 +50,7 @@ public class SysMenuController {
             List<SysMenu> menus = sysMenuService.selectMenuList(menu, SecurityContextUtil.getSysUser().getId());
             return ResponseVO.success(menus);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取菜单列表异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取菜单列表异常", e);
         }
     }
 
@@ -62,47 +60,46 @@ public class SysMenuController {
     @PostMapping(value = "/addMenu")
     @OperateLog(title = "菜单管理", businessType = BusinessType.INSERT, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:menu:add')")
-    public ResponseVO addMenu(@RequestBody SysMenu menu) {
-        if (RyStringUtils.isEmpty(menu.getMenuName())) {
-            return ResponseVO.fail("菜单名称不能为空!");
-        } else if (menu.getMenuName().length() > 50) {
-            return ResponseVO.fail("菜单名长度不能超过50个字符!");
-        }
-        if (!"F".equals(menu.getMenuType())) {
-            if (RyStringUtils.isEmpty(menu.getPath())) {
-                return ResponseVO.fail("路由地址不能为空!");
-            } else if (menu.getPath().length() > 200) {
-                return ResponseVO.fail("路由地址长度不能超过200个字符!");
+    public ResponseVO addMenu(@RequestBody SysMenu menu) throws CustomException {
+        try {
+            if (RyStringUtils.isEmpty(menu.getMenuName())) {
+                return ResponseVO.fail("菜单名称不能为空!");
+            } else if (menu.getMenuName().length() > 50) {
+                return ResponseVO.fail("菜单名长度不能超过50个字符!");
             }
-        }
-        if (menu.getOrderNum() == null) {
-            return ResponseVO.fail("排序不能为空!");
-        } else if (!NumberUtil.isInteger(menu.getOrderNum() + "")) {
-            return ResponseVO.fail("排序不是整型数值!");
-        }
-        if (RyStringUtils.isNotEmpty(menu.getComponent())) {
-            if (menu.getComponent().length() > 200) {
-                return ResponseVO.fail("组件路径长度不能超过200个字符!");
+            if (!"F".equals(menu.getMenuType())) {
+                if (RyStringUtils.isEmpty(menu.getPath())) {
+                    return ResponseVO.fail("路由地址不能为空!");
+                } else if (menu.getPath().length() > 200) {
+                    return ResponseVO.fail("路由地址长度不能超过200个字符!");
+                }
             }
-        }
-        if (RyStringUtils.isNotEmpty(menu.getQuery())) {
-            if (menu.getQuery().length() > 200) {
-                return ResponseVO.fail("路由参数长度不能超过200个字符!");
+            if (menu.getOrderNum() == null) {
+                return ResponseVO.fail("排序不能为空!");
+            } else if (!NumberUtil.isInteger(menu.getOrderNum() + "")) {
+                return ResponseVO.fail("排序不是整型数值!");
             }
-        }
-        if (RyStringUtils.isNotEmpty(menu.getPerms())) {
-            if (menu.getPerms().length() > 100) {
-                return ResponseVO.fail("权限字符长度不能超过100个字符!");
+            if (RyStringUtils.isNotEmpty(menu.getComponent())) {
+                if (menu.getComponent().length() > 200) {
+                    return ResponseVO.fail("组件路径长度不能超过200个字符!");
+                }
+            }
+            if (RyStringUtils.isNotEmpty(menu.getQuery())) {
+                if (menu.getQuery().length() > 200) {
+                    return ResponseVO.fail("路由参数长度不能超过200个字符!");
+                }
+            }
+            if (RyStringUtils.isNotEmpty(menu.getPerms())) {
+                if (menu.getPerms().length() > 100) {
+                    return ResponseVO.fail("权限字符长度不能超过100个字符!");
+                }
+            }
+            if (UserConstants.NOT_UNIQUE.equals(sysMenuService.checkMenuNameUnique(menu))) {
+                return ResponseVO.fail(menu.getMenuName() + "'失败,菜单名称已存在!");
+            }
+            if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !RyStringUtils.ishttp(menu.getPath())) {
+                return ResponseVO.fail(menu.getMenuName() + "'失败,地址必须以http(s)://开头!");
             }
-        }
-        if (UserConstants.NOT_UNIQUE.equals(sysMenuService.checkMenuNameUnique(menu))) {
-            return ResponseVO.fail(menu.getMenuName() + "'失败,菜单名称已存在!");
-        }
-        if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !RyStringUtils.ishttp(menu.getPath())) {
-            return ResponseVO.fail(menu.getMenuName() + "'失败,地址必须以http(s)://开头!");
-        }
-
-        try {
             menu.setCreateBy(SecurityContextUtil.getSysUser().getUsername());
             int bo = sysMenuService.insertMenu(menu);
             if (bo == 1) {
@@ -112,9 +109,7 @@ public class SysMenuController {
                 return ResponseVO.fail("添加菜单失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("添加菜单异常");
-            return ResponseVO.error(e);
+            throw new CustomException("添加菜单异常", e);
         }
     }
 
@@ -127,54 +122,54 @@ public class SysMenuController {
     @PostMapping(value = "/updateMenu")
     @OperateLog(title = "菜单管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:menu:edit')")
-    public ResponseVO updateMenu(@RequestBody SysMenu menu) {
-        if (menu.getMenuId() == null) {
-            return ResponseVO.fail("主键为空不能修改!");
-        }
-        if (RyStringUtils.isEmpty(menu.getMenuName())) {
-            return ResponseVO.fail("菜单名称不能为空!");
-        } else if (menu.getMenuName().length() > 50) {
-            return ResponseVO.fail("菜单名长度不能超过50个字符!");
-        }
-        if (!"F".equals(menu.getMenuType())) {
-            if (RyStringUtils.isEmpty(menu.getPath())) {
-                return ResponseVO.fail("路由地址不能为空!");
-            } else if (menu.getPath().length() > 200) {
-                return ResponseVO.fail("路由地址长度不能超过200个字符!");
+    public ResponseVO updateMenu(@RequestBody SysMenu menu) throws CustomException {
+        try {
+            if (menu.getMenuId() == null) {
+                return ResponseVO.fail("主键为空不能修改!");
             }
-        }
-        if (menu.getOrderNum() == null) {
-            return ResponseVO.fail("排序不能为空!");
-        } else if (!NumberUtil.isInteger(menu.getOrderNum() + "")) {
-            return ResponseVO.fail("排序不是整型数值!");
-        }
-        if (RyStringUtils.isNotEmpty(menu.getComponent())) {
-            if (menu.getComponent().length() > 200) {
-                return ResponseVO.fail("组件路径长度不能超过200个字符!");
+            if (RyStringUtils.isEmpty(menu.getMenuName())) {
+                return ResponseVO.fail("菜单名称不能为空!");
+            } else if (menu.getMenuName().length() > 50) {
+                return ResponseVO.fail("菜单名长度不能超过50个字符!");
             }
-        }
-        if (RyStringUtils.isNotEmpty(menu.getQuery())) {
-            if (menu.getQuery().length() > 200) {
-                return ResponseVO.fail("路由参数长度不能超过200个字符!");
+            if (!"F".equals(menu.getMenuType())) {
+                if (RyStringUtils.isEmpty(menu.getPath())) {
+                    return ResponseVO.fail("路由地址不能为空!");
+                } else if (menu.getPath().length() > 200) {
+                    return ResponseVO.fail("路由地址长度不能超过200个字符!");
+                }
             }
-        }
-        if (RyStringUtils.isNotEmpty(menu.getPerms())) {
-            if (menu.getPerms().length() > 100) {
-                return ResponseVO.fail("权限字符长度不能超过100个字符!");
+            if (menu.getOrderNum() == null) {
+                return ResponseVO.fail("排序不能为空!");
+            } else if (!NumberUtil.isInteger(menu.getOrderNum() + "")) {
+                return ResponseVO.fail("排序不是整型数值!");
+            }
+            if (RyStringUtils.isNotEmpty(menu.getComponent())) {
+                if (menu.getComponent().length() > 200) {
+                    return ResponseVO.fail("组件路径长度不能超过200个字符!");
+                }
+            }
+            if (RyStringUtils.isNotEmpty(menu.getQuery())) {
+                if (menu.getQuery().length() > 200) {
+                    return ResponseVO.fail("路由参数长度不能超过200个字符!");
+                }
+            }
+            if (RyStringUtils.isNotEmpty(menu.getPerms())) {
+                if (menu.getPerms().length() > 100) {
+                    return ResponseVO.fail("权限字符长度不能超过100个字符!");
+                }
+            }
+            if (sysMenuService.selectMenuById(menu.getMenuId()) == null) {
+                return ResponseVO.fail("非法访问不能修改!");
+            }
+            if (UserConstants.NOT_UNIQUE.equals(sysMenuService.checkMenuNameUnique(menu))) {
+                return ResponseVO.fail("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在!");
+            } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !RyStringUtils.ishttp(menu.getPath())) {
+                return ResponseVO.fail("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
+            } else if (menu.getMenuId().equals(menu.getParentId())) {
+                return ResponseVO.fail("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
             }
-        }
-        if (sysMenuService.selectMenuById(menu.getMenuId()) == null) {
-            return ResponseVO.fail("非法访问不能修改!");
-        }
-        if (UserConstants.NOT_UNIQUE.equals(sysMenuService.checkMenuNameUnique(menu))) {
-            return ResponseVO.fail("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在!");
-        } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !RyStringUtils.ishttp(menu.getPath())) {
-            return ResponseVO.fail("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
-        } else if (menu.getMenuId().equals(menu.getParentId())) {
-            return ResponseVO.fail("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
-        }
 
-        try {
             int bo = sysMenuService.updateMenu(menu);
             if (bo == 1) {
                 return ResponseVO.success("修改菜单成功");
@@ -183,9 +178,7 @@ public class SysMenuController {
                 return ResponseVO.fail("修改菜单失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("修改菜单异常");
-            return ResponseVO.error(e);
+            throw new CustomException("修改菜单异常", e);
         }
     }
 
@@ -193,14 +186,12 @@ public class SysMenuController {
      * 根据菜单编号获取详细信息
      */
     @GetMapping(value = "/{getDetailInfo}")
-    public ResponseVO getDetailInfo(Long menuId) {
+    public ResponseVO getDetailInfo(Long menuId) throws CustomException {
         try {
             SysMenu sysMenu = sysMenuService.selectMenuById(menuId);
             return ResponseVO.success(sysMenu);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取菜单明细异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取菜单明细异常", e);
         }
     }
 
@@ -210,29 +201,27 @@ public class SysMenuController {
     @PostMapping(value = "delMenu")
     @OperateLog(title = "菜单管理", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:menu:remove')")
-    public ResponseVO delMenu(String menuId) {
-        if (org.apache.commons.lang3.StringUtils.isEmpty(menuId)) {
-            return ResponseVO.fail("删除菜单的id不能为空!");
-        }
-        if (sysMenuService.hasChildByMenuId(Long.parseLong(menuId))) {
-            return ResponseVO.fail("存在子菜单,不允许删除");
-        }
-
-        if (sysMenuService.checkMenuExistRole(Long.parseLong(menuId))) {
-            return ResponseVO.fail("菜单已分配,不允许删除");
-        }
+    public ResponseVO delMenu(String menuId) throws CustomException {
         try {
+            if (org.apache.commons.lang3.StringUtils.isEmpty(menuId)) {
+                return ResponseVO.fail("删除菜单的id不能为空!");
+            }
+            if (sysMenuService.hasChildByMenuId(Long.parseLong(menuId))) {
+                return ResponseVO.fail("存在子菜单,不允许删除");
+            }
+
+            if (sysMenuService.checkMenuExistRole(Long.parseLong(menuId))) {
+                return ResponseVO.fail("菜单已分配,不允许删除");
+            }
             int bo = sysMenuService.deleteMenuById(Long.parseLong(menuId));
             if (bo == 1) {
-                return ResponseVO.success("删除成功");
+                return ResponseVO.success("删除菜单成功");
             } else {
-                log.error("删除失败");
-                return ResponseVO.fail("删除失败");
+                log.error("删除菜单失败");
+                return ResponseVO.fail("删除菜单失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("删除异常");
-            return ResponseVO.error(e);
+            throw new CustomException("删除菜单异常", e);
         }
     }
 
@@ -240,20 +229,28 @@ public class SysMenuController {
      * 获取菜单下拉树列表
      */
     @GetMapping("/treeselect")
-    public ResponseVO treeselect(SysMenu menu) {
-        List<SysMenu> menus = sysMenuService.selectMenuList(menu, SecurityContextUtil.getSysUser().getId());
-        return ResponseVO.success(sysMenuService.buildMenuTreeSelect(menus));
+    public ResponseVO treeselect(SysMenu menu) throws CustomException {
+        try {
+            List<SysMenu> menus = sysMenuService.selectMenuList(menu, SecurityContextUtil.getSysUser().getId());
+            return ResponseVO.success(sysMenuService.buildMenuTreeSelect(menus));
+        } catch (Exception e) {
+            throw new CustomException("获取菜单下拉树列表异常", e);
+        }
     }
 
     /**
      * 加载对应角色菜单列表树
      */
     @GetMapping(value = "/roleMenuTreeselect")
-    public ResponseVO roleMenuTreeselect(Long roleId) {
-        List<SysMenu> menus = sysMenuService.selectMenuList(SecurityContextUtil.getSysUser().getId());
-        Map<String, Object> map = new HashMap<>();
-        map.put("checkedKeys", sysMenuService.selectMenuListByRoleId(roleId));
-        map.put("menus", sysMenuService.buildMenuTreeSelect(menus));
-        return ResponseVO.success(map);
+    public ResponseVO roleMenuTreeselect(Long roleId) throws CustomException {
+        try {
+            List<SysMenu> menus = sysMenuService.selectMenuList(SecurityContextUtil.getSysUser().getId());
+            Map<String, Object> map = new HashMap<>();
+            map.put("checkedKeys", sysMenuService.selectMenuListByRoleId(roleId));
+            map.put("menus", sysMenuService.buildMenuTreeSelect(menus));
+            return ResponseVO.success(map);
+        } catch (Exception e) {
+            throw new CustomException("获取对应角色菜单列表树异常", e);
+        }
     }
 }

+ 46 - 52
backend/src/main/java/com/jiayue/ssi/controller/SysOperlogController.java

@@ -3,11 +3,10 @@ package com.jiayue.ssi.controller;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.jiayue.ssi.annotation.InterfaceLimit;
 import com.jiayue.ssi.annotation.OperateLog;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
-import com.jiayue.ssi.entity.SysLogininfor;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.SysOperLog;
 import com.jiayue.ssi.service.SysOperLogService;
 import com.jiayue.ssi.util.DateUtils;
@@ -32,6 +31,7 @@ import java.util.stream.Collectors;
 public class SysOperlogController {
     @Autowired
     SysOperLogService sysOperLogService;
+
     /**
      * 获取列表分页信息
      *
@@ -39,8 +39,8 @@ public class SysOperlogController {
      */
     @GetMapping(value = "/getAll")
     @PreAuthorize("@ss.hasPermi('auditManager:operlog:list')")
-    public ResponseVO getAll(Integer currentPage, Integer pageSize, String title, String operName,String auditType,
-                             String businessType, String status,String startOperTime, String endOperTime,String sortOrder) {
+    public ResponseVO getAll(Integer currentPage, Integer pageSize, String title, String operName, String auditType,
+                             String businessType, String status, String startOperTime, String endOperTime, String sortOrder) throws CustomException {
         try {
             if (StringUtils.isNotEmpty(title)) {
                 if (title.length() > 50) {
@@ -74,21 +74,20 @@ public class SysOperlogController {
             if (StringUtils.isNotEmpty(endOperTime)) {
                 wrapper.le("oper_time", DateUtils.getDayLastTime(DateUtil.parseDate(endOperTime)));
             }
-            if (StringUtils.isNotEmpty(sortOrder)){
+            if (StringUtils.isNotEmpty(sortOrder)) {
                 String[] orders = sortOrder.split("&");
                 String sortDbField = "";
-                if ("operTime".equals(orders[0])){
+                if ("operTime".equals(orders[0])) {
                     sortDbField = "oper_time";
-                } else if ("title".equals(orders[0])){
+                } else if ("title".equals(orders[0])) {
                     sortDbField = "title";
-                } else if ("operName".equals(orders[0])){
+                } else if ("operName".equals(orders[0])) {
                     sortDbField = "oper_name";
                 }
 
-                if ("asc".equals(orders[1])){
+                if ("asc".equals(orders[1])) {
                     wrapper.orderByAsc(sortDbField);
-                }
-                else{
+                } else {
                     wrapper.orderByDesc(sortDbField);
                 }
             }
@@ -96,56 +95,53 @@ public class SysOperlogController {
             Page<SysOperLog> result = sysOperLogService.page(new Page<>(currentPage, pageSize), wrapper);
             return ResponseVO.success(result);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取操作日志列表异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取操作日志列表异常", e);
         }
     }
+
     /**
      * 删除登录信息
      */
     @PostMapping(value = "/delOperlog")
-    @OperateLog(title = "操作日志", businessType = BusinessType.DELETE,auditType = AuditType.SYS)
+    @OperateLog(title = "操作日志", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('auditManager:operlog:remove')")
-    public ResponseVO delOperlog(String operId) {
-        if (StringUtils.isEmpty(operId)) {
-            return ResponseVO.fail("id不能为空!");
-        }
+    public ResponseVO delOperlog(String operId) throws CustomException {
         try {
+            if (StringUtils.isEmpty(operId)) {
+                return ResponseVO.fail("id不能为空!");
+            }
             boolean bo = sysOperLogService.removeOperlogById(Long.parseLong(operId));
             if (bo) {
-                return ResponseVO.success("删除操作信息成功");
+                return ResponseVO.success("操作日志删除成功");
             } else {
-                log.error("删除操作信息失败");
-                return ResponseVO.fail("删除操作信息失败");
+                log.error("操作日志删除失败");
+                return ResponseVO.fail("操作日志删除失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("删除操作信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("操作日志删除异常", e);
         }
     }
+
     /**
-     * 清空登录信息
+     * 操作日志清空
      */
     @PostMapping("/cleanOperLog")
-    @OperateLog(title = "操作日志", businessType = BusinessType.CLEAN,auditType = AuditType.SYS)
+    @OperateLog(title = "操作日志", businessType = BusinessType.CLEAN, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('auditManager:operlog:remove')")
-    public ResponseVO cleanOperLog() {
+    public ResponseVO cleanOperLog() throws CustomException {
         try {
             boolean bo = sysOperLogService.cleanOperLog();
             if (bo) {
-                return ResponseVO.success("清空成功");
+                return ResponseVO.success("操作日志清空成功");
             } else {
-                log.error("清空失败");
-                return ResponseVO.fail("清空失败");
+                log.error("操作日志清空失败");
+                return ResponseVO.fail("操作日志清空失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("清空异常");
-            return ResponseVO.error(e);
+            throw new CustomException("操作日志清空异常", e);
         }
     }
+
     /**
      * 操作日志统计分析
      *
@@ -153,7 +149,7 @@ public class SysOperlogController {
      */
     @GetMapping(value = "/sysOperlogTotal")
     @PreAuthorize("@ss.hasPermi('auditManager:sysOperlogTotal:list')")
-    public ResponseVO sysOperlogTotal(String startLoginTime,String endLoginTime) {
+    public ResponseVO sysOperlogTotal(String startLoginTime, String endLoginTime) throws CustomException {
         try {
             QueryWrapper<SysOperLog> wrapper = new QueryWrapper<>();
             if (StringUtils.isNotEmpty(startLoginTime)) {
@@ -163,27 +159,27 @@ public class SysOperlogController {
                 wrapper.le("oper_time", DateUtils.getDayLastTime(DateUtil.parseDate(endLoginTime)));
             }
             List<SysOperLog> sysOperLogList = sysOperLogService.list(wrapper);
-            Map<String,List<SysOperLog>> map = sysOperLogList.stream().collect(Collectors.groupingBy(item->DateUtil.format(item.getOperTime(),"yyyy-MM-dd")));
-            List<Map<String,String>> resultList = new ArrayList<>();
-            map.forEach((key,value)->{
+            Map<String, List<SysOperLog>> map = sysOperLogList.stream().collect(Collectors.groupingBy(item -> DateUtil.format(item.getOperTime(), "yyyy-MM-dd")));
+            List<Map<String, String>> resultList = new ArrayList<>();
+            map.forEach((key, value) -> {
                 List<SysOperLog> list = value;
-                Map<String,String> recordMap = new HashMap<>();
-                recordMap.put("day",key);
+                Map<String, String> recordMap = new HashMap<>();
+                recordMap.put("day", key);
                 // 系统类型统计
-                List<SysOperLog> sysTypeList = list.stream().filter(sysOperLog->sysOperLog.getAuditType()==0).collect(Collectors.toList());
-                recordMap.put("syscount",sysTypeList.size()+"");
+                List<SysOperLog> sysTypeList = list.stream().filter(sysOperLog -> sysOperLog.getAuditType() == 0).collect(Collectors.toList());
+                recordMap.put("syscount", sysTypeList.size() + "");
                 // 业务类型统计
-                List<SysOperLog> bizTypeList = list.stream().filter(sysOperLog->sysOperLog.getAuditType()==1).collect(Collectors.toList());
-                recordMap.put("bizcount",bizTypeList.size()+"");
+                List<SysOperLog> bizTypeList = list.stream().filter(sysOperLog -> sysOperLog.getAuditType() == 1).collect(Collectors.toList());
+                recordMap.put("bizcount", bizTypeList.size() + "");
                 // 操作成功统计
-                List<SysOperLog> successList = list.stream().filter(sysOperLog->sysOperLog.getStatus()==0).collect(Collectors.toList());
-                recordMap.put("success",successList.size()+"");
+                List<SysOperLog> successList = list.stream().filter(sysOperLog -> sysOperLog.getStatus() == 0).collect(Collectors.toList());
+                recordMap.put("success", successList.size() + "");
                 // 操作失败统计
-                List<SysOperLog> failList = list.stream().filter(sysOperLog->sysOperLog.getStatus()==1).collect(Collectors.toList());
-                recordMap.put("fail",failList.size()+"");
+                List<SysOperLog> failList = list.stream().filter(sysOperLog -> sysOperLog.getStatus() == 1).collect(Collectors.toList());
+                recordMap.put("fail", failList.size() + "");
                 // 操作ip个数统计
                 int ips = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(s -> s.getOperIp()))), ArrayList::new)).size();
-                recordMap.put("ips",ips+"");
+                recordMap.put("ips", ips + "");
                 resultList.add(recordMap);
             });
             Collections.sort(resultList, new Comparator<Map<String, String>>() {
@@ -194,9 +190,7 @@ public class SysOperlogController {
             });
             return ResponseVO.success(resultList);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取操作日志统计列表异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取操作日志统计列表异常", e);
         }
     }
 }

+ 63 - 73
backend/src/main/java/com/jiayue/ssi/controller/SysParameterController.java

@@ -7,6 +7,7 @@ import com.jiayue.ssi.annotation.OperateLog;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
 import com.jiayue.ssi.constant.CacheConstants;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.SysParameter;
 import com.jiayue.ssi.service.SysParameterService;
 import com.jiayue.ssi.util.ResponseVO;
@@ -37,33 +38,32 @@ public class SysParameterController {
      * @return 执行结果
      */
     @PostMapping(value = "/addParameter")
-    @OperateLog(title = "参数管理", businessType = BusinessType.INSERT,auditType = AuditType.SYS)
+    @OperateLog(title = "参数管理", businessType = BusinessType.INSERT, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:config:add')")
-    public ResponseVO addParameter(@RequestBody SysParameter sysParameter) {
-        if (StringUtils.isEmpty(sysParameter.getSysKey())) {
-            return ResponseVO.fail("参数名不能为空!");
-        } else if (!"null".equals(sysParameterService.queryByKey(sysParameter.getSysKey(), "null"))) {
-            return ResponseVO.fail(sysParameter.getSysKey() + "参数名已存在!");
-        } else if (sysParameter.getSysKey().length() > 50) {
-            return ResponseVO.fail("参数名长度不能超过50个字符!");
-        }
-
-        if (StringUtils.isEmpty(sysParameter.getSysValue())) {
-            return ResponseVO.fail("参数值不能为空!");
-        } else if (sysParameter.getSysValue().length() > 50) {
-            return ResponseVO.fail("参数值长度不能超过50个字符!");
-        }
+    public ResponseVO addParameter(@RequestBody SysParameter sysParameter) throws CustomException {
+        try {
+            if (StringUtils.isEmpty(sysParameter.getSysKey())) {
+                return ResponseVO.fail("参数名不能为空!");
+            } else if (!"null".equals(sysParameterService.queryByKey(sysParameter.getSysKey(), "null"))) {
+                return ResponseVO.fail(sysParameter.getSysKey() + "参数名已存在!");
+            } else if (sysParameter.getSysKey().length() > 50) {
+                return ResponseVO.fail("参数名长度不能超过50个字符!");
+            }
 
-        if (StringUtils.isEmpty(sysParameter.getSysDescribe())) {
-            return ResponseVO.fail("参数描述不能为空!");
-        } else if (sysParameter.getSysDescribe().length() > 200) {
-            return ResponseVO.fail("参数描述长度不能超过200个字符!");
-        }
+            if (StringUtils.isEmpty(sysParameter.getSysValue())) {
+                return ResponseVO.fail("参数值不能为空!");
+            } else if (sysParameter.getSysValue().length() > 50) {
+                return ResponseVO.fail("参数值长度不能超过50个字符!");
+            }
 
-        try {
+            if (StringUtils.isEmpty(sysParameter.getSysDescribe())) {
+                return ResponseVO.fail("参数描述不能为空!");
+            } else if (sysParameter.getSysDescribe().length() > 200) {
+                return ResponseVO.fail("参数描述长度不能超过200个字符!");
+            }
             boolean bo = sysParameterService.save(sysParameter);
             if (bo) {
-                if ("useSendMail".equals(sysParameter.getSysKey())){
+                if ("useSendMail".equals(sysParameter.getSysKey())) {
                     CacheConstants.use_send_mail = Boolean.parseBoolean(sysParameter.getSysValue());
                 }
                 return ResponseVO.success("添加参数信息成功");
@@ -72,9 +72,7 @@ public class SysParameterController {
                 return ResponseVO.fail("添加参数信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("添加参数信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("添加参数信息异常", e);
         }
     }
 
@@ -85,40 +83,39 @@ public class SysParameterController {
      * @return 执行结果
      */
     @PostMapping(value = "/updateParameter")
-    @OperateLog(title = "参数管理", businessType = BusinessType.UPDATE,auditType = AuditType.SYS)
+    @OperateLog(title = "参数管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:config:edit')")
-    public ResponseVO updateParameter(@RequestBody SysParameter sysParameter) {
-        SysParameter existSysParameter = sysParameterService.getById(sysParameter.getId());
-        if (existSysParameter == null) {
-            return ResponseVO.fail("非法访问不能修改!");
-        }
-
-        if (StringUtils.isEmpty(sysParameter.getSysKey())) {
-            return ResponseVO.fail("参数名不能为空!");
-        } else if (sysParameter.getSysKey().length() > 50) {
-            return ResponseVO.fail("参数名长度不能超过50个字符!");
-        } else if (!existSysParameter.getSysKey().equals(sysParameter.getSysKey())) {
-            if (!"null".equals(sysParameterService.queryByKey(sysParameter.getSysKey(), "null"))) {
-                return ResponseVO.fail(sysParameter.getSysKey() + "参数名已存在!");
+    public ResponseVO updateParameter(@RequestBody SysParameter sysParameter) throws CustomException {
+        try {
+            SysParameter existSysParameter = sysParameterService.getById(sysParameter.getId());
+            if (existSysParameter == null) {
+                return ResponseVO.fail("非法访问不能修改!");
             }
-        }
 
-        if (StringUtils.isEmpty(sysParameter.getSysValue())) {
-            return ResponseVO.fail("参数值不能为空!");
-        } else if (sysParameter.getSysValue().length() > 50) {
-            return ResponseVO.fail("参数值长度不能超过50个字符!");
-        }
+            if (StringUtils.isEmpty(sysParameter.getSysKey())) {
+                return ResponseVO.fail("参数名不能为空!");
+            } else if (sysParameter.getSysKey().length() > 50) {
+                return ResponseVO.fail("参数名长度不能超过50个字符!");
+            } else if (!existSysParameter.getSysKey().equals(sysParameter.getSysKey())) {
+                if (!"null".equals(sysParameterService.queryByKey(sysParameter.getSysKey(), "null"))) {
+                    return ResponseVO.fail(sysParameter.getSysKey() + "参数名已存在!");
+                }
+            }
 
-        if (StringUtils.isEmpty(sysParameter.getSysDescribe())) {
-            return ResponseVO.fail("参数描述不能为空!");
-        } else if (sysParameter.getSysDescribe().length() > 200) {
-            return ResponseVO.fail("参数描述长度不能超过200个字符!");
-        }
+            if (StringUtils.isEmpty(sysParameter.getSysValue())) {
+                return ResponseVO.fail("参数值不能为空!");
+            } else if (sysParameter.getSysValue().length() > 50) {
+                return ResponseVO.fail("参数值长度不能超过50个字符!");
+            }
 
-        try {
+            if (StringUtils.isEmpty(sysParameter.getSysDescribe())) {
+                return ResponseVO.fail("参数描述不能为空!");
+            } else if (sysParameter.getSysDescribe().length() > 200) {
+                return ResponseVO.fail("参数描述长度不能超过200个字符!");
+            }
             boolean bo = sysParameterService.updateById(sysParameter);
             if (bo) {
-                if ("useSendMail".equals(sysParameter.getSysKey())){
+                if ("useSendMail".equals(sysParameter.getSysKey())) {
                     CacheConstants.use_send_mail = Boolean.parseBoolean(sysParameter.getSysValue());
                 }
                 return ResponseVO.success("修改参数信息成功");
@@ -127,9 +124,7 @@ public class SysParameterController {
                 return ResponseVO.fail("修改参数信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("修改参数信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("修改参数信息异常", e);
         }
     }
 
@@ -137,15 +132,15 @@ public class SysParameterController {
      * 删除用户信息
      */
     @PostMapping(value = "/deleteParameter")
-    @OperateLog(title = "参数管理", businessType = BusinessType.DELETE,auditType = AuditType.SYS)
+    @OperateLog(title = "参数管理", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:config:remove')")
-    public ResponseVO deleteParameter(String id) {
-        if (StringUtils.isEmpty(id)) {
-            return ResponseVO.fail("id不能为空!");
-        }
+    public ResponseVO deleteParameter(String id) throws CustomException {
         try {
+            if (StringUtils.isEmpty(id)) {
+                return ResponseVO.fail("id不能为空!");
+            }
             SysParameter sysParameter = sysParameterService.getById(Integer.parseInt(id));
-            if ("useSendMail".equals(sysParameter.getSysKey())){
+            if ("useSendMail".equals(sysParameter.getSysKey())) {
                 CacheConstants.use_send_mail = true;
             }
             boolean bo = sysParameterService.removeById(Integer.parseInt(id));
@@ -156,9 +151,7 @@ public class SysParameterController {
                 return ResponseVO.fail("删除参数信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("删除参数信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("删除参数信息异常", e);
         }
     }
 
@@ -169,7 +162,7 @@ public class SysParameterController {
      */
     @GetMapping(value = "/getAll")
     @PreAuthorize("@ss.hasPermi('system:config:list')")
-    public ResponseVO getAll(Integer currentPage, Integer pageSize, String keywords) {
+    public ResponseVO getAll(Integer currentPage, Integer pageSize, String keywords) throws CustomException {
         try {
             if (StringUtils.isNotEmpty(keywords)) {
                 if (keywords.length() > 200) {
@@ -183,26 +176,23 @@ public class SysParameterController {
             Page<SysParameter> result = sysParameterService.page(new Page<>(currentPage, pageSize), wrapper);
             return ResponseVO.success(result);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取参数异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取参数异常", e);
         }
     }
+
     /**
      * 获取是否邮箱口令参数
      *
      * @return 邮箱口令
      */
     @GetMapping(value = "/getUseSendMail")
-    @InterfaceLimit(value = 2,time = 1000)
-    public ResponseVO getUseSendMail() {
+    @InterfaceLimit(value = 2, time = 1000)
+    public ResponseVO getUseSendMail() throws CustomException {
         try {
             String useSendMail = sysParameterService.queryByKey("useSendMail", "true");
             return ResponseVO.success(useSendMail);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取邮箱口令参数异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取邮箱口令参数异常", e);
         }
     }
 }

+ 61 - 65
backend/src/main/java/com/jiayue/ssi/controller/SysPolicyController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.jiayue.ssi.annotation.OperateLog;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.SysPolicy;
 import com.jiayue.ssi.service.SysPolicyService;
 import com.jiayue.ssi.util.*;
@@ -34,14 +35,12 @@ public class SysPolicyController {
      */
     @GetMapping(value = "/getAll")
     @PreAuthorize("@ss.hasPermi('system:policy:getAll')")
-    public ResponseVO getAll() {
+    public ResponseVO getAll() throws CustomException {
         try {
             SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
             return ResponseVO.success(sysPolicy);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取策略配置信息异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取策略配置信息异常", e);
         }
     }
 
@@ -51,71 +50,70 @@ public class SysPolicyController {
     @PostMapping
     @OperateLog(title = "策略配置", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:policy:update')")
-    public ResponseVO update(@RequestBody SysPolicy sysPolicy) {
-        if (sysPolicy.getLoginFails()==null) {
-            return ResponseVO.fail("登录失败次数限制不能为空!");
-        } else if (!String.valueOf(sysPolicy.getLoginFails()).matches("^([1-9]|10)$")) {
-            return ResponseVO.fail("登录失败次数限制请输入1-10整数");
-        }
-
-        if (sysPolicy.getLoginLock()==null) {
-            return ResponseVO.fail("登录失败锁定时长不能为空!");
-        } else if (!String.valueOf(sysPolicy.getLoginLock()).matches("^(?:[2-9]\\d|100)$")) {
-            return ResponseVO.fail("登录失败锁定时长请输入20-100整数");
-        }
+    public ResponseVO update(@RequestBody SysPolicy sysPolicy) throws CustomException {
+        try {
+            if (sysPolicy.getLoginFails() == null) {
+                return ResponseVO.fail("登录失败次数限制不能为空!");
+            } else if (!String.valueOf(sysPolicy.getLoginFails()).matches("^([1-9]|10)$")) {
+                return ResponseVO.fail("登录失败次数限制请输入1-10整数");
+            }
 
-        if (sysPolicy.getInactiveLogout()==null) {
-            return ResponseVO.fail("非活动状态登出系统不能为空!");
-        } else if (!String.valueOf(sysPolicy.getInactiveLogout()).matches("^(?:[2-9]\\d|100)$")) {
-            return ResponseVO.fail("非活动状态登出系统请输入20-100整数");
-        }
+            if (sysPolicy.getLoginLock() == null) {
+                return ResponseVO.fail("登录失败锁定时长不能为空!");
+            } else if (!String.valueOf(sysPolicy.getLoginLock()).matches("^(?:[2-9]\\d|100)$")) {
+                return ResponseVO.fail("登录失败锁定时长请输入20-100整数");
+            }
 
-        if (sysPolicy.getMemoryWarn()==null) {
-            return ResponseVO.fail("内存低于阈值告警不能为空!");
-        } else if (!String.valueOf(sysPolicy.getMemoryWarn()).matches("^(?:[2-8]\\d|90)$")) {
-            return ResponseVO.fail("内存低于阈值告警请输入20-90整数");
-        }
+            if (sysPolicy.getInactiveLogout() == null) {
+                return ResponseVO.fail("非活动状态登出系统不能为空!");
+            } else if (!String.valueOf(sysPolicy.getInactiveLogout()).matches("^(?:[2-9]\\d|100)$")) {
+                return ResponseVO.fail("非活动状态登出系统请输入20-100整数");
+            }
 
-        if (sysPolicy.getLogSpaceWarn()==null) {
-            return ResponseVO.fail("日志存储低于阈值告警不能为空!");
-        } else if (!String.valueOf(sysPolicy.getMemoryWarn()).matches("^(?:[2-8]\\d|90)$")) {
-            return ResponseVO.fail("日志存储低于阈值告警请输入20-90整数");
-        }
+            if (sysPolicy.getMemoryWarn() == null) {
+                return ResponseVO.fail("内存低于阈值告警不能为空!");
+            } else if (!String.valueOf(sysPolicy.getMemoryWarn()).matches("^(?:[2-8]\\d|90)$")) {
+                return ResponseVO.fail("内存低于阈值告警请输入20-90整数");
+            }
 
-        if (sysPolicy.getAuditLog()==null) {
-            return ResponseVO.fail("审计日志保留月数不能为空!");
-        } else if (!String.valueOf(sysPolicy.getAuditLog()).matches("^([3-9]|(1[0-2]))$")) {
-            return ResponseVO.fail("审计日志保留月数请输入3-12整数");
-        }
+            if (sysPolicy.getLogSpaceWarn() == null) {
+                return ResponseVO.fail("日志存储低于阈值告警不能为空!");
+            } else if (!String.valueOf(sysPolicy.getMemoryWarn()).matches("^(?:[2-8]\\d|90)$")) {
+                return ResponseVO.fail("日志存储低于阈值告警请输入20-90整数");
+            }
 
-        if (sysPolicy.getScanAccount()==null) {
-            return ResponseVO.fail("扫描未使用的账号不能为空!");
-        } else if (!String.valueOf(sysPolicy.getScanAccount()).matches("^([0-9]|(1[0-2]))$")) {
-            return ResponseVO.fail("扫描未使用的账号请输入0-12整数");
-        }
+            if (sysPolicy.getAuditLog() == null) {
+                return ResponseVO.fail("审计日志保留月数不能为空!");
+            } else if (!String.valueOf(sysPolicy.getAuditLog()).matches("^([3-9]|(1[0-2]))$")) {
+                return ResponseVO.fail("审计日志保留月数请输入3-12整数");
+            }
 
-        if (StringUtils.isEmpty(sysPolicy.getExcNoticeWayA())) {
-            return ResponseVO.fail("A级别异常通知方式不能为空!");
-        } else if (!NumberUtil.isInteger(sysPolicy.getExcNoticeWayA())) {
-            return ResponseVO.fail("A级别异常通知方式不是整型!");
-        }
-        if (StringUtils.isEmpty(sysPolicy.getExcNoticeWayB())) {
-            return ResponseVO.fail("B级别异常通知方式不能为空!");
-        } else if (!NumberUtil.isInteger(sysPolicy.getExcNoticeWayB())) {
-            return ResponseVO.fail("B级别异常通知方式不是整型!");
-        }
-        if (StringUtils.isEmpty(sysPolicy.getExcLevelLogin())) {
-            return ResponseVO.fail("连续登录失败异常级别不能为空!");
-        } else if (!NumberUtil.isInteger(sysPolicy.getExcLevelLogin())) {
-            return ResponseVO.fail("连续登录失败异常级别不是整型!");
-        }
-        if (StringUtils.isEmpty(sysPolicy.getExcLevelSameUser())) {
-            return ResponseVO.fail("同一用户多点登录异常级别不能为空!");
-        } else if (!NumberUtil.isInteger(sysPolicy.getExcLevelSameUser())) {
-            return ResponseVO.fail("同一用户多点登录异常级别不是整型!");
-        }
+            if (sysPolicy.getScanAccount() == null) {
+                return ResponseVO.fail("扫描未使用的账号不能为空!");
+            } else if (!String.valueOf(sysPolicy.getScanAccount()).matches("^([0-9]|(1[0-2]))$")) {
+                return ResponseVO.fail("扫描未使用的账号请输入0-12整数");
+            }
 
-        try {
+            if (StringUtils.isEmpty(sysPolicy.getExcNoticeWayA())) {
+                return ResponseVO.fail("A级别异常通知方式不能为空!");
+            } else if (!NumberUtil.isInteger(sysPolicy.getExcNoticeWayA())) {
+                return ResponseVO.fail("A级别异常通知方式不是整型!");
+            }
+            if (StringUtils.isEmpty(sysPolicy.getExcNoticeWayB())) {
+                return ResponseVO.fail("B级别异常通知方式不能为空!");
+            } else if (!NumberUtil.isInteger(sysPolicy.getExcNoticeWayB())) {
+                return ResponseVO.fail("B级别异常通知方式不是整型!");
+            }
+            if (StringUtils.isEmpty(sysPolicy.getExcLevelLogin())) {
+                return ResponseVO.fail("连续登录失败异常级别不能为空!");
+            } else if (!NumberUtil.isInteger(sysPolicy.getExcLevelLogin())) {
+                return ResponseVO.fail("连续登录失败异常级别不是整型!");
+            }
+            if (StringUtils.isEmpty(sysPolicy.getExcLevelSameUser())) {
+                return ResponseVO.fail("同一用户多点登录异常级别不能为空!");
+            } else if (!NumberUtil.isInteger(sysPolicy.getExcLevelSameUser())) {
+                return ResponseVO.fail("同一用户多点登录异常级别不是整型!");
+            }
             boolean bo = sysPolicyService.saveOrUpdate(sysPolicy);
             if (bo) {
                 return ResponseVO.success("策略配置保存成功");
@@ -124,9 +122,7 @@ public class SysPolicyController {
                 return ResponseVO.fail("策略配置保存失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("策略配置保存异常");
-            return ResponseVO.fail("策略配置保存失败");
+            throw new CustomException("策略配置保存异常", e);
         }
     }
 }

+ 25 - 29
backend/src/main/java/com/jiayue/ssi/controller/SysRoleController.java

@@ -8,6 +8,7 @@ import com.jiayue.ssi.annotation.InterfaceLimit;
 import com.jiayue.ssi.annotation.OperateLog;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.constant.UserConstants;
 import com.jiayue.ssi.entity.SysParameter;
 import com.jiayue.ssi.entity.SysRole;
@@ -46,7 +47,7 @@ public class SysRoleController {
      */
     @GetMapping(value = "/getAll")
     @PreAuthorize("@ss.hasPermi('system:role:list')")
-    public ResponseVO getAll(Integer currentPage, Integer pageSize, String roleName, String status, String roleKey) {
+    public ResponseVO getAll(Integer currentPage, Integer pageSize, String roleName, String status, String roleKey) throws CustomException {
         try {
             if (StringUtils.isNotEmpty(roleName)) {
                 if (roleName.length() > 15) {
@@ -71,9 +72,7 @@ public class SysRoleController {
             Page<SysRole> result = roleService.page(new Page<>(currentPage, pageSize), wrapper);
             return ResponseVO.success(result);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取角色列表异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取角色列表异常", e);
         }
     }
 
@@ -84,9 +83,9 @@ public class SysRoleController {
      * @return 执行结果
      */
     @PostMapping(value = "/addRole")
-    @OperateLog(title = "角色管理", businessType = BusinessType.INSERT,auditType = AuditType.SYS)
+    @OperateLog(title = "角色管理", businessType = BusinessType.INSERT, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:role:add')")
-    public ResponseVO addRole(@RequestBody SysRole role) {
+    public ResponseVO addRole(@RequestBody SysRole role) throws CustomException {
         try {
             if (StringUtils.isEmpty(role.getRoleName())) {
                 return ResponseVO.fail("角色名称不能为空!");
@@ -119,9 +118,7 @@ public class SysRoleController {
                 return ResponseVO.fail("添加角色失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("添加角色异常");
-            return ResponseVO.error(e);
+            throw new CustomException("添加角色异常", e);
         }
     }
 
@@ -132,9 +129,9 @@ public class SysRoleController {
      * @return 执行结果
      */
     @PostMapping(value = "/updateRole")
-    @OperateLog(title = "角色管理", businessType = BusinessType.UPDATE,auditType = AuditType.SYS)
+    @OperateLog(title = "角色管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:role:edit')")
-    public ResponseVO updateRole(@RequestBody SysRole role) {
+    public ResponseVO updateRole(@RequestBody SysRole role) throws CustomException {
         try {
             SysRole existRole = roleService.getById(role.getRoleId());
             if (existRole == null) {
@@ -174,9 +171,7 @@ public class SysRoleController {
                 return ResponseVO.fail("修改角色信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("修改角色信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("修改角色信息异常", e);
         }
     }
 
@@ -184,21 +179,25 @@ public class SysRoleController {
      * 根据角色编号获取详细信息
      */
     @GetMapping(value = "getInfo")
-    public ResponseVO getInfo(Long roleId) {
-        return ResponseVO.success(roleService.selectRoleById(roleId));
+    public ResponseVO getInfo(Long roleId) throws CustomException {
+        try {
+            return ResponseVO.success(roleService.selectRoleById(roleId));
+        } catch (Exception e) {
+            throw new CustomException("角色编号获取异常", e);
+        }
     }
 
     /**
      * 删除角色
      */
     @PostMapping(value = "/delRole")
-    @OperateLog(title = "角色管理", businessType = BusinessType.DELETE,auditType = AuditType.SYS)
+    @OperateLog(title = "角色管理", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:role:remove')")
-    public ResponseVO delRole(String roleId) {
-        if (StringUtils.isEmpty(roleId)) {
-            return ResponseVO.fail("id不能为空!");
-        }
+    public ResponseVO delRole(String roleId) throws CustomException {
         try {
+            if (StringUtils.isEmpty(roleId)) {
+                return ResponseVO.fail("id不能为空!");
+            }
             int bo = roleService.deleteRoleById(Long.parseLong(roleId));
             if (bo > 0) {
                 return ResponseVO.success("删除角色信息成功");
@@ -207,11 +206,10 @@ public class SysRoleController {
                 return ResponseVO.fail("删除角色信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("删除角色信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("删除角色信息异常", e);
         }
     }
+
     /**
      * 获取分配角色信息
      *
@@ -219,10 +217,10 @@ public class SysRoleController {
      */
     @GetMapping(value = "/getRoleByType")
     @PreAuthorize("@ss.hasPermi('system:user:role')")
-    public ResponseVO getRoleByType(String usertype) {
+    public ResponseVO getRoleByType(String usertype) throws CustomException {
         try {
             if (StringUtils.isEmpty(usertype)) {
-               return ResponseVO.fail("用户类型为空不能获取角色列表!");
+                return ResponseVO.fail("用户类型为空不能获取角色列表!");
             }
             QueryWrapper<SysRole> wrapper = new QueryWrapper<>();
             wrapper.eq("role_type", usertype);
@@ -230,9 +228,7 @@ public class SysRoleController {
             List<SysRole> result = roleService.list(wrapper);
             return ResponseVO.success(result);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取分配角色列表异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取分配角色列表异常", e);
         }
     }
 }

+ 170 - 176
backend/src/main/java/com/jiayue/ssi/controller/SysUserController.java

@@ -13,6 +13,7 @@ import com.jiayue.ssi.backenum.ApproveStatusEnum;
 import com.jiayue.ssi.backenum.AuditType;
 import com.jiayue.ssi.backenum.BusinessType;
 import com.jiayue.ssi.config.SendMailUtil;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.constant.SecretKeyConstants;
 import com.jiayue.ssi.entity.SysApprove;
 import com.jiayue.ssi.entity.SysUser;
@@ -59,7 +60,7 @@ public class SysUserController {
     @GetMapping(value = "/getAll")
     @PreAuthorize("@ss.hasPermi('system:user:list')")
     public ResponseVO getAll(Integer currentPage, Integer pageSize, String username, String phonenumber,
-                             String status) {
+                             String status) throws CustomException {
         try {
             if (StringUtils.isNotEmpty(username)) {
                 if (username.length() > 20) {
@@ -76,7 +77,7 @@ public class SysUserController {
                 wrapper.eq("username", username);
             }
             if (StringUtils.isNotEmpty(phonenumber)) {
-                wrapper.eq("AES_DECRYPT(UNHEX(phonenumber), '"+new String(AesUtils.key)+"')", phonenumber);
+                wrapper.eq("AES_DECRYPT(UNHEX(phonenumber), '" + new String(AesUtils.key) + "')", phonenumber);
             }
             if (StringUtils.isNotEmpty(status)) {
                 wrapper.eq("status", status);
@@ -85,7 +86,7 @@ public class SysUserController {
             List<SysUser> records = result.getRecords();
             //遍历对象数组的方法
             records.forEach(
-                    record->{
+                    record -> {
                         record.setMailbox(AesUtils.decryptStr(record.getMailbox()));
                         record.setPhonenumber(AesUtils.decryptStr(record.getPhonenumber()));
                         record.setNickname(AesUtils.decryptStr(record.getNickname()));
@@ -93,9 +94,7 @@ public class SysUserController {
             );
             return ResponseVO.success(result);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取所有用户异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取所有用户异常", e);
         }
     }
 
@@ -105,7 +104,7 @@ public class SysUserController {
      * @return 用户信息
      */
     @GetMapping(value = "/getCurrentUser")
-    public ResponseVO getCurrentUser() {
+    public ResponseVO getCurrentUser() throws CustomException {
         try {
             SysUser sysUser = SecurityContextUtil.getSysUser();
             // 权限集合
@@ -118,9 +117,7 @@ public class SysUserController {
             map.put("permissions", permissions);
             return ResponseVO.success(map);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取当前用户异常");
-            return ResponseVO.error(null);
+            throw new CustomException("获取当前用户异常", e);
         }
     }
 
@@ -130,50 +127,49 @@ public class SysUserController {
     @PostMapping(value = "/addUser")
     @OperateLog(title = "用户管理", businessType = BusinessType.INSERT, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:user:add')")
-    public ResponseVO addUser(@RequestBody SysUser user) {
-        if (StringUtils.isEmpty(user.getUsername())) {
-            return ResponseVO.fail("用户账号不能为空!");
-        } else if (sysUserService.queryUserName(user.getUsername()) != null) {
-            return ResponseVO.fail(user.getUsername() + "账号已存在!");
-        } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
-            return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
-        }
+    public ResponseVO addUser(@RequestBody SysUser user) throws CustomException {
+        try {
+            if (StringUtils.isEmpty(user.getUsername())) {
+                return ResponseVO.fail("用户账号不能为空!");
+            } else if (sysUserService.queryUserName(user.getUsername()) != null) {
+                return ResponseVO.fail(user.getUsername() + "账号已存在!");
+            } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
+                return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
+            }
 
-        if (StringUtils.isEmpty(user.getPhonenumber())) {
-            return ResponseVO.fail("手机号码不能为空!");
-        } else if (!Validator.isMobile(user.getPhonenumber())) {
-            return ResponseVO.fail("请输入正确的手机号码!");
-        }
-        // 加密手机号
-        user.setPhonenumber(AesUtils.encryptHex(user.getPhonenumber()).toUpperCase());
+            if (StringUtils.isEmpty(user.getPhonenumber())) {
+                return ResponseVO.fail("手机号码不能为空!");
+            } else if (!Validator.isMobile(user.getPhonenumber())) {
+                return ResponseVO.fail("请输入正确的手机号码!");
+            }
+            // 加密手机号
+            user.setPhonenumber(AesUtils.encryptHex(user.getPhonenumber()).toUpperCase());
 
-        if (StringUtils.isEmpty(user.getNickname())) {
-            return ResponseVO.fail("姓名不能为空!");
-        } else if (user.getNickname().length() > 30) {
-            return ResponseVO.fail("姓名长度不能超过30个字符!");
-        }
-        // 加密姓名
-        user.setNickname(AesUtils.encryptHex(user.getNickname()).toUpperCase());
+            if (StringUtils.isEmpty(user.getNickname())) {
+                return ResponseVO.fail("姓名不能为空!");
+            } else if (user.getNickname().length() > 30) {
+                return ResponseVO.fail("姓名长度不能超过30个字符!");
+            }
+            // 加密姓名
+            user.setNickname(AesUtils.encryptHex(user.getNickname()).toUpperCase());
 
-        if (StringUtils.isEmpty(user.getMailbox())) {
-            return ResponseVO.fail("邮箱不能为空!");
-        } else if (!Validator.isEmail(user.getMailbox())) {
-            return ResponseVO.fail("请输入正确的邮箱地址!");
-        } else if (user.getMailbox().length() > 50) {
-            return ResponseVO.fail("邮箱长度不能超过50个字符!");
-        } else if (sysUserService.queryMailBox(user.getMailbox()) != null) {
-            return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
-        }
-        // 加密邮箱
-        user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
+            if (StringUtils.isEmpty(user.getMailbox())) {
+                return ResponseVO.fail("邮箱不能为空!");
+            } else if (!Validator.isEmail(user.getMailbox())) {
+                return ResponseVO.fail("请输入正确的邮箱地址!");
+            } else if (user.getMailbox().length() > 50) {
+                return ResponseVO.fail("邮箱长度不能超过50个字符!");
+            } else if (sysUserService.queryMailBox(user.getMailbox()) != null) {
+                return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
+            }
+            // 加密邮箱
+            user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
 
 //        // 生成8位初始密码
 //        String randomPwd = RandomPwd.getRandomPwd(8);
 //        user.setPassword(SmUtil.sm3(randomPwd).toUpperCase());
 //        user.setErrNum(0);
 //        user.setLockTime(0L);
-
-        try {
             boolean bo = sysUserService.save(user);
             if (bo) {
                 return ResponseVO.success("添加用户信息成功");
@@ -182,9 +178,7 @@ public class SysUserController {
                 return ResponseVO.fail("添加用户信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("添加用户信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("添加用户信息异常", e);
         }
     }
 
@@ -197,53 +191,54 @@ public class SysUserController {
     @PostMapping(value = "/updateUser")
     @OperateLog(title = "用户管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:user:edit')")
-    public ResponseVO updateUser(@RequestBody SysUser user) {
-        SysUser existUser = sysUserService.getById(user.getId());
-        if (existUser == null) {
-            return ResponseVO.fail("非法访问不能修改!");
-        }
+    public ResponseVO updateUser(@RequestBody SysUser user) throws CustomException {
+        try {
+            SysUser existUser = sysUserService.getById(user.getId());
+            if (existUser == null) {
+                return ResponseVO.fail("非法访问不能修改!");
+            }
 
-        if (StringUtils.isEmpty(user.getUsername())) {
-            return ResponseVO.fail("用户账号不能为空!");
-        } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
-            return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
-        } else if (!existUser.getUsername().equals(user.getUsername())) {
-            if (sysUserService.queryUserName(user.getUsername()) != null) {
-                return ResponseVO.fail(user.getUsername() + "账号已存在!");
+            if (StringUtils.isEmpty(user.getUsername())) {
+                return ResponseVO.fail("用户账号不能为空!");
+            } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
+                return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
+            } else if (!existUser.getUsername().equals(user.getUsername())) {
+                if (sysUserService.queryUserName(user.getUsername()) != null) {
+                    return ResponseVO.fail(user.getUsername() + "账号已存在!");
+                }
             }
-        }
 
-        if (StringUtils.isEmpty(user.getMailbox())) {
-            return ResponseVO.fail("邮箱不能为空!");
-        } else if (!Validator.isEmail(user.getMailbox())) {
-            return ResponseVO.fail("请输入正确的邮箱地址!");
-        } else if (user.getMailbox().length() > 50) {
-            return ResponseVO.fail("邮箱长度不能超过50个字符!");
-        } else if (!existUser.getMailbox().equals(user.getMailbox())) {
-            if (sysUserService.queryMailBox(user.getMailbox()) != null) {
-                return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
+            if (StringUtils.isEmpty(user.getMailbox())) {
+                return ResponseVO.fail("邮箱不能为空!");
+            } else if (!Validator.isEmail(user.getMailbox())) {
+                return ResponseVO.fail("请输入正确的邮箱地址!");
+            } else if (user.getMailbox().length() > 50) {
+                return ResponseVO.fail("邮箱长度不能超过50个字符!");
+            } else if (!existUser.getMailbox().equals(user.getMailbox())) {
+                if (sysUserService.queryMailBox(user.getMailbox()) != null) {
+                    return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
+                }
             }
-        }
-        // 加密邮箱
-        user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
+            // 加密邮箱
+            user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
 
-        if (StringUtils.isEmpty(user.getPhonenumber())) {
-            return ResponseVO.fail("手机号码不能为空!");
-        } else if (!Validator.isMobile(user.getPhonenumber())) {
-            return ResponseVO.fail("请输入正确的手机号码!");
-        }
-        // 加密手机号
-        user.setPhonenumber(AesUtils.encryptHex(user.getPhonenumber()).toUpperCase());
+            if (StringUtils.isEmpty(user.getPhonenumber())) {
+                return ResponseVO.fail("手机号码不能为空!");
+            } else if (!Validator.isMobile(user.getPhonenumber())) {
+                return ResponseVO.fail("请输入正确的手机号码!");
+            }
+            // 加密手机号
+            user.setPhonenumber(AesUtils.encryptHex(user.getPhonenumber()).toUpperCase());
+
+            if (StringUtils.isEmpty(user.getNickname())) {
+                return ResponseVO.fail("姓名不能为空!");
+            } else if (user.getNickname().length() > 30) {
+                return ResponseVO.fail("姓名长度不能超过30个字符!");
+            }
+            // 加密姓名
+            user.setNickname(AesUtils.encryptHex(user.getNickname()).toUpperCase());
 
-        if (StringUtils.isEmpty(user.getNickname())) {
-            return ResponseVO.fail("姓名不能为空!");
-        } else if (user.getNickname().length() > 30) {
-            return ResponseVO.fail("姓名长度不能超过30个字符!");
-        }
-        // 加密姓名
-        user.setNickname(AesUtils.encryptHex(user.getNickname()).toUpperCase());
 
-        try {
             if ("0".equals(user.getStatus())) {
                 user.setErrNum(0);
                 user.setLockTime(0L);
@@ -256,9 +251,7 @@ public class SysUserController {
                 return ResponseVO.fail("修改用户信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("修改用户信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("修改用户信息异常", e);
         }
     }
 
@@ -300,16 +293,17 @@ public class SysUserController {
     @AgainVerify
     @OperateLog(title = "用户管理", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:user:remove')")
-    public ResponseVO delete(String id) {
-        if (StringUtils.isEmpty(id)) {
-            return ResponseVO.fail("id不能为空!");
-        }
-        // id获取用户
-        SysUser sysUser = sysUserService.getById(id);
-        if (sysUser == null) {
-            return ResponseVO.fail("不能删除用户!");
-        }
+    public ResponseVO delete(String id) throws CustomException {
         try {
+            if (StringUtils.isEmpty(id)) {
+                return ResponseVO.fail("id不能为空!");
+            }
+            // id获取用户
+            SysUser sysUser = sysUserService.getById(id);
+            if (sysUser == null) {
+                return ResponseVO.fail("不能删除用户!");
+            }
+
             // 获取审批表是否存在此操作
             QueryWrapper<SysApprove> wrapper = new QueryWrapper<>();
             // 条件:待审批
@@ -319,7 +313,7 @@ public class SysUserController {
             // 条件:实体名
             wrapper.eq("entity_name", "SysUser");
             List<SysApprove> list = sysApproveService.list(wrapper);
-            if (list.size()>0){
+            if (list.size() > 0) {
                 return ResponseVO.fail("此记录存在未审批的操作,不能进行删除!");
             }
 
@@ -331,9 +325,7 @@ public class SysUserController {
                 return ResponseVO.fail("删除用户信息失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("删除用户信息异常");
-            return ResponseVO.error(e);
+            throw new CustomException("删除用户信息异常", e);
         }
     }
 
@@ -342,53 +334,57 @@ public class SysUserController {
      */
     @PostMapping(value = "/updatePassword")
     @OperateLog(title = "用户管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
-    public ResponseVO updatePassword(String id, String oldPassword, String newPassword, String confirmPassword) {
-        if (StringUtils.isEmpty(id)) {
-            return ResponseVO.fail("修改密码缺失id!");
-        }
-        // id获取用户
-        SysUser sysUser = sysUserService.getById(id);
-        if (sysUser == null) {
-            return ResponseVO.fail("修改密码失败!");
-        }
+    public ResponseVO updatePassword(String id, String oldPassword, String newPassword, String confirmPassword) throws CustomException {
+        try {
+            if (StringUtils.isEmpty(id)) {
+                return ResponseVO.fail("修改密码缺失id!");
+            }
+            // id获取用户
+            SysUser sysUser = sysUserService.getById(id);
+            if (sysUser == null) {
+                return ResponseVO.fail("修改密码失败!");
+            }
 
-        if (StringUtils.isEmpty(oldPassword)) {
-            return ResponseVO.fail("旧密码不能为空!");
-        } else if (!sysUser.getPassword().equals(SmUtil.sm3(oldPassword).toUpperCase())) {
-            return ResponseVO.fail("旧密码不正确!");
-        }
+            if (StringUtils.isEmpty(oldPassword)) {
+                return ResponseVO.fail("旧密码不能为空!");
+            } else if (!sysUser.getPassword().equals(SmUtil.sm3(oldPassword).toUpperCase())) {
+                return ResponseVO.fail("旧密码不正确!");
+            }
 
-        if (StringUtils.isEmpty(newPassword)) {
-            return ResponseVO.fail("新密码不能为空!");
-        } else if (StringUtils.isEmpty(confirmPassword)) {
-            return ResponseVO.fail("确认密码不能为空!");
-        } else if (!newPassword.equals(confirmPassword)) {
-            return ResponseVO.fail("新密码两次输入的密码不一致!");
-        }
-        // 对新密码规则验证
-        if (newPassword.contains(sysUser.getUsername())) {
-            return ResponseVO.fail("密码不能含有账号!");
-        }
-        if (SmUtil.sm3(newPassword).toUpperCase().equals(sysUser.getPassword())) {
-            return ResponseVO.fail("新密码不能与上次密码相同!");
-        }
-        if (RegexUtil.sameReg(newPassword)) {
-            return ResponseVO.fail("新密码不能含有连续4位相同的数字或字母!");
-        } else if (RegexUtil.keyboardSlopeArr(newPassword)) {
-            return ResponseVO.fail("新密码不能含有4位斜方向连续的字符!");
-        } else if (RegexUtil.keyboardHorizontalReg(newPassword)) {
-            return ResponseVO.fail("新密码不能含有4位连续的字符!");
-        } else if (!RegexUtil.checkPwd(newPassword)) {
-            return ResponseVO.fail("新密码不满足8~20位大写字母、小写字母、数字、特殊字符三种以上的组合!");
-        }
+            if (StringUtils.isEmpty(newPassword)) {
+                return ResponseVO.fail("新密码不能为空!");
+            } else if (StringUtils.isEmpty(confirmPassword)) {
+                return ResponseVO.fail("确认密码不能为空!");
+            } else if (!newPassword.equals(confirmPassword)) {
+                return ResponseVO.fail("新密码两次输入的密码不一致!");
+            }
+            // 对新密码规则验证
+            if (newPassword.contains(sysUser.getUsername())) {
+                return ResponseVO.fail("密码不能含有账号!");
+            }
+            if (SmUtil.sm3(newPassword).toUpperCase().equals(sysUser.getPassword())) {
+                return ResponseVO.fail("新密码不能与上次密码相同!");
+            }
+            if (RegexUtil.sameReg(newPassword)) {
+                return ResponseVO.fail("新密码不能含有连续4位相同的数字或字母!");
+            } else if (RegexUtil.keyboardSlopeArr(newPassword)) {
+                return ResponseVO.fail("新密码不能含有4位斜方向连续的字符!");
+            } else if (RegexUtil.keyboardHorizontalReg(newPassword)) {
+                return ResponseVO.fail("新密码不能含有4位连续的字符!");
+            } else if (!RegexUtil.checkPwd(newPassword)) {
+                return ResponseVO.fail("新密码不满足8~20位大写字母、小写字母、数字、特殊字符三种以上的组合!");
+            }
 
-        sysUser.setPassword(SmUtil.sm3(newPassword).toUpperCase());
-        sysUser.setLastUpdatePwdTime(new Date());
-        boolean bo = sysUserService.updateById(sysUser);
-        if (!bo) {
-            return ResponseVO.fail("修改密码失败!");
+            sysUser.setPassword(SmUtil.sm3(newPassword).toUpperCase());
+            sysUser.setLastUpdatePwdTime(new Date());
+            boolean bo = sysUserService.updateById(sysUser);
+            if (!bo) {
+                return ResponseVO.fail("修改密码失败!");
+            }
+            return ResponseVO.success();
+        } catch (Exception e) {
+            throw new CustomException("修改密码异常", e);
         }
-        return ResponseVO.success();
     }
 
     /**
@@ -397,19 +393,20 @@ public class SysUserController {
     @PostMapping(value = "/relockUser")
     @OperateLog(title = "用户管理", businessType = BusinessType.OTHER, auditType = AuditType.SYS)
     @PreAuthorize("@ss.hasPermi('system:user:relock')")
-    public ResponseVO relockUser(String id) {
-        if (StringUtils.isEmpty(id)) {
-            return ResponseVO.fail("id不能为空!");
-        }
-        // id获取用户
-        SysUser sysUser = sysUserService.getById(id);
-        if (sysUser == null) {
-            return ResponseVO.fail("不能解锁用户!");
-        }
-        if (!"1".equals(sysUser.getStatus())) {
-            return ResponseVO.fail("只能对【锁定】状态的进行解锁!");
-        }
+    public ResponseVO relockUser(String id) throws CustomException {
         try {
+            if (StringUtils.isEmpty(id)) {
+                return ResponseVO.fail("id不能为空!");
+            }
+            // id获取用户
+            SysUser sysUser = sysUserService.getById(id);
+            if (sysUser == null) {
+                return ResponseVO.fail("不能解锁用户!");
+            }
+            if (!"1".equals(sysUser.getStatus())) {
+                return ResponseVO.fail("只能对【锁定】状态的进行解锁!");
+            }
+
             boolean bo = sysUserService.relockUserById(Integer.parseInt(id));
             if (bo) {
                 return ResponseVO.success("解锁成功");
@@ -418,50 +415,47 @@ public class SysUserController {
                 return ResponseVO.fail("解锁失败");
             }
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("解锁异常");
-            return ResponseVO.error(e);
+            throw new CustomException("解锁异常", e);
         }
     }
+
     /**
      * 用户授权角色
      */
     @PostMapping("/authRole")
     @PreAuthorize("@ss.hasPermi('system:user:role')")
     @OperateLog(title = "用户管理", businessType = BusinessType.GRANT, auditType = AuditType.SYS)
-    public ResponseVO authRole(Long userId, Long roleId) {
-        if (userId==null) {
-            return ResponseVO.fail("用户id不能为空!");
-        }
+    public ResponseVO authRole(Long userId, Long roleId) throws CustomException {
         try {
+            if (userId == null) {
+                return ResponseVO.fail("用户id不能为空!");
+            }
             sysUserService.insertUserAuth(userId, roleId);
             return ResponseVO.success("分配角色成功");
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("分配角色异常");
-            return ResponseVO.error(e);
+            throw new CustomException("分配角色异常", e);
         }
     }
 
     /**
      * 根据用户ID获取角色
+     *
      * @param userId
      * @return
      */
     @GetMapping("/getUserRole")
-    public ResponseVO getUserRole(Long userId) {
-        if (userId==null) {
-            return ResponseVO.fail("用户id不能为空!");
-        }
+    public ResponseVO getUserRole(Long userId) throws CustomException {
         try {
+            if (userId == null) {
+                return ResponseVO.fail("用户id不能为空!");
+            }
+
             QueryWrapper<SysUserRole> wrapper = new QueryWrapper<>();
             wrapper.eq("user_id", userId);
             SysUserRole sysUserRole = sysUserRoleService.getOne(wrapper);
             return ResponseVO.success(sysUserRole);
         } catch (Exception e) {
-            e.printStackTrace();
-            log.error("分配角色异常");
-            return ResponseVO.error(e);
+            throw new CustomException("获取用户角色异常", e);
         }
     }
 }

+ 82 - 66
backend/src/main/java/com/jiayue/ssi/controller/UserLoginController.java

@@ -7,6 +7,7 @@ import com.jiayue.ssi.annotation.OperateLog;
 import com.jiayue.ssi.backenum.BusinessType;
 import com.jiayue.ssi.config.SendMailUtil;
 import com.jiayue.ssi.constant.CacheConstants;
+import com.jiayue.ssi.constant.CustomException;
 import com.jiayue.ssi.entity.SysMenu;
 import com.jiayue.ssi.entity.SysUser;
 import com.jiayue.ssi.service.SysMenuService;
@@ -54,7 +55,7 @@ public class UserLoginController {
      * @throws IOException
      */
     @GetMapping("/getVerifyCode")
-    public ResponseVO getVerifyCode(HttpServletResponse httpServletResponse) throws IOException {
+    public ResponseVO getVerifyCode(HttpServletResponse httpServletResponse) throws CustomException {
         // gif类型
         // GifCaptcha captcha = new GifCaptcha(130, 48);
         // 中文类型
@@ -65,50 +66,53 @@ public class UserLoginController {
         // ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);
         // png类型
         // 三个参数分别为宽、高、位数
-        String textcode="";
-        String base64 = "";
-        while (true) {
-            SpecCaptcha captcha = new SpecCaptcha(150, 40, 4);
-            /**
-             * 验证码字符类型 TYPE_DEFAULT 数字和字母混合 TYPE_ONLY_NUMBER 纯数字 TYPE_ONLY_CHAR 纯字母 TYPE_ONLY_UPPER 纯大写字母 TYPE_ONLY_LOWER
-             * 纯小写字母 TYPE_NUM_AND_UPPER 数字和大写字母
-             **/
-            // 设置类型 数字和字母混合
-            captcha.setCharType(Captcha.TYPE_DEFAULT);
-            // 设置字体
-            captcha.setCharType(Captcha.FONT_9);
-            int digits = 0;
-            char[] text = captcha.textChar();
-            for (int i = 0; i < text.length; i++) {
-                if (Character.isDigit(text[i])) {
-                    digits++;
+        try {
+            String textcode = "";
+            String base64 = "";
+            while (true) {
+                SpecCaptcha captcha = new SpecCaptcha(150, 40, 4);
+                /**
+                 * 验证码字符类型 TYPE_DEFAULT 数字和字母混合 TYPE_ONLY_NUMBER 纯数字 TYPE_ONLY_CHAR 纯字母 TYPE_ONLY_UPPER 纯大写字母 TYPE_ONLY_LOWER
+                 * 纯小写字母 TYPE_NUM_AND_UPPER 数字和大写字母
+                 **/
+                // 设置类型 数字和字母混合
+                captcha.setCharType(Captcha.TYPE_DEFAULT);
+                // 设置字体
+                captcha.setCharType(Captcha.FONT_9);
+                int digits = 0;
+                char[] text = captcha.textChar();
+                for (int i = 0; i < text.length; i++) {
+                    if (Character.isDigit(text[i])) {
+                        digits++;
+                    }
+                }
+                if (digits == 0 || digits == 4) {
+                    // 重新生成
+                } else {
+                    textcode = String.valueOf(text);
+                    base64 = captcha.toBase64();
+                    break;
                 }
             }
-            if (digits == 0 || digits == 4) {
-                // 重新生成
-            }
-            else{
-                textcode = String.valueOf(text);
-                base64 = captcha.toBase64();
-                break;
-            }
-        }
 
-        String uuid = IdUtils.simpleUUID();
-        String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
-        // uuid存入缓存,失效时间默认5分钟
-        LocalCache.set(verifyKey, textcode);
-        // 输出图片流
-        // captcha.out(httpServletResponse.getOutputStream());
+            String uuid = IdUtils.simpleUUID();
+            String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
+            // uuid存入缓存,失效时间默认5分钟
+            LocalCache.set(verifyKey, textcode);
+            // 输出图片流
+            // captcha.out(httpServletResponse.getOutputStream());
 
-        int index = base64.indexOf(",");
-        String substring = base64.substring(index + 1);
+            int index = base64.indexOf(",");
+            String substring = base64.substring(index + 1);
 
-        Map<String, String> dataMap = new HashMap<>(16);
-        dataMap.put("uuid", uuid);
-        dataMap.put("imgBase64", substring);
-        dataMap.put("captchaText", textcode);
-        return ResponseVO.success(dataMap);
+            Map<String, String> dataMap = new HashMap<>(16);
+            dataMap.put("uuid", uuid);
+            dataMap.put("imgBase64", substring);
+            dataMap.put("captchaText", textcode);
+            return ResponseVO.success(dataMap);
+        } catch (Exception e) {
+            throw new CustomException("生成验证码异常", e);
+        }
     }
 
     /**
@@ -119,25 +123,29 @@ public class UserLoginController {
      * @throws IOException
      */
     @PostMapping("/getMailCode")
-    public ResponseVO getMailCode(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
-        String username = httpServletRequest.getParameter("username");
-        // 口令保存到服务器
-        String mailKey = CacheConstants.MAIL_CODE_KEY + username;
-        SysUser sysUser = sysUserService.queryUserName(username);
-        if (sysUser != null) {
-            // 生成6位邮箱口令
-            String mailRandom = RandomUtil.mailRandom();
-            // uuid存入缓存,失效时间4分钟
-            LocalCache.set(mailKey, mailRandom, 60000 * 4);
-            try {
-                String[] mailArray = {sysUser.getMailbox()};
-                sendMailUtil.executeSendMail(mailArray,"邮箱验证码","口令:" + mailRandom + ",有效期4分钟。");
-            } catch (Exception e) {
-                e.printStackTrace();
-                return ResponseVO.fail("邮箱验证码发送失败!");
+    public ResponseVO getMailCode(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws CustomException {
+        try {
+            String username = httpServletRequest.getParameter("username");
+            // 口令保存到服务器
+            String mailKey = CacheConstants.MAIL_CODE_KEY + username;
+            SysUser sysUser = sysUserService.queryUserName(username);
+            if (sysUser != null) {
+                // 生成6位邮箱口令
+                String mailRandom = RandomUtil.mailRandom();
+                // uuid存入缓存,失效时间4分钟
+                LocalCache.set(mailKey, mailRandom, 60000 * 4);
+                try {
+                    String[] mailArray = {sysUser.getMailbox()};
+                    sendMailUtil.executeSendMail(mailArray, "邮箱验证码", "口令:" + mailRandom + ",有效期4分钟。");
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    return ResponseVO.fail("邮箱验证码发送失败!");
+                }
             }
+            return ResponseVO.success();
+        } catch (Exception e) {
+            throw new CustomException("获取邮箱口令异常", e);
         }
-        return ResponseVO.success();
     }
 
     /**
@@ -149,11 +157,15 @@ public class UserLoginController {
      */
     @PostMapping("/refreshToken")
     public ResponseVO refreshToken(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
-            throws Exception {
-        String oldToken = httpServletRequest.getHeader("Authorization");
-        String newToken = jwtTokenUtil.refreshToken(oldToken);
-        CacheConstants.LOGIN_TOKEN_MAP.put(SecurityContextUtil.getSysUser().getUsername(),newToken);
-        return ResponseVO.success(newToken);
+            throws CustomException {
+        try {
+            String oldToken = httpServletRequest.getHeader("Authorization");
+            String newToken = jwtTokenUtil.refreshToken(oldToken);
+            CacheConstants.LOGIN_TOKEN_MAP.put(SecurityContextUtil.getSysUser().getUsername(), newToken);
+            return ResponseVO.success(newToken);
+        } catch (Exception e) {
+            throw new CustomException("刷新token异常", e);
+        }
     }
 
     /**
@@ -162,9 +174,13 @@ public class UserLoginController {
      * @return 路由菜单信息
      */
     @GetMapping("getRouters")
-    public ResponseVO getRouters() {
-        Long userId = SecurityContextUtil.getSysUser().getId();
-        List<SysMenu> menus = sysMenuService.selectMenuTreeByUserId(userId);
-        return ResponseVO.success(sysMenuService.buildMenus(menus));
+    public ResponseVO getRouters() throws CustomException {
+        try {
+            Long userId = SecurityContextUtil.getSysUser().getId();
+            List<SysMenu> menus = sysMenuService.selectMenuTreeByUserId(userId);
+            return ResponseVO.success(sysMenuService.buildMenus(menus));
+        } catch (Exception e) {
+            throw new CustomException("获取路由菜单信息异常", e);
+        }
     }
 }

+ 2 - 0
backend/src/main/java/com/jiayue/ssi/service/impl/UserServiceImpl.java

@@ -2,6 +2,7 @@ package com.jiayue.ssi.service.impl;
 
 
 import com.jiayue.ssi.service.SysParameterService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.security.core.userdetails.UserDetailsService;
@@ -19,6 +20,7 @@ import com.jiayue.ssi.mapper.SysUserMapper;
  * @version 3.0
  */
 @Service
+@Slf4j
 public class UserServiceImpl implements UserDetailsService {
     @Autowired
     SysUserMapper sysUserMapper;

+ 3 - 0
backend/src/main/resources/application.yml

@@ -7,6 +7,9 @@ server:
 #  tomcat:
 #    max-connections: 1000
 
+logging:
+  config: classpath:logback-ssi.xml
+
 #设置提供的服务名
 spring:
   application:

+ 82 - 0
backend/src/main/resources/logback-ssi.xml

@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<configuration scan="false" scanPeriod="60 seconds" debug="false"><!-- 这个是根配置文件,一定要有的
+                            scan:
+                                是当配置文件被修改后会被重新加载
+                            scanPeriod:
+                                设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,
+                                默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。
+                            debug:
+                                当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。
+                                默认值为false。
+                             -->
+  <!-- 日志存放路径
+      下面的标签可以自己定义
+      name:相当于Map的key
+      value:就是map的value
+      ${catalina.base}是tomcat的当前路径
+      /logs:就是tomcat下的日志路径,
+      /ehrlog:如果没有目录会默认创建
+  -->
+  <property name="logbase" value="./ssiLogs/"/>
+  <!-- 时间戳:这个时间戳可以作为每日日志的名称 -->
+  <timestamp key="bySecond" datePattern="yyyy-MM-dd"/>
+  <!-- appender:
+      name相当于一个名称
+      class:确定要加载哪个类
+      encoder:一定要加 encoder ,
+      默认配置为PatternLayoutEncoder
+      patter:必填
+      ConsoleAppender:也明白是什么意思,就是输出在控制台上-->
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+      <charset>UTF-8</charset>
+    </encoder>
+  </appender>
+  <!-- 把日志存储
+      encoding:日志的编码
+      file:指定当前生成的日志文件名称
+      rollingPolicy:滚动策略
+      FileNamePattern:移动文件最后的名称,跟file标签结合使用,
+      比如file里面的内容是  1.txt
+      那么,FileNamePattern里面写的是2.txt,那么最后文件名就为2.txt
+      如果最后结尾是gz或者zip,那么,就会自动打成压缩包
+      -->
+  <appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <!-- 编码 -->
+    <!--<Encoding>UTF-8</Encoding>-->
+    <!-- 按照时间来 -->
+    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+      <!--日志文件输出的文件名-->
+      <FileNamePattern>${logbase}/%d{yyyy-MM-dd}/ssi.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
+      <!--日志文件保留天数-->
+      <MaxHistory>180</MaxHistory>
+      <maxFileSize>10MB</maxFileSize>
+      <totalSizeCap>1024MB</totalSizeCap>
+      <cleanHistoryOnStart>true</cleanHistoryOnStart>
+    </rollingPolicy>
+    <!-- 布局 -->
+    <encoder>
+      <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
+      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+      <charset>UTF-8</charset>
+    </encoder>
+    <append>false</append>
+  </appender>
+
+  <logger name="com.jiayue" level="info" additivity="true">
+    <appender-ref ref="logFile"/>
+  </logger>
+  <logger name="com.alibaba.druid.filter.stat.StatFilter" level="info" additivity="true">
+    <appender-ref ref="logFile"/>
+  </logger>
+
+  <logger name="org" level="info" additivity="true">
+    <appender-ref ref="logFile"/>
+  </logger>
+
+  <root level="info">
+    <appender-ref ref="STDOUT"/>
+  </root>
+</configuration>

+ 1 - 2
backend/src/main/java/com/jiayue/ssi/util/JasyptStringEncryptorDemo.java → backend/src/test/java/com/jiayue/ssi/JasyptStringEncryptorDemo.java

@@ -1,7 +1,6 @@
-package com.jiayue.ssi.util;
+package com.jiayue.ssi;
 
 import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
-import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
 import org.jasypt.util.text.BasicTextEncryptor;
 
 /**

+ 23 - 16
ui/src/utils/request.js

@@ -98,7 +98,6 @@ service.interceptors.response.use(
     let data = JSON.parse(decData)
     // if the custom code is not 20000, it is judged as an error.
     //console.log(res.code)
-
     if (data.code > 1) {
       // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
       if (data.code === 50008 || data.code === 50012 || data.code === 50014) {
@@ -121,6 +120,13 @@ service.interceptors.response.use(
   async error => {
     if (error.response) {
       switch (error.response.status) {
+        case 400:
+          Message({
+            message: '系统异常,请联系管理员!',
+            type: 'error',
+            duration: 5 * 1000
+          })
+          break
         case 401:
           console.log('用户验证失败!')
           // 返回 401 清除token信息并跳转到登录页面
@@ -155,21 +161,6 @@ service.interceptors.response.use(
             duration: 5 * 1000
           })
           break
-        case 500:
-          Message({
-            message: '服务器关闭了!请联系相关工作人员',
-            type: 'error',
-            duration: 5 * 1000
-          })
-          removeToken()
-          resetRouter()
-          router.push('/login')
-          break
-        case 504:
-          console.log('服务器关闭了!')
-          removeToken()
-          resetRouter()
-          break
         case 410:
           removeToken()
           router.push('/404')
@@ -220,6 +211,22 @@ service.interceptors.response.use(
             })
           }
           break
+        case 500:
+          Message({
+            message: '服务器关闭了!请联系相关工作人员',
+            type: 'error',
+            duration: 5 * 1000
+          })
+          removeToken()
+          resetRouter()
+          router.push('/login')
+          break
+        case 504:
+          console.log('服务器关闭了!')
+          removeToken()
+          resetRouter()
+          break
+
         // return Promise.reject(error.response.data)
       }
     }

+ 4 - 3
ui/src/views/sysManager/userManager/index.vue

@@ -390,6 +390,7 @@ export default {
         }
         this.loading = false
       }).catch((error) => {
+        this.loading = false;
         // this.$message.error(error)
       })
     },
@@ -581,7 +582,6 @@ export default {
           type: 'error',
           message: '删除失败!'
         });
-        console.log(error)
         this.loading = false
       })
     },500),
@@ -668,6 +668,7 @@ export default {
           resolve(res.data)
         })
       }).catch((error) => {
+        this.loading = false
         console.error('获取用户角色出错' + error)
       })
     },
@@ -694,6 +695,7 @@ export default {
           }
         })
       }).catch((error) => {
+        this.loading = false
         this.$message.error(error)
       })
     },
@@ -716,7 +718,7 @@ export default {
           }
         }
       }).catch(e=>{
-        console.log(e)
+        this.loading = false
         this.$message.error("获取分配角色异常:"+e)
       })
     },1000),
@@ -758,7 +760,6 @@ export default {
           type: 'error',
           message: '角色分配失败!'
         });
-        console.log(error)
         this.loading = false
       })
     },1000)