yj
2020-03-06 207dc8655711cddac2653e18b51e58a88dba2084
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java
@@ -159,11 +159,17 @@
      for (TaoBaoGoodsBrief goods : goodsList)
         goodsIdList.add(goods.getAuctionId());
      List<DaTaoKeDetailV2> dtList = listByGoodsIds(goodsIdList);
      List<DaTaoKeDetailV2> dtList = null;
      try {
         dtList = listByGoodsIds(goodsIdList);
      } catch (Exception e) {
      }
      Map<Long, DaTaoKeDetailV2> map = new HashMap<>();
      for (DaTaoKeDetailV2 goods : dtList)
         map.put(goods.getGoodsId(), goods);
      if (dtList != null)
         for (DaTaoKeDetailV2 goods : dtList)
            map.put(goods.getGoodsId(), goods);
      for (TaoBaoGoodsBrief goods : goodsList) {
         DaTaoKeDetailV2 detail = map.get(goods.getAuctionId());
         goods = DaTaoKeUtil.filterTaoBaoGoods(goods, detail);
@@ -210,6 +216,8 @@
   @Override
   public List<DaTaoKeDetailV2> getGoodsNotInList(Long cid, List<Long> listId, int count) {
      if (cid != null && cid == 0L)
         cid = null;
      return daTaoKeGoodsDetailV2Dao.getGoodsNotInList(cid, listId, count);
   }
@@ -252,11 +260,23 @@
   public List<DaTaoKeDetailV2> listPreTLJBuyGoods(int page) {
      if (page == 1) {
         List<DaTaoKeDetailV2> listPreGoodsList = new ArrayList<>();
         // 热销榜
         DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_HOT, null);
         if (result != null && result.getGoodsList() != null)
            listPreGoodsList.addAll(result.getGoodsList());
         // 复购榜
         result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_REBUY, null);
         if (result != null && result.getGoodsList() != null)
            listPreGoodsList.addAll(result.getGoodsList());
         // 综合搜索
         try {
            result = DaTaoKeApiUtil.search("", null, null, null, 1, 200, DaTaoKeApiUtil.SORT_DEFAULT);
            if (result == null)
               throw new Exception();
         } catch (Exception e) {// 异常重复一次
            result = DaTaoKeApiUtil.search("", null, null, null, 1, 200, DaTaoKeApiUtil.SORT_DEFAULT);
         }
         if (result != null && result.getGoodsList() != null)
            listPreGoodsList.addAll(result.getGoodsList());
@@ -328,17 +348,38 @@
   @Async
   private void updateGoods(Long id) {
      DaTaoKeDetailV2 v2 = DaTaoKeApiUtil.getGoodsDetail(id);
      // TODO暂时关闭服务
      DaTaoKeDetailV2 v2 = null;// DaTaoKeApiUtil.getGoodsDetail(id);
      if (v2 != null)
         daTaoKeGoodsDetailV2Dao.save(v2);
   }
   private List<DaTaoKeDetailV2> getDefaultDingDongQiang() {
      // 按更新时间加
      DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_TIME, null);
      if (result != null && result.getGoodsList().size() > 0) {
         List<DaTaoKeDetailV2> finalList = new ArrayList<>();
         Collections.shuffle(result.getGoodsList());
         finalList.addAll(result.getGoodsList().subList(0,
               result.getGoodsList().size() > 8 ? 8 : result.getGoodsList().size()));
         for (DaTaoKeDetailV2 detail : finalList) {
            detail.setCouponReceiveNum(detail.getCouponTotalNum() - (int) (200 + Math.random() * 1000));
            if (detail.getCouponTotalNum() - detail.getCouponReceiveNum() <= 0)
               detail.setCouponReceiveNum(detail.getCouponTotalNum());
         }
         return finalList;
      }
      return null;
   }
   @Cacheable(value = "daTaoKeGoodsCache", key = "'getDingDongQiangData-'+#time")
   @Override
   public List<DaTaoKeDetailV2> getDingDongQiangData(String time) {
      List<DingDongQiangDTO> list = getDingDongQiangData();
      if (list == null)
         return null;
      if (list == null || list.size() == 0) {
         return getDefaultDingDongQiang();
      }
      Map<String, DingDongQiangDTO> map = new HashMap<>();
      for (DingDongQiangDTO dto : list)
         map.put(dto.getTime(), dto);
@@ -350,8 +391,10 @@
            idList.add(td.getId());
         List<DaTaoKeDetailV2> finalList = listByIds(idList);
         if (finalList.size() != idList.size()) {
            for (Long id : idList)
               updateGoods(id);
            for (Long id : idList) {
               // updateGoods(id);
               // TODO 不能异步调用
            }
            finalList = listByIds(idList);
         }
@@ -372,8 +415,9 @@
               detail.setCouponReceiveNum(detail.getCouponTotalNum());
         }
         return finalList;
      } else {
         return getDefaultDingDongQiang();
      }
      return null;
   }
   @Override
@@ -386,4 +430,21 @@
      return dateList;
   }
   @Override
   public List<DaTaoKeDetailV2> listByMaxPrice(Integer cid, BigDecimal maxPrice, String sortName, int page,
         int count) {
      return daTaoKeGoodsDetailV2Dao.listByMaxPrice(cid, maxPrice, sortName, (page - 1) * count, count);
   }
   @Override
   public int countByMaxPrice(Integer cid, BigDecimal maxPrice) {
      return (int) daTaoKeGoodsDetailV2Dao.countByMaxPrice(cid, maxPrice);
   }
   @Override
   public List<DaTaoKeDetailV2> listBySellerId(long start, int count, Long sellerId) {
      return daTaoKeGoodsDetailV2Dao.listBySellerId((int) start, count, sellerId);
   }
}