mitao
2024-07-29 fc8b51f40e71aa09bb49f407c1e9f68ac94ceb58
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSeckillAppointmentServiceImpl.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.goods.domain.GoodsSeckillAppointment;
import com.ruoyi.goods.mapper.GoodsSeckillAppointmentMapper;
@@ -38,11 +39,7 @@
   private RedisService redisService;
    @Override
    public R goodsSeckillAppointment(HomeGoodsSkuDTO homeGoodsSkuDTO) {
        GoodsSeckillAppointment goodsSeckillAppointment=new GoodsSeckillAppointment();
        goodsSeckillAppointment.setGoodsSeckillId(homeGoodsSkuDTO.getGoodsSkuId());
        goodsSeckillAppointment.setMemberId(homeGoodsSkuDTO.getMemberId());
        goodsSeckillAppointment.setFormId(homeGoodsSkuDTO.getFormId());
        this.save(goodsSeckillAppointment);
        GoodsSeckill byId = goodsSeckillMapper.selectById(homeGoodsSkuDTO.getGoodsSkuId());
@@ -54,10 +51,19 @@
        sysUserClient.addDelayTask(delayTask, SecurityConstants.INNER);
        Duration duration = Duration.between(LocalDateTime.now(), byId.getStartTime().minusMinutes(30));
        try {
            redisService.setCacheObject(
                    DelayTaskEnum.AUTOMATIC_CANCEL.getCode() + "-" + byId.getId(),
                    byId.getStartTime().minusMinutes(30), duration.getSeconds(), TimeUnit.SECONDS);
        }catch (Exception e){
        redisService.setCacheObject(
                DelayTaskEnum.AUTOMATIC_CANCEL.getCode() + "-" + byId.getId(),
                byId.getStartTime().minusMinutes(30), duration.getSeconds(), TimeUnit.SECONDS);
        }
        GoodsSeckillAppointment goodsSeckillAppointment=new GoodsSeckillAppointment();
        goodsSeckillAppointment.setGoodsSeckillId(homeGoodsSkuDTO.getGoodsSkuId());
        goodsSeckillAppointment.setMemberId(homeGoodsSkuDTO.getMemberId());
        goodsSeckillAppointment.setFormId(homeGoodsSkuDTO.getFormId());
        this.save(goodsSeckillAppointment);
        return R.ok();
    }