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;
|
}
|
|
}
|