mitao
2024-09-13 b3cef9d27013afee054bdd467defd0b6be218526
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
521
522
523
524
525
526
527
528
529
530
531
532
533
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.google.common.collect.Lists;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.enums.ClientTypeEnum;
import com.ruoyi.common.core.enums.ListingStatusEnum;
import com.ruoyi.common.core.enums.StartStatusEnum;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.page.BeanUtils;
import com.ruoyi.common.core.utils.page.CollUtils;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.goods.controller.management.dto.GoodsSeckillDTO;
import com.ruoyi.goods.controller.management.dto.GoodsSeckillQuery;
import com.ruoyi.goods.controller.management.dto.GoodsSeckillUpd;
import com.ruoyi.goods.controller.management.vo.GoodsSeckillVO;
import com.ruoyi.goods.domain.GoodsSeckillAppointment;
import com.ruoyi.goods.domain.MemberGoodsCollection;
import com.ruoyi.goods.mapper.GoodsSeckillMapper;
import com.ruoyi.goods.service.IGoodsSeckillAppointmentService;
import com.ruoyi.goods.service.IGoodsSeckillService;
import com.ruoyi.goods.service.IGoodsSkuService;
import com.ruoyi.goods.service.IMemberGoodsCollectionService;
import com.ruoyi.goods.service.async.AsyncMethodService;
import com.ruoyi.system.api.constants.NotificationTypeConstant;
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.GoodsSeckill;
import com.ruoyi.system.api.domain.GoodsSeries;
import com.ruoyi.system.api.domain.GoodsSku;
import com.ruoyi.system.api.domain.WebsocketMessageDTO;
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.HomeGoodsSeckillInfoVO;
import com.ruoyi.system.api.domain.vo.HomeGoodsSeckillVO;
import com.ruoyi.system.api.feignClient.GoodsSkuClient;
import com.ruoyi.system.api.feignClient.OrderClient;
import com.ruoyi.system.api.feignClient.SysUserClient;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
/**
 * <p>
 * 商品秒杀表 服务实现类
 * </p>
 *
 * @author mitao
 * @since 2024-05-16
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class GoodsSeckillServiceImpl extends ServiceImpl<GoodsSeckillMapper, GoodsSeckill> implements IGoodsSeckillService {
 
    private final IGoodsSkuService goodsSkuService;
    private final OrderClient orderClient;
    private final GoodsSkuClient goodsSkuClient;
    private final RedisService redisService;
    private final SysUserClient sysUserClient;
    private final AsyncMethodService asyncMethodService;
    // 创建一个静态共享的ObjectMapper实例以重用
    private static final ObjectMapper objectMapper = new ObjectMapper();
 
    @Resource
    private IMemberGoodsCollectionService iMemberGoodsCollectionService;
 
    @Resource
    private IGoodsSeckillAppointmentService iGoodsSeckillAppointmentService;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addGoodsSeckill(GoodsSeckillDTO dto) {
        List<GoodsSeckill> goodsSeckills = BeanUtils.copyList(dto.getGoodsSkuList(),
                GoodsSeckill.class);
        for (GoodsSeckill goodsSeckill : goodsSeckills) {
            goodsSeckill.setShareTitle(dto.getShareTitle());
            goodsSeckill.setSharePic(dto.getSharePic());
            goodsSeckill.setStartTime(dto.getStartTime());
            goodsSeckill.setEndTime(dto.getEndTime());
            goodsSeckill.setStartStatus(StartStatusEnum.NOT_STARTED);
        }
        // 查询该时间范围内,是否已经存在该秒杀商品
        List<Long> skuIds = goodsSeckills.stream().map(GoodsSeckill::getGoodsSkuId)
                .collect(Collectors.toList());
        List<GoodsSeckill> list = this.lambdaQuery()
                .ne(GoodsSeckill::getStartStatus, StartStatusEnum.ENDED)
                .in(GoodsSeckill::getGoodsSkuId, skuIds).list();
        Set<Long> existGoodsSkuIdSet = list.stream().map(GoodsSeckill::getGoodsSkuId)
                .collect(Collectors.toSet());
        if (!existGoodsSkuIdSet.isEmpty()) {
            List<GoodsSku> goodsSkuList = goodsSkuService.listByIds(existGoodsSkuIdSet);
            Map<Long, String> goodsSkuMap = goodsSkuList.stream()
                    .collect(Collectors.toMap(GoodsSku::getId, GoodsSku::getSkuName));
            Optional<GoodsSeckill> first = goodsSeckills.stream()
                    .filter(goodsSeckill -> existGoodsSkuIdSet.contains(
                            goodsSeckill.getGoodsSkuId()))
                    .findFirst();
            if (first.isPresent()) {
                String skuName = goodsSkuMap.get(first.get().getGoodsSkuId());
                throw new ServiceException(
                        String.format("添加失败,商品%s在该时间段内有其他秒杀活动", skuName));
            }
        }
        this.saveBatch(goodsSeckills);
 
        for (GoodsSeckill goodsSeckill : goodsSeckills) {
            GoodsSku goodsSku = goodsSkuService.getById(goodsSeckill.getGoodsSkuId());
            if (StringUtils.isNull(goodsSku)) {
                throw new ServiceException("商品不存在");
            }
 
            Integer seckillStock = goodsSeckill.getSeckillStock();
            if (goodsSku.getStock() < seckillStock) {
                throw new ServiceException(
                        String.format("秒杀商品%s剩余库存不足,请修改秒杀库存",
                                goodsSku.getSkuName()));
            }
            GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO();
            goodsStockUpdDTO.setAuctionStock(seckillStock * -1);
            goodsStockUpdDTO.setGoodsSkuId(goodsSku.getId());
            goodsSkuService.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO));
            if (goodsSeckill.getEndTime().isBefore(LocalDateTime.now())) {
                goodsSeckill.setStartStatus(StartStatusEnum.ENDED);
                this.updateById(goodsSeckill);
            } else {
                asyncMethodService.seckillScheduleTask(Lists.newArrayList(goodsSeckill));
            }
        }
    }
 
 
    /**
     * 获取秒杀商品列表的分页数据
     *
     * @param query 秒杀商品查询对象
     * @return PageDTO<GoodsSeckillVO>
     */
    @Override
    public PageDTO<GoodsSeckillVO> getGoodsSeckillPage(GoodsSeckillQuery query) {
        return PageDTO.of(baseMapper.getGoodsSeckillPage(query.getGoodsSkuName(),
                new Page<>(query.getPageCurr(), query.getPageSize())
        ));
    }
 
    /**
     * 修改秒杀商品
     *
     * @param upd 商品秒杀数据传输对象
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updGoodsSeckill(GoodsSeckillUpd upd) {
        //查询秒杀商品
        GoodsSeckill goodsSeckill = this.getById(upd.getId());
        if (StringUtils.isNull(goodsSeckill)) {
            throw new ServiceException("秒杀商品不存在");
        }
        if (goodsSeckill.getStartStatus().equals(StartStatusEnum.STARTED)
                && goodsSeckill.getListingStatus().equals(ListingStatusEnum.ON_SHELVES)) {
            throw new ServiceException("秒杀商品已开始秒杀,不能修改");
        }
        GoodsSku goodsSku = goodsSkuService.getById(goodsSeckill.getGoodsSkuId());
        if (goodsSku.getStock() < upd.getSeckillStock()) {
            throw new ServiceException("编辑失败,商品库存不足");
        }
        Optional<GoodsSeckill> seckillOpt = this.lambdaQuery()
                .ne(GoodsSeckill::getStartStatus, StartStatusEnum.ENDED)
                .ne(GoodsSeckill::getId, goodsSeckill.getId())
                .eq(GoodsSeckill::getGoodsSkuId, goodsSeckill.getGoodsSkuId()).oneOpt();
        if (seckillOpt.isPresent()) {
            throw new ServiceException("编辑失败,商品在该时间段内有其他秒杀活动");
        }
        GoodsSeckill goodsSeckillUpd = BeanUtils.copyBean(upd, GoodsSeckill.class);
        goodsSeckillUpd.setListingStatus(ListingStatusEnum.ON_SHELVES);
        goodsSeckillUpd.setStartStatus(StartStatusEnum.NOT_STARTED);
        this.updateById(goodsSeckillUpd);
 
        if (goodsSeckillUpd.getEndTime().isBefore(LocalDateTime.now())) {
            goodsSeckillUpd.setStartStatus(StartStatusEnum.ENDED);
            this.updateById(goodsSeckillUpd);
        } else {
            // 修改库存
            GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO();
            goodsStockUpdDTO.setAuctionStock(upd.getSeckillStock() * -1);
            goodsStockUpdDTO.setGoodsSkuId(goodsSeckill.getGoodsSkuId());
            goodsSkuService.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO));
            asyncMethodService.seckillScheduleTask(Lists.newArrayList(goodsSeckillUpd));
        }
    }
 
    /**
     * 上架/下架 秒杀商品
     *
     * @param dto 商品上下架状态对象
     */
    @Override
    public void updStatus(ListStatusDTO dto) {
        GoodsSeckill goodsSeckill = this.getById(dto.getId());
        if (StringUtils.isNull(goodsSeckill)) {
            throw new ServiceException("秒杀商品不存在");
        }
        goodsSeckill.setListingStatus(dto.getListingStatus());
        if (dto.getListingStatus().equals(ListingStatusEnum.REMOVED_FROM_THE_SHELF)
                && !goodsSeckill.getStartStatus().equals(StartStatusEnum.ENDED)) {
            // 退回剩余库存
            GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO();
            goodsStockUpdDTO.setAuctionStock(goodsSeckill.getSeckillStock());
            goodsStockUpdDTO.setGoodsSkuId(goodsSeckill.getGoodsSkuId());
            goodsSkuService.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO));
        }
        this.updateById(goodsSeckill);
    }
 
    /**
     * 查看详情
     *
     * @param id 秒杀商品id
     * @return GoodsSeckillVO 商品秒杀视图对象
     */
    @Override
    public GoodsSeckillVO getDetail(Long id) {
        GoodsSeckill goodsSeckill = this.getById(id);
        if (StringUtils.isNull(goodsSeckill)) {
            throw new ServiceException("秒杀商品不存在");
        }
        GoodsSeckillVO vo = BeanUtils.copyBean(goodsSeckill, GoodsSeckillVO.class);
        GoodsSku goods = goodsSkuService.getById(goodsSeckill.getGoodsSkuId());
        Optional.of(goods).ifPresent(goodsSku -> {
            vo.setGoodsSkuName(goodsSku.getSkuName());
            vo.setGoodsSkuStock(goodsSku.getStock());
        });
        Integer num = orderClient.getSeckillMembers(goodsSeckill.getId(),
                SecurityConstants.INNER).getData();
        vo.setNumberOfPurchasedMembers(StringUtils.isNull(num) ? 0 : num);
        return vo;
    }
 
    /**
     * 开始秒杀
     *
     * @param seckillId 秒杀id
     */
    @Override
    public void startSeckill(Long seckillId) throws JsonProcessingException {
        log.info(">>>>>>>>>>>>>>>>>>>>{}秒杀开始<<<<<<<<<<<<<<<<<<<<", seckillId);
        GoodsSeckill goodsSeckill = this.getById(seckillId);
        // 秒杀商品不能为空且上架状态为上架中 状态为未开始
        if (StringUtils.isNotNull(goodsSeckill)
                && goodsSeckill.getStartStatus().equals(StartStatusEnum.NOT_STARTED)) {
            //开始秒杀
            this.lambdaUpdate().set(GoodsSeckill::getStartStatus, StartStatusEnum.STARTED)
                    .eq(GoodsSeckill::getId, seckillId).update();
//            将秒杀商品放入缓存
            redisService.setCacheObject(
                    CacheConstants.SECKILL_GOODS + goodsSeckill.getId(),
                    goodsSeckill.getSeckillStock());
        }
        //推送秒杀开始消息
        Map<String, Object> map = new ConcurrentHashMap<>();
        map.put("notification_type", NotificationTypeConstant.SECKILL);
        map.put("notification_time", DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        map.put("target_id", seckillId);
        map.put("message_type", "start");
        String msg = objectMapper.writeValueAsString(map);
        sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(msg)
                .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER);
        log.info("===================>发送websocket通知,消息体{}", msg);
    }
 
    /**
     * 结束秒杀
     *
     * @param seckillId 秒杀id
     */
    @Override
    public void endSeckill(Long seckillId) throws JsonProcessingException {
        log.info(">>>>>>>>>>>>>>>>>>>>{}秒杀结束<<<<<<<<<<<<<<<<<<<<", seckillId);
        GoodsSeckill goodsSeckill = this.getById(seckillId);
        if (StringUtils.isNotNull(goodsSeckill)
                && !goodsSeckill.getStartStatus().equals(StartStatusEnum.ENDED)) {
            //结束秒杀
            this.lambdaUpdate().set(GoodsSeckill::getStartStatus, StartStatusEnum.ENDED)
                    .eq(GoodsSeckill::getId, seckillId).update();
//            将秒杀商品从缓存中移除
            redisService.deleteObject(CacheConstants.SECKILL_GOODS + goodsSeckill.getId());
            // 退回剩余库存
            GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO();
            goodsStockUpdDTO.setAuctionStock(goodsSeckill.getSeckillStock());
            goodsStockUpdDTO.setGoodsSkuId(goodsSeckill.getGoodsSkuId());
            goodsSkuService.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO));
        }
        Map<String, Object> map = new ConcurrentHashMap<>();
        map.put("notification_type", NotificationTypeConstant.SECKILL);
        map.put("notification_time", DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        map.put("target_id", seckillId);
        map.put("message_type", "end");
        String msg = objectMapper.writeValueAsString(map);
        sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(msg)
                .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER);
        log.info("===================>发送websocket通知,消息体{}", msg);
    }
 
    @Override
    public PageDTO<HomeGoodsSeckillVO> getHomeGoodsSeckillVOList(HomeGoodsSkuDTO homeGoodsSkuDTO) {
        LambdaQueryWrapper<GoodsSku> wrapper3= Wrappers.lambdaQuery();
        wrapper3.eq(GoodsSku::getDelFlag,0);
        if (homeGoodsSkuDTO.getSkuName()!=null && homeGoodsSkuDTO.getSkuName()!=""){
            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);
        }
 
        List<GoodsSku> page1 =  goodsSkuService.list(wrapper3);
 
        Set<Long> goodsSkuIdList = null;
        goodsSkuIdList = page1.stream().map(GoodsSku::getId)
                .collect(Collectors.toSet());
        if (CollUtils.isEmpty(goodsSkuIdList)) {
            return PageDTO.empty(0L, 0L);
        }
        Page<GoodsSeckill> page = new Page<>();
        page.setSize(homeGoodsSkuDTO.getPageSize());
        page.setCurrent(homeGoodsSkuDTO.getPageCurr());
 
        LambdaQueryWrapper<GoodsSeckill> wrapper4= Wrappers.lambdaQuery();
        wrapper4.eq(GoodsSeckill::getDelFlag,0);
        wrapper4.eq(GoodsSeckill::getListingStatus,0);
        List<Integer> in=new ArrayList<>();
        in.add(0);
        in.add(1);
        wrapper4.in(GoodsSeckill::getStartStatus,in);
        if(goodsSkuIdList.size()>0){
            wrapper4.in(GoodsSeckill::getGoodsSkuId,goodsSkuIdList);
        }
 
        wrapper4.orderByDesc(GoodsSeckill::getSortNum);
        Page<GoodsSeckill> page2 = this.page(page, wrapper4);
 
        PageDTO<HomeGoodsSeckillVO> HomeGoodsSeckillVOPageDTO = PageDTO.of(page2, HomeGoodsSeckillVO.class);
        List<HomeGoodsSeckillVO> list2 = HomeGoodsSeckillVOPageDTO.getList();
        for (HomeGoodsSeckillVO homeGoodsSeckillVO:list2){
            GoodsSku data = goodsSkuClient.getGoodsSkuOne(homeGoodsSeckillVO.getGoodsSkuId(), SecurityConstants.INNER).getData();
            homeGoodsSeckillVO.setPrice(data.getPrice());
            homeGoodsSeckillVO.setYears(String.valueOf(data.getYears().getYear()));
            homeGoodsSeckillVO.setCoverPic(data.getCoverPic());
            homeGoodsSeckillVO.setSkuName(data.getSkuName());
        }
        return HomeGoodsSeckillVOPageDTO;
    }
 
    @Override
    public HomeGoodsSeckillInfoVO getHomeGoodsSeckillInfo(HomeGoodsSkuDTO homeGoodsSkuDTO) {
        GoodsSeckill byId = this.getById(homeGoodsSkuDTO.getGoodsSkuId());
        GoodsSku data6 = goodsSkuClient.getGoodsSkuOne(byId.getGoodsSkuId(), SecurityConstants.INNER).getData();
        HomeGoodsSeckillInfoVO homeGoodsSeckillInfoVO=new HomeGoodsSeckillInfoVO();
        homeGoodsSeckillInfoVO.setGoodsSkuId(byId.getId());
        homeGoodsSeckillInfoVO.setSkuName(data6.getSkuName());
        homeGoodsSeckillInfoVO.setYears(String.valueOf(data6.getYears().getYear()));
        GoodsBrand data = goodsSkuClient.getBrandOne(data6.getBrandId(), SecurityConstants.INNER).getData();
        GoodsCategory data1 = goodsSkuClient.getCategoryOne(data6.getCategoryId(), SecurityConstants.INNER).getData();
        GoodsSeries data2 = goodsSkuClient.getSeriesOne(data6.getSeriesId(), SecurityConstants.INNER).getData();
        GoodsFlavorType data3 = goodsSkuClient.getFlavorTypeOne(data6.getFlavorTypeId(), SecurityConstants.INNER).getData();
        if(data!=null){
            homeGoodsSeckillInfoVO.setBrand(data.getBrandName());
        }
        if(data1!=null){
        homeGoodsSeckillInfoVO.setCategory(data1.getCategoryName());
        }
            if(data2!=null){
        homeGoodsSeckillInfoVO.setSeries(data2.getSeriesName());
            }
                if(data3!=null){
        homeGoodsSeckillInfoVO.setFlavorType(data3.getFlavorTypeName());
                }
 
        homeGoodsSeckillInfoVO.setPrice(data6.getPrice());
        homeGoodsSeckillInfoVO.setSoldQuantity(byId.getSoldQuantity());
        homeGoodsSeckillInfoVO.setUnit(data6.getUnit());
        homeGoodsSeckillInfoVO.setSpec(data6.getSpec());
        homeGoodsSeckillInfoVO.setSpecUnit(data6.getSpecUnit());
        homeGoodsSeckillInfoVO.setCoverPic(data6.getCoverPic());
        homeGoodsSeckillInfoVO.setAlbum(data6.getAlbum());
        homeGoodsSeckillInfoVO.setShareTitle(byId.getShareTitle());
        if (StringUtils.isNotBlank(byId.getShareTitle())) {
            homeGoodsSeckillInfoVO.setShareTitle(byId.getShareTitle());
        } else {
            homeGoodsSeckillInfoVO.setShareTitle(data6.getSkuName());
        }
        if (StringUtils.isNotBlank(byId.getSharePic())) {
            homeGoodsSeckillInfoVO.setSharePic(byId.getSharePic());
        } else {
            homeGoodsSeckillInfoVO.setSharePic(data6.getCoverPic());
        }
        homeGoodsSeckillInfoVO.setSeckillPrice(byId.getSeckillPrice());
        homeGoodsSeckillInfoVO.setDescription(data6.getDescription());
        homeGoodsSeckillInfoVO.setDetail(data6.getDetail());
        homeGoodsSeckillInfoVO.setLimitNumber(byId.getLimitNumber());
        homeGoodsSeckillInfoVO.setSeckillPrice(byId.getSeckillPrice());
        homeGoodsSeckillInfoVO.setStartTime(byId.getStartTime());
        homeGoodsSeckillInfoVO.setEndTime(byId.getEndTime());
        homeGoodsSeckillInfoVO.setStartStatus(byId.getStartStatus());
        homeGoodsSeckillInfoVO.setSeckillStock(byId.getSeckillStock());
 
 
        LambdaQueryWrapper<MemberGoodsCollection> wrapper3= Wrappers.lambdaQuery();
        wrapper3.eq(MemberGoodsCollection::getDelFlag,0);
        wrapper3.eq(MemberGoodsCollection::getMemberId,homeGoodsSkuDTO.getMemberId());
        wrapper3.eq(MemberGoodsCollection::getTargetId,homeGoodsSkuDTO.getGoodsSkuId());
        wrapper3.eq(MemberGoodsCollection::getType,3);
        List<MemberGoodsCollection> list = iMemberGoodsCollectionService.list(wrapper3);
        if (list.size()>0){
            homeGoodsSeckillInfoVO.setIsCollection(2);
        }else{
            homeGoodsSeckillInfoVO.setIsCollection(1);
        }
 
        LambdaQueryWrapper<GoodsSeckillAppointment> wrapper4= Wrappers.lambdaQuery();
        wrapper4.eq(GoodsSeckillAppointment::getDelFlag,0);
        wrapper4.eq(GoodsSeckillAppointment::getMemberId,homeGoodsSkuDTO.getMemberId());
        wrapper4.eq(GoodsSeckillAppointment::getGoodsSeckillId,homeGoodsSkuDTO.getGoodsSkuId());
        List<GoodsSeckillAppointment> list2 = iGoodsSeckillAppointmentService.list(wrapper4);
        if (list2.size()>0){
            homeGoodsSeckillInfoVO.setIsAppointment(2);
        }else{
            homeGoodsSeckillInfoVO.setIsAppointment(1);
        }
 
        return homeGoodsSeckillInfoVO;
    }
 
    /**
     * 结束异常的秒杀
     */
    @Override
    public void updSeckillStatus() {
        baseMapper.updSeckillStatus();
    }
}