yujian
2020-01-18 f4a0f2acc63d7785eab108419a4e16f5f688cb95
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java
@@ -3,7 +3,9 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
@@ -14,6 +16,7 @@
import org.yeshi.utils.JsonUtil;
import com.yeshi.fanli.dao.mybatis.brand.BrandClassShopMapper;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.entity.brand.BrandClass;
import com.yeshi.fanli.entity.brand.BrandClassShop;
import com.yeshi.fanli.entity.goods.CommonGoods;
@@ -27,8 +30,9 @@
import com.yeshi.fanli.service.inter.brand.TaoBaoShopHistoryService;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
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.service.inter.taobao.TaoBaoShopService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -64,13 +68,16 @@
   @Resource
   private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
   @Resource
   private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
   @Override
   public List<BrandClassShop> getExistByShopIds(List<Long> list) {
      return brandClassShopMapper.getExistByShopIds(list);
   }
   @Override
   @Transactional
   @Transactional(rollbackFor=Exception.class)
   public String saveShopInfo(Long cid, List<Long> list) throws BrandClassShopException {
      if (list == null || list.size() == 0) {
         throw new BrandClassShopException(1, "请选择店铺");
@@ -127,9 +134,9 @@
   }
   @Override
   @Transactional
   public void changeShopInfo(MultipartFile file, Long id, Long cid, String shopName, Integer state, Integer top,String key)
         throws BrandClassShopException {
   @Transactional(rollbackFor=Exception.class)
   public void changeShopInfo(MultipartFile file, Long id, Long cid, String shopName, Integer state, Integer top,
         String key) throws BrandClassShopException {
      if (id == null) {
         throw new BrandClassShopException(1, "数据为空:请选择店铺");
@@ -150,7 +157,7 @@
      }
      // 自定义图片
      taoBaoShopService.changeInfo(file, shop.getId(), shopName,key);
      taoBaoShopService.changeInfo(file, shop.getId(), shopName, key);
      BrandClassShop updateshop = new BrandClassShop();
      updateshop.setState(state);
@@ -170,7 +177,8 @@
      for (BrandClassShop brandClassShop : listQuery) {
         TaoBaoShop shop = brandClassShop.getShop();
         if (shop != null) {
            long couponNum = commonGoodsService.countBySellerIdAndHasCoupon(shop.getId(), Constant.SOURCE_TYPE_TAOBAO);
            long couponNum = commonGoodsService.countBySellerIdAndHasCoupon(shop.getId(),
                  Constant.SOURCE_TYPE_TAOBAO);
            brandClassShop.setCouponNum(couponNum);
            String shopLink = shop.getShopLink();
@@ -306,6 +314,9 @@
         count = taoBaoShopService.countBrandShopinfo(cid);
      }
      // 淘宝商品信息过滤
      Map<Long, TaoBaoGoodsBrief> goodsMap = getFilterTaoBaoGoods(listInfo);
      BigDecimal proportion = hongBaoManageService.getFanLiRate();
      for (TaoBaoShopVO taoBaoShopVO : listInfo) {
@@ -327,7 +338,8 @@
         List<TaoBaoGoodsBriefExtra> listGoods = new ArrayList<TaoBaoGoodsBriefExtra>();
         List<TaoBaoGoodsBrief> listGoodsBrief = taoBaoShopVO.getListGoodsBrief();
         for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoodsBrief) {
            listGoods.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null));
            listGoods.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsMap.get(taoBaoGoodsBrief.getAuctionId()),
                  proportion.toString(), null));
         }
         taoBaoShopVO.setListGoods(listGoods);
      }
