| | |
| | | package com.ruoyi.goods.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.goods.domain.MemberGoodsCollection; |
| | | import com.ruoyi.goods.mapper.GoodsSkuMapper; |
| | | import com.ruoyi.goods.mapper.MemberGoodsCollectionMapper; |
| | | import com.ruoyi.goods.service.IMemberGoodsCollectionService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.system.api.domain.AuctionGoods; |
| | | import com.ruoyi.system.api.domain.GoodsSku; |
| | | import com.ruoyi.system.api.domain.dto.AuctionCollectionDTO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionGoodsListVO; |
| | | import com.ruoyi.system.api.domain.vo.HomeGoodsSkuListVO; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class MemberGoodsCollectionServiceImpl extends ServiceImpl<MemberGoodsCollectionMapper, MemberGoodsCollection> implements IMemberGoodsCollectionService { |
| | | |
| | | |
| | | @Resource |
| | | private GoodsSkuMapper goodsSkuMapper; |
| | | |
| | | @Override |
| | | public void saveGoodsCollection(AuctionCollectionDTO auctionCollectionDTO) { |
| | | if (auctionCollectionDTO.getMemberId()!=null) { |
| | | throw new ServiceException("用户ID不能为空"); |
| | | } |
| | | if (auctionCollectionDTO.getState()!=null) { |
| | | throw new ServiceException("类型不能为空"); |
| | | } |
| | | |
| | | LambdaQueryWrapper< MemberGoodsCollection> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(MemberGoodsCollection::getMemberId,auctionCollectionDTO.getMemberId()); |
| | | wrapper.eq(MemberGoodsCollection::getTargetId,auctionCollectionDTO.getGoodsSkuId()); |
| | | if (auctionCollectionDTO.getState()==1){ |
| | | List<MemberGoodsCollection> list = this.list(wrapper); |
| | | if (list.size()==0){ |
| | | MemberGoodsCollection m =new MemberGoodsCollection(); |
| | | m.setMemberId(auctionCollectionDTO.getMemberId()); |
| | | m.setTargetId(auctionCollectionDTO.getGoodsSkuId()); |
| | | this.save(m); |
| | | } |
| | | }else{ |
| | | List<MemberGoodsCollection> list = this.list(wrapper); |
| | | if (list.size()>0){ |
| | | for (MemberGoodsCollection memberArticleCollection:list){ |
| | | this.removeById(memberArticleCollection); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PageDTO<HomeGoodsSkuListVO> getGoodsCollectionList(AuctionCollectionDTO auctionCollectionDTO) { |
| | | Page<HomeGoodsSkuListVO> page = new Page<>(); |
| | | page.setSize(auctionCollectionDTO.getPageSize()); |
| | | page.setCurrent(auctionCollectionDTO.getPageCurr()); |
| | | LambdaQueryWrapper< MemberGoodsCollection> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(MemberGoodsCollection::getMemberId,auctionCollectionDTO.getMemberId()); |
| | | List<MemberGoodsCollection> list = this.list(wrapper); |
| | | |
| | | List<HomeGoodsSkuListVO> auctionGoodsVOS=new ArrayList<>(); |
| | | for (MemberGoodsCollection auctionCollection:list){ |
| | | HomeGoodsSkuListVO auctionGoodsVO=new HomeGoodsSkuListVO(); |
| | | GoodsSku goodsSku = goodsSkuMapper.selectById(auctionCollection.getTargetId()); |
| | | auctionGoodsVO.setId(goodsSku.getId()); |
| | | auctionGoodsVO.setPrice(goodsSku.getPrice()); |
| | | auctionGoodsVO.setCoverPic(goodsSku.getCoverPic()); |
| | | auctionGoodsVO.setSkuName(goodsSku.getSkuName()); |
| | | auctionGoodsVO.setSoldQuantity(goodsSku.getSoldQuantity()); |
| | | auctionGoodsVO.setIsCollection(2); |
| | | } |
| | | page.setRecords(auctionGoodsVOS); |
| | | return PageDTO.of(page); |
| | | } |
| | | } |