rentaiming
2024-06-13 fe2d5b14031edbe43238770fb1fc21e8a322b51a
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
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.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.enums.ListingStatusEnum;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.page.BeanUtils;
import com.ruoyi.common.core.utils.page.Checker;
import com.ruoyi.common.core.utils.page.CollUtils;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.goods.controller.management.dto.GoodsInfoTitleValueDTO;
import com.ruoyi.goods.controller.management.dto.GoodsSkuDTO;
import com.ruoyi.goods.controller.management.dto.GoodsSkuQuery;
import com.ruoyi.goods.controller.management.vo.GoodsInfoTitleValueVO;
import com.ruoyi.goods.controller.management.vo.GoodsSkuVO;
import com.ruoyi.goods.domain.GoodsInfoTitleValue;
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.service.IGoodsInfoTitleValueService;
import com.ruoyi.goods.service.IGoodsSkuService;
import com.ruoyi.goods.service.IMemberGoodsCollectionService;
import com.ruoyi.system.api.domain.GoodsBrand;
import com.ruoyi.system.api.domain.GoodsCategory;
import com.ruoyi.system.api.domain.GoodsFlavorType;
import com.ruoyi.system.api.domain.GoodsGroupPurchase;
import com.ruoyi.system.api.domain.GoodsSeckill;
import com.ruoyi.system.api.domain.GoodsSeries;
import com.ruoyi.system.api.domain.GoodsSku;
import com.ruoyi.system.api.domain.dto.GoodsStockUpdDTO;
import com.ruoyi.system.api.domain.dto.HomeGoodsSkuDTO;
import com.ruoyi.system.api.domain.dto.ListStatusDTO;
import com.ruoyi.system.api.domain.vo.HomeGoodsSkuInfoVO;
import com.ruoyi.system.api.domain.vo.HomeGoodsSkuListVO;
import com.ruoyi.system.api.domain.vo.getHomeGoodsSkuXxiVO;
import com.ruoyi.system.api.feignClient.GoodsSkuClient;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author mitao
 * @since 2024-05-16
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> implements IGoodsSkuService {
 
    private final IGoodsInfoTitleValueService goodsInfoTitleValueService;
    private final GoodsSeckillMapper goodsSeckillMapper;
    private final GoodsGroupPurchaseMapper goodsGroupPurchaseMapper;
    private final RedissonClient redissonClient;
 
    @Resource
    private  GoodsSkuClient goodsSkuClient;
 
    @Resource
    private IMemberGoodsCollectionService iMemberGoodsCollectionService;
 
 
    private static final ObjectMapper objectMapper = new ObjectMapper();
 
    /**
     * 保存商品SKU信息。
     *
     * @param dto 商品SKU的DTO(数据传输对象),包含要保存或更新的商品SKU的详细信息。
     * @throws JsonProcessingException 当处理JSON数据时发生错误。
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveGoods(GoodsSkuDTO dto) throws JsonProcessingException {
        // 使用BeanUtils将DTO对象复制到GoodsSku实体对象
        GoodsSku goodsSku = BeanUtils.copyBean(dto, GoodsSku.class);
 
        // 分割并处理专辑图片字符串,将其转换为JSON格式
        String albumStr = processAlbumString(goodsSku.getAlbum());
 
        goodsSku.setAlbum(albumStr);
 
        // 根据ID判断是进行新增还是更新操作
        if (Objects.isNull(dto.getId())) {
            this.save(goodsSku);
        } else {
            GoodsSku goodsSkuOrg = this.getById(dto.getId());
            if (StringUtils.isNull(goodsSkuOrg)) {
                throw new ServiceException("商品不存在");
            }
            this.updateById(goodsSku);
        }
 
        // 处理商品额外信息,如规格、属性等
        processGoodsInfoTitleValue(dto, goodsSku);
    }
 
    /**
     * 处理相册字符串。 该方法将输入的相册字符串分割为字符串数组,并将其序列化为JSON字符串形式返回。 如果输入的相册字符串为空或仅包含空白字符,则返回空字符串。
     *
     * @param album 输入的相册字符串,可能包含多个相册名称,各相册名称之间以逗号分隔。
     * @return 返回序列化后的相册名称数组的JSON字符串。如果输入为空,则返回空字符串。
     * @throws JsonProcessingException 如果在序列化过程中发生错误,则抛出此异常。
     */
    private String processAlbumString(String album) throws JsonProcessingException {
        if (StringUtils.isEmpty(album)) {
            return ""; // 返回空字符串,避免后续处理出现问题
        }
        String[] albumArr = album.split(",");
        return objectMapper.writeValueAsString(albumArr);
    }
 
    /**
     * 处理商品信息标题和值的逻辑。 将DTO列表复制到实体列表中,校验其完整性和正确性,然后关联SKU ID,并最后保存到数据库。
     *
     * @param dto      包含商品信息标题和值的DTO对象
     * @param goodsSku 商品SKU实体,用于关联商品额外信息
     * @throws ServiceException 如果校验失败或数据处理出现异常,则抛出服务异常
     */
    private void processGoodsInfoTitleValue(GoodsSkuDTO dto, GoodsSku goodsSku)
            throws ServiceException {
        List<GoodsInfoTitleValueDTO> goodsInfoTitleValueDTOList = dto.getGoodsInfoTitleValueDTOList();
 
        // 复制DTO列表到实体列表
        List<GoodsInfoTitleValue> goodsInfoTitleValues = BeanUtils.copyList(
                goodsInfoTitleValueDTOList, GoodsInfoTitleValue.class);
 
        // 校验商品额外信息的完整性和正确性
        CollUtils.check(goodsInfoTitleValues, new Checker<GoodsInfoTitleValue>() {
            @Override
            public void check(GoodsInfoTitleValue data) {
                if (StringUtils.isNull(data.getGoodsInfoTitleId())) {
                    throw new ServiceException("商品信息标题id不能为空");
                }
                if (StringUtils.isEmpty(data.getContent())) {
                    throw new ServiceException("商品信息内容不能为空");
                }
            }
        });
 
        // 给每个商品额外信息关联上SKU ID
        for (GoodsInfoTitleValue goodsInfoTitleValue : goodsInfoTitleValues) {
            goodsInfoTitleValue.setGoodsSkuId(goodsSku.getId());
        }
 
        // 先清除旧的商品信息,再批量保存新的商品信息
        goodsInfoTitleValueService.removeByGoodsSkuId(goodsSku.getId());
        goodsInfoTitleValueService.saveBatch(goodsInfoTitleValues);
    }
 
    /**
     * 获取商品SKU分页数据
     *
     * @param query 查询条件,包括SKU名称、上架状态、页码和页大小
     * @return 分页数据对象,包含商品SKU的信息
     */
    @Override
    public PageDTO<GoodsSkuVO> getGoodsPage(GoodsSkuQuery query) {
        Page<GoodsSku> page = this.lambdaQuery()
                .select(GoodsSku::getId, GoodsSku::getSkuName, GoodsSku::getPrice,
                        GoodsSku::getStock, GoodsSku::getSoldQuantity, GoodsSku::getSortNum,
                        GoodsSku::getListingStatus)
                .like(StringUtils.isNotEmpty(query.getSkuName()), GoodsSku::getSkuName,
                        query.getSkuName())
                .eq(StringUtils.isNotNull(query.getListingStatus()
                ), GoodsSku::getListingStatus, query.getListingStatus())
                .eq(query.getQueryType().equals(1), GoodsSku::getListingStatus,
                        ListingStatusEnum.ON_SHELVES)
                .page(new Page<>(query.getPageCurr(), query.getPageSize()));
        return PageDTO.of(page, GoodsSkuVO.class);
    }
 
    /**
     * 更新商品SKU的状态。
     *
     * @param dto 数据传输对象,包含需要更新的SKU的ID和新的上架状态。 其中,ID用于指定要更新的具体SKU,listingStatus用于指定新的上架状态。
     */
    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public void updStatus(ListStatusDTO dto) {
        this.lambdaUpdate()
                .eq(GoodsSku::getId, dto.getId())
                .set(GoodsSku::getListingStatus, dto.getListingStatus())
                .update();
        //关联的秒杀商品和团购商品同步下架
        if (dto.getListingStatus().equals(ListingStatusEnum.REMOVED_FROM_THE_SHELF)) {
            updateGoodsStatus(dto);
        }
    }
 
    private void updateGoodsStatus(ListStatusDTO dto) {
        LambdaQueryWrapper<GoodsSeckill> queryWrapper =new LambdaQueryWrapper<>();
        queryWrapper.eq(GoodsSeckill::getListingStatus, ListingStatusEnum.ON_SHELVES)
                .eq(GoodsSeckill::getGoodsSkuId, dto.getId());
        List<GoodsSeckill> goodsSeckillList = goodsSeckillMapper.selectList(queryWrapper);
        if (StringUtils.isNotNull(goodsSeckillList)) {
            for (GoodsSeckill goodsSeckill : goodsSeckillList) {
                goodsSeckill.setListingStatus(ListingStatusEnum.REMOVED_FROM_THE_SHELF);
                goodsSeckillMapper.updateById(goodsSeckill);
            }
        }
 
        LambdaQueryWrapper<GoodsGroupPurchase> queryWrapper1 =new LambdaQueryWrapper<>();
        queryWrapper1.eq(GoodsGroupPurchase::getListingStatus,
                        ListingStatusEnum.ON_SHELVES)
                .eq(GoodsGroupPurchase::getGoodsSkuId, dto.getId());
        GoodsGroupPurchase goodsGroupPurchase = goodsGroupPurchaseMapper.selectOne(queryWrapper1);
        if (StringUtils.isNotNull(goodsGroupPurchase)) {
            goodsGroupPurchase.setListingStatus(ListingStatusEnum.REMOVED_FROM_THE_SHELF);
            goodsGroupPurchaseMapper.updateById(goodsGroupPurchase);
        }
    }
 
    /**
     * 根据商品名称查询商品SKU列表。
     *
     * @param goodsSkuName 商品名称
     * @return List<GoodsSku>商品SKU列表
     */
    @Override
    public List<GoodsSku> getGoodsByName(String goodsSkuName) {
        return this.lambdaQuery()
                .like(StringUtils.isNotEmpty(goodsSkuName), GoodsSku::getSkuName, goodsSkuName)
                .list();
    }
 
 
    /**
     * 批量更新商品库存 auctionStock 负数则为减库存,正数为加库存
     *
     * @param goodsStockUpdDTOS 商品库存修改数据传输对象
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void updGoodsStock(List<GoodsStockUpdDTO> goodsStockUpdDTOS) {
        List<Long> goodsSkuIdList = goodsStockUpdDTOS.stream()
                .map(GoodsStockUpdDTO::getGoodsSkuId)
                .collect(Collectors.toList());
        List<GoodsSku> goodsSkus = this.listByIds(goodsSkuIdList);
 
        if (StringUtils.isEmpty(goodsSkus)) {
            throw new ServiceException("商品不存在");
        }
        Map<Long, Integer> stockMap = goodsStockUpdDTOS.stream()
                .collect(Collectors.toMap(GoodsStockUpdDTO::getGoodsSkuId,
                        GoodsStockUpdDTO::getAuctionStock));
        for (GoodsSku skus : goodsSkus) {
            String goodsLock = "goods_lock:" + skus.getId();
            RLock redissonLock = redissonClient.getLock(goodsLock);
            try {
                redissonLock.lock(30, TimeUnit.SECONDS);
                Integer auctionStock = stockMap.get(skus.getId());
                if (StringUtils.isNotNull(auctionStock) && auctionStock > 0) {
                    // 更新商品库存,更新五次失败抛出异常
                    boolean isUpdated = false;
                    for (int i = 0; i < 5; i++) {
                        isUpdated = updateGoodsStock(skus, auctionStock);
                        if (isUpdated) {
                            break;
                        } else {
                            skus = this.getById(skus.getId());
                        }
                    }
                    if (!isUpdated) {
                        throw new ServiceException("商品库存回退失败");
                    }
                }
            } finally {
                redissonLock.unlock();
            }
        }
 
    }
 
    @Override
    public PageDTO<HomeGoodsSkuListVO> getHomeGoodsSkuVOList(HomeGoodsSkuDTO homeGoodsSkuDTO) {
        Page<GoodsSku> page = new Page<>();
        page.setSize(homeGoodsSkuDTO.getPageSize());
        page.setCurrent(homeGoodsSkuDTO.getPageCurr());
 
        LambdaQueryWrapper<GoodsSku> wrapper3= Wrappers.lambdaQuery();
        wrapper3.eq(GoodsSku::getDelFlag,0);
        wrapper3.eq(GoodsSku::getListingStatus,0);
        if (homeGoodsSkuDTO.getSkuName()!=null){
            wrapper3.like(GoodsSku::getSkuName,homeGoodsSkuDTO.getSkuName());
        }
        if (homeGoodsSkuDTO.getBrandId()!=null){
            wrapper3.eq(GoodsSku::getBrandId,homeGoodsSkuDTO.getBrandId());
        }
        if (homeGoodsSkuDTO.getCategoryId()!=null){
            wrapper3.eq(GoodsSku::getCategoryId,homeGoodsSkuDTO.getCategoryId());
        }
 
        if (homeGoodsSkuDTO.getSeriesId()!=null){
            wrapper3.eq(GoodsSku::getSeriesId,homeGoodsSkuDTO.getSeriesId());
        }
        if (homeGoodsSkuDTO.getFlavorTypeId()!=null){
            wrapper3.eq(GoodsSku::getFlavorTypeId,homeGoodsSkuDTO.getFlavorTypeId());
        }
        if (homeGoodsSkuDTO.getSort()==2){
            wrapper3.orderByAsc(GoodsSku::getPrice);
        }
        if (homeGoodsSkuDTO.getSort()==3){
            wrapper3.orderByDesc(GoodsSku::getPrice);
        }
        if (homeGoodsSkuDTO.getSort()==4){
            wrapper3.orderByAsc(GoodsSku::getSoldQuantity);
        }
        if (homeGoodsSkuDTO.getSort()==5){
            wrapper3.orderByDesc(GoodsSku::getSoldQuantity);
        }
        if(homeGoodsSkuDTO.getYear()==2){
            LocalDateTime now = LocalDateTime.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDateTime newTime7 = now.minusYears(30);
            String formattedDate7 = newTime7.format(formatter);
            LocalDateTime parseTime7 = LocalDate.parse(formattedDate7).atStartOfDay();
            wrapper3.le(GoodsSku::getYears,parseTime7);
        }
        if(homeGoodsSkuDTO.getYear()==3){
            LocalDateTime now = LocalDateTime.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDateTime newTime7 = now.minusYears(30);
            String formattedDate7 = newTime7.format(formatter);
            LocalDateTime parseTime7 = LocalDate.parse(formattedDate7).atStartOfDay();
 
            LocalDateTime newTime15 = now.minusYears(15);
            String formattedDate15 = newTime15.format(formatter);
            LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay();
            wrapper3.le(GoodsSku::getYears, parseTime15)
                    .gt(GoodsSku::getYears, parseTime7);
        }
 
        if(homeGoodsSkuDTO.getYear()==4){
            LocalDateTime now = LocalDateTime.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDateTime newTime7 = now.minusYears(5);
            String formattedDate7 = newTime7.format(formatter);
            LocalDateTime parseTime7 = LocalDate.parse(formattedDate7).atStartOfDay();
 
            LocalDateTime newTime15 = now.minusYears(15);
            String formattedDate15 = newTime15.format(formatter);
            LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay();
            wrapper3.le(GoodsSku::getYears, parseTime7)
                    .gt(GoodsSku::getYears, parseTime15);
        }
 
        if(homeGoodsSkuDTO.getYear()==5){
            LocalDateTime now = LocalDateTime.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDateTime newTime7 = now.minusYears(1);
            String formattedDate7 = newTime7.format(formatter);
            LocalDateTime parseTime7 = LocalDate.parse(formattedDate7).atStartOfDay();
 
            LocalDateTime newTime15 = now.minusYears(5);
            String formattedDate15 = newTime15.format(formatter);
            LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay();
            wrapper3.le(GoodsSku::getYears, parseTime7)
                    .ge(GoodsSku::getYears, parseTime15);
        }
        wrapper3.orderByAsc(GoodsSku::getSortNum);
        Page<GoodsSku> page1 = this.page(page, wrapper3);
        PageDTO<HomeGoodsSkuListVO> articleCommentsVOPageDTO = PageDTO.of(page1, HomeGoodsSkuListVO.class);
        return  articleCommentsVOPageDTO;
 
    }
 
    @Override
    public HomeGoodsSkuInfoVO getHomeGoodsSkuInfo(HomeGoodsSkuDTO homeGoodsSkuDTO) {
        GoodsSku byId = this.getById(homeGoodsSkuDTO.getGoodsSkuId());
        HomeGoodsSkuInfoVO homeGoodsSkuInfoVO=new HomeGoodsSkuInfoVO();
        homeGoodsSkuInfoVO.setId(byId.getId());
        homeGoodsSkuInfoVO.setSkuName(byId.getSkuName());
        homeGoodsSkuInfoVO.setYears(String.valueOf(byId.getYears().getYear()));
        GoodsBrand data = goodsSkuClient.getBrandOne(byId.getBrandId(), SecurityConstants.INNER).getData();
        GoodsCategory data1 = goodsSkuClient.getCategoryOne(byId.getCategoryId(), SecurityConstants.INNER).getData();
        GoodsSeries data2 = goodsSkuClient.getSeriesOne(byId.getSeriesId(), SecurityConstants.INNER).getData();
        GoodsFlavorType data3 = goodsSkuClient.getFlavorTypeOne(byId.getFlavorTypeId(), SecurityConstants.INNER).getData();
        homeGoodsSkuInfoVO.setBrand(data.getBrandName());
        homeGoodsSkuInfoVO.setCategory(data1.getCategoryName());
        homeGoodsSkuInfoVO.setSeries(data2.getSeriesName());
        homeGoodsSkuInfoVO.setFlavorType(data3.getFlavorTypeName());
        homeGoodsSkuInfoVO.setPrice(byId.getPrice());
        homeGoodsSkuInfoVO.setSoldQuantity(byId.getSoldQuantity());
        homeGoodsSkuInfoVO.setUnit(byId.getUnit());
        homeGoodsSkuInfoVO.setSpec(byId.getSpec());
        homeGoodsSkuInfoVO.setSpecUnit(byId.getSpecUnit());
        homeGoodsSkuInfoVO.setCoverPic(byId.getCoverPic());
        homeGoodsSkuInfoVO.setAlbum(byId.getAlbum());
        homeGoodsSkuInfoVO.setDescription(byId.getDescription());
        homeGoodsSkuInfoVO.setDetail(byId.getDetail());
        homeGoodsSkuInfoVO.setShareTitle(byId.getShareTitle());
        homeGoodsSkuInfoVO.setSharePic(byId.getSharePic());
        LambdaQueryWrapper<GoodsGroupPurchase> queryWrapper1 =new LambdaQueryWrapper<>();
        queryWrapper1.eq(GoodsGroupPurchase::getListingStatus,
                        ListingStatusEnum.ON_SHELVES)
                .eq(GoodsGroupPurchase::getGoodsSkuId, byId.getId());
        GoodsGroupPurchase goodsGroupPurchase = goodsGroupPurchaseMapper.selectOne(queryWrapper1);
        if(goodsGroupPurchase!=null){
            homeGoodsSkuInfoVO.setGroupPurchaseGoods(2);
        }else {
            homeGoodsSkuInfoVO.setGroupPurchaseGoods(1);
        }
 
        LambdaQueryWrapper<MemberGoodsCollection> wrapper3= Wrappers.lambdaQuery();
        wrapper3.eq(MemberGoodsCollection::getDelFlag,0);
        wrapper3.eq(MemberGoodsCollection::getMemberId,homeGoodsSkuDTO.getMemberId());
        wrapper3.eq(MemberGoodsCollection::getTargetId,homeGoodsSkuDTO.getGoodsSkuId());
        List<MemberGoodsCollection> list = iMemberGoodsCollectionService.list(wrapper3);
        if (list.size()>0){
            homeGoodsSkuInfoVO.setIsCollection(2);
        }else{
            homeGoodsSkuInfoVO.setIsCollection(1);
        }
        LambdaQueryWrapper<GoodsGroupPurchase> queryWrapper1 =new LambdaQueryWrapper<>();
        queryWrapper1.eq(GoodsGroupPurchase::getListingStatus,
                        ListingStatusEnum.ON_SHELVES)
                .eq(GoodsGroupPurchase::getGoodsSkuId, byId.getId());
        GoodsGroupPurchase goodsGroupPurchase = goodsGroupPurchaseMapper.selectOne(queryWrapper1);
        if (goodsGroupPurchase!=null){
            homeGoodsSkuInfoVO.setIsGoodsGroupPurchase(2);
        }else{
            homeGoodsSkuInfoVO.setIsGoodsGroupPurchase(1);
        }
        return homeGoodsSkuInfoVO;
    }
 
    @Override
    public List<getHomeGoodsSkuXxiVO> getHomeGoodsSkuXxi(HomeGoodsSkuDTO homeGoodsSkuDTO) {
        List<getHomeGoodsSkuXxiVO> homeGoodsSkuXxiVOS=new ArrayList<>();
        GoodsSku byId = this.getById(homeGoodsSkuDTO.getGoodsSkuId());
        GoodsBrand data = goodsSkuClient.getBrandOne(byId.getBrandId(), SecurityConstants.INNER).getData();
        GoodsCategory data1 = goodsSkuClient.getCategoryOne(byId.getCategoryId(), SecurityConstants.INNER).getData();
        GoodsSeries data2 = goodsSkuClient.getSeriesOne(byId.getSeriesId(), SecurityConstants.INNER).getData();
        GoodsFlavorType data3 = goodsSkuClient.getFlavorTypeOne(byId.getFlavorTypeId(), SecurityConstants.INNER).getData();
 
 
        getHomeGoodsSkuXxiVO getHomeGoodsSkuXxiVO1=new getHomeGoodsSkuXxiVO();
        getHomeGoodsSkuXxiVO1.setContent(data1.getCategoryName());
        getHomeGoodsSkuXxiVO1.setTitleName("分类");
        homeGoodsSkuXxiVOS.add(getHomeGoodsSkuXxiVO1);
 
        getHomeGoodsSkuXxiVO getHomeGoodsSkuXxiVO2=new getHomeGoodsSkuXxiVO();
        getHomeGoodsSkuXxiVO2.setContent(data2.getSeriesName());
        getHomeGoodsSkuXxiVO2.setTitleName("系列");
        homeGoodsSkuXxiVOS.add(getHomeGoodsSkuXxiVO2);
 
        getHomeGoodsSkuXxiVO getHomeGoodsSkuXxiVO=new getHomeGoodsSkuXxiVO();
        getHomeGoodsSkuXxiVO.setContent(data.getBrandName());
        getHomeGoodsSkuXxiVO.setTitleName("品牌");
        homeGoodsSkuXxiVOS.add(getHomeGoodsSkuXxiVO);
 
        getHomeGoodsSkuXxiVO getHomeGoodsSkuXxiVO3=new getHomeGoodsSkuXxiVO();
        getHomeGoodsSkuXxiVO3.setContent(data3.getFlavorTypeName());
        getHomeGoodsSkuXxiVO3.setTitleName("香型");
        homeGoodsSkuXxiVOS.add(getHomeGoodsSkuXxiVO3);
 
 
        List<GoodsInfoTitleValueVO> goodsInfoTitleValueVOList = goodsInfoTitleValueService.listByGoodsId(homeGoodsSkuDTO.getGoodsSkuId());
        Collections.sort(goodsInfoTitleValueVOList, Comparator.comparingInt(GoodsInfoTitleValueVO::getSortNum));
        for (GoodsInfoTitleValueVO goodsInfoTitleValueVO:goodsInfoTitleValueVOList){
            getHomeGoodsSkuXxiVO getHomeGoodsSkuXxiVOs=new getHomeGoodsSkuXxiVO();
            getHomeGoodsSkuXxiVOs.setContent(goodsInfoTitleValueVO.getContent());
            getHomeGoodsSkuXxiVOs.setTitleName(goodsInfoTitleValueVO.getTitleName());
            homeGoodsSkuXxiVOS.add(getHomeGoodsSkuXxiVOs);
        }
 
 
        return homeGoodsSkuXxiVOS;
    }
 
    private boolean updateGoodsStock(GoodsSku skus, Integer auctionStock) {
        return this.lambdaUpdate()
                .set(skus.getStock() + auctionStock > 0, GoodsSku::getStock,
                        skus.getStock() + auctionStock)
                .eq(GoodsSku::getId, skus.getId())
                .eq(GoodsSku::getStock, skus.getStock())
                .update();
    }
 
    /**
     * 根据商品id查询信息标题列表
     *
     * @param id 商品id
     * @return List<GoodsInfoTitleValueVO>
     */
    @Override
    public GoodsSkuVO getGoodsDetail(Long id) {
        GoodsSku goodsSku = this.getById(id);
        if (StringUtils.isNull(goodsSku)) {
            throw new ServiceException("商品不存在");
        }
        GoodsSkuVO goodsSkuVO = BeanUtils.copyBean(goodsSku, GoodsSkuVO.class);
        List<GoodsInfoTitleValueVO> goodsInfoTitleValueVOList = goodsInfoTitleValueService.listByGoodsId(
                id);
        goodsSkuVO.setGoodsInfoTitleValueVOList(goodsInfoTitleValueVOList);
        return goodsSkuVO;
    }
}