| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import org.aspectj.lang.ProceedingJoinPoint;
|
| | | import org.aspectj.lang.Signature;
|
| | | import org.aspectj.lang.annotation.Around;
|
| | |
| | | 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
|
| | |
| | | return expression.getValue(context).toString();
|
| | | }
|
| | |
|
| | | @Around("execution(public * com.yeshi.fanli.service.impl.integral.*.*(..))")
|
| | | @Around("execution(public * com.yeshi.fanli.service.impl.user.integral.*.*(..))")
|
| | | public Object requestSerializable(ProceedingJoinPoint joinPoint) throws Throwable {
|
| | | Signature signature = joinPoint.getSignature();
|
| | | MethodSignature methodSignature = (MethodSignature) signature;
|
| | |
| | | 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 =redisManager.getJedis();
|
| | | 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);
|
| | | jedis.close();
|
| | | }
|
| | | }
|
| | | } catch (NoSuchMethodException e) {
|