ruoyi-admin/src/main/java/org/dromara/web/listener/UserActionListener.java
@@ -71,6 +71,7 @@ logininforEvent.setUsername(username); logininforEvent.setStatus(Constants.LOGIN_SUCCESS); logininforEvent.setMessage(MessageUtils.message("user.login.success")); logininforEvent.setRequest(ServletUtils.getRequest()); SpringUtils.context().publishEvent(logininforEvent); // æ´æ°ç»å½ä¿¡æ¯ loginService.recordLoginInfo((Long) loginModel.getExtra(LoginHelper.USER_KEY), ip); ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java
@@ -19,10 +19,7 @@ import org.dromara.common.core.enums.TenantStatus; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.exception.user.UserException; import org.dromara.common.core.utils.DateUtils; import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.*; import org.dromara.common.log.event.LogininforEvent; import org.dromara.common.mybatis.helper.DataPermissionHelper; import org.dromara.common.redis.utils.RedisUtils; @@ -142,6 +139,7 @@ logininforEvent.setUsername(username); logininforEvent.setStatus(status); logininforEvent.setMessage(message); logininforEvent.setRequest(ServletUtils.getRequest()); SpringUtils.context().publishEvent(logininforEvent); } ruoyi-admin/src/main/java/org/dromara/web/service/SysRegisterService.java
@@ -11,6 +11,7 @@ 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; @@ -107,6 +108,7 @@ logininforEvent.setUsername(username); logininforEvent.setStatus(status); logininforEvent.setMessage(message); logininforEvent.setRequest(ServletUtils.getRequest()); SpringUtils.context().publishEvent(logininforEvent); } ruoyi-common/ruoyi-common-core/pom.xml
@@ -99,13 +99,6 @@ <artifactId>transmittable-thread-local</artifactId> </dependency> <dependency> <groupId>jakarta.faces</groupId> <artifactId>jakarta.faces-api</artifactId> <version>4.1.0</version> <optional>true</optional> </dependency> </dependencies> </project> ruoyi-common/ruoyi-common-core/src/main/java/org/springframework/web/context/request/RequestContextHolder.java
ÎļþÒÑɾ³ý ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/aspect/LogAspect.java
@@ -13,6 +13,7 @@ import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.StringUtils; @@ -20,6 +21,7 @@ import org.dromara.common.log.annotation.Log; import org.dromara.common.log.enums.BusinessStatus; import org.dromara.common.log.event.OperLogEvent; import org.dromara.common.satoken.utils.LoginHelper; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.http.HttpMethod; import org.springframework.validation.BindingResult; @@ -86,6 +88,16 @@ // *========æ°æ®åºæ¥å¿=========*// OperLogEvent operLog = new OperLogEvent(); operLog.setTenantId(LoginHelper.getTenantId()); operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); // 请æ±çå°å String ip = ServletUtils.getClientIP(); operLog.setOperIp(ip); operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)); LoginUser loginUser = LoginHelper.getLoginUser(); operLog.setOperName(loginUser.getUsername()); operLog.setDeptName(loginUser.getDeptName()); if (e != null) { operLog.setStatus(BusinessStatus.FAIL.ordinal()); operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); @@ -94,6 +106,8 @@ String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); operLog.setMethod(className + "." + methodName + "()"); // è®¾ç½®è¯·æ±æ¹å¼ operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); // å¤ç设置注解ä¸çåæ° getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); // 设置æ¶èæ¶é´ ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/event/LogininforEvent.java
@@ -2,6 +2,8 @@ import lombok.Data; import jakarta.servlet.http.HttpServletRequest; import java.io.Serial; import java.io.Serializable; @@ -38,6 +40,11 @@ private String message; /** * 请æ±ä½ */ private HttpServletRequest request; /** * å ¶ä»åæ° */ private Object[] args; ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java
@@ -55,7 +55,7 @@ @Async @EventListener public void recordLogininfor(LogininforEvent logininforEvent) { HttpServletRequest request = ServletUtils.getRequest(); HttpServletRequest request = logininforEvent.getRequest(); final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent")); final String ip = ServletUtils.getClientIP(request); // 客æ·ç«¯ä¿¡æ¯ ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOperLogServiceImpl.java
@@ -3,23 +3,18 @@ import cn.hutool.core.util.ArrayUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.dromara.common.core.domain.model.LoginUser; import org.dromara.common.core.utils.MapstructUtils; 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.log.enums.BusinessStatus; import org.dromara.common.log.event.OperLogEvent; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.ip.AddressUtils; import org.dromara.common.log.event.OperLogEvent; import org.dromara.system.domain.SysOperLog; import org.dromara.system.domain.bo.SysOperLogBo; import org.dromara.system.domain.vo.SysOperLogVo; import org.dromara.system.mapper.SysOperLogMapper; import org.dromara.system.service.ISysOperLogService; import lombok.RequiredArgsConstructor; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -49,18 +44,6 @@ @EventListener public void recordOper(OperLogEvent operLogEvent) { SysOperLogBo operLog = MapstructUtils.convert(operLogEvent, SysOperLogBo.class); operLog.setTenantId(LoginHelper.getTenantId()); operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); // 请æ±çå°å String ip = ServletUtils.getClientIP(); operLog.setOperIp(ip); HttpServletRequest request = ServletUtils.getRequest(); operLog.setOperUrl(StringUtils.substring(request.getRequestURI(), 0, 255)); LoginUser loginUser = LoginHelper.getLoginUser(); operLog.setOperName(loginUser.getUsername()); operLog.setDeptName(loginUser.getDeptName()); // è®¾ç½®è¯·æ±æ¹å¼ operLog.setRequestMethod(request.getMethod()); // è¿ç¨æ¥è¯¢æä½å°ç¹ operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp())); insertOperlog(operLog);