yujian
2019-09-03 d1dccd08a249b830a95eeeb04af25f87d5c056be
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) {