修复记录操作时,会存在调用异常的情况

This commit is contained in:
YunaiV 2023-07-28 13:57:10 +08:00
parent 0ff2f9783d
commit 3930fd739a
5 changed files with 33 additions and 5 deletions

View File

@ -227,8 +227,7 @@ public class OperateLogAspect {
private static void fillMethodFields(OperateLog operateLogObj,
ProceedingJoinPoint joinPoint,
cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog operateLog,
LocalDateTime startTime, Object result, Throwable exception) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
LocalDateTime startTime, Object result, Throwable exception) {MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
operateLogObj.setJavaMethod(methodSignature.toString());
if (operateLog == null || operateLog.logArgs()) {
operateLogObj.setJavaMethodArgs(obtainMethodArgs(joinPoint));
@ -258,6 +257,11 @@ public class OperateLogAspect {
if (operateLog != null) {
return operateLog.enable();
}
// Cloud 专属逻辑如果是 RPC 请求则必须 @OperateLog 注解才会记录操作日志
String className = joinPoint.getSignature().getDeclaringType().getName();
if (WebFrameworkUtils.isRpcRequest(className)) {
return false;
}
// 没有 @ApiOperation 注解的情况下只记录 POSTPUTDELETE 的情况
return obtainFirstLogRequestMethod(obtainRequestMethod(joinPoint)) != null;
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.framework.web.core.util;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.RpcConstants;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
@ -136,4 +135,16 @@ public class WebFrameworkUtils {
return request.getRequestURI().startsWith(RpcConstants.RPC_API_PREFIX);
}
/**
* 判断是否为 RPC 请求
*
* 约定大于配置只要以 Api 结尾都认为是 RPC 接口
*
* @param className 类名
* @return 是否为 RPC 请求
*/
public static boolean isRpcRequest(String className) {
return className.endsWith("Api");
}
}

View File

@ -64,7 +64,13 @@ spring:
- Path=/app-api/pay/**
filters:
- RewritePath=/app-api/pay/v3/api-docs, /v3/api-docs
## mp-server 服务
- id: mp-admin-api # 路由的编号
uri: grayLb://mp-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/mp/**
filters:
- RewritePath=/admin-api/mp/v3/api-docs, /v3/api-docs
x-forwarded:
prefix-enabled: false # 避免 Swagger 重复带上额外的 /admin-api/system 前缀
@ -85,3 +91,6 @@ knife4j:
- name: pay-server
service-name: pay-server
url: /admin-api/pay/v3/api-docs
- name: mp-server
service-name: mp-server
url: /admin-api/mp/v3/api-docs

View File

@ -71,6 +71,7 @@ wx:
type: RedisTemplate # 采用 RedisTemplate 操作 Redis会自动从 Spring 中获取
key-prefix: wx # Redis Key 的前缀
http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台
app-id: null # 避免 weixin-java-mp starter 报错
--- #################### 芋道相关配置 ####################
@ -81,6 +82,9 @@ yudao:
web:
admin-ui:
url: http://dashboard.yudao.iocoder.cn # Admin 管理后台 UI 的地址
security:
permit-all_urls:
- /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,不需要登录
swagger:
title: 管理后台
description: 提供管理员管理的所有功能

View File

@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.system.api.logger;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;