fix 修复 日志记录 异步不生效问题
parent
a8777acc88
commit
03d50188a6
|
|
@ -74,7 +74,6 @@ public class UserActionListener implements SaTokenListener {
|
||||||
logininforEvent.setUsername(username);
|
logininforEvent.setUsername(username);
|
||||||
logininforEvent.setStatus(Constants.LOGIN_SUCCESS);
|
logininforEvent.setStatus(Constants.LOGIN_SUCCESS);
|
||||||
logininforEvent.setMessage(MessageUtils.message("user.login.success"));
|
logininforEvent.setMessage(MessageUtils.message("user.login.success"));
|
||||||
logininforEvent.setRequest(ServletUtils.getRequest());
|
|
||||||
SpringUtils.context().publishEvent(logininforEvent);
|
SpringUtils.context().publishEvent(logininforEvent);
|
||||||
// 更新登录信息
|
// 更新登录信息
|
||||||
remoteUserService.recordLoginInfo((Long) loginModel.getExtra(LoginHelper.USER_KEY), ip);
|
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.CaptchaExpireException;
|
||||||
import org.dromara.common.core.exception.user.UserException;
|
import org.dromara.common.core.exception.user.UserException;
|
||||||
import org.dromara.common.core.utils.MessageUtils;
|
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.SpringUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.log.event.LogininforEvent;
|
import org.dromara.common.log.event.LogininforEvent;
|
||||||
|
|
@ -186,7 +185,6 @@ public class SysLoginService {
|
||||||
logininforEvent.setUsername(username);
|
logininforEvent.setUsername(username);
|
||||||
logininforEvent.setStatus(status);
|
logininforEvent.setStatus(status);
|
||||||
logininforEvent.setMessage(message);
|
logininforEvent.setMessage(message);
|
||||||
logininforEvent.setRequest(ServletUtils.getRequest());
|
|
||||||
SpringUtils.context().publishEvent(logininforEvent);
|
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.bo.RemoteOperLogBo;
|
||||||
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,7 +37,6 @@ public class LogEventListener {
|
||||||
/**
|
/**
|
||||||
* 保存系统日志记录
|
* 保存系统日志记录
|
||||||
*/
|
*/
|
||||||
@Async
|
|
||||||
@EventListener
|
@EventListener
|
||||||
public void saveLog(OperLogEvent operLogEvent) {
|
public void saveLog(OperLogEvent operLogEvent) {
|
||||||
RemoteOperLogBo sysOperLog = BeanUtil.toBean(operLogEvent, RemoteOperLogBo.class);
|
RemoteOperLogBo sysOperLog = BeanUtil.toBean(operLogEvent, RemoteOperLogBo.class);
|
||||||
|
|
@ -48,10 +46,9 @@ public class LogEventListener {
|
||||||
/**
|
/**
|
||||||
* 保存系统访问记录
|
* 保存系统访问记录
|
||||||
*/
|
*/
|
||||||
@Async
|
|
||||||
@EventListener
|
@EventListener
|
||||||
public void saveLogininfor(LogininforEvent logininforEvent) {
|
public void saveLogininfor(LogininforEvent logininforEvent) {
|
||||||
HttpServletRequest request = logininforEvent.getRequest();
|
HttpServletRequest request = ServletUtils.getRequest();
|
||||||
final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||||
final String ip = ServletUtils.getClientIP(request);
|
final String ip = ServletUtils.getClientIP(request);
|
||||||
// 客户端信息
|
// 客户端信息
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ package org.dromara.common.log.event;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
@ -39,11 +37,6 @@ public class LogininforEvent implements Serializable {
|
||||||
*/
|
*/
|
||||||
private String message;
|
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.domain.bo.SysOperLogBo;
|
||||||
import org.dromara.system.service.ISysLogininforService;
|
import org.dromara.system.service.ISysLogininforService;
|
||||||
import org.dromara.system.service.ISysOperLogService;
|
import org.dromara.system.service.ISysOperLogService;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -25,12 +26,14 @@ public class RemoteLogServiceImpl implements RemoteLogService {
|
||||||
private final ISysOperLogService operLogService;
|
private final ISysOperLogService operLogService;
|
||||||
private final ISysLogininforService logininforService;
|
private final ISysLogininforService logininforService;
|
||||||
|
|
||||||
|
@Async
|
||||||
@Override
|
@Override
|
||||||
public void saveLog(RemoteOperLogBo remoteOperLogBo) {
|
public void saveLog(RemoteOperLogBo remoteOperLogBo) {
|
||||||
SysOperLogBo sysOperLogBo = MapstructUtils.convert(remoteOperLogBo, SysOperLogBo.class);
|
SysOperLogBo sysOperLogBo = MapstructUtils.convert(remoteOperLogBo, SysOperLogBo.class);
|
||||||
operLogService.insertOperlog(sysOperLogBo);
|
operLogService.insertOperlog(sysOperLogBo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
@Override
|
@Override
|
||||||
public void saveLogininfor(RemoteLogininforBo remoteLogininforBo) {
|
public void saveLogininfor(RemoteLogininforBo remoteLogininforBo) {
|
||||||
SysLogininforBo sysLogininforBo = MapstructUtils.convert(remoteLogininforBo, SysLogininforBo.class);
|
SysLogininforBo sysLogininforBo = MapstructUtils.convert(remoteLogininforBo, SysLogininforBo.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue