admin
2019-11-20 8b2191df2f7d94aa299bd43dcbe97c94e5a61bbd
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandGoodsCaheServiceImpl.java
@@ -68,6 +68,10 @@
    * @return
    */
   private int addBrandGoodsTB(BrandInfo brandInfo) {
      String shopKey = brandInfo.getShopKey();
      if (StringUtil.isNullOrEmpty(shopKey))
         shopKey = brandInfo.getName();
      String searchKey = brandInfo.getSearchKey();
      if (StringUtil.isNullOrEmpty(searchKey))
         searchKey = brandInfo.getName();
@@ -81,6 +85,10 @@
      filter.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
      TaoBaoSearchResult searchResult = TaoKeApiUtil.searchWuLiao(filter);
      
      // 删除店铺
       brandShopCaheService.removeByDateAndType(brandInfo.getId(), 11, date);
       // 组织商品 + 添加店铺
      int count = 0;
      if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null 
            && searchResult.getTaoBaoGoodsBriefs().size() > 0) {
@@ -90,8 +98,8 @@
            // 添加店铺
            String shopTitle = goods.getShopTitle();
            if (addShop && !StringUtil.isNullOrEmpty(shopTitle) && shopTitle.contains("旗舰店") 
                  && shopTitle.contains(brandInfo.getName())) {
               addShop = brandShopCaheService.addBrandShopTB(brandInfo.getId(), goods.getAuctionId(),
                  && shopTitle.toLowerCase().contains(shopKey.toLowerCase())) {
               addShop = brandShopCaheService.addBrandShopTB(brandInfo, goods.getAuctionId(),
                     goods.getSellerId());
            }
            
@@ -110,9 +118,10 @@
            }
         }
      }
      // 删除之前的
       brandGoodsCaheDao.removeByDate(brandInfo.getId(), 1 , date);
      return count;
   }
   
@@ -124,6 +133,10 @@
    * @return
    */
   private int addBrandGoodsJD(BrandInfo brandInfo) {
      String shopKey = brandInfo.getShopKey();
      if (StringUtil.isNullOrEmpty(shopKey))
         shopKey = brandInfo.getName();
      String searchKey = brandInfo.getSearchKey();
      if (StringUtil.isNullOrEmpty(searchKey))
         searchKey = brandInfo.getName();
@@ -132,6 +145,12 @@
      JDSearchResult result = null;
      String way = configService.get("jd_api_search_key");
      Date date = new Date();
      // 删除店铺
       brandShopCaheService.removeByDateAndType(brandInfo.getId(), 20, date);
       boolean addShop = true;
      for (int i=0; i < 2;i ++) {
         if ("1".equals(way)) {
            JDFilter filterAPI = new JDFilter();
@@ -152,29 +171,30 @@
            result = JDUtil.searchByKey(jdfilter);
         }
         
         if (result != null) {
         if (result != null && result.getGoodsList() != null && result.getGoodsList().size() > 0) {
            List<JDGoods> goodsList = result.getGoodsList();
            if (goodsList != null && goodsList.size() > 0) {
               for (JDGoods goods : goodsList) {
                  BrandGoodsCahe brandGoods = new BrandGoodsCahe();
                  brandGoods.setBrandId(brandInfo.getId());
                  brandGoods.setWeight((int) (Math.random() * 1000));
                  brandGoods.setGoodsJD(goods);
                  brandGoods.setGoodsType(2);
                  brandGoods.setCreateTime(date);
                  brandGoodsCaheDao.insert(brandGoods);
                  if (count == 0) {
                     JDShopInfo shopInfo = goods.getShopInfo();
                     if(shopInfo != null) {
                        brandShopCaheService.addBrandShopJD(brandInfo, shopInfo);
                     }
            for (JDGoods goods : goodsList) {
               BrandGoodsCahe brandGoods = new BrandGoodsCahe();
               brandGoods.setBrandId(brandInfo.getId());
               brandGoods.setWeight((int) (Math.random() * 1000));
               brandGoods.setGoodsJD(goods);
               brandGoods.setGoodsType(2);
               brandGoods.setCreateTime(date);
               brandGoodsCaheDao.insert(brandGoods);
               JDShopInfo shopInfo = goods.getShopInfo();
               if (addShop && shopInfo != null) {
                  // 包含该品牌名称
                  String shopName = shopInfo.getShopName();
                  if (!StringUtil.isNullOrEmpty(shopName) && shopName.toLowerCase().contains(shopKey.toLowerCase())) {
                     addShop = false;
                     brandShopCaheService.addBrandShopJD(brandInfo, shopInfo);
                  }
                  count ++;
                  if (count >= 50) {
                     break;
                  }
               }
               count ++;
               if (count >= 50) {
                  break;
               }
            }
         }
@@ -202,9 +222,11 @@
      pddfilter.setPage(1);
      pddfilter.setPageSize(100);
      pddfilter.setSortType(6);
      Date date = new Date();
      int count = 0;
      PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter);
      int count = 0;
      Date date = new Date();
      if (result != null) {
         List<PDDGoodsDetail> goodsList = result.getGoodsList();
         if (goodsList != null && goodsList.size() > 0) {
@@ -223,14 +245,14 @@
            }
         }
      }
      // 删除之前
      brandGoodsCaheDao.removeByDate(brandInfo.getId(), 3, date);
      // 删除之前店铺
      brandShopCaheService.removeByDateAndType(brandInfo.getId(), 30, date);
      // 添加店铺
      brandShopCaheService.addBrandShopPDD(brandInfo);
      
      // 删除之前
      brandGoodsCaheDao.removeByDate(brandInfo.getId(), 3, date);
      return count;
   }
   
   
@@ -243,4 +265,14 @@
   public long countByBrandId(Long brandId){
      return brandGoodsCaheDao.countByBrandId(brandId);
   }
   @Override
   public void removeAgoByDate(Date createTime) {
      brandGoodsCaheDao.removeAgoByDate(createTime);
   }
   @Override
   public void removeByBrandId(Long brandId) {
      brandGoodsCaheDao.removeByBrandId(brandId);
   }
}