admin
2019-09-20 db88b87df461820152d68d3d55a28f30c2da83e6
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.service.impl.brand;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -9,29 +10,35 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.brand.BrandGoodsCaheDao;
import com.yeshi.fanli.dao.brand.BrandShopCaheDao;
import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.brand.BrandGoodsCahe;
import com.yeshi.fanli.entity.brand.BrandInfo;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
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.brand.BrandShopCaheService;
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.util.StringUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.vo.brand.BrandInfoVO;
import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
@Service
public class BrandInfoServiceImpl implements BrandInfoService {
   @Resource
   private BrandInfoMapper brandInfoMapper;
   @Resource
   private HongBaoManageService hongBaoManageService;
@@ -43,28 +50,29 @@
   @Resource
   private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
   @Resource
   private BrandClassShopService brandClassShopService;
   @Resource
   private BrandShopCaheDao brandShopCaheDao;
   @Resource
   private BrandGoodsCaheDao brandGoodsCaheDao;
   private BrandGoodsCaheService brandGoodsCaheService;
   @Resource
   private BrandShopCaheService brandShopCaheService;
   @Override
   public void saveObject(BrandInfo record) throws BrandInfoException{
   public void saveObject(BrandInfo record) throws BrandInfoException {
      String name = record.getName();
      if (name == null || name.trim().length() == 0)
         throw new BrandInfoException(1, "名称不能为空");
      Integer state = record.getState();
      if (state == null)
         record.setState(0);
      Long id = record.getId();
      if (id == null) {
         record.setCreateTime(new Date());
@@ -74,36 +82,33 @@
         BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id);
         if (resultObj == null)
            throw new BrandInfoException(1, "修改内容已不存在");
         record.setCreateTime(resultObj.getCreateTime());
         record.setUpdateTime(new Date());
         brandInfoMapper.updateByPrimaryKey(record);
      }
   }
   @Override
   public int deleteBatchByPrimaryKey(List<Long> list) {
      return brandInfoMapper.deleteBatchByPrimaryKey(list);
   }
   @Override
   public List<BrandInfo> listQuery(long start, int count, String key, Integer state) {
      return null;
   public List<BrandInfo> listQuery(long start, int count, String key, Long cid, Integer state) {
      return brandInfoMapper.listQuery(start, count, key, cid, state);
   }
   @Override
   public long countQuery(String key, Integer state) {
      return 0;
   public long countQuery(String key, Long cid, Integer state) {
      return brandInfoMapper.countQuery(key, cid, state);
   }
   @Override
   @Cacheable(value = "brandCache", key = "'listValidBrandInfoCache-'+#cid")
   public List<BrandInfo> listValidBrandInfoCache(Long cid) {
      List<BrandInfo> listInfo = new ArrayList<BrandInfo>();
      List<TaoBaoShop> listShop = brandClassShopService.listEffectiveClassShop(cid);
      if (listShop == null || listShop.size() == 0)
         return listInfo;
@@ -116,17 +121,16 @@
      }
      return listInfo;
   }
   @Override
   @Cacheable(value = "brandCache", key = "'listBrandInfoCache-'+#start+'-'+#start +'-'+#cid")
   public List<BrandInfoVO> listBrandInfoCache(long start, int count, Long cid) {
      List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>();
      List<TaoBaoShopVO> listShop = brandClassShopService.listEffectiveShop(start, count, cid);
      if (listShop == null || listShop.size() == 0)
         return listInfo;
      for (TaoBaoShopVO taoBaoShopVO : listShop) {
         String shopNameCustom = taoBaoShopVO.getShopNameCustom();
         if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
@@ -136,7 +140,7 @@
         if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
            taoBaoShopVO.setShopIcon(shopIconCustom);
         }
         BrandInfoVO brandInfoVO = new BrandInfoVO();
         brandInfoVO.setId(taoBaoShopVO.getId());
         brandInfoVO.setName(taoBaoShopVO.getShopName());
@@ -147,18 +151,95 @@
      return listInfo;
   }
   @Override
   public long countBrandInfo(Long cid){
   public long countBrandInfo(Long cid) {
      return brandClassShopService.countBrandShopinfo(cid);
   }
   public void addShopAndGoods(BrandInfo record) {
//      TaoKeApiUtil.searchShop(key, page);
   @Override
   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;
         // 添加商品
         int goodsTotal = brandGoodsCaheService.addBrandGoods(brandInfo);
         brandInfo.setGoodsTotal(goodsTotal);
         brandInfo.setUpdateTime(new Date());
         brandInfoMapper.updateByPrimaryKeySelective(brandInfo);
      }
   }
   @Override
   public long countValidByCid(Long cid) {
      return brandInfoMapper.countValidByCid(cid);
   }
   @Override
   public long countValidByCidToApp(Long cid) {
      return brandInfoMapper.countValidByCidToApp(cid);
   }
   @Override
   @Cacheable(value = "brandCache", key = "'listValidByCidToApp-'+#cid")
   public List<BrandInfo> listValidByCidToApp(Long cid) {
      if (cid == null)
         return null;
      return brandInfoMapper.listValidByCidToApp(cid);
   }
   @Cacheable(value = "brandCache", key = "'listValidToApp-'+#start+'-'+#start +'-'+#cid")
   @Override
   public List<BrandInfoVO> listValidToApp(long start, int count, Long cid) {
      List<BrandInfoVO> list = brandInfoMapper.listBrandInfoVO(start, count, cid);
      if (list == null || list.size() == 0)
         return null;
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      List<BrandInfoVO> listInfo = new ArrayList<BrandInfoVO>();
      for (int i = 0; i < list.size(); i++) {
         BrandInfoVO brand = list.get(i);
         if (brand == null)
            continue;
         List<BrandGoodsCahe> listGoods = brandGoodsCaheService.getByBrandId(1, 3, brand.getId());
         if (listGoods == null || listGoods.size() < 3)
            continue;
         List<GoodsDetailVO> listGoodsVO = new ArrayList<GoodsDetailVO>();
         for (BrandGoodsCahe brandGoods : listGoods) {
            JDGoods goodsJD = brandGoods.getGoodsJD();
            if (goodsJD != null) {
               listGoodsVO.add(GoodsDetailVOFactory.convertJDGoods(goodsJD, fanLiRate, shareRate));
               continue;
            }
            TaoBaoGoodsBrief goodsTB = brandGoods.getGoodsTB();
            if (goodsTB != null) {
               listGoodsVO.add(GoodsDetailVOFactory.convertTaoBao(goodsTB, null, fanLiRate, shareRate));
               continue;
            }
            PDDGoodsDetail goodsPDD = brandGoods.getGoodsPDD();
            if (goodsPDD != null) {
               listGoodsVO.add(GoodsDetailVOFactory.convertPDDGoods(goodsPDD, fanLiRate, shareRate));
               continue;
            }
         }
         if (listGoodsVO.size() >= 3) {
            brand.setListGoods(listGoodsVO);
            listInfo.add(brand);
         }
      }
      return listInfo;
   }
}