|
@@ -15,8 +15,8 @@ import cn.iocoder.yudao.framework.operatelog.core.service.OperateLog;
|
|
import cn.iocoder.yudao.framework.operatelog.core.service.OperateLogFrameworkService;
|
|
import cn.iocoder.yudao.framework.operatelog.core.service.OperateLogFrameworkService;
|
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
-import io.swagger.annotations.Api;
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Around;
|
|
@@ -71,15 +71,15 @@ public class OperateLogAspect {
|
|
@Resource
|
|
@Resource
|
|
private OperateLogFrameworkService operateLogFrameworkService;
|
|
private OperateLogFrameworkService operateLogFrameworkService;
|
|
|
|
|
|
- @Around("@annotation(apiOperation)")
|
|
|
|
- public Object around(ProceedingJoinPoint joinPoint, ApiOperation apiOperation) throws Throwable {
|
|
|
|
|
|
+ @Around("@annotation(operation)")
|
|
|
|
+ public Object around(ProceedingJoinPoint joinPoint, Operation operation) throws Throwable {
|
|
// 可能也添加了 @ApiOperation 注解
|
|
// 可能也添加了 @ApiOperation 注解
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog = getMethodAnnotation(joinPoint,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog = getMethodAnnotation(joinPoint,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog.class);
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog.class);
|
|
- return around0(joinPoint, operateLog, apiOperation);
|
|
|
|
|
|
+ return around0(joinPoint, operateLog, operation);
|
|
}
|
|
}
|
|
|
|
|
|
- @Around("!@annotation(io.swagger.annotations.ApiOperation) && @annotation(operateLog)")
|
|
|
|
|
|
+ @Around("!@annotation(io.swagger.v3.oas.annotations.Operation) && @annotation(operateLog)")
|
|
// 兼容处理,只添加 @OperateLog 注解的情况
|
|
// 兼容处理,只添加 @OperateLog 注解的情况
|
|
public Object around(ProceedingJoinPoint joinPoint,
|
|
public Object around(ProceedingJoinPoint joinPoint,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog) throws Throwable {
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog) throws Throwable {
|
|
@@ -88,7 +88,7 @@ public class OperateLogAspect {
|
|
|
|
|
|
private Object around0(ProceedingJoinPoint joinPoint,
|
|
private Object around0(ProceedingJoinPoint joinPoint,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
|
|
- ApiOperation apiOperation) throws Throwable {
|
|
|
|
|
|
+ Operation operation) throws Throwable {
|
|
// 目前,只有管理员,才记录操作日志!所以非管理员,直接调用,不进行记录
|
|
// 目前,只有管理员,才记录操作日志!所以非管理员,直接调用,不进行记录
|
|
Integer userType = WebFrameworkUtils.getLoginUserType();
|
|
Integer userType = WebFrameworkUtils.getLoginUserType();
|
|
if (!Objects.equals(userType, UserTypeEnum.ADMIN.getValue())) {
|
|
if (!Objects.equals(userType, UserTypeEnum.ADMIN.getValue())) {
|
|
@@ -101,10 +101,10 @@ public class OperateLogAspect {
|
|
// 执行原有方法
|
|
// 执行原有方法
|
|
Object result = joinPoint.proceed();
|
|
Object result = joinPoint.proceed();
|
|
// 记录正常执行时的操作日志
|
|
// 记录正常执行时的操作日志
|
|
- this.log(joinPoint, operateLog, apiOperation, startTime, result, null);
|
|
|
|
|
|
+ this.log(joinPoint, operateLog, operation, startTime, result, null);
|
|
return result;
|
|
return result;
|
|
} catch (Throwable exception) {
|
|
} catch (Throwable exception) {
|
|
- this.log(joinPoint, operateLog, apiOperation, startTime, null, exception);
|
|
|
|
|
|
+ this.log(joinPoint, operateLog, operation, startTime, null, exception);
|
|
throw exception;
|
|
throw exception;
|
|
} finally {
|
|
} finally {
|
|
clearThreadLocal();
|
|
clearThreadLocal();
|
|
@@ -129,7 +129,7 @@ public class OperateLogAspect {
|
|
|
|
|
|
private void log(ProceedingJoinPoint joinPoint,
|
|
private void log(ProceedingJoinPoint joinPoint,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
|
|
- ApiOperation apiOperation,
|
|
|
|
|
|
+ Operation operation,
|
|
LocalDateTime startTime, Object result, Throwable exception) {
|
|
LocalDateTime startTime, Object result, Throwable exception) {
|
|
try {
|
|
try {
|
|
// 判断不记录的情况
|
|
// 判断不记录的情况
|
|
@@ -137,16 +137,16 @@ public class OperateLogAspect {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// 真正记录操作日志
|
|
// 真正记录操作日志
|
|
- this.log0(joinPoint, operateLog, apiOperation, startTime, result, exception);
|
|
|
|
|
|
+ this.log0(joinPoint, operateLog, operation, startTime, result, exception);
|
|
} catch (Throwable ex) {
|
|
} catch (Throwable ex) {
|
|
log.error("[log][记录操作日志时,发生异常,其中参数是 joinPoint({}) operateLog({}) apiOperation({}) result({}) exception({}) ]",
|
|
log.error("[log][记录操作日志时,发生异常,其中参数是 joinPoint({}) operateLog({}) apiOperation({}) result({}) exception({}) ]",
|
|
- joinPoint, operateLog, apiOperation, result, exception, ex);
|
|
|
|
|
|
+ joinPoint, operateLog, operation, result, exception, ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void log0(ProceedingJoinPoint joinPoint,
|
|
private void log0(ProceedingJoinPoint joinPoint,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
|
|
- ApiOperation apiOperation,
|
|
|
|
|
|
+ Operation operation,
|
|
LocalDateTime startTime, Object result, Throwable exception) {
|
|
LocalDateTime startTime, Object result, Throwable exception) {
|
|
OperateLog operateLogObj = new OperateLog();
|
|
OperateLog operateLogObj = new OperateLog();
|
|
// 补全通用字段
|
|
// 补全通用字段
|
|
@@ -155,7 +155,7 @@ public class OperateLogAspect {
|
|
// 补充用户信息
|
|
// 补充用户信息
|
|
fillUserFields(operateLogObj);
|
|
fillUserFields(operateLogObj);
|
|
// 补全模块信息
|
|
// 补全模块信息
|
|
- fillModuleFields(operateLogObj, joinPoint, operateLog, apiOperation);
|
|
|
|
|
|
+ fillModuleFields(operateLogObj, joinPoint, operateLog, operation);
|
|
// 补全请求信息
|
|
// 补全请求信息
|
|
fillRequestFields(operateLogObj);
|
|
fillRequestFields(operateLogObj);
|
|
// 补全方法信息
|
|
// 补全方法信息
|
|
@@ -173,21 +173,21 @@ public class OperateLogAspect {
|
|
private static void fillModuleFields(OperateLog operateLogObj,
|
|
private static void fillModuleFields(OperateLog operateLogObj,
|
|
ProceedingJoinPoint joinPoint,
|
|
ProceedingJoinPoint joinPoint,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
|
|
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
|
|
- ApiOperation apiOperation) {
|
|
|
|
|
|
+ Operation operation) {
|
|
// module 属性
|
|
// module 属性
|
|
if (operateLog != null) {
|
|
if (operateLog != null) {
|
|
operateLogObj.setModule(operateLog.module());
|
|
operateLogObj.setModule(operateLog.module());
|
|
}
|
|
}
|
|
if (StrUtil.isEmpty(operateLogObj.getModule())) {
|
|
if (StrUtil.isEmpty(operateLogObj.getModule())) {
|
|
- Api api = getClassAnnotation(joinPoint, Api.class);
|
|
|
|
- if (api != null) {
|
|
|
|
- // 优先读取 @API 的 name 属性
|
|
|
|
- if (StrUtil.isNotEmpty(api.value())) {
|
|
|
|
- operateLogObj.setModule(api.value());
|
|
|
|
|
|
+ Tag tag = getClassAnnotation(joinPoint, Tag.class);
|
|
|
|
+ if (tag != null) {
|
|
|
|
+ // 优先读取 @Tag 的 name 属性
|
|
|
|
+ if (StrUtil.isNotEmpty(tag.name())) {
|
|
|
|
+ operateLogObj.setModule(tag.name());
|
|
}
|
|
}
|
|
- // 没有的话,读取 @API 的 tags 属性
|
|
|
|
- if (StrUtil.isEmpty(operateLogObj.getModule()) && ArrayUtil.isNotEmpty(api.tags())) {
|
|
|
|
- operateLogObj.setModule(api.tags()[0]);
|
|
|
|
|
|
+ // 没有的话,读取 @API 的 description 属性
|
|
|
|
+ if (StrUtil.isEmpty(operateLogObj.getModule()) && ArrayUtil.isNotEmpty(tag.description())) {
|
|
|
|
+ operateLogObj.setModule(tag.description());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -195,8 +195,8 @@ public class OperateLogAspect {
|
|
if (operateLog != null) {
|
|
if (operateLog != null) {
|
|
operateLogObj.setName(operateLog.name());
|
|
operateLogObj.setName(operateLog.name());
|
|
}
|
|
}
|
|
- if (StrUtil.isEmpty(operateLogObj.getName()) && apiOperation != null) {
|
|
|
|
- operateLogObj.setName(apiOperation.value());
|
|
|
|
|
|
+ if (StrUtil.isEmpty(operateLogObj.getName()) && operation != null) {
|
|
|
|
+ operateLogObj.setName(operation.summary());
|
|
}
|
|
}
|
|
// type 属性
|
|
// type 属性
|
|
if (operateLog != null && ArrayUtil.isNotEmpty(operateLog.type())) {
|
|
if (operateLog != null && ArrayUtil.isNotEmpty(operateLog.type())) {
|