From d6400e382a91fe7b00fa9dc7a24499a5ebf0c211 Mon Sep 17 00:00:00 2001
From: zlyx <1242874891@qq.com>
Date: 星期三, 14 九月 2022 14:22:49 +0800
Subject: [PATCH] fix 修正控制台日志打印格式化问题 ;
---
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java | 27 ++++++++++++++-------------
1 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java
index d0422e9..7c2fa2a 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java
@@ -4,7 +4,7 @@
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
import com.ruoyi.common.annotation.RepeatSubmit;
-import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.JsonUtils;
@@ -12,7 +12,6 @@
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.redis.RedisUtils;
-import com.ruoyi.framework.config.properties.RepeatSubmitProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
@@ -26,9 +25,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.time.Duration;
import java.util.Collection;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
/**
* 闃叉閲嶅鎻愪氦(鍙傝�冪編鍥TIS闃查噸绯荤粺)
@@ -43,12 +42,10 @@
private static final ThreadLocal<String> KEY_CACHE = new ThreadLocal<>();
- private final RepeatSubmitProperties repeatSubmitProperties;
-
@Before("@annotation(repeatSubmit)")
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
// 濡傛灉娉ㄨВ涓嶄负0 鍒欎娇鐢ㄦ敞瑙f暟鍊�
- long interval = repeatSubmitProperties.getInterval();
+ long interval = 0;
if (repeatSubmit.interval() > 0) {
interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
}
@@ -66,10 +63,10 @@
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
// 鍞竴鏍囪瘑锛堟寚瀹歬ey + url + 娑堟伅澶达級
- String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + url + submitKey;
+ String cacheRepeatKey = CacheConstants.REPEAT_SUBMIT_KEY + url + submitKey;
String key = RedisUtils.getCacheObject(cacheRepeatKey);
if (key == null) {
- RedisUtils.setCacheObject(cacheRepeatKey, "", interval, TimeUnit.MILLISECONDS);
+ RedisUtils.setCacheObject(cacheRepeatKey, "", Duration.ofMillis(interval));
KEY_CACHE.set(cacheRepeatKey);
} else {
String message = repeatSubmit.message();
@@ -88,12 +85,16 @@
@AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult")
public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) {
if (jsonResult instanceof R) {
- R<?> r = (R<?>) jsonResult;
- if (r.getCode() == R.SUCCESS) {
- return;
+ try {
+ R<?> r = (R<?>) jsonResult;
+ // 鎴愬姛鍒欎笉鍒犻櫎redis鏁版嵁 淇濊瘉鍦ㄦ湁鏁堟椂闂村唴鏃犳硶閲嶅鎻愪氦
+ if (r.getCode() == R.SUCCESS) {
+ return;
+ }
+ RedisUtils.deleteObject(KEY_CACHE.get());
+ } finally {
+ KEY_CACHE.remove();
}
- RedisUtils.deleteObject(KEY_CACHE.get());
- KEY_CACHE.remove();
}
}
--
Gitblit v1.9.3