mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-11-28 01:00:05 +08:00
fix 修复 日志记录 异步不生效问题
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = "";
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* 其他参数
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user