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/controller/client/v2/IntegralControllerV2.java
@@ -36,10 +36,10 @@ import com.yeshi.fanli.entity.integral.CodePublishRecord; import com.yeshi.fanli.entity.integral.IntegralExchange; import com.yeshi.fanli.entity.integral.IntegralTask; import com.yeshi.fanli.entity.integral.IntegralTask.TaskUniqueKeyEnum; import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum; import com.yeshi.fanli.entity.integral.IntegralTaskRecord; import com.yeshi.fanli.exception.integral.IntegralExchangeException; import com.yeshi.fanli.exception.integral.IntegralGetException; import com.yeshi.fanli.exception.integral.IntegralTaskRecordException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; @@ -537,7 +537,7 @@ * @param out */ @RequestMapping(value = "pushEvent", method = RequestMethod.POST) public void pushEvent(AcceptData acceptData, String event, Long uid, PrintWriter out) { public void pushEvent(AcceptData acceptData, String event, Long uid, String data, PrintWriter out) { if (uid == null || uid == 0) { out.print(JsonUtil.loadFalseResult("用户尚未登录")); return; @@ -548,34 +548,49 @@ return; } IntegralTaskRecord record = null; try { record = integralGetService.addEventStatistic(uid, event); } catch (IntegralGetException e) { } if (record == null) { out.print(JsonUtil.loadFalseResult("添加失败")); return; if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)) { record = integralGetService.addRecommendSearch(uid); } else if (TaskUniqueKeyEnum.shareInvite.name().equalsIgnoreCase(event)) { record = integralGetService.addShareInvite(uid); } else if (TaskUniqueKeyEnum.inShop.name().equalsIgnoreCase(event)) { JSONObject json = JSONObject.fromObject(data); record = integralGetService.addIntoShop(uid, StringUtil.Md5(json.optString("url"))); } else if (TaskUniqueKeyEnum.scanPush.name().equalsIgnoreCase(event)) { record = integralGetService.addScanPushHistory(uid); } else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)) { JSONObject json = JSONObject.fromObject(data); record = integralGetService.addScanGoodsDetail(uid, json.optInt("goodsType"), json.optLong("goodsId")); } else if (TaskUniqueKeyEnum.scanHomeBanner.name().equalsIgnoreCase(event)) { JSONObject json = JSONObject.fromObject(data); record = integralGetService.addScanRecommendBanner(uid, json.optString("id")); } else if (TaskUniqueKeyEnum.scanSpecial.name().equalsIgnoreCase(event)) { JSONObject json = JSONObject.fromObject(data); record = integralGetService.addScanRecommendSpecial(uid, json.optString("id")); } else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) { record = integralGetService.addScanTaoBaoCart(uid); } JSONObject data = new JSONObject(); if ("recommendSearch".equalsIgnoreCase(event) || "scanGoods".equalsIgnoreCase(event) || "scanTBCart".equalsIgnoreCase(event)) { JSONObject notify = new JSONObject(); switch (event) { case "recommendSearch": notify.put("name", "完成一次智能搜索"); break; case "scanGoods": notify.put("name", "完成一次商品浏览"); break; case "scanTBCart": notify.put("name", "完成一次购物车浏览"); break; if (record != null) { JSONObject notifyData = new JSONObject(); if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event) || TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event) || TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) { JSONObject notify = new JSONObject(); if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)) notify.put("name", "完成一次智能搜索"); else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)) notify.put("name", "完成一次商品浏览"); else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) notify.put("name", "完成一次购物车浏览"); notify.put("score", String.format("+%s金币", record.getGoldCoin())); notifyData.put("notify", notify); } notify.put("score", String.format("+%s金币", record.getGoldCoin())); data.put("notify", notify); out.print(JsonUtil.loadTrueResult(notifyData)); } else { out.print(JsonUtil.loadFalseResult("")); } out.print(JsonUtil.loadTrueResult(data)); } /** 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