Prechádzať zdrojové kódy

新增TerminatedException异常及相关处理逻辑;优化数据库实体增加、修改、删除事件模型;

woody 11 mesiacov pred
rodič
commit
9e1b3437bc
17 zmenil súbory, kde vykonal 182 pridanie a 343 odobranie
  1. 30 24
      framework-base/src/main/java/com/chelvc/framework/base/context/Result.java
  2. 1 80
      framework-base/src/main/java/com/chelvc/framework/base/context/SessionContextHolder.java
  3. 8 6
      framework-base/src/main/java/com/chelvc/framework/base/interceptor/GlobalExceptionInterceptor.java
  4. 22 0
      framework-common/src/main/java/com/chelvc/framework/common/exception/TerminatedException.java
  5. 0 47
      framework-database/src/main/java/com/chelvc/framework/database/context/DatabaseContextHolder.java
  6. 35 0
      framework-database/src/main/java/com/chelvc/framework/database/context/EntityAddedEvent.java
  7. 35 0
      framework-database/src/main/java/com/chelvc/framework/database/context/EntityDeletedEvent.java
  8. 39 0
      framework-database/src/main/java/com/chelvc/framework/database/context/EntityUpdatedEvent.java
  9. 0 18
      framework-database/src/main/java/com/chelvc/framework/database/listener/AddListener.java
  10. 0 18
      framework-database/src/main/java/com/chelvc/framework/database/listener/DeleteListener.java
  11. 0 19
      framework-database/src/main/java/com/chelvc/framework/database/listener/ModifyListener.java
  12. 0 11
      framework-database/src/main/java/com/chelvc/framework/database/listener/OperateListener.java
  13. 1 65
      framework-database/src/main/java/com/chelvc/framework/database/support/DefaultEnhanceService.java
  14. 1 1
      framework-database/src/main/java/com/chelvc/framework/database/support/EnhanceService.java
  15. 0 44
      framework-database/src/main/java/com/chelvc/framework/database/support/EventService.java
  16. 8 8
      framework-oauth/src/main/java/com/chelvc/framework/oauth/config/OAuthConfigurer.java
  17. 2 2
      framework-security/src/main/java/com/chelvc/framework/security/interceptor/SecurityExceptionInterceptor.java

+ 30 - 24
framework-base/src/main/java/com/chelvc/framework/base/context/Result.java

@@ -4,15 +4,18 @@ import java.io.Serializable;
 import java.util.Objects;
 
 import com.chelvc.framework.common.exception.FrameworkException;
+import com.chelvc.framework.common.exception.TerminatedException;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.NonNull;
 import lombok.ToString;
+import org.springframework.http.HttpStatus;
 
 /**
  * 请求结果对象
  *
+ * @param <T> 结果数据类型
  * @author Woody
  * @date 2024/1/30
  */
