From f423ecd8c8cb77ada01782eb89308d60a946d690 Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Thu, 3 Sep 2026 17:24:03 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=20=E6=8E=92=E9=99=A4=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supervision/aop/SystemLogAspect.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/biutag/supervision/aop/SystemLogAspect.java b/src/main/java/com/biutag/supervision/aop/SystemLogAspect.java index 8c83455..4bcdc8b 100644 --- a/src/main/java/com/biutag/supervision/aop/SystemLogAspect.java +++ b/src/main/java/com/biutag/supervision/aop/SystemLogAspect.java @@ -41,9 +41,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; /** - * 统一记录进入 Controller 调用链的接口访问日志。 + * 统一记录进入 Controller 调用链的非 GET 请求及白名单 GET 请求日志。 *

* 日志切面优先级高于现有参数检查切面,因此参数检查抛出的业务异常也可以被记录; * 在 Spring MVC 调用 Controller 之前就被鉴权拦截的请求不会进入本切面。 @@ -62,6 +63,19 @@ public class SystemLogAspect { private static final String MASK_VALUE = "******"; private static final String TRUNCATED_MARK = "...[内容已截断]"; + /** 存在业务数据写入的 GET 接口,后续新增同类接口时需同步维护。 */ + private static final Set LOGGED_GET_REQUEST_URIS = Set.of( + "/common/updateBaseData", + "/common/rights", + "/rights/supervise", + "/common/mailbox", + "/policeUpdateAvatar", + "/depart/updatePoliceSize", + "/score/police", + "/score/depart", + "/score/personal" + ); + private final SystemLogService systemLogService; private final ObjectMapper objectMapper; private final RedisTemplate redisTemplate; @@ -74,12 +88,16 @@ public class SystemLogAspect { } /** - * 包裹 Controller 调用并在 finally 中保存日志,确保业务异常场景也能记录。 + * 需要记录的请求在 finally 中保存日志,确保业务异常场景也能记录。 */ @Around("controllerPointcut()") public Object recordSystemLog(ProceedingJoinPoint joinPoint) throws Throwable { ServletRequestAttributes attributes = getRequestAttributes(); HttpServletRequest request = attributes == null ? null : attributes.getRequest(); + if (!shouldRecordLog(request)) { + return joinPoint.proceed(); + } + HttpServletResponse response = attributes == null ? null : attributes.getResponse(); LocalDateTime logTime = LocalDateTime.now(); long startTime = System.nanoTime(); @@ -102,6 +120,17 @@ public class SystemLogAspect { } } + private boolean shouldRecordLog(HttpServletRequest request) { + if (request == null || !"GET".equalsIgnoreCase(request.getMethod())) { + return true; + } + String requestPath = request.getServletPath(); + if (requestPath.endsWith("/")) { + requestPath = requestPath.substring(0, requestPath.length() - 1); + } + return LOGGED_GET_REQUEST_URIS.contains(requestPath); + } + private ServletRequestAttributes getRequestAttributes() { if (RequestContextHolder.getRequestAttributes() instanceof ServletRequestAttributes attributes) { return attributes;