admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/recommend/RecommendGoodsDeleteHistoryServiceImpl.java
@@ -1,80 +1,80 @@
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.goods.facade.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;
   }
   @Override
   public List<RecommendGoodsDeleteHistory> listBackStage(long start, int count, String key) {
      return recommendGoodsDeleteHistoryMapper.listBackStage(start, count, key);
   }
   @Override
   public long countBackStage(String key) {
      return recommendGoodsDeleteHistoryMapper.countBackStage(key);
   }
}
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.goods.facade.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<String, 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;
   }
   @Override
   public List<RecommendGoodsDeleteHistory> listBackStage(long start, int count, String key) {
      return recommendGoodsDeleteHistoryMapper.listBackStage(start, count, key);
   }
   @Override
   public long countBackStage(String key) {
      return recommendGoodsDeleteHistoryMapper.countBackStage(key);
   }
}