admin
2019-05-16 4114e871bcb3dce771b6aed64a1027d0bbb95ca6
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java
@@ -7,7 +7,6 @@
import javax.annotation.Resource;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -61,16 +60,6 @@
   private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
   
   @Override
   public List<BrandClassShop> listEffective(long start, int count, Long cid) {
      return brandClassShopMapper.listEffective(start, count, cid);
   }
   @Override
   public long countEffective(Long cid) {
      return brandClassShopMapper.countEffective(cid);
   }
   @Override
   public List<BrandClassShop> getExistByShopIds(List<Long> list){
@@ -183,7 +172,15 @@
            long couponNum = commonGoodsService.countBySellerIdAndHasCoupon(shop.getId());
            brandClassShop.setCouponNum(couponNum);
            
            shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
            String shopLink = shop.getShopLink();
            if (StringUtil.isNullOrEmpty(shopLink)) {
               shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
            }
            String shopNameCustom = shop.getShopNameCustom();
            if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
               shop.setShopName(shopNameCustom);
            }
            
            String shopIconCustom = shop.getShopIconCustom();
            if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
@@ -210,6 +207,14 @@
      for (Long id: list) {
         brandClassShopMapper.deleteByPrimaryKey(id);
      }
   }
   @Override
   public void deleteBatchByClassId(List<Long> list) {
      if (list == null || list.size() == 0) {
         return;
      }
      brandClassShopMapper.deleteBatchByClassId(list);
   }
   
   
@@ -251,108 +256,91 @@
   @Override
   @Cacheable(value = "brandCache", key = "'listEffectiveCache-'+#page+'-'+#cid")
   public JSONObject listEffectiveCache(int page, Long cid) {
      long count = 0;
      int pageSize = Constant.PAGE_SIZE;
      List<BrandClassShop> list = brandClassShopMapper.listEffective((page - 1) * pageSize, pageSize, cid);
      if (list == null) {
         list = new ArrayList<BrandClassShop>();
      } else if (list.size() > 0) {
         count = brandClassShopMapper.countEffective(cid);
      long countShop = 0;
      if (cid != null && cid <= 0) {
         cid = null;
      }
      JSONObject data = new JSONObject();
      if (page == 1 && cid != null && cid > 0 && count > pageSize) {
         List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
         List<BrandClassShop> listBrand = brandClassShopMapper.listEffective(0, Integer.MAX_VALUE, cid);
         for (BrandClassShop brandClassShop : listBrand) {
            TaoBaoShop shop = brandClassShop.getShop();
            if (shop != null) {
               String shopIconCustom = shop.getShopIconCustom();
               if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
                  shop.setShopIcon(shopIconCustom);
               }
               listShop.add(shop);
            }
      List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
      // 第一页 查询全部分类下店铺
      if (page == 1 &&  cid != null) {
         List<BrandClassShop> list = brandClassShopMapper.listEffective(cid);
         if (list == null) {
            list = new ArrayList<BrandClassShop>();
         } else if (list.size() > 0) {
            countShop = brandClassShopMapper.countEffective(cid);
         }
         data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop));
      } else if (page == 1 && cid != null && cid > 0) {
         List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
         for (BrandClassShop brandClassShop : list) {
            TaoBaoShop shop = brandClassShop.getShop();
            if (shop != null) {
               String shopLink = shop.getShopLink();
               if (StringUtil.isNullOrEmpty(shopLink)) {
                  shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
               }
               String shopNameCustom = shop.getShopNameCustom();
               if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
                  shop.setShopName(shopNameCustom);
               }
               String shopIconCustom = shop.getShopIconCustom();
               if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
                  shop.setShopIcon(shopIconCustom);
               }
               listShop.add(shop);
            }
         }
         data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop));
      }
      List<TaoBaoShopVO> listVO = new ArrayList<TaoBaoShopVO>();
      for (BrandClassShop brandClassShop : list) {
         TaoBaoShop shop = brandClassShop.getShop();
         if (shop == null) {
            continue;
      JSONObject data = new JSONObject();
      data.put("countShop", countShop);
      data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop));
      long count = 0;
      List<TaoBaoShopVO> listInfo = taoBaoShopService.listBrandShopinfo((page-1)*Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid);
      if (listInfo == null) {
         listInfo = new ArrayList<TaoBaoShopVO>();
      } else if (listInfo.size() > 0) {
         count = taoBaoShopService.countBrandShopinfo(cid);
      }
      BigDecimal proportion = manageService.getFanLiRate();
      for (TaoBaoShopVO taoBaoShopVO : listInfo) {
         String shopLink = taoBaoShopVO.getShopLink();
         if (StringUtil.isNullOrEmpty(shopLink)) {
            taoBaoShopVO.setShopLink(TaoBaoUtil.getShopLink(taoBaoShopVO.getId()));
         }
         
         String shopIconCustom = shop.getShopIconCustom();
         String shopNameCustom = taoBaoShopVO.getShopNameCustom();
         if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
            taoBaoShopVO.setShopName(shopNameCustom);
         }
         String shopIconCustom = taoBaoShopVO.getShopIconCustom();
         if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
            shop.setShopIcon(shopIconCustom);
            taoBaoShopVO.setShopIcon(shopIconCustom);
         }
         
         List<Long> listgid = new ArrayList<Long>();
         listgid.add(543572782962L);
         listgid.add(578504974101L);
         listgid.add(530275132249L);
         
         BigDecimal proportion = manageService.getFanLiRate();
         List<TaoBaoGoodsBriefExtra> listGoods = new ArrayList<TaoBaoGoodsBriefExtra>();
         List<TaoBaoGoodsBrief> listgd = taoBaoGoodsBriefService.listQueryByAuctionId(listgid);
         for (TaoBaoGoodsBrief taoBaoGoodsBrief : listgd) {
         List<TaoBaoGoodsBrief> listGoodsBrief = taoBaoShopVO.getListGoodsBrief();
         for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoodsBrief) {
            listGoods.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null));
         }
//         List<QualityFactory> listFactory = qualityGoodsService.listByShopId(0, 3, shop.getId());
//         if (listFactory == null || listFactory.size() < 3) {
//            count --;
//            continue;
//         }
//
//         List<TaoBaoGoodsBriefExtra> listGoods = new ArrayList<TaoBaoGoodsBriefExtra>();
//         BigDecimal proportion = manageService.getFanLiRate();
//         for (QualityFactory selectionGoods : listFactory) {
//            TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
//            if (taoBaoGoodsBrief == null) {
//               break;
//            }
//            listGoods.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null));
//         }
//
//         if (listGoods == null || listGoods.size() < 3) {
//            count --;
//            continue;
//         }
//
         TaoBaoShopVO vo = new TaoBaoShopVO();
         try {
            PropertyUtils.copyProperties(vo, shop);
         } catch (Exception e) {
            e.printStackTrace();
         }
         vo.setListGoods(listGoods);
         listVO.add(vo);
         taoBaoShopVO.setListGoods(listGoods);
      }
      data.put("count", count);
      data.put("list", JsonUtil.getApiCommonGson().toJson(listVO));
      data.put("list", JsonUtil.getApiCommonGson().toJson(listInfo));
      
      return data;
   }
   
   @Override
   public void addClick(Long shopId) {
      BrandClassShop brandClassShop = brandClassShopMapper.getByShopId(shopId);