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:
@@ -1,7 +1,14 @@
|
||||
package org.dromara.common.log.event;
|
||||
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.utils.BeanCopyUtils;
|
||||
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.system.api.RemoteLogService;
|
||||
import org.dromara.system.api.domain.bo.RemoteLogininforBo;
|
||||
import org.dromara.system.api.domain.bo.RemoteOperLogBo;
|
||||
@@ -9,12 +16,15 @@ import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 异步调用日志服务
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LogEventListener {
|
||||
|
||||
@DubboReference
|
||||
@@ -33,8 +43,46 @@ public class LogEventListener {
|
||||
@Async
|
||||
@EventListener
|
||||
public void saveLogininfor(LogininforEvent logininforEvent) {
|
||||
RemoteLogininforBo sysLogininfor = BeanCopyUtils.copy(logininforEvent, RemoteLogininforBo.class);
|
||||
remoteLogService.saveLogininfor(sysLogininfor);
|
||||
HttpServletRequest request = logininforEvent.getRequest();
|
||||
final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||
final String ip = ServletUtils.getClientIP(request);
|
||||
|
||||
String address = AddressUtils.getRealAddressByIP(ip);
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(getBlock(ip));
|
||||
s.append(address);
|
||||
s.append(getBlock(logininforEvent.getUsername()));
|
||||
s.append(getBlock(logininforEvent.getStatus()));
|
||||
s.append(getBlock(logininforEvent.getMessage()));
|
||||
// 打印信息到日志
|
||||
log.info(s.toString(), logininforEvent.getArgs());
|
||||
// 获取客户端操作系统
|
||||
String os = userAgent.getOs().getName();
|
||||
// 获取客户端浏览器
|
||||
String browser = userAgent.getBrowser().getName();
|
||||
// 封装对象
|
||||
RemoteLogininforBo logininfor = new RemoteLogininforBo();
|
||||
logininfor.setTenantId(logininforEvent.getTenantId());
|
||||
logininfor.setUserName(logininforEvent.getUsername());
|
||||
logininfor.setIpaddr(ip);
|
||||
logininfor.setLoginLocation(address);
|
||||
logininfor.setBrowser(browser);
|
||||
logininfor.setOs(os);
|
||||
logininfor.setMsg(logininforEvent.getMessage());
|
||||
// 日志状态
|
||||
if (StringUtils.equalsAny(logininforEvent.getStatus(), Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER)) {
|
||||
logininfor.setStatus(Constants.SUCCESS);
|
||||
} else if (Constants.LOGIN_FAIL.equals(logininforEvent.getStatus())) {
|
||||
logininfor.setStatus(Constants.FAIL);
|
||||
}
|
||||
remoteLogService.saveLogininfor(logininfor);
|
||||
}
|
||||
|
||||
private String getBlock(Object msg) {
|
||||
if (msg == null) {
|
||||
msg = "";
|
||||
}
|
||||
return "[" + msg + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user