From ce7536df9f82833044c9cbc479f0de42de2beffe Mon Sep 17 00:00:00 2001 From: 抓蛙师 <770492966@qq.com> Date: 星期四, 14 七月 2022 19:15:17 +0800 Subject: [PATCH] !201 redission处理增加前缀 * redission处理判断无前缀则不处理 * redission处理增加前缀 --- ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 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 f519370..66827cb 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,14 +4,14 @@ 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; +import com.ruoyi.common.utils.MessageUtils; 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; @@ -25,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闃查噸绯荤粺) @@ -42,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()); } @@ -65,13 +63,17 @@ 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 { - throw new ServiceException(repeatSubmit.message()); + String message = repeatSubmit.message(); + if (StringUtils.startsWith(message, "{") && StringUtils.endsWith(message, "}")) { + message = MessageUtils.message(StringUtils.substring(message, 1, message.length() - 1)); + } + throw new ServiceException(message); } } -- Gitblit v1.9.3