@@ -53,9 +56,10 @@ public class Result<T> implements Serializable {
     /**
      * 构建成功结果
      *
+     * @param <T> 结果数据类型
      * @return 结果对象
      */
-    public static <M> Result<M> success() {
+    public static <T> Result<T> success() {
         return success(null);
     }
 
@@ -63,9 +67,10 @@ public class Result<T> implements Serializable {
      * 构建成功结果
      *
      * @param data 结果数据
+     * @param <T>  结果数据类型
      * @return 结果对象
      */
-    public static <M> Result<M> success(M data) {
+    public static <T> Result<T> success(T data) {
         return success(data, "Success");
     }
 
@@ -74,18 +79,20 @@ public class Result<T> implements Serializable {
      *
      * @param data    结果数据
      * @param message 结果信息
+     * @param <T>     结果数据类型
      * @return 结果对象
      */
-    public static <M> Result<M> success(M data, String message) {
+    public static <T> Result<T> success(T data, String message) {
         return of(OK, data, message);
     }
 
     /**
      * 构建异常结果
      *
+     * @param <T> 结果数据类型
      * @return 结果对象
      */
-    public static <M> Result<M> failure() {
+    public static <T> Result<T> failure() {
         return failure("Failure");
     }
 
@@ -93,20 +100,22 @@ public class Result<T> implements Serializable {
      * 构建异常结果
      *
      * @param message 异常消息
+     * @param <T>     结果数据类型
      * @return 结果对象
      */
-    public static <M> Result<M> failure(String message) {
+    public static <T> Result<T> failure(String message) {
         return of(ERROR, null, message);
     }
 
     /**
      * 构建异常结果
-     * param data    结果数据
      *
+     * @param data    结果数据
      * @param message 异常消息
+     * @param <T>     结果数据类型
      * @return 结果对象
      */
-    public static <M> Result<M> failure(M data, String message) {
+    public static <T> Result<T> failure(T data, String message) {
         return of(ERROR, data, message);
     }
 
@@ -125,9 +134,10 @@ public class Result<T> implements Serializable {
      *
      * @param code 状态码
      * @param data 结果数据
+     * @param <T>  结果数据类型
      * @return 结果对象
      */
-    public static <M> Result<M> of(@NonNull String code, M data) {
+    public static <T> Result<T> of(@NonNull String code, T data) {
         return of(code, data, null);
     }
 
@@ -137,10 +147,11 @@ public class Result<T> implements Serializable {
      * @param code    状态码
      * @param data    结果数据
      * @param message 结果信息
+     * @param <T>     结果数据类型
      * @return 结果对象
      */
-    public static <M> Result<M> of(@NonNull String code, M data, String message) {
-        Result<M> result = new Result<>();
+    public static <T> Result<T> of(@NonNull String code, T data, String message) {
+        Result<T> result = new Result<>();
         result.code = code;
         result.data = data;
         result.message = message;
@@ -148,22 +159,17 @@ public class Result<T> implements Serializable {
     }
 
     /**
-     * 是否成功
-     *
-     * @return true/false
-     */
-    @JsonIgnore
-    public boolean isSuccess() {
-        return Objects.equals(this.code, OK);
-    }
-
-    /**
-     * 是否失败
+     * 获取Http状态码
      *
-     * @return true/false
+     * @return Http状态码
      */
     @JsonIgnore
-    public boolean isFailure() {
-        return Objects.equals(this.code, ERROR);
+    public HttpStatus status() {
+        if (Objects.equals(this.code, OK) || Objects.equals(this.code, TerminatedException.CODE)) {
+            return HttpStatus.OK;
+        } else if (Objects.equals(this.code, ERROR)) {
+            return HttpStatus.INTERNAL_SERVER_ERROR;
+        }
+        return HttpStatus.BAD_REQUEST;
     }
 }

+ 1 - 80
framework-base/src/main/java/com/chelvc/framework/base/context/SessionContextHolder.java

@@ -21,7 +21,6 @@ import com.fasterxml.jackson.core.JsonEncoding;
 import lombok.NonNull;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -395,84 +394,6 @@ public class SessionContextHolder implements ServletRequestListener {
         return StringUtils.ifEmpty(ObjectUtils.ifNull(getRequest(), request -> request.getParameter(name)), adapter);
     }
 
-    /**
-     * 将Http状态码转换成请求结果
-     *
-     * @param status Http状态码
-     * @param <T>    结果数据类型
-     * @return 请求结果对象实例
-     */
-    public static <T> Result<T> result(@NonNull HttpStatus status) {
-        if (status.is5xxServerError()) {
-            return Result.failure(ApplicationContextHolder.getMessage("Failure"));
-        } else if (status.isError()) {
-            return Result.of(status.name(), null, status.getReasonPhrase());
-        }
-        return Result.success(null, ApplicationContextHolder.getMessage("Success"));
-    }
-
-    /**
-     * 将Http状态码转换成请求结果
-     *
-     * @param status  Http状态码
-     * @param message 结果消息
-     * @param <T>     结果数据类型
-     * @return 请求结果对象实例
-     */
-    public static <T> Result<T> result(@NonNull HttpStatus status, String message) {
-        return Result.of(status.name(), null, message);
-    }
-
-    /**
-     * 将响应结果转换成Http状态码
-     *
-     * @param result 结果对象实例
-     * @return Http状态码
-     */
-    public static HttpStatus result2status(Result<?> result) {
-        if (result == null || result.isSuccess()) {
-            return HttpStatus.OK;
-        }
-        return result.isFailure() ? HttpStatus.INTERNAL_SERVER_ERROR : HttpStatus.BAD_REQUEST;
-    }
-
-    /**
-     * 相应请求结果
-     *
-     * @param response Http响应对象
-     * @param status   Http状态码
-     * @throws IOException I/O异常
-     */
-    public static void response(@NonNull HttpServletResponse response, @NonNull HttpStatus status) throws IOException {
-        response(response, result(status));
-    }
-
-    /**
-     * 相应请求结果
-     *
-     * @param response Http响应对象
-     * @param status   Http状态码
-     * @param message  结果消息
-     * @throws IOException I/O异常
-     */
-    public static void response(@NonNull HttpServletResponse response, @NonNull HttpStatus status, String message)
-            throws IOException {
-        response(response, result(status, message));
-    }
-
-    /**
-     * 相应请求结果
-     *
-     * @param response Http响应对象
-     * @param code     结果码
-     * @param message  结果消息
-     * @throws IOException I/O异常
-     */
-    public static void response(@NonNull HttpServletResponse response, @NonNull String code, String message)
-            throws IOException {
-        response(response, Result.of(code, null, message));
-    }
-
     /**
      * 相应请求结果
      *
@@ -481,7 +402,7 @@ public class SessionContextHolder implements ServletRequestListener {
      * @throws IOException I/O异常
      */
     public static void response(@NonNull HttpServletResponse response, @NonNull Result<?> result) throws IOException {
-        response.setStatus(result2status(result).value());
+        response.setStatus(result.status().value());
         response.setContentType(MediaType.APPLICATION_JSON_VALUE);
         response.setCharacterEncoding(JsonEncoding.UTF8.getJavaName());
         OutputStream output = response.getOutputStream();

+ 8 - 6
framework-base/src/main/java/com/chelvc/framework/base/interceptor/GlobalExceptionInterceptor.java

@@ -92,8 +92,9 @@ public class GlobalExceptionInterceptor extends AbstractErrorController implemen
             chain.doFilter(request, response);
         } catch (Exception e) {
             LoggingContextHolder.warn(log, request, e);
-            SessionContextHolder.response((HttpServletResponse) response, HttpStatus.BAD_REQUEST,
-                    ApplicationContextHolder.getMessage("Request.Invalid"));
+            String message = ApplicationContextHolder.getMessage("Request.Invalid");
+            Result<?> result = Result.of(HttpStatus.BAD_REQUEST.name(), null, message);
+            SessionContextHolder.response((HttpServletResponse) response, result);
         }
     }
 
@@ -256,7 +257,7 @@ public class GlobalExceptionInterceptor extends AbstractErrorController implemen
             result = Result.of(HttpStatus.BAD_REQUEST.name(), null,
                     ApplicationContextHolder.getMessage("Request.Invalid"));
         }
-        response.setStatus(SessionContextHolder.result2status(result).value());
+        response.setStatus(result.status().value());
         return result;
     }
 
@@ -271,12 +272,13 @@ public class GlobalExceptionInterceptor extends AbstractErrorController implemen
     @ExceptionHandler(Exception.class)
     public Result<?> exception(HttpServletRequest request, HttpServletResponse response, Exception e) {
         Result<?> result = this.error2result(ErrorUtils.real(e));
-        if (Result.ERROR.equals(result.getCode()) && !CLIENT_ABORT_EXCEPTION.equals(e.getClass().getName())) {
+        HttpStatus status = result.status();
+        if (status.is5xxServerError() && !CLIENT_ABORT_EXCEPTION.equals(e.getClass().getName())) {
             LoggingContextHolder.error(log, request, e);
-        } else {
+        } else if (status.isError()) {
             LoggingContextHolder.warn(log, request, e);
         }
-        response.setStatus(SessionContextHolder.result2status(result).value());
+        response.setStatus(status.value());
         return result;
     }
 }

+ 22 - 0
framework-common/src/main/java/com/chelvc/framework/common/exception/TerminatedException.java

@@ -0,0 +1,22 @@
+package com.chelvc.framework.common.exception;
+
+/**
+ * 操作终止异常
+ *
+ * @author Woody
+ * @date 2024/6/30
+ */
+public class TerminatedException extends FrameworkException {
+    /**
+     * 异常编码
+     */
+    public static final String CODE = "TERMINATED";
+
+    public TerminatedException(Object data) {
+        this(data, null);
+    }
+
+    public TerminatedException(Object data, String message) {
+        super(CODE, data, message);
+    }
+}

+ 0 - 47
framework-database/src/main/java/com/chelvc/framework/database/context/DatabaseContextHolder.java

@@ -37,7 +37,6 @@ import com.chelvc.framework.common.model.Paging;
 import com.chelvc.framework.common.util.AssertUtils;
 import com.chelvc.framework.common.util.ObjectUtils;
 import com.chelvc.framework.database.entity.Entity;
-import com.chelvc.framework.database.support.EventService;
 import com.google.common.collect.Maps;
 import lombok.NonNull;
 import org.apache.ibatis.reflection.property.PropertyNamer;
@@ -623,50 +622,4 @@ public final class DatabaseContextHolder {
         }
         return Pagination.<T>builder().total(page.getTotal()).pages(page.getPages()).records(records).build();
     }
-
-    /**
-     * 发布数据新增事件
-     *
-     * @param entity 新增对象实例
-     * @param <T>    数据类型
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> void publishAddition(@NonNull T entity) {
-        Class<T> type = (Class<T>) entity.getClass();
-        IService<T> service = lookupEntityService(type);
-        if (service instanceof EventService) {
-            ((EventService<T>) service).publishAddition(entity);
-        }
-    }
-
-    /**
-     * 发布数据删除事件
-     *
-     * @param entity 删除对象实例
-     * @param <T>    数据类型
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> void publishDeletion(@NonNull T entity) {
-        Class<T> type = (Class<T>) entity.getClass();
-        IService<T> service = lookupEntityService(type);
-        if (service instanceof EventService) {
-            ((EventService<T>) service).publishDeletion(entity);
-        }
-    }
-
-    /**
-     * 发布数据更新事件
-     *
-     * @param before 更新前对象实例
-     * @param after  更新后对象实例
-     * @param <T>    数据类型
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> void publishModification(@NonNull T before, @NonNull T after) {
-        Class<T> type = (Class<T>) before.getClass();
-        IService<T> service = lookupEntityService(type);
-        if (service instanceof EventService) {
-            ((EventService<T>) service).publishModification(before, after);
-        }
-    }
 }

+ 35 - 0
framework-database/src/main/java/com/chelvc/framework/database/context/EntityAddedEvent.java

@@ -0,0 +1,35 @@
+package com.chelvc.framework.database.context;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import com.chelvc.framework.database.entity.Entity;
+import lombok.NonNull;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * 实体增加事件
+ *
+ * @author Woody
+ * @date 2024/6/30
+ */
+public class EntityAddedEvent extends ApplicationEvent {
+    public EntityAddedEvent(@NonNull Entity<?>... entities) {
+        this(Arrays.asList(entities));
+    }
+
+    public EntityAddedEvent(@NonNull List<Entity<?>> entities) {
+        super(Collections.unmodifiableList(entities));
+    }
+
+    /**
+     * 获取已增加实体
+     *
+     * @return 实体对象实例列表
+     */
+    @SuppressWarnings("unchecked")
+    public List<Entity<?>> getEntities() {
+        return (List<Entity<?>>) this.source;
+    }
+}

+ 35 - 0
framework-database/src/main/java/com/chelvc/framework/database/context/EntityDeletedEvent.java

@@ -0,0 +1,35 @@
+package com.chelvc.framework.database.context;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import com.chelvc.framework.database.entity.Entity;
+import lombok.NonNull;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * 实体删除事件
+ *
+ * @author Woody
+ * @date 2024/6/30
+ */
+public class EntityDeletedEvent extends ApplicationEvent {
+    public EntityDeletedEvent(@NonNull Entity<?>... entities) {
+        this(Arrays.asList(entities));
+    }
+
+    public EntityDeletedEvent(@NonNull List<Entity<?>> entities) {
+        super(Collections.unmodifiableList(entities));
+    }
+
+    /**
+     * 获取已删除实体
+     *
+     * @return 实体对象实例列表
+     */
+    @SuppressWarnings("unchecked")
+    public List<Entity<?>> getEntities() {
+        return (List<Entity<?>>) this.source;
+    }
+}

+ 39 - 0
framework-database/src/main/java/com/chelvc/framework/database/context/EntityUpdatedEvent.java

@@ -0,0 +1,39 @@
+package com.chelvc.framework.database.context;
+
+import java.util.Collections;
+import java.util.List;
+
+import com.chelvc.framework.database.entity.Entity;
+import lombok.NonNull;
+import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * 实体修改事件
+ *
+ * @author Woody
+ * @date 2024/6/30
+ */
+public class EntityUpdatedEvent extends ApplicationEvent {
+    public EntityUpdatedEvent(@NonNull Entity<?> entity) {
+        this(entity, entity);
+    }
+
+    public EntityUpdatedEvent(@NonNull Entity<?> before, @NonNull Entity<?> after) {
+        this(Collections.singletonList(Pair.of(before, after)));
+    }
+
+    public EntityUpdatedEvent(@NonNull List<Pair<Entity<?>, Entity<?>>> entities) {
+        super(Collections.unmodifiableList(entities));
+    }
+
+    /**
+     * 获取已修改实体
+     *
+     * @return 实体对象实例列表
+     */
+    @SuppressWarnings("unchecked")
+    public List<Pair<Entity<?>, Entity<?>>> getEntities() {
+        return (List<Pair<Entity<?>, Entity<?>>>) this.source;
+    }
+}

+ 0 - 18
framework-database/src/main/java/com/chelvc/framework/database/listener/AddListener.java

@@ -1,18 +0,0 @@
-package com.chelvc.framework.database.listener;
-
-/**
- * 数据新增操作监听器接口
- *
- * @param <T> 数据类型
- * @author Woody
- * @date 2024/4/30
- */
-public interface AddListener<T> extends OperateListener<T> {
-    /**
-     * 监听数据新增
-     *
-     * @param entity 对象实例
-     */
-    default void add(T entity) {
-    }
-}

+ 0 - 18
framework-database/src/main/java/com/chelvc/framework/database/listener/DeleteListener.java

@@ -1,18 +0,0 @@
-package com.chelvc.framework.database.listener;
-
-/**
- * 数据删除操作监听器接口
- *
- * @param <T> 数据类型
- * @author Woody
- * @date 2024/4/30
- */
-public interface DeleteListener<T> extends OperateListener<T> {
-    /**
-     * 监听数据删除
-     *
-     * @param entity 对象实例
-     */
-    default void delete(T entity) {
-    }
-}

+ 0 - 19
framework-database/src/main/java/com/chelvc/framework/database/listener/ModifyListener.java

@@ -1,19 +0,0 @@
-package com.chelvc.framework.database.listener;
-
-/**
- * 数据更新操作监听器接口
- *
- * @param <T> 数据类型
- * @author Woody
- * @date 2024/4/30
- */
-public interface ModifyListener<T> extends OperateListener<T> {
-    /**
-     * 监听数据更新
-     *
-     * @param before 更新前对象实例
-     * @param after  更新后对象实例
-     */
-    default void modify(T before, T after) {
-    }
-}

+ 0 - 11
framework-database/src/main/java/com/chelvc/framework/database/listener/OperateListener.java

@@ -1,11 +0,0 @@
-package com.chelvc.framework.database.listener;
-
-/**
- * 数据操作事件监听器接口
- *
- * @param <T> 数据类型
- * @author Woody
- * @date 2024/4/29
- */
-public interface OperateListener<T> {
-}

+ 1 - 65
framework-database/src/main/java/com/chelvc/framework/database/support/DefaultEnhanceService.java

@@ -1,22 +1,9 @@
 package com.chelvc.framework.database.support;
 
-import java.lang.reflect.Type;
-import java.util.List;
-
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
 import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.chelvc.framework.common.util.ObjectUtils;
-import com.chelvc.framework.database.listener.AddListener;
-import com.chelvc.framework.database.listener.DeleteListener;
-import com.chelvc.framework.database.listener.ModifyListener;
-import com.chelvc.framework.database.listener.OperateListener;
-import com.google.common.collect.Lists;
-import lombok.NonNull;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
 
 /**
  * 业务增强操作默认实现
@@ -26,30 +13,7 @@ import org.springframework.context.ApplicationContextAware;
  * @author Woody
  * @date 2024/4/29
  */
-public class DefaultEnhanceService<M extends BaseMapper<T>, T> extends ServiceImpl<M, T>
-        implements EnhanceService<T>, ApplicationContextAware {
-    private final List<AddListener<T>> addListeners = Lists.newLinkedList();
-    private final List<DeleteListener<T>> deleteListeners = Lists.newLinkedList();
-    private final List<ModifyListener<T>> modifyListeners = Lists.newLinkedList();
-
-    /**
-     * 判断是否是当前数据模型监听器
-     *
-     * @param type     操作类型
-     * @param listener 监听器实例
-     * @return true/false
-     */
-    private boolean isEntityListener(Class<?> type, OperateListener<?> listener) {
-        Type parameterized = ObjectUtils.lookupSuperclassParameterized(listener.getClass(), type);
-        return ObjectUtils.type2class(parameterized) == this.getEntityClass();
-    }
-
-    @Override
-    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
-        // 注册事件监听器
-        applicationContext.getBeansOfType(OperateListener.class).values().forEach(this::register);
-    }
-
+public class DefaultEnhanceService<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements EnhanceService<T> {
     @Override
     public QueryChainWrapper<T> query() {
         QueryChainWrapper<T> query = super.query();
@@ -63,32 +27,4 @@ public class DefaultEnhanceService<M extends BaseMapper<T>, T> extends ServiceIm
         query.setEntityClass(this.getEntityClass());
         return query;
     }
-
-    @Override
-    public synchronized void register(@NonNull OperateListener<T> listener) {
-        if (listener instanceof AddListener && this.isEntityListener(AddListener.class, listener)) {
-            this.addListeners.add((AddListener<T>) listener);
-        }
-        if (listener instanceof DeleteListener && this.isEntityListener(DeleteListener.class, listener)) {
-            this.deleteListeners.add((DeleteListener<T>) listener);
-        }
-        if (listener instanceof ModifyListener && this.isEntityListener(ModifyListener.class, listener)) {
-            this.modifyListeners.add((ModifyListener<T>) listener);
-        }
-    }
-
-    @Override
-    public void publishAddition(@NonNull T entity) {
-        this.addListeners.forEach(listener -> listener.add(entity));
-    }
-
-    @Override
-    public void publishDeletion(@NonNull T entity) {
-        this.deleteListeners.forEach(listener -> listener.delete(entity));
-    }
-
-    @Override
-    public void publishModification(@NonNull T before, @NonNull T after) {
-        this.modifyListeners.forEach(listener -> listener.modify(before, after));
-    }
 }

+ 1 - 1
framework-database/src/main/java/com/chelvc/framework/database/support/EnhanceService.java

@@ -18,7 +18,7 @@ import lombok.NonNull;
  * @author Woody
  * @date 2024/4/3
  */
-public interface EnhanceService<T> extends IService<T>, EventService<T> {
+public interface EnhanceService<T> extends IService<T> {
     /**
      * 获取增强Mapper
      *

+ 0 - 44
framework-database/src/main/java/com/chelvc/framework/database/support/EventService.java

@@ -1,44 +0,0 @@
-package com.chelvc.framework.database.support;
-
-import com.chelvc.framework.database.listener.OperateListener;
-
-/**
- * 数据操作事件业务接口
- *
- * @author Woody
- * @date 2024/4/30
- */
-public interface EventService<T> {
-    /**
-     * 注册操作事件监听器
-     *
-     * @param listener 监听器实例
-     */
-    default void register(OperateListener<T> listener) {
-    }
-
-    /**
-     * 发布数据新增事件
-     *
-     * @param entity 新增对象实例
-     */
-    default void publishAddition(T entity) {
-    }
-
-    /**
-     * 发布数据删除事件
-     *
-     * @param entity 删除对象实例
-     */
-    default void publishDeletion(T entity) {
-    }
-
-    /**
-     * 发布数据更新事件
-     *
-     * @param before 更新前对象实例
-     * @param after  更新后对象实例
-     */
-    default void publishModification(T before, T after) {
-    }
-}

+ 8 - 8
framework-oauth/src/main/java/com/chelvc/framework/oauth/config/OAuthConfigurer.java

@@ -12,6 +12,7 @@ import javax.crypto.spec.SecretKeySpec;
 import com.chelvc.framework.base.config.MultiserverMvcConfigurer;
 import com.chelvc.framework.base.context.ApplicationContextHolder;
 import com.chelvc.framework.base.context.LoggingContextHolder;
+import com.chelvc.framework.base.context.Result;
 import com.chelvc.framework.base.context.SessionContextHolder;
 import com.chelvc.framework.base.util.HttpUtils;
 import com.chelvc.framework.base.util.SpringUtils;
@@ -98,9 +99,8 @@ public class OAuthConfigurer extends WebSecurityConfigurerAdapter {
     public AccessDeniedHandler accessDeniedHandler() {
         return (request, response, e) -> {
             LoggingContextHolder.warn(log, request, e);
-            SessionContextHolder.response(
-                    response, HttpStatus.FORBIDDEN, ApplicationContextHolder.getMessage("Forbidden")
-            );
+            String message = ApplicationContextHolder.getMessage("Forbidden");
+            SessionContextHolder.response(response, Result.of(HttpStatus.FORBIDDEN.name(), null, message));
         };
     }
 
@@ -109,14 +109,14 @@ public class OAuthConfigurer extends WebSecurityConfigurerAdapter {
         return (request, response, e) -> {
             LoggingContextHolder.warn(log, request, e);
             if (e instanceof InvalidBearerTokenException) {
-                SessionContextHolder.response(response, "TOKEN_INVALID",
-                        ApplicationContextHolder.getMessage("Token.Invalid"));
+                String message = ApplicationContextHolder.getMessage("Token.Invalid");
+                SessionContextHolder.response(response, Result.of("TOKEN_INVALID", null, message));
             } else if (e instanceof OAuth2AuthenticationException) {
                 OAuth2Error error = ((OAuth2AuthenticationException) e).getError();
-                SessionContextHolder.response(response, error.getErrorCode(), error.getDescription());
+                SessionContextHolder.response(response, Result.of(error.getErrorCode(), null, error.getDescription()));
             } else {
-                SessionContextHolder.response(response, HttpStatus.UNAUTHORIZED,
-                        ApplicationContextHolder.getMessage("Unauthorized"));
+                String message = ApplicationContextHolder.getMessage("Unauthorized");
+                SessionContextHolder.response(response, Result.of(HttpStatus.UNAUTHORIZED.name(), null, message));
             }
         };
     }

+ 2 - 2
framework-security/src/main/java/com/chelvc/framework/security/interceptor/SecurityExceptionInterceptor.java

@@ -5,7 +5,6 @@ import javax.servlet.http.HttpServletRequest;
 import com.chelvc.framework.base.context.ApplicationContextHolder;
 import com.chelvc.framework.base.context.LoggingContextHolder;
 import com.chelvc.framework.base.context.Result;
-import com.chelvc.framework.base.context.SessionContextHolder;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.core.Ordered;
 import org.springframework.core.annotation.Order;
@@ -36,6 +35,7 @@ public class SecurityExceptionInterceptor {
     @ExceptionHandler(AccessDeniedException.class)
     public Result<?> exception(HttpServletRequest request, AccessDeniedException e) {
         LoggingContextHolder.warn(log, request, e);
-        return SessionContextHolder.result(HttpStatus.FORBIDDEN, ApplicationContextHolder.getMessage("Forbidden"));
+        String message = ApplicationContextHolder.getMessage("Forbidden");
+        return Result.of(HttpStatus.FORBIDDEN.name(), null, message);
     }
 }