|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package org.dromara.common.log.event;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.http.useragent.UserAgent;
|
|
|
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
@ -10,9 +11,12 @@ import org.dromara.common.core.constant.Constants;
|
|
|
|
|
import org.dromara.common.core.utils.ServletUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.core.utils.ip.AddressUtils;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
import org.dromara.system.api.RemoteClientService;
|
|
|
|
|
import org.dromara.system.api.RemoteLogService;
|
|
|
|
|
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;
|
|
|
|
@ -28,6 +32,8 @@ public class LogEventListener {
|
|
|
|
|
|
|
|
|
|
@DubboReference
|
|
|
|
|
private RemoteLogService remoteLogService;
|
|
|
|
|
@DubboReference
|
|
|
|
|
private RemoteClientService remoteClientService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存系统日志记录
|
|
|
|
@ -45,6 +51,12 @@ public class LogEventListener {
|
|
|
|
|
HttpServletRequest request = logininforEvent.getRequest();
|
|
|
|
|
final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
|
|
|
|
final String ip = ServletUtils.getClientIP(request);
|
|
|
|
|
// 客户端信息
|
|
|
|
|
String clientid = request.getHeader(LoginHelper.CLIENT_KEY);
|
|
|
|
|
RemoteClientVo clientVo = null;
|
|
|
|
|
if (StringUtils.isNotBlank(clientid)) {
|
|
|
|
|
clientVo = remoteClientService.queryByClientId(clientid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String address = AddressUtils.getRealAddressByIP(ip);
|
|
|
|
|
StringBuilder s = new StringBuilder();
|
|
|
|
@ -63,6 +75,10 @@ public class LogEventListener {
|
|
|
|
|
RemoteLogininforBo logininfor = new RemoteLogininforBo();
|
|
|
|
|
logininfor.setTenantId(logininforEvent.getTenantId());
|
|
|
|
|
logininfor.setUserName(logininforEvent.getUsername());
|
|
|
|
|
if (ObjectUtil.isNotNull(clientVo)) {
|
|
|
|
|
logininfor.setClientKey(clientVo.getClientKey());
|
|
|
|
|
logininfor.setDeviceType(clientVo.getDeviceType());
|
|
|
|
|
}
|
|
|
|
|
logininfor.setIpaddr(ip);
|
|
|
|
|
logininfor.setLoginLocation(address);
|
|
|
|
|
logininfor.setBrowser(browser);
|
|
|
|
|