admin
2019-08-22 7807cb3070262b84a3f583314a88fad16d12abc0
限时秒杀接口更改
2个文件已修改
1个文件已添加
72 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/cache/IntegralGetCacheManager.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
    }
}