admin
2019-07-30 573c491b4a1ba60e12a5678a01c1546c0077c1ee
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoGoodsUpdateServiceImpl.java
@@ -12,14 +12,17 @@
import com.google.gson.Gson;
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.goods.CommonGoodsException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsUpdateException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.activity.ActivityService;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.goods.RecommendSectionGoodsService;
import com.yeshi.fanli.service.inter.lable.QualityFactoryService;
import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService;
import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
import com.yeshi.fanli.util.BeanUtil;
import com.yeshi.fanli.util.StringUtil;
@@ -28,8 +31,6 @@
@Service
public class TaoBaoGoodsUpdateServiceImpl implements TaoBaoGoodsUpdateService {
   @Resource
   private RecommendSectionGoodsService recommendSectionGoodsService;
   @Resource
   private ActivityService activityService;
@@ -42,6 +43,12 @@
   @Resource
   private CommonGoodsService commonGoodsService;
   @Resource
   private ShareHotGoodsService shareHotGoodsService;
   @Resource
   private TLJBuyGoodsService tljBuyGoodsService;
   @Override
   public void startUpdate() {
@@ -60,7 +67,7 @@
            }
         } catch (TaobaoGoodsDownException e) {
            downTaoBaoGoods(goods.getAuctionId());
            offlineTaoBaoGoods(goods.getAuctionId());
         } catch (Exception e) {
         }
