yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CollectionGoodsV2ServiceImpl.java
@@ -11,11 +11,11 @@
import com.yeshi.fanli.dao.mybatis.goods.CollectionGoodsV2Mapper;
import com.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.goods.CollectionGoodsException;
import com.yeshi.fanli.exception.goods.CommonGoodsException;
import com.yeshi.fanli.goods.CollectionGoodsV2;
import com.yeshi.fanli.goods.CommonGoods;
import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service;
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.util.factory.CommonGoodsFactory;
@@ -62,7 +62,27 @@
      collectionGoodsV2Mapper.insertSelective(collectionGoodsV2);
   }
   @Override
   public void addCollection(CollectionGoodsV2 goods) throws CollectionGoodsException {
      if (goods.getUserInfo() == null || goods.getCommonGoods() == null)
         throw new CollectionGoodsException(1, "数据不完整");
      try {
         CommonGoods commonGoods = commonGoodsService.addOrUpdateCommonGoods(goods.getCommonGoods());
         goods.setCommonGoods(commonGoods);
      } catch (CommonGoodsException e) {
         goods.setCommonGoods(null);
      }
      if (goods.getCommonGoods() == null)
         throw new CollectionGoodsException(3, "商品信息添加失败");
      CollectionGoodsV2 collectionGoodsV2 = collectionGoodsV2Mapper
            .selectByUidAndCommonGoodsId(goods.getUserInfo().getId(), goods.getCommonGoods().getId());
      if (collectionGoodsV2 != null)
         throw new CollectionGoodsException(4, "商品已被收藏");
      collectionGoodsV2Mapper.insertSelective(goods);
   }
   @Transactional
   @Override
   public void cancelCollection(Long uid, Long id) throws CollectionGoodsException {
@@ -82,12 +102,33 @@
   @Override
   public List<CollectionGoodsV2> getCollectionGoodsList(Long uid, int page, int pageSize) {
      return null;
      return collectionGoodsV2Mapper.selectByUidOrderByCreateTimeDesc(uid, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long getCollectionGoodsCount(Long uid) {
      return 0;
      return collectionGoodsV2Mapper.selectCountByUid(uid);
   }
   @Override
   public void cancelCollectionByAuctionId(Long uid, Long auctionId) throws CollectionGoodsException {
      CollectionGoodsV2 goodsV2 = collectionGoodsV2Mapper.selectByUidAndGoodsTypeAndGoodsId(uid,
            CommonGoods.GOODS_TYPE_TB, auctionId);
      if (goodsV2 == null)
         throw new CollectionGoodsException(1, "无收藏");
      collectionGoodsV2Mapper.deleteByPrimaryKey(goodsV2.getId());
   }
   @Override
   public void cancelCollectionByUid(Long uid) throws CollectionGoodsException {
      collectionGoodsV2Mapper.deleteByUid(uid);
   }
   @Override
   public CollectionGoodsV2 findByUidAndAuctionId(Long uid, Long actionId) {
      CollectionGoodsV2 v2 = collectionGoodsV2Mapper.selectByUidAndGoodsTypeAndGoodsId(uid, CommonGoods.GOODS_TYPE_TB,
            actionId);
      return v2;
   }
}