提交resultCode pr

pull/2/head
lst 2022-06-19 13:09:36 +08:00
parent 69a3a835a5
commit 892fa63ac3
1 changed files with 12 additions and 13 deletions

View File

@ -44,7 +44,7 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC
* *
* 1. 使 @ApiOperation + @GetMapping * 1. 使 @ApiOperation + @GetMapping
* 2. 使 @OperateLog * 2. 使 @OperateLog
* * <p>
* @OperateLog enable false * @OperateLog enable false
* *
* @author * @author
@ -77,7 +77,8 @@ public class OperateLogAspect {
return around0(joinPoint, operateLog, apiOperation); return around0(joinPoint, operateLog, apiOperation);
} }
@Around("!@annotation(io.swagger.annotations.ApiOperation) && @annotation(operateLog)") // 兼容处理,只添加 @OperateLog 注解的情况 @Around("!@annotation(io.swagger.annotations.ApiOperation) && @annotation(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 {
return around0(joinPoint, operateLog, null); return around0(joinPoint, operateLog, null);
@ -236,14 +237,12 @@ public class OperateLogAspect {
} }
operateLogObj.setDuration((int) (System.currentTimeMillis() - startTime.getTime())); operateLogObj.setDuration((int) (System.currentTimeMillis() - startTime.getTime()));
// (正常)处理 resultCode 和 resultMsg 字段 // (正常)处理 resultCode 和 resultMsg 字段
if (result != null) { if (result instanceof CommonResult) {
if (result instanceof CommonResult) { CommonResult<?> commonResult = (CommonResult<?>) result;
CommonResult<?> commonResult = (CommonResult<?>) result; operateLogObj.setResultCode(commonResult.getCode());
operateLogObj.setResultCode(commonResult.getCode()); operateLogObj.setResultMsg(commonResult.getMsg());
operateLogObj.setResultMsg(commonResult.getMsg()); } else {
} else { operateLogObj.setResultCode(SUCCESS.getCode());
operateLogObj.setResultCode(SUCCESS.getCode());
}
} }
// (异常)处理 resultCode 和 resultMsg 字段 // (异常)处理 resultCode 和 resultMsg 字段
if (exception != null) { if (exception != null) {
@ -267,9 +266,9 @@ public class OperateLogAspect {
return null; return null;
} }
return Arrays.stream(requestMethods).filter(requestMethod -> return Arrays.stream(requestMethods).filter(requestMethod ->
requestMethod == RequestMethod.POST requestMethod == RequestMethod.POST
|| requestMethod == RequestMethod.PUT || requestMethod == RequestMethod.PUT
|| requestMethod == RequestMethod.DELETE) || requestMethod == RequestMethod.DELETE)
.findFirst().orElse(null); .findFirst().orElse(null);
} }