admin
2019-09-17 5eab2b71f0749e9f61fc83d9d7e03553e9fa75ef
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -9,17 +9,24 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.brand.BrandShopCaheDao;
import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper;
import com.yeshi.fanli.entity.brand.BrandInfo;
import com.yeshi.fanli.entity.brand.BrandShopCahe;
import com.yeshi.fanli.entity.taobao.SearchShopFilter;
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo;
import com.yeshi.fanli.exception.brand.BrandInfoException;
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
import com.yeshi.fanli.service.inter.brand.BrandGoodsCaheService;
import com.yeshi.fanli.service.inter.brand.BrandInfoService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.goods.ShopInfoVOFactory;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.brand.BrandInfoVO;
import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
@@ -44,6 +51,13 @@
   @Resource
   private BrandClassShopService brandClassShopService;
   @Resource
   private BrandShopCaheDao brandShopCaheDao;
   @Resource
   private BrandGoodsCaheService brandGoodsCaheService;
   
   @Override
   public void saveObject(BrandInfo record) throws BrandInfoException{
@@ -142,4 +156,73 @@
   public long countBrandInfo(Long cid){
      return brandClassShopService.countBrandShopinfo(cid);
   }
   public void addShopAndGoods(long start, int count) {
      List<BrandInfo> list = brandInfoMapper.listValidAll(start, count);
      if(list == null || list.size() == 0)
         return;
      for (BrandInfo brandInfo: list) {
         String key = brandInfo.getName();
         if(StringUtil.isNullOrEmpty(key))
            continue;
         // 添加店铺
         addBrandShop(brandInfo);
         // 添加店铺
         int goodsTotal = brandGoodsCaheService.addBrandGoods(brandInfo);
         brandInfo.setGoodsTotal(goodsTotal);
         brandInfoMapper.updateByPrimaryKeySelective(brandInfo);
      }
   }
   /**
    * 加入品牌店铺
    * @param brandInfo
    */
   private void addBrandShop(BrandInfo brandInfo) {
      SearchShopFilter filter = new SearchShopFilter();
      filter.setKey(brandInfo.getName());
      filter.setPageSize(100);
      filter.setTmall(true);
      filter.setSort("(total_auction_des");
      TaoBaoShopInfo taoBaoShop = null;
      for(int page = 1; page < 3; page++) {
         filter.setPage(page);
         List<TaoBaoShopInfo> listShop = TaoKeApiUtil.searchShop(filter);
         if(listShop == null || listShop.size() == 0)
            continue;
         for (TaoBaoShopInfo shop: listShop) {
            String shopTitle = shop.getShopTitle();
            if(StringUtil.isNullOrEmpty(shopTitle))
               continue;
            if(!shopTitle.contains("旗舰店"))
               continue;
            taoBaoShop = shop;
            break;
         }
         if (taoBaoShop != null)
            break;
      }
      BrandShopCahe brandShop = new BrandShopCahe();
      brandShop.setBrandId(brandInfo.getId());
      brandShop.setShop(ShopInfoVOFactory.convertTaoBaoShop(taoBaoShop));
      brandShop.setCreateTime(new Date());
      brandShop.setUpdateTime(new Date());
      brandShopCaheDao.save(brandShop);
   }
}