@@ -70,11 +77,8 @@
   @Transactional
   @Override
   public void deleteTaoBaoGoods(Long auctionId) {
      // 删除首页推荐数据
      recommendSectionGoodsService.deleteRecommendSectionGoodsByTbAuctionId(auctionId);
      // 删除精选库相关的数据
      qualityFactoryService.deleteByTbAuctionId(auctionId);
      qualityFactoryService.deleteByTaoBaoGoodsId(auctionId);
      // 删除商品本身数据
      taoBaoGoodsBriefMapper.deleteByAuctionId(auctionId);
@@ -82,17 +86,22 @@
   @Transactional
   @Override
   public void downTaoBaoGoods(Long auctionId) {
      // 删除首页推荐数据
      recommendSectionGoodsService.deleteRecommendSectionGoodsByTbAuctionId(auctionId);
   public void offlineTaoBaoGoods(Long auctionId) {
      // 更新动态数据
      activityService.downTaoBaoGoods(auctionId);
      // 删除精选库相关的数据
      qualityFactoryService.deleteByTbAuctionId(auctionId);
      qualityFactoryService.deleteByTaoBaoGoodsId(auctionId);
      // 删除商品本身数据
      taoBaoGoodsBriefMapper.deleteByAuctionId(auctionId);
      // 更新简版商品状态为下架
      commonGoodsService.offlineCommonGoods(auctionId, CommonGoods.GOODS_TYPE_TB);
      // 分享爆款数据删除
      shareHotGoodsService.deleteByGoodsId(auctionId);
   }
   @Transactional
@@ -104,6 +113,8 @@
      if (goods.getAuctionId() == null || goods.getAuctionId() == 0)
         throw new TaobaoGoodsUpdateException(2, "商品ID为空");
      // 设置商品正常上线
      goods.setState(0);
      // 更新收藏信息
      try {
         commonGoodsService.updateCommonGoods(CommonGoodsFactory.create(goods));
@@ -111,20 +122,26 @@
         e.printStackTrace();
      }
      List<TaoBaoGoodsBrief> goodsList = taoBaoGoodsBriefMapper.queryByAuctionId(goods.getAuctionId());
      if (goodsList != null)
         for (TaoBaoGoodsBrief tb : goodsList) {
            goods.setId(tb.getId());
            TaoBaoGoodsBrief updateGoods = getUpdateTaoBaoGoodsBrief(goods);
            System.out.println("更细信息:" + new Gson().toJson(updateGoods));
            taoBaoGoodsBriefMapper.updateByPrimaryKeySelective(updateGoods);
      TaoBaoGoodsBrief tb = taoBaoGoodsBriefMapper.selectByPrimaryKey(goods.getAuctionId());
      if (tb != null) {
         goods.setId(tb.getId());
         TaoBaoGoodsBrief updateGoods = getUpdateTaoBaoGoodsBrief(goods);
         System.out.println("更细信息:" + new Gson().toJson(updateGoods));
         taoBaoGoodsBriefMapper.updateByPrimaryKeySelective(updateGoods);
      }
         }
      // 更新动态商品
      activityService.updateRecommendActivityGoods(goods);
      // 更新分享库的商品
      shareHotGoodsService.updateShareGoods(goods);
      // 更新自购立减库商品
      tljBuyGoodsService.updateGoods(goods);
   }
   @Override
   public void deleteOutOfDate() {
      TaoBaoGoodsBriefMapper taoBaoGoodsBriefMapper = BeanUtil.getBean(TaoBaoGoodsBriefMapper.class);
      List<Long> list = taoBaoGoodsBriefMapper
            .queryCanDeleteGoods(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 2), 0, 2000);
      for (Long auctionId : list) {
@@ -145,6 +162,7 @@
      // 更新标题,商品图片,销量,价格,券信息,返利信息,店铺信息,分类信息
      updateGoods.setTitle(goods.getTitle());
      updateGoods.setPictUrl(goods.getPictUrl());
      updateGoods.setPictUrlWhite(goods.getPictUrlWhite());
      updateGoods.setImgList(goods.getImgList());
      updateGoods.setBiz30day(goods.getBiz30day());
      updateGoods.setZkPrice(goods.getZkPrice());
@@ -182,6 +200,7 @@
      updateGoods.setRootCategoryName(goods.getRootCategoryName());
      updateGoods.setLeafCatId(goods.getLeafCatId());
      updateGoods.setLeafName(goods.getLeafName());
      updateGoods.setMaterialLibType(goods.getMaterialLibType());
      return updateGoods;
   }
@@ -192,21 +211,58 @@
         throw new TaobaoGoodsUpdateException(1, "商品列表为空");
      List<TaoBaoGoodsBrief> updateList = new ArrayList<>();
      for (TaoBaoGoodsBrief goods : goodsList) {
         if (goods.getId() == null || goods.getId() == 0L) {
            throw new TaobaoGoodsUpdateException(1, "商品主键ID为空");
         }
         // 需要更新的信息
         TaoBaoGoodsBrief updateGoods = getUpdateTaoBaoGoodsBrief(goods);
         updateGoods.setCreatetime(goods.getCreatetime());
         updateList.add(updateGoods);
      }
      taoBaoGoodsBriefMapper.updateBatchSelective(updateList);
   }
   @Override
   public List<Long> listNeedUpdateGoodsId(long start, int count, int hour) {
      return taoBaoGoodsBriefMapper.listNeedUpdateGoodsId(start, count, hour);
   }
   @Override
   public void updateByTaoKeGoodsDetail(Long id) {
      try {
         TaoBaoGoodsBrief oldGoods = taoBaoGoodsBriefMapper.selectByPrimaryKey(id);
         if (oldGoods == null) {
            return;
         }
         TaoBaoGoodsBrief newGoods = TaoKeApiUtil.searchGoodsDetail(id);
         if (newGoods == null) {
            return;
         }
         // 更新精选商品
         newGoods.setId(id);
         TaoBaoGoodsBrief updateGoods = getUpdateTaoBaoGoodsBrief(newGoods);
         taoBaoGoodsBriefMapper.updateByPrimaryKeySelective(updateGoods);
         // 更新动态商品
         activityService.updateRecommendActivityGoods(newGoods);
         // 更新收藏信息
         try {
            commonGoodsService.updateCommonGoods(CommonGoodsFactory.create(newGoods));
         } catch (CommonGoodsException e) {
            e.printStackTrace();
         }
      } catch (TaobaoGoodsDownException e) {
         offlineTaoBaoGoods(id);
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
   }
}