fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.javacopy from fanli/src/main/java/com/yeshi/fanli/aspect/IntegralGetVersionLimitAspect.java copy to fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetFrequencyLimitAspect.java
File was copied from fanli/src/main/java/com/yeshi/fanli/aspect/IntegralGetVersionLimitAspect.java @@ -1,6 +1,5 @@ package com.yeshi.fanli.aspect; package com.yeshi.fanli.aspect.integral; import java.io.IOException; import java.lang.reflect.Method; import javax.annotation.Resource; @@ -20,17 +19,19 @@ import org.yeshi.utils.NumberUtil; import com.yeshi.fanli.entity.bus.user.UserActiveLog; import com.yeshi.fanli.log.LogHelper; 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; @Component @Aspect public class IntegralGetVersionLimitAspect { public class IntegralGetFrequencyLimitAspect { @Resource private UserActiveLogService userActiveLogService; private RedisManager redisManager; private ExpressionParser parser = new SpelExpressionParser(); @@ -56,19 +57,20 @@ try { Method realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(), targetMethod.getParameterTypes()); if (realMethod.isAnnotationPresent(IntegralGetVersionLimit.class)) { IntegralGetVersionLimit rs = realMethod.getAnnotation(IntegralGetVersionLimit.class); String key = rs.uid(); String uid = generateKeyBySpEL(key, joinPoint); if (uid != null && NumberUtil.isNumeric(uid)) { UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(Long.parseLong(uid)); if (activeLog != null) { // 小于1.6.5版本不增加积分 if (!VersionUtil.greaterThan_1_6_5( "appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android", activeLog.getVersionCode())) return null; } 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)); if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(catchKey))) { return null; } try { return joinPoint.proceed(); } finally { // 30分钟内不允许操作 redisManager.cacheCommonString(catchKey, "1", 60 * 30); } } } catch (NoSuchMethodException e) { @@ -78,7 +80,7 @@ } return joinPoint.proceed(); } } fanli/src/main/java/com/yeshi/fanli/aspect/integral/IntegralGetVersionLimitAspect.java
File was renamed from fanli/src/main/java/com/yeshi/fanli/aspect/IntegralGetVersionLimitAspect.java @@ -1,4 +1,4 @@ package com.yeshi.fanli.aspect; package com.yeshi.fanli.aspect.integral; import java.io.IOException; import java.lang.reflect.Method; fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java
@@ -4,7 +4,6 @@ import javax.annotation.Resource; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -22,6 +21,7 @@ import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService; import com.yeshi.fanli.service.inter.integral.IntegralTaskService; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.annotation.integral.IntegralGetFrequencyLimit; import com.yeshi.fanli.util.annotation.integral.IntegralGetVersionLimit; @Lazy @@ -45,7 +45,7 @@ return threeSaleMapper.selectBoss(uid); } @IntegralGetVersionLimit(uid="#uid") @IntegralGetVersionLimit(uid = "#uid") @Override public IntegralTaskRecord addEventStatistic(Long uid, String event) throws IntegralGetException { Date nowDate = new Date(); @@ -88,7 +88,7 @@ } } @Cacheable(value = "integralGetCache", key = "'addRecommendSearch-'+#uid") @IntegralGetFrequencyLimit(key = "'addRecommendSearch-'+#uid") @Override public IntegralTaskRecord addRecommendSearch(Long uid) { try { @@ -99,7 +99,7 @@ return null; } @Cacheable(value = "integralGetCache", key = "'addSearchResultScan-'+#uid+'-'+#kw") @IntegralGetFrequencyLimit(key = "'addSearchResultScan-'+#uid+'-'+#kw") @Override public IntegralTaskRecord addSearchResultScan(Long uid, String kw) { try { @@ -111,7 +111,7 @@ return null; } @Cacheable(value = "integralGetCache", key = "'addShareInvite-'+#uid") @IntegralGetFrequencyLimit(key = "'addShareInvite-'+#uid") @Override public IntegralTaskRecord addShareInvite(Long uid) { try { @@ -122,7 +122,7 @@ return null; } @Cacheable(value = "integralGetCache", key = "'addIntoShop-'+#uid+'-'+#shopUrlMD5") @IntegralGetFrequencyLimit(key = "'addIntoShop-'+#uid+'-'+#shopUrlMD5") @Override public IntegralTaskRecord addIntoShop(Long uid, String shopUrlMD5) { try { @@ -157,7 +157,7 @@ } } @Cacheable(value = "integralGetCache", key = "'addScanPushHistory-'+#uid") @IntegralGetFrequencyLimit(key = "'addScanPushHistory-'+#uid") @Override public IntegralTaskRecord addScanPushHistory(Long uid) { try { @@ -168,7 +168,7 @@ return null; } @Cacheable(value = "integralGetCache", key = "'addScanGoodsDetail-'+#uid+'-'+#goodsType+'-'+#goodsId") @IntegralGetFrequencyLimit(key = "'addScanGoodsDetail-'+#uid+'-'+#goodsType+'-'+#goodsId") @Override public IntegralTaskRecord addScanGoodsDetail(Long uid, int goodsType, Long goodsId) { try { @@ -179,7 +179,7 @@ return null; } @Cacheable(value = "integralGetCache", key = "'addScanRecommendBanner-'+#uid+'-'+#id") @IntegralGetFrequencyLimit(key = "'addScanRecommendBanner-'+#uid+'-'+#id") @Override public IntegralTaskRecord addScanRecommendBanner(Long uid, String id) { try { @@ -190,7 +190,7 @@ return null; } @Cacheable(value = "integralGetCache", key = "'addScanRecommendSpecial-'+#uid+'-'+#id") @IntegralGetFrequencyLimit(key = "'addScanRecommendSpecial-'+#uid+'-'+#id") @Override public IntegralTaskRecord addScanRecommendSpecial(Long uid, String id) { try { @@ -202,7 +202,7 @@ return null; } @Cacheable(value = "integralGetCache", key = "'addScanTaoBaoCart-'+#uid") @IntegralGetFrequencyLimit(key = "'addScanTaoBaoCart-'+#uid") @Override public IntegralTaskRecord addScanTaoBaoCart(Long uid) { try { fanli/src/main/java/com/yeshi/fanli/util/annotation/integral/IntegralGetFrequencyLimit.java
New file @@ -0,0 +1,22 @@ package com.yeshi.fanli.util.annotation.integral; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * 金币获得频率控制 * * @author Administrator * */ @Documented @Target(ElementType.METHOD) @Inherited @Retention(RetentionPolicy.RUNTIME) public @interface IntegralGetFrequencyLimit { String key(); } fanli/src/main/resource/log4j.properties
@@ -202,7 +202,7 @@ log4j.logger.tljLog=info,tljLog log4j.appender.tljLog=org.apache.log4j.DailyRollingFileAppender log4j.appender.tljLog.File=logs/request/requestTimeLog.log log4j.appender.tljLog.File=logs/request/tljLog.log log4j.appender.tljLog.MaxFileSize=20MB log4j.appender.tljLog.MaxBackupIndex=100 log4j.appender.tljLog.layout=org.apache.log4j.PatternLayout