ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSeckillServiceImpl.java
@@ -5,6 +5,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
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.StringUtils;
@@ -19,6 +21,7 @@
import com.ruoyi.goods.service.IGoodsSeckillService;
import com.ruoyi.goods.service.IGoodsSkuService;
import com.ruoyi.goods.service.async.AsyncMethodService;
import com.ruoyi.system.api.constants.DelayTaskEnum;
import com.ruoyi.system.api.constants.NotificationTypeConstant;
import com.ruoyi.system.api.domain.GoodsSeckill;
import com.ruoyi.system.api.domain.GoodsSku;
@@ -109,7 +112,10 @@
        //查询秒杀商品
        GoodsSeckill goodsSeckill = this.getById(upd.getId());
        if (StringUtils.isNull(goodsSeckill)) {
            throw new RuntimeException("秒杀商品不存在");
            throw new ServiceException("秒杀商品不存在");
        }
        if (goodsSeckill.getStartStatus().equals(StartStatusEnum.STARTED)) {
            throw new ServiceException("秒杀商品已开始秒杀,不能修改");
        }
        GoodsSeckill goodsSeckillUpd = BeanUtils.copyBean(upd, GoodsSeckill.class);
        this.updateById(goodsSeckillUpd);
@@ -123,10 +129,21 @@
     */
    @Override
    public void updStatus(ListStatusDTO dto) {
        GoodsSeckill goodsSeckill = this.getById(dto.getId());
        if (StringUtils.isNull(goodsSeckill)) {
            throw new ServiceException("秒杀商品不存在");
        }
        this.lambdaUpdate()
                .eq(GoodsSeckill::getId, dto.getId())
                .set(GoodsSeckill::getListingStatus, dto.getListingStatus())
                .update();
        if (dto.getListingStatus().equals(ListingStatusEnum.REMOVED_FROM_THE_SHELF)) {
            //移除该秒杀商品的延时任务
            redisService.deleteObject(
                    DelayTaskEnum.SECKILL_START_TASK.getCode() + "-" + goodsSeckill.getId());
            redisService.deleteObject(
                    DelayTaskEnum.SECKILL_END_TASK.getCode() + "-" + goodsSeckill.getId());
        }
    }
    /**
@@ -139,12 +156,13 @@
    public GoodsSeckillVO getDetail(Long id) {
        GoodsSeckill goodsSeckill = this.getById(id);
        if (StringUtils.isNull(goodsSeckill)) {
            throw new RuntimeException("秒杀商品不存在");
            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()));
        Integer num = orderClient.getSeckillMembers(goodsSeckill.getGoodsSkuId()).getData();
        Integer num = orderClient.getSeckillMembers(goodsSeckill.getGoodsSkuId(),
                SecurityConstants.INNER).getData();
        vo.setNumberOfPurchasedMembers(num);
        return vo;
    }