| | |
| | | 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; |
| | |
| | | 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()); |
| | | |
| | | DelayTask delayTask = new DelayTask(); |
| | | delayTask.setDelFlag(0); |
| | | delayTask.setCreateTime(LocalDateTime.now()); |
| | | delayTask.setExecuteTime(byId.getStartTime().minusMinutes(5)); |
| | | delayTask.setExecuteTime(byId.getStartTime().minusMinutes(30)); |
| | | delayTask.setRedisKey(DelayTaskEnum.AUTOMATIC_CANCEL.getCode() + "-" + byId.getId()); |
| | | sysUserClient.addDelayTask(delayTask, SecurityConstants.INNER); |
| | | |
| | | Duration duration = Duration.between(LocalDateTime.now(), byId.getStartTime().minusMinutes(5)); |
| | | 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){ |
| | | throw new ServiceException("即将开始已无法遇约"); |
| | | } |
| | | |
| | | 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(); |
| | | } |