|
@@ -5,18 +5,17 @@ import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.ruoyi.common.core.utils.JsonUtils;
|
|
import com.ruoyi.common.core.utils.JsonUtils;
|
|
|
import com.ruoyi.common.core.utils.ServletUtils;
|
|
import com.ruoyi.common.core.utils.ServletUtils;
|
|
|
|
|
+import com.ruoyi.common.core.utils.SpringUtils;
|
|
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
|
import com.ruoyi.common.log.annotation.Log;
|
|
import com.ruoyi.common.log.annotation.Log;
|
|
|
import com.ruoyi.common.log.enums.BusinessStatus;
|
|
import com.ruoyi.common.log.enums.BusinessStatus;
|
|
|
-import com.ruoyi.common.log.service.AsyncLogService;
|
|
|
|
|
|
|
+import com.ruoyi.common.log.event.OperLogEvent;
|
|
|
import com.ruoyi.common.satoken.utils.LoginHelper;
|
|
import com.ruoyi.common.satoken.utils.LoginHelper;
|
|
|
-import com.ruoyi.system.api.domain.SysOperLog;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.annotation.AfterReturning;
|
|
import org.aspectj.lang.annotation.AfterReturning;
|
|
|
import org.aspectj.lang.annotation.AfterThrowing;
|
|
import org.aspectj.lang.annotation.AfterThrowing;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
|
import org.springframework.http.HttpMethod;
|
|
import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.validation.BindingResult;
|
|
@@ -42,9 +41,6 @@ public class LogAspect {
|
|
|
*/
|
|
*/
|
|
|
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
|
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private AsyncLogService asyncLogService;
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 处理完请求后执行
|
|
* 处理完请求后执行
|
|
|
*
|
|
*
|
|
@@ -69,7 +65,7 @@ public class LogAspect {
|
|
|
protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) {
|
|
protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) {
|
|
|
try {
|
|
try {
|
|
|
// *========数据库日志=========*//
|
|
// *========数据库日志=========*//
|
|
|
- SysOperLog operLog = new SysOperLog();
|
|
|
|
|
|
|
+ OperLogEvent operLog = new OperLogEvent();
|
|
|
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
|
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
|
|
// 请求的地址
|
|
// 请求的地址
|
|
|
operLog.setOperIp(ServletUtils.getClientIP());
|
|
operLog.setOperIp(ServletUtils.getClientIP());
|
|
@@ -91,8 +87,8 @@ public class LogAspect {
|
|
|
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
|
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
|
|
// 处理设置注解上的参数
|
|
// 处理设置注解上的参数
|
|
|
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
|
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
|
|
- // 保存数据库
|
|
|
|
|
- asyncLogService.saveSysLog(operLog);
|
|
|
|
|
|
|
+ // 发布事件保存数据库
|
|
|
|
|
+ SpringUtils.context().publishEvent(operLog);
|
|
|
} catch (Exception exp) {
|
|
} catch (Exception exp) {
|
|
|
// 记录本地异常日志
|
|
// 记录本地异常日志
|
|
|
log.error("异常信息:{}", exp.getMessage());
|
|
log.error("异常信息:{}", exp.getMessage());
|
|
@@ -107,7 +103,7 @@ public class LogAspect {
|
|
|
* @param operLog 操作日志
|
|
* @param operLog 操作日志
|
|
|
* @throws Exception
|
|
* @throws Exception
|
|
|
*/
|
|
*/
|
|
|
- public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception {
|
|
|
|
|
|
|
+ public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLogEvent operLog, Object jsonResult) throws Exception {
|
|
|
// 设置action动作
|
|
// 设置action动作
|
|
|
operLog.setBusinessType(log.businessType().ordinal());
|
|
operLog.setBusinessType(log.businessType().ordinal());
|
|
|
// 设置标题
|
|
// 设置标题
|
|
@@ -131,7 +127,7 @@ public class LogAspect {
|
|
|
* @param operLog 操作日志
|
|
* @param operLog 操作日志
|
|
|
* @throws Exception 异常
|
|
* @throws Exception 异常
|
|
|
*/
|
|
*/
|
|
|
- private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception {
|
|
|
|
|
|
|
+ private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog) throws Exception {
|
|
|
String requestMethod = operLog.getRequestMethod();
|
|
String requestMethod = operLog.getRequestMethod();
|
|
|
if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
|
|
if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
|
|
|
String params = argsArrayToString(joinPoint.getArgs());
|
|
String params = argsArrayToString(joinPoint.getArgs());
|