From c903e9db81839c62dc3a046cfe3434d1a58726ce Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 31 十二月 2024 15:53:25 +0800
Subject: [PATCH] 调度代码优化

---
 iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java b/iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java
index 958589c..79930b8 100644
--- a/iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java
+++ b/iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java
@@ -25,6 +25,7 @@
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
 import org.springframework.web.servlet.NoHandlerFoundException;
+import org.springframework.dao.DuplicateKeyException;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.ConstraintViolation;
@@ -94,6 +95,9 @@
         }
         if (ex instanceof AccessDeniedException) {
             return accessDeniedExceptionHandler(request, (AccessDeniedException) ex);
+        }
+        if (ex instanceof DuplicateKeyException) {
+            return duplicateKeyExceptionHandler((DuplicateKeyException) ex);
         }
         return defaultExceptionHandler(request, ex);
     }
@@ -199,6 +203,17 @@
     }
 
     /**
+     * 处理业务异常 SQLIntegrityConstraintViolationException
+     *
+     * 数据库存在重复数据
+     */
+    @ExceptionHandler(value = DuplicateKeyException.class)
+    public CommonResult<?> duplicateKeyExceptionHandler(DuplicateKeyException ex) {
+        log.warn("[duplicateKeyExceptionHandler]", ex);
+        return CommonResult.error(DATA_REPETITION.getCode(), DATA_REPETITION.getMsg());
+    }
+
+    /**
      * 处理业务异常 ServiceException
      *
      * 例如说,商品库存不足,用户手机号已存在。

--
Gitblit v1.9.3