mitao
2024-08-16 d7dc4db8d005a58f51d21d35147317762a16373f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.page.CollUtils;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.goods.domain.MemberGoodsCollection;
import com.ruoyi.goods.mapper.GoodsGroupPurchaseMapper;
import com.ruoyi.goods.mapper.GoodsSeckillMapper;
import com.ruoyi.goods.mapper.GoodsSkuMapper;
import com.ruoyi.goods.mapper.MemberGoodsCollectionMapper;
import com.ruoyi.goods.service.IMemberGoodsCollectionService;
import com.ruoyi.system.api.domain.GoodsGroupPurchase;
import com.ruoyi.system.api.domain.GoodsSeckill;
import com.ruoyi.system.api.domain.GoodsSku;
import com.ruoyi.system.api.domain.dto.AuctionCollectionDTO;
import com.ruoyi.system.api.domain.vo.HomeGoodsSkuListVO;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
 
/**
 * <p>
 * 会员收藏普通商品 服务实现类
 * </p>
 *
 * @author mitao
 * @since 2024-05-27
 */
@Service
public class MemberGoodsCollectionServiceImpl extends ServiceImpl<MemberGoodsCollectionMapper, MemberGoodsCollection> implements IMemberGoodsCollectionService {
 
 
     @Resource
     private GoodsSkuMapper goodsSkuMapper;
 
    @Resource
    private GoodsSeckillMapper goodsSeckillMapper;
 
 
    @Resource
    private GoodsGroupPurchaseMapper goodsGroupPurchaseMapper;
 
    @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.getType()!=null){
            wrapper.eq(MemberGoodsCollection::getType,auctionCollectionDTO.getType());
        }
        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());
                m.setType(auctionCollectionDTO.getType());
                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) {
 
        Set<Long> goodsSkuIdList = null;
        if (StringUtils.isNotEmpty(auctionCollectionDTO.getGoodsSkuName())) {
            LambdaQueryWrapper<GoodsSku> wrapper= Wrappers.lambdaQuery();
            wrapper.like(GoodsSku::getSkuName,auctionCollectionDTO.getGoodsSkuName());
            wrapper.eq(GoodsSku::getDelFlag,0);
            List<GoodsSku> page1 = goodsSkuMapper.selectList(wrapper);
            goodsSkuIdList = page1.stream().map(GoodsSku::getId)
                    .collect(Collectors.toSet());
        }
 
 
        Page<HomeGoodsSkuListVO> page = new Page<>();
        page.setSize(auctionCollectionDTO.getPageSize());
        page.setCurrent(auctionCollectionDTO.getPageCurr());
        LambdaQueryWrapper< MemberGoodsCollection> wrapper= Wrappers.lambdaQuery();
        wrapper.eq(MemberGoodsCollection::getMemberId,auctionCollectionDTO.getMemberId());
        if (StringUtils.isNotEmpty(auctionCollectionDTO.getGoodsSkuName())){
            if (goodsSkuIdList.size()>0){
                wrapper.in(MemberGoodsCollection::getTargetId,goodsSkuIdList);
            }else{
                goodsSkuIdList=new HashSet<>();
                goodsSkuIdList.add(0L);
                wrapper.in(MemberGoodsCollection::getTargetId,goodsSkuIdList);
            }
        }
        List<MemberGoodsCollection> list = this.list(wrapper);
        if (CollUtils.isNotEmpty(list)) {
            List<HomeGoodsSkuListVO> auctionGoodsVOS = new ArrayList<>();
            for (MemberGoodsCollection auctionCollection : list) {
                if (auctionCollection.getType() == 1) {
                    HomeGoodsSkuListVO auctionGoodsVO = new HomeGoodsSkuListVO();
                    GoodsSku goodsSku = goodsSkuMapper.selectById(auctionCollection.getTargetId());
                    if (Objects.nonNull(goodsSku)) {
                        auctionGoodsVO.setId(goodsSku.getId());
                        auctionGoodsVO.setPrice(goodsSku.getPrice());
                        auctionGoodsVO.setCoverPic(goodsSku.getCoverPic());
                        auctionGoodsVO.setSkuName(goodsSku.getSkuName());
                        auctionGoodsVO.setSoldQuantity(goodsSku.getSoldQuantity());
                        auctionGoodsVO.setIsCollection(2);
                        auctionGoodsVO.setType(auctionCollection.getType());
                        auctionGoodsVOS.add(auctionGoodsVO);
                    }
                }
                if (auctionCollection.getType() == 3) {
                    HomeGoodsSkuListVO auctionGoodsVO = new HomeGoodsSkuListVO();
                    GoodsSeckill goodsSeckill = goodsSeckillMapper.selectById(
                            auctionCollection.getTargetId());
                    GoodsSku goodsSku = goodsSkuMapper.selectById(goodsSeckill.getGoodsSkuId());
                    auctionGoodsVO.setId(auctionCollection.getTargetId());
                    auctionGoodsVO.setPrice(goodsSeckill.getSeckillPrice());
                    auctionGoodsVO.setCoverPic(goodsSku.getCoverPic());
                    auctionGoodsVO.setSkuName(goodsSku.getSkuName());
                    auctionGoodsVO.setSoldQuantity(goodsSku.getSoldQuantity());
                    auctionGoodsVO.setIsCollection(2);
                    auctionGoodsVO.setStartStatus(goodsSeckill.getStartStatus());
                    auctionGoodsVO.setStartTime(goodsSeckill.getStartTime());
                    auctionGoodsVO.setEndTime(goodsSeckill.getEndTime());
                    auctionGoodsVO.setXiaosPrice(goodsSku.getPrice());
                    auctionGoodsVO.setType(auctionCollection.getType());
                    auctionGoodsVOS.add(auctionGoodsVO);
                }
                if (auctionCollection.getType() == 2) {
                    GoodsGroupPurchase goodsGroupPurchase = goodsGroupPurchaseMapper.selectById(
                            auctionCollection.getTargetId());
                    HomeGoodsSkuListVO auctionGoodsVO = new HomeGoodsSkuListVO();
                    if (goodsGroupPurchase != null) {
                        GoodsSku goodsSku = goodsSkuMapper.selectById(
                                goodsGroupPurchase.getGoodsSkuId());
                        auctionGoodsVO.setId(auctionCollection.getTargetId());
                        auctionGoodsVO.setPrice(goodsGroupPurchase.getGroupPurchasePrice());
                        auctionGoodsVO.setCoverPic(goodsSku.getCoverPic());
                        auctionGoodsVO.setSkuName(goodsSku.getSkuName());
                        auctionGoodsVO.setSoldQuantity(goodsSku.getSoldQuantity());
                        auctionGoodsVO.setIsCollection(2);
                        auctionGoodsVO.setXiaosPrice(goodsSku.getPrice());
                        auctionGoodsVO.setStartTime(goodsGroupPurchase.getStartTime());
                        auctionGoodsVO.setEndTime(goodsGroupPurchase.getEndTime());
                        auctionGoodsVO.setXiaosPrice(goodsGroupPurchase.getGroupPurchasePrice());
                        auctionGoodsVO.setType(auctionCollection.getType());
                        auctionGoodsVOS.add(auctionGoodsVO);
                    }
 
                }
 
            }
            page.setRecords(auctionGoodsVOS);
        }
        return PageDTO.of(page);
    }
}