admin
2019-07-09 531d93708df8017e59830f15b41f3cc42d6126e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.yeshi.fanli.service.impl.goods.recommend;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
import javax.annotation.Resource;
 
import org.springframework.cache.Cache;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.goods.recommend.RecommendGoodsDeleteHistoryMapper;
import com.yeshi.fanli.entity.goods.recommend.RecommendGoodsDeleteHistory;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.service.inter.goods.recommend.RecommendGoodsDeleteHistoryService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class RecommendGoodsDeleteHistoryServiceImpl implements RecommendGoodsDeleteHistoryService {
 
    @Resource
    private RecommendGoodsDeleteHistoryMapper recommendGoodsDeleteHistoryMapper;
    @Resource
    private EhCacheCacheManager ehCacheCacheManager;
 
    @Override
    public void addRecommendGoodsDeleteHistory(RecommendGoodsDeleteHistory history) {
        if (history.getGoodsId() == null || history.getGoodsSource() == null
                || StringUtil.isNullOrEmpty(history.getDevice()))
            return;
        if (history.getCreateTime() == null)
            history.setCreateTime(new Date());
        recommendGoodsDeleteHistoryMapper.insertSelective(history);
        try {
            // 清除个人推荐的缓存
            Cache cache = ehCacheCacheManager.getCache("recommendUserCache");
            cache.clear();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @Override
    public List<TaoBaoGoodsBrief> filterGoods(String device, List<TaoBaoGoodsBrief> goodsList) {
        List<TaoBaoGoodsBrief> resultList = new ArrayList<>();
        if (goodsList == null || goodsList.size() == 0)
            return goodsList;
 
        Map<Long, TaoBaoGoodsBrief> resultMap = new ConcurrentHashMap<>();
        List<RecommendGoodsDeleteHistory> hlist = new ArrayList<>();
        for (TaoBaoGoodsBrief goods : goodsList) {
            hlist.add(new RecommendGoodsDeleteHistory(goods.getAuctionId(), Constant.SOURCE_TYPE_TAOBAO));
            resultMap.put(goods.getAuctionId(), goods);
        }
        List<RecommendGoodsDeleteHistory> existList = recommendGoodsDeleteHistoryMapper.listByGoodsInfo(device, hlist);
        if (existList != null)
            for (RecommendGoodsDeleteHistory dh : existList)
                resultMap.remove(dh.getGoodsId());
 
        for (TaoBaoGoodsBrief goods : goodsList) {
            if (resultMap.get(goods.getAuctionId()) != null)
                resultList.add(resultMap.get(goods.getAuctionId()));
        }
        return resultList;
    }
 
}