1
luofl
2025-03-11 b8dedd4e1962cf4f7984b01d500f950fe5e8fea3
ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/MemberAuctionCollectionServiceImpl.java
@@ -1,9 +1,31 @@
package com.ruoyi.auction.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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.auction.domain.AuctionBidRecord;
import com.ruoyi.auction.domain.MemberAuctionCollection;
import com.ruoyi.auction.mapper.AuctionBidRecordMapper;
import com.ruoyi.auction.mapper.AuctionGoodsMapper;
import com.ruoyi.auction.mapper.MemberAuctionCollectionMapper;
import com.ruoyi.auction.service.IMemberAuctionCollectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.page.PageDTO;
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.dto.AuctionGoodsListPageDTO;
import com.ruoyi.system.api.domain.vo.AuctionGoodsListVO;
import com.ruoyi.system.api.feignClient.GoodsSkuClient;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
/**
@@ -17,4 +39,130 @@
@Service
public class MemberAuctionCollectionServiceImpl extends ServiceImpl<MemberAuctionCollectionMapper, MemberAuctionCollection> implements IMemberAuctionCollectionService {
    @Resource
    private GoodsSkuClient goodsSkuClient;
    @Resource
    private AuctionGoodsMapper auctionGoodsMapper;
    @Resource
    private AuctionBidRecordMapper auctionBidRecordMapper;
    @Override
    public void saveAuctionCollection(AuctionCollectionDTO auctionCollectionDTO) {
        if (auctionCollectionDTO.getMemberId()==null) {
            throw new ServiceException("用户ID不能为空");
        }
        if (auctionCollectionDTO.getState()==null) {
            throw new ServiceException("类型不能为空");
        }
        LambdaQueryWrapper< MemberAuctionCollection> wrapper= Wrappers.lambdaQuery();
        wrapper.eq(MemberAuctionCollection::getMemberId,auctionCollectionDTO.getMemberId());
        wrapper.eq(MemberAuctionCollection::getTargetId,auctionCollectionDTO.getGoodsSkuId());
        if (auctionCollectionDTO.getState()==1){
            List<MemberAuctionCollection> list = this.list(wrapper);
            if (list.size()==0){
                MemberAuctionCollection m =new MemberAuctionCollection();
                m.setMemberId(auctionCollectionDTO.getMemberId());
                m.setTargetId(auctionCollectionDTO.getGoodsSkuId());
                this.save(m);
            }
        }else{
            List<MemberAuctionCollection> list = this.list(wrapper);
            if (list.size()>0){
                for (MemberAuctionCollection memberArticleCollection:list){
                    this.removeById(memberArticleCollection);
                }
            }
        }
    }
    @Override
    public PageDTO<AuctionGoodsListVO> getMemberAuctionCollectionList(AuctionCollectionDTO auctionCollectionDTO) {
        Set<Long> goodsSkuIdList = null;
        if (StringUtils.isNotEmpty(auctionCollectionDTO.getGoodsSkuName())) {
            List<GoodsSku> goodsSku = goodsSkuClient.getGoodsByName(auctionCollectionDTO.getGoodsSkuName(),
                            SecurityConstants.INNER)
                    .getData();
            goodsSkuIdList = goodsSku.stream().map(GoodsSku::getId)
                    .collect(Collectors.toSet());
        }
        AuctionGoodsListPageDTO auctionGoodsListPageDTO=new AuctionGoodsListPageDTO();
        auctionGoodsListPageDTO.setGoodsSkuIdList(goodsSkuIdList);
        Set<Long> goodsSkuIdList1 = new HashSet<>();
        if (StringUtils.isNotEmpty(goodsSkuIdList)){
            for (Long i:goodsSkuIdList){
                LambdaQueryWrapper<AuctionGoods> wrapper= Wrappers.lambdaQuery();
                wrapper.eq(AuctionGoods::getGoodsSkuId,i);
                wrapper.eq(AuctionGoods::getDelFlag,0);
                List<AuctionGoods> auctionGoods = auctionGoodsMapper.selectList(wrapper);
                for (AuctionGoods a:auctionGoods){
                    goodsSkuIdList1.add(a.getId());
                }
            }
        }
        Page<AuctionGoodsListVO> page = new Page<>();
        page.setSize(auctionCollectionDTO.getPageSize());
        page.setCurrent(auctionCollectionDTO.getPageCurr());
        LambdaQueryWrapper<MemberAuctionCollection> wrapper= Wrappers.lambdaQuery();
        wrapper.eq(MemberAuctionCollection::getMemberId,auctionCollectionDTO.getMemberId());
        if (StringUtils.isNotEmpty(auctionCollectionDTO.getGoodsSkuName())){
            if (goodsSkuIdList1.size()>0){
                wrapper.in(MemberAuctionCollection::getTargetId,goodsSkuIdList1);
            }else{
                goodsSkuIdList1=new HashSet<>();
                goodsSkuIdList1.add(0L);
                wrapper.in(MemberAuctionCollection::getTargetId,goodsSkuIdList1);
            }
        }
        wrapper.orderByDesc(MemberAuctionCollection::getCreateTime);
        List<MemberAuctionCollection> list = this.list(wrapper);
        List<AuctionGoodsListVO> auctionGoodsVOS=new ArrayList<>();
        for (MemberAuctionCollection auctionCollection:list){
            AuctionGoods auctionGoods = auctionGoodsMapper.selectById(auctionCollection.getTargetId());
            AuctionGoodsListVO auctionGoodsVO=new AuctionGoodsListVO();
            auctionGoodsVO.setAuctionStock(auctionGoods.getAuctionStock());
            auctionGoodsVO.setGoodsSkuId(auctionGoods.getId());
            auctionGoodsVO.setEndTime(auctionGoods.getEndTime());
            auctionGoodsVO.setStartTime(auctionGoods.getStartTime());
            auctionGoodsVO.setStartingPrice(auctionGoods.getStartingPrice());
            auctionGoodsVO.setStartStatus(auctionGoods.getStartStatus());
            GoodsSku goodsSkuOne = goodsSkuClient.getGoodsSkuOne(auctionGoods.getGoodsSkuId(), SecurityConstants.INNER).getData();
            auctionGoodsVO.setUnit(goodsSkuOne.getUnit());
            auctionGoodsVO.setSpec(goodsSkuOne.getSpec());
            auctionGoodsVO.setIsCollection(2);
            auctionGoodsVO.setSpecUnit(goodsSkuOne.getSpecUnit());
            auctionGoodsVO.setGoodsSkuName(goodsSkuOne.getSkuName());
            auctionGoodsVO.setCoverPic(goodsSkuOne.getCoverPic());
            LambdaQueryWrapper<AuctionBidRecord> wrapper1=Wrappers.lambdaQuery();
            wrapper1.eq(AuctionBidRecord::getMemberId,auctionCollectionDTO.getMemberId());
            wrapper1.eq(AuctionBidRecord::getAuctionType,1);
            wrapper1.eq(AuctionBidRecord::getTargetId,auctionGoods.getId());
            wrapper1.eq(AuctionBidRecord::getDelFlag,0);
            AuctionBidRecord list1 = auctionBidRecordMapper.selectOne(wrapper1);
            if (list1!=null){
                if (list1.getStatus().getCode()==2){
                    auctionGoodsVO.setIsStatus(2);
                }else{
                    auctionGoodsVO.setIsStatus(1);
                }
            }else{
                auctionGoodsVO.setIsStatus(1);
            }
            auctionGoodsVOS.add(auctionGoodsVO);
        }
        page.setRecords(auctionGoodsVOS);
       return PageDTO.of(page);
    }
}