fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -57,6 +57,7 @@ import com.yeshi.fanli.util.ThreadUtil; import com.yeshi.fanli.util.Utils; import com.yeshi.fanli.util.VersionUtil; import com.yeshi.fanli.util.cache.IntegralGetCacheManager; import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil; import com.yeshi.fanli.util.factory.CommonGoodsFactory; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; @@ -119,6 +120,9 @@ @Resource private IntegralGetService integralGetService; @Resource private IntegralGetCacheManager integralGetCacheManager; /** * 粘贴板信息推荐 @@ -415,6 +419,7 @@ @RequestMapping(value = "searchGoods") public void searchGoods(AcceptData acceptData, Integer goodsType, String key, Integer page, String filter, Integer order, Long uid, HttpSession session, PrintWriter out) { if (goodsType == null || goodsType < 1 || goodsType > 3) { out.print(JsonUtil.loadFalseResult(1, "请传递正确平台参数")); return; @@ -433,24 +438,22 @@ if (uid != null) { if (page == 1) { session.setAttribute("searchFirstTime", System.currentTimeMillis()); } else if (page == 2) { Long lastTime = (Long) session.getAttribute("searchFirstTime"); integralGetCacheManager.cacheSearchGoods(acceptData.getDevice(), System.currentTimeMillis()); } else if (page > 1) { Long lastTime = integralGetCacheManager.getLastSearchTime(acceptData.getDevice()); if (lastTime != null && System.currentTimeMillis() - lastTime >= 15 * 1000L) {// 超过15s浏览 integralGetCacheManager.clearSearchTime(acceptData.getDevice()); ThreadUtil.run(new Runnable() { @Override public void run() { try { // 增加金币 integralGetService.addSearchResultScan(uid,key); integralGetService.addSearchResultScan(uid, key); } catch (IntegralGetException e) { e.printStackTrace(); } } }); } } } fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java
@@ -89,7 +89,7 @@ } @Cacheable(value = "integralGetCache", key = "'addSearchResultScan-'+#uid+'-'+kw") @Cacheable(value = "integralGetCache", key = "'addSearchResultScan-'+#uid+'-'+#kw") @Override public void addSearchResultScan(Long uid, String kw) throws IntegralGetException { System.out.println("搜索"); fanli/src/main/java/com/yeshi/fanli/util/cache/IntegralGetCacheManager.java
New file @@ -0,0 +1,53 @@ package com.yeshi.fanli.util.cache; import javax.annotation.Resource; import org.springframework.stereotype.Component; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; /** * 金币缓存 * * @author Administrator * */ @Component public class IntegralGetCacheManager { @Resource private RedisManager redisManager; /** * 缓存商品搜索记录 * * @param device * @param time */ public void cacheSearchGoods(String device, Long time) { redisManager.cacheCommonString("integral-seacrh-goods-" + device, time + "", 60 * 5); } /** * 获取上次搜索时间 * * @param device * @return */ public Long getLastSearchTime(String device) { String value = redisManager.getCommonString("integral-seacrh-goods-" + device); if (StringUtil.isNullOrEmpty(value)) return null; return Long.parseLong(value); } /** * 清除设备搜索时间 * @param device */ public void clearSearchTime(String device) { redisManager.removeCommonString("integral-seacrh-goods-" + device); } }