From 03d50188a6cce9b5f1aebb9e20d6b24a36ca7c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Sun, 4 Feb 2024 13:01:33 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=20=E5=BC=82=E6=AD=A5=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/dromara/auth/listener/UserActionListener.java | 1 - .../java/org/dromara/auth/service/SysLoginService.java | 2 -- .../org/dromara/common/log/event/LogEventListener.java | 7 ++----- .../java/org/dromara/common/log/event/LogininforEvent.java | 7 ------- .../org/dromara/system/dubbo/RemoteLogServiceImpl.java | 3 +++ 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/listener/UserActionListener.java b/ruoyi-auth/src/main/java/org/dromara/auth/listener/UserActionListener.java index 211b911b..c4a1a0e1 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/listener/UserActionListener.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/listener/UserActionListener.java @@ -74,7 +74,6 @@ public class UserActionListener implements SaTokenListener { logininforEvent.setUsername(username); logininforEvent.setStatus(Constants.LOGIN_SUCCESS); logininforEvent.setMessage(MessageUtils.message("user.login.success")); - logininforEvent.setRequest(ServletUtils.getRequest()); SpringUtils.context().publishEvent(logininforEvent); // 更新登录信息 remoteUserService.recordLoginInfo((Long) loginModel.getExtra(LoginHelper.USER_KEY), ip); diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/SysLoginService.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/SysLoginService.java index daa87ff7..7d614a2e 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/SysLoginService.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/SysLoginService.java @@ -23,7 +23,6 @@ import org.dromara.common.core.exception.user.CaptchaException; import org.dromara.common.core.exception.user.CaptchaExpireException; import org.dromara.common.core.exception.user.UserException; import org.dromara.common.core.utils.MessageUtils; -import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.log.event.LogininforEvent; @@ -186,7 +185,6 @@ public class SysLoginService { logininforEvent.setUsername(username); logininforEvent.setStatus(status); logininforEvent.setMessage(message); - logininforEvent.setRequest(ServletUtils.getRequest()); SpringUtils.context().publishEvent(logininforEvent); } diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogEventListener.java b/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogEventListener.java index 4c3e8e3e..3584e0c6 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogEventListener.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogEventListener.java @@ -18,7 +18,6 @@ import org.dromara.system.api.domain.bo.RemoteLogininforBo; import org.dromara.system.api.domain.bo.RemoteOperLogBo; import org.dromara.system.api.domain.vo.RemoteClientVo; import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; /** @@ -38,7 +37,6 @@ public class LogEventListener { /** * 保存系统日志记录 */ - @Async @EventListener public void saveLog(OperLogEvent operLogEvent) { RemoteOperLogBo sysOperLog = BeanUtil.toBean(operLogEvent, RemoteOperLogBo.class); @@ -48,10 +46,9 @@ public class LogEventListener { /** * 保存系统访问记录 */ - @Async @EventListener public void saveLogininfor(LogininforEvent logininforEvent) { - HttpServletRequest request = logininforEvent.getRequest(); + HttpServletRequest request = ServletUtils.getRequest(); final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent")); final String ip = ServletUtils.getClientIP(request); // 客户端信息 @@ -95,7 +92,7 @@ public class LogEventListener { } remoteLogService.saveLogininfor(logininfor); } - + private String getBlock(Object msg) { if (msg == null) { msg = ""; diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogininforEvent.java b/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogininforEvent.java index 938eaadd..212bf18b 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogininforEvent.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogininforEvent.java @@ -2,8 +2,6 @@ package org.dromara.common.log.event; import lombok.Data; -import jakarta.servlet.http.HttpServletRequest; - import java.io.Serial; import java.io.Serializable; @@ -39,11 +37,6 @@ public class LogininforEvent implements Serializable { */ private String message; - /** - * 请求体 - */ - private HttpServletRequest request; - /** * 其他参数 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteLogServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteLogServiceImpl.java index fd2a69e3..bcb0e058 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteLogServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteLogServiceImpl.java @@ -10,6 +10,7 @@ import org.dromara.system.domain.bo.SysLogininforBo; import org.dromara.system.domain.bo.SysOperLogBo; import org.dromara.system.service.ISysLogininforService; import org.dromara.system.service.ISysOperLogService; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; /** @@ -25,12 +26,14 @@ public class RemoteLogServiceImpl implements RemoteLogService { private final ISysOperLogService operLogService; private final ISysLogininforService logininforService; + @Async @Override public void saveLog(RemoteOperLogBo remoteOperLogBo) { SysOperLogBo sysOperLogBo = MapstructUtils.convert(remoteOperLogBo, SysOperLogBo.class); operLogService.insertOperlog(sysOperLogBo); } + @Async @Override public void saveLogininfor(RemoteLogininforBo remoteLogininforBo) { SysLogininforBo sysLogininforBo = MapstructUtils.convert(remoteLogininforBo, SysLogininforBo.class);