From 6c7c445a0f4462c4e94f24a40bd1f59e8cc6fd63 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 30 八月 2019 18:00:06 +0800
Subject: [PATCH] 金币请求频率限制添加时间

---
 fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java |   36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java b/fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java
index 75f0472..48fb69b 100644
--- a/fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java
+++ b/fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java
@@ -16,22 +16,20 @@
 import org.springframework.expression.spel.standard.SpelExpressionParser;
 import org.springframework.expression.spel.support.StandardEvaluationContext;
 import org.springframework.stereotype.Component;
-import org.yeshi.utils.NumberUtil;
 
-import com.yeshi.fanli.entity.bus.user.UserActiveLog;
-import com.yeshi.fanli.service.inter.user.UserActiveLogService;
 import com.yeshi.fanli.util.RedisManager;
 import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.VersionUtil;
 import com.yeshi.fanli.util.annotation.integral.IntegralGetFrequencyLimit;
-import com.yeshi.fanli.util.annotation.integral.IntegralGetVersionLimit;
+
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
 
 @Component
 @Aspect
 public class IntegralGetFrequencyLimitAspect {
 
 	@Resource
-	private RedisManager redisManager;
+	private JedisPool jedisPool;
 
 	private ExpressionParser parser = new SpelExpressionParser();
 
@@ -60,17 +58,29 @@
 			if (realMethod.isAnnotationPresent(IntegralGetFrequencyLimit.class)) {
 				IntegralGetFrequencyLimit rs = realMethod.getAnnotation(IntegralGetFrequencyLimit.class);
 				String key = rs.key();
-				String catchKey = StringUtil.Md5("integral-get-frequency-" + generateKeyBySpEL(key, joinPoint));
+				int timeS = rs.time();
 
-				if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(catchKey))) {
-					return null;
-				}
+				String catchKey = "integral-get-frequency-" + StringUtil.Md5(generateKeyBySpEL(key, joinPoint));
 
+				Jedis jedis = jedisPool.getResource();
 				try {
-					return joinPoint.proceed();
+					if (jedis.setnx(catchKey, "1") > 0) {
+						jedis.expire(catchKey, timeS);
+						try {
+							return joinPoint.proceed();
+						} catch (Exception e) {// 寮傚父浜嗘湰娆¤姹備笉绠�
+							jedis.del(catchKey);
+						}
+					} else {
+						return null;
+					}
+				} catch (Exception e) {
+					try {
+						return joinPoint.proceed();
+					} finally {
+					}
 				} finally {
-					// 30鍒嗛挓鍐呬笉鍏佽鎿嶄綔
-					redisManager.cacheCommonString(catchKey, "1", 60 * 30);
+					jedisPool.returnResource(jedis);
 				}
 			}
 		} catch (NoSuchMethodException e) {

--
Gitblit v1.8.0