@@ -337,11 +349,28 @@
      return data;
   }
   /**
    * 获取过滤商品
    *
    * @param listInfo
    * @return
    */
   private Map<Long, TaoBaoGoodsBrief> getFilterTaoBaoGoods(List<TaoBaoShopVO> listInfo) {
      // 过滤商品
      List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
      for (TaoBaoShopVO taoBaoShopVO : listInfo) {
         goodsList.addAll(taoBaoShopVO.getListGoodsBrief());
      }
      goodsList = taoBaoGoodsUpdateService.filterImportantTaoBaoGoods(goodsList);
      Map<Long, TaoBaoGoodsBrief> goodsMap = new HashMap<>();
      for (TaoBaoGoodsBrief goods : goodsList)
         goodsMap.put(goods.getAuctionId(), goods);
      return goodsMap;
   }
   @Override
   @Cacheable(value = "brandCache", key = "'listEffectiveCacheV2-'+#page+'-'+#cid")
   public JSONObject listEffectiveCacheV2(int page, Long cid) {
   @Cacheable(value = "brandCache", key = "'listEffectiveCacheV2-'+#page+'-'+#cid+'-'+#platform+'-'+#version")
   public JSONObject listEffectiveCacheV2(int page, Long cid,String platform,String version) {
      long countShop = 0;
      if (cid != null && cid <= 0) {
@@ -361,14 +390,14 @@
         for (BrandClassShop brandClassShop : list) {
            TaoBaoShop shop = brandClassShop.getShop();
            if (shop != null) {
               Integer userType = shop.getUserType();
               if (userType == null || userType == 0) {
                  shop.setUserType(10);
               } else {
                  shop.setUserType(11);
               }
               String shopLink = shop.getShopLink();
               if (StringUtil.isNullOrEmpty(shopLink)) {
                  shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
@@ -402,8 +431,11 @@
         count = taoBaoShopService.countBrandShopinfo(cid);
      }
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      ConfigParamsDTO paramsDTO =    hongBaoManageService.getShowComputeRate(platform, version);
      // 淘宝商品信息过滤
      Map<Long, TaoBaoGoodsBrief> goodsMap = getFilterTaoBaoGoods(listInfo);
      for (TaoBaoShopVO taoBaoShopVO : listInfo) {
         Integer userType = taoBaoShopVO.getUserType();
@@ -412,7 +444,7 @@
         } else {
            taoBaoShopVO.setUserType(11);
         }
         String shopLink = taoBaoShopVO.getShopLink();
         if (StringUtil.isNullOrEmpty(shopLink)) {
            taoBaoShopVO.setShopLink(TaoBaoUtil.getShopLink(taoBaoShopVO.getId()));
@@ -430,8 +462,12 @@
         List<GoodsDetailVO> listGoods = new ArrayList<GoodsDetailVO>();
         List<TaoBaoGoodsBrief> listGoodsBrief = taoBaoShopVO.getListGoodsBrief();
         // 商品添加到更新队列
         taoBaoGoodsUpdateService.addUpdateQueueAsync(listGoodsBrief);
         for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoodsBrief) {
            GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, null, fanLiRate, shareRate);
            GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory
                  .convertTaoBao(goodsMap.get(taoBaoGoodsBrief.getAuctionId()),paramsDTO);
            listGoods.add(goodsDetailVO);
         }
         taoBaoShopVO.setListGoodsVO(listGoods);
@@ -441,9 +477,7 @@
      return data;
   }
   @Override
   public void addClick(Long shopId) {
      BrandClassShop brandClassShop = brandClassShopMapper.getByShopId(shopId);
@@ -490,4 +524,98 @@
   }
   @Override
   public List<TaoBaoShopVO> listEffectiveShop(long start, int count, Long cid,String platform,String version) {
      if (cid != null && cid <= 0) {
         cid = null;
      }
      List<TaoBaoShopVO> listInfo = taoBaoShopService.listBrandShopinfo(start, count, cid);
      if (listInfo == null || listInfo.size() == 0)
         return listInfo;
      ConfigParamsDTO paramsDTO =
            hongBaoManageService.getShowComputeRate(platform, version);
      // 淘宝商品信息过滤
      Map<Long, TaoBaoGoodsBrief> goodsMap = getFilterTaoBaoGoods(listInfo);
      for (TaoBaoShopVO taoBaoShopVO : listInfo) {
         String shopNameCustom = taoBaoShopVO.getShopNameCustom();
         if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
            taoBaoShopVO.setShopName(shopNameCustom);
         }
         String shopIconCustom = taoBaoShopVO.getShopIconCustom();
         if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
            taoBaoShopVO.setShopIcon(shopIconCustom);
         }
         List<GoodsDetailVO> listGoods = new ArrayList<GoodsDetailVO>();
         List<TaoBaoGoodsBrief> listGoodsBrief = taoBaoShopVO.getListGoodsBrief();
         // 商品添加到更新队列
         taoBaoGoodsUpdateService.addUpdateQueueAsync(listGoodsBrief);
         for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoodsBrief) {
            GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory
                  .convertTaoBao(goodsMap.get(taoBaoGoodsBrief.getAuctionId()), paramsDTO);
            listGoods.add(goodsDetailVO);
         }
         taoBaoShopVO.setListGoodsVO(listGoods);
      }
      return listInfo;
   }
   @Override
   public long countBrandShopinfo(Long cid) {
      if (cid != null && cid <= 0) {
         cid = null;
      }
      return taoBaoShopService.countBrandShopinfo(cid);
   }
   @Override
   public List<TaoBaoShop> listEffectiveClassShop(Long cid) {
      if (cid == null)
         return null;
      List<BrandClassShop> list = brandClassShopMapper.listEffective(cid);
      if (list == null || list.size() == 0)
         return null;
       List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
      for (BrandClassShop brandClassShop : list) {
         TaoBaoShop shop = brandClassShop.getShop();
         if (shop != null) {
            Integer userType = shop.getUserType();
            if (userType == null || userType == 0) {
               shop.setUserType(10);
            } else {
               shop.setUserType(11);
            }
            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);
         }
      }
      return listShop;
   }
}