yujian
2020-06-09 554de444b87aab5f93cb1593a8095612cf9479a7
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CollectionGoodsV2ServiceImpl.java
@@ -11,6 +11,8 @@
import com.yeshi.fanli.dao.mybatis.goods.CollectionGoodsV2Mapper;
import com.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
import com.yeshi.fanli.dto.vip.goods.VIPGoodsInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
import com.yeshi.fanli.entity.goods.CommonGoods;
@@ -34,99 +36,75 @@
   @Resource
   private CommonGoodsService commonGoodsService;
   @Transactional(rollbackFor=Exception.class)
   private void addCollection(Long uid, CommonGoods commonGoods) throws CollectionGoodsException {
      if (commonGoods == null)
         throw new CollectionGoodsException(2, "商品信息获取失败");
      // 判断商品是否存在
      try {
         commonGoods = commonGoodsService.addOrUpdateCommonGoods(commonGoods);
      } catch (CommonGoodsException e) {
         commonGoods = null;
      }
      if (commonGoods == null || commonGoods.getId() == null)
         throw new CollectionGoodsException(3, "商品信息添加失败");
      CollectionGoodsV2 collectionGoodsV2 = collectionGoodsV2Mapper.selectByUidAndCommonGoodsId(uid,
            commonGoods.getId());
      if (collectionGoodsV2 != null)
         throw new CollectionGoodsException(4, "商品已被收藏");
      collectionGoodsV2 = new CollectionGoodsV2();
      collectionGoodsV2.setCommonGoods(commonGoods);
      collectionGoodsV2.setCreateTime(new Date());
      collectionGoodsV2.setUpdateTime(new Date());
      collectionGoodsV2.setUserInfo(new UserInfo(uid));
      collectionGoodsV2Mapper.insertSelective(collectionGoodsV2);
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void addCollection(Long uid, TaoBaoGoodsBrief goods) throws CollectionGoodsException {
      if (uid == null || uid == 0)
         throw new CollectionGoodsException(1, "无用户ID");
      CommonGoods commonGoods = CommonGoodsFactory.create(goods);
      if (commonGoods == null)
         throw new CollectionGoodsException(2, "商品信息获取失败");
      // 判断商品是否存在
      try {
         commonGoods = commonGoodsService.addOrUpdateCommonGoods(commonGoods);
      } catch (CommonGoodsException e) {
         commonGoods = null;
      }
      if (commonGoods == null || commonGoods.getId() == null)
         throw new CollectionGoodsException(3, "商品信息添加失败");
      CollectionGoodsV2 collectionGoodsV2 = collectionGoodsV2Mapper.selectByUidAndCommonGoodsId(uid,
            commonGoods.getId());
      if (collectionGoodsV2 != null)
         throw new CollectionGoodsException(4, "商品已被收藏");
      collectionGoodsV2 = new CollectionGoodsV2();
      collectionGoodsV2.setCommonGoods(commonGoods);
      collectionGoodsV2.setCreateTime(new Date());
      collectionGoodsV2.setUpdateTime(new Date());
      collectionGoodsV2.setUserInfo(new UserInfo(uid));
      collectionGoodsV2Mapper.insertSelective(collectionGoodsV2);
      addCollection(uid,commonGoods);
   }
   @Transactional(rollbackFor=Exception.class)
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void addJDCollection(Long uid, JDGoods jdGoods) throws CollectionGoodsException {
      if (uid == null || uid == 0)
         throw new CollectionGoodsException(1, "无用户ID");
      CommonGoods commonGoods = CommonGoodsFactory.create(jdGoods);
      if (commonGoods == null)
         throw new CollectionGoodsException(2, "商品信息获取失败");
      // 判断商品是否存在
      try {
         commonGoods = commonGoodsService.addOrUpdateCommonGoods(commonGoods);
      } catch (CommonGoodsException e) {
         commonGoods = null;
      }
      if (commonGoods == null || commonGoods.getId() == null)
         throw new CollectionGoodsException(3, "商品信息添加失败");
      CollectionGoodsV2 collectionGoodsV2 = collectionGoodsV2Mapper.selectByUidAndCommonGoodsId(uid,
            commonGoods.getId());
      if (collectionGoodsV2 != null)
         throw new CollectionGoodsException(4, "商品已被收藏");
      collectionGoodsV2 = new CollectionGoodsV2();
      collectionGoodsV2.setCommonGoods(commonGoods);
      collectionGoodsV2.setCreateTime(new Date());
      collectionGoodsV2.setUpdateTime(new Date());
      collectionGoodsV2.setUserInfo(new UserInfo(uid));
      collectionGoodsV2Mapper.insertSelective(collectionGoodsV2);
      addCollection(uid,commonGoods);
   }
   @Transactional(rollbackFor=Exception.class)
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void addPDDCollection(Long uid, PDDGoodsDetail goods) throws CollectionGoodsException {
      if (uid == null || uid == 0)
         throw new CollectionGoodsException(1, "无用户ID");
      CommonGoods commonGoods = CommonGoodsFactory.create(goods);
      if (commonGoods == null)
         throw new CollectionGoodsException(2, "商品信息获取失败");
      // 判断商品是否存在
      try {
         commonGoods = commonGoodsService.addOrUpdateCommonGoods(commonGoods);
      } catch (CommonGoodsException e) {
         commonGoods = null;
      }
      if (commonGoods == null || commonGoods.getId() == null)
         throw new CollectionGoodsException(3, "商品信息添加失败");
      CollectionGoodsV2 collectionGoodsV2 = collectionGoodsV2Mapper.selectByUidAndCommonGoodsId(uid,
            commonGoods.getId());
      if (collectionGoodsV2 != null)
         throw new CollectionGoodsException(4, "商品已被收藏");
      collectionGoodsV2 = new CollectionGoodsV2();
      collectionGoodsV2.setCommonGoods(commonGoods);
      collectionGoodsV2.setCreateTime(new Date());
      collectionGoodsV2.setUpdateTime(new Date());
      collectionGoodsV2.setUserInfo(new UserInfo(uid));
      collectionGoodsV2Mapper.insertSelective(collectionGoodsV2);
      addCollection(uid,commonGoods);
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void addVIPCollection(Long uid, VIPGoodsInfo goods) throws CollectionGoodsException {
      if (uid == null || uid == 0)
         throw new CollectionGoodsException(1, "无用户ID");
      CommonGoods commonGoods = CommonGoodsFactory.create(goods);
      addCollection(uid,commonGoods);
   }
   @Override
   public void addSuningCollection(Long uid, SuningGoodsInfo goods) throws CollectionGoodsException {
      if (uid == null || uid == 0)
         throw new CollectionGoodsException(1, "无用户ID");
      CommonGoods commonGoods = CommonGoodsFactory.create(goods);
      addCollection(uid,commonGoods);
   }
   @Override
   public void addCollection(CollectionGoodsV2 goods) throws CollectionGoodsException {
      if (goods.getUserInfo() == null || goods.getCommonGoods() == null)
@@ -148,7 +126,7 @@
      collectionGoodsV2Mapper.insertSelective(goods);
   }
   @Transactional(rollbackFor=Exception.class)
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void cancelCollection(Long uid, Long id) throws CollectionGoodsException {
      if (uid == null || uid == 0)
@@ -166,8 +144,10 @@
   }
   @Override
   public List<CollectionGoodsV2> getCollectionGoodsList(Long uid, int page, int pageSize, Integer source, boolean notBackSuVip) {
      return collectionGoodsV2Mapper.selectByUidOrderByCreateTimeDesc(uid, (page - 1) * pageSize, pageSize, source, notBackSuVip);
   public List<CollectionGoodsV2> getCollectionGoodsList(Long uid, int page, int pageSize, Integer source,
         boolean notBackSuVip) {
      return collectionGoodsV2Mapper.selectByUidOrderByCreateTimeDesc(uid, (page - 1) * pageSize, pageSize, source,
            notBackSuVip);
   }
   @Override
@@ -176,7 +156,8 @@
   }
   @Override
   public void cancelCollectionByAuctionId(Long uid, Long auctionId, Integer goodsType) throws CollectionGoodsException {
   public void cancelCollectionByAuctionId(Long uid, Long auctionId, Integer goodsType)
         throws CollectionGoodsException {
      CollectionGoodsV2 goodsV2 = collectionGoodsV2Mapper.selectByUidAndGoodsType(uid, auctionId, goodsType);
      if (goodsV2 == null)
         throw new CollectionGoodsException(1, "无收藏");
@@ -193,12 +174,12 @@
      CollectionGoodsV2 v2 = collectionGoodsV2Mapper.selectByUidAndGoodsType(uid, actionId, goodsType);
      return v2;
   }
   @Override
   public void deteleBYByUidAndCommonId(Long uid, Long commonId) {
      List<CollectionGoodsV2> list = collectionGoodsV2Mapper.getByUidAndCommonId(uid, commonId);
      if (list != null && list.size() > 0) {
         for (CollectionGoodsV2 v2: list) {
         for (CollectionGoodsV2 v2 : list) {
            collectionGoodsV2Mapper.deleteByPrimaryKey(v2.getId());
         }
      }