mitao
2024-05-31 d5cd5518fb4c9ec771dbf3d8db691fef36d18a45
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSeckillServiceImpl.java
@@ -4,6 +4,7 @@
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.ListingStatusEnum;
@@ -83,7 +84,7 @@
                    .set(GoodsSku::getStock, goodsSku.getStock() - seckillStock)
                    .ge(GoodsSku::getStock, seckillStock)
                    .eq(GoodsSku::getId, goodsSku.getId());
            asyncMethodService.seckillScheduleTask(goodsSeckill);
            asyncMethodService.seckillScheduleTask(Lists.newArrayList(goodsSeckill));
        }
    }
@@ -119,7 +120,7 @@
        }
        GoodsSeckill goodsSeckillUpd = BeanUtils.copyBean(upd, GoodsSeckill.class);
        this.updateById(goodsSeckillUpd);
        asyncMethodService.seckillScheduleTask(goodsSeckill);
        asyncMethodService.seckillScheduleTask(Lists.newArrayList(goodsSeckill));
    }
    /**
@@ -176,9 +177,11 @@
    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)) {
                && goodsSeckill.getStartStatus().equals(StartStatusEnum.NOT_STARTED) &&
                goodsSeckill.getListingStatus()
                        .equals(ListingStatusEnum.ON_SHELVES)) {
            //开始秒杀
            this.lambdaUpdate().set(GoodsSeckill::getStartStatus, StartStatusEnum.STARTED)
                    .eq(GoodsSeckill::getId, seckillId).update();
@@ -191,6 +194,7 @@
        Map<String, Object> map = new ConcurrentHashMap<>();
        map.put("notification_type", NotificationTypeConstant.SECKILL);
        map.put("notification_time", LocalDateTime.now());
        map.put("target_id", seckillId);
        map.put("message_type", "start");
        String msg = objectMapper.writeValueAsString(map);
        WebSocketUsers.sendMessageToUsersByText(msg);
@@ -217,6 +221,7 @@
        Map<String, Object> map = new ConcurrentHashMap<>();
        map.put("notification_type", NotificationTypeConstant.SECKILL);
        map.put("notification_time", LocalDateTime.now());
        map.put("target_id", seckillId);
        map.put("message_type", "end");
        String msg = objectMapper.writeValueAsString(map);
        WebSocketUsers.sendMessageToUsersByText(msg);