From d0c4b5bc76eed132a1d2028d205078866fc346fa Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期二, 23 十一月 2021 10:20:44 +0800
Subject: [PATCH] add 增加 RedisUtils set 保留 TTL 有效期方法
---
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java | 67 +++++++++++++++++++++++++++++----
1 files changed, 59 insertions(+), 8 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 3814a2c..71d438c 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
@@ -1,6 +1,5 @@
package com.ruoyi.framework.aspectj;
-import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.lock.LockInfo;
import com.baomidou.lock.LockTemplate;
@@ -8,6 +7,7 @@
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.properties.TokenProperties;
+import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.properties.RepeatSubmitProperties;
@@ -18,8 +18,13 @@
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Collection;
+import java.util.Map;
/**
* 闃叉閲嶅鎻愪氦
@@ -39,15 +44,15 @@
@Before("@annotation(repeatSubmit)")
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
// 濡傛灉娉ㄨВ涓嶄负0 鍒欎娇鐢ㄦ敞瑙f暟鍊�
- long intervalTime = repeatSubmitProperties.getIntervalTime();
- if (repeatSubmit.intervalTime() > 0) {
- intervalTime = repeatSubmit.timeUnit().toMillis(repeatSubmit.intervalTime());
+ long interval = repeatSubmitProperties.getInterval();
+ if (repeatSubmit.interval() > 0) {
+ interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
}
- if (intervalTime < 1000) {
+ if (interval < 1000) {
throw new ServiceException("閲嶅鎻愪氦闂撮殧鏃堕棿涓嶈兘灏忎簬'1'绉�");
}
HttpServletRequest request = ServletUtils.getRequest();
- String nowParams = StrUtil.join(",", point.getArgs());
+ String nowParams = argsArrayToString(point.getArgs());
// 璇锋眰鍦板潃锛堜綔涓哄瓨鏀綾ache鐨刱ey鍊硷級
String url = request.getRequestURI();
@@ -60,10 +65,56 @@
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
// 鍞竴鏍囪瘑锛堟寚瀹歬ey + 娑堟伅澶达級
String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + submitKey;
- LockInfo lock = lockTemplate.lock(cacheRepeatKey, intervalTime, intervalTime / 2);
+ LockInfo lock = lockTemplate.lock(cacheRepeatKey, interval, interval / 2);
if (lock == null) {
- throw new ServiceException("涓嶅厑璁搁噸澶嶆彁浜わ紝璇风◢鍚庡啀璇�!");
+ throw new ServiceException(repeatSubmit.message());
}
}
+ /**
+ * 鍙傛暟鎷艰
+ */
+ private String argsArrayToString(Object[] paramsArray) {
+ StringBuilder params = new StringBuilder();
+ if (paramsArray != null && paramsArray.length > 0) {
+ for (Object o : paramsArray) {
+ if (StringUtils.isNotNull(o) && !isFilterObject(o)) {
+ try {
+ params.append(JsonUtils.toJsonString(o)).append(" ");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ return params.toString().trim();
+ }
+
+ /**
+ * 鍒ゆ柇鏄惁闇�瑕佽繃婊ょ殑瀵硅薄銆�
+ *
+ * @param o 瀵硅薄淇℃伅銆�
+ * @return 濡傛灉鏄渶瑕佽繃婊ょ殑瀵硅薄锛屽垯杩斿洖true锛涘惁鍒欒繑鍥瀎alse銆�
+ */
+ @SuppressWarnings("rawtypes")
+ public boolean isFilterObject(final Object o) {
+ Class<?> clazz = o.getClass();
+ if (clazz.isArray()) {
+ return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
+ } else if (Collection.class.isAssignableFrom(clazz)) {
+ Collection collection = (Collection) o;
+ for (Object value : collection) {
+ return value instanceof MultipartFile;
+ }
+ } else if (Map.class.isAssignableFrom(clazz)) {
+ Map map = (Map) o;
+ for (Object value : map.entrySet()) {
+ Map.Entry entry = (Map.Entry) value;
+ return entry.getValue() instanceof MultipartFile;
+ }
+ }
+ return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
+ || o instanceof BindingResult;
+ }
+
}
--
Gitblit v1.9.3