| | |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.api.constant.DelayTaskEnum; |
| | | import com.ruoyi.system.api.service.RemoteActivityService; |
| | | import com.ruoyi.system.api.service.RemoteConfigService; |
| | | import com.ruoyi.system.api.service.RemoteCouponService; |
| | | import com.ruoyi.system.api.service.RemoteOrderService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.data.redis.connection.Message; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | |
| | | private RemoteCouponService remoteCouponService; |
| | | |
| | | private RemoteActivityService remoteActivityService; |
| | | |
| | | private RemoteOrderService remoteOrderService; |
| | | |
| | | public RedisListener(RedisMessageListenerContainer listenerContainer, |
| | | RedisTemplate redisTemplate) { |
| | | super(listenerContainer); |
| | |
| | | String[] split = expiredKey.split("-"); |
| | | String operation=split[0]; |
| | | if(DelayTaskEnum.COUPON_SEND_DELAY_TASK.getCode().equals(operation)){ |
| | | //自动关闭订单 |
| | | //自动发送优惠券 |
| | | autoTimeSendCoupon(split[1]); |
| | | }else if(DelayTaskEnum.ACTIVITY_START_TASK.getCode().equals(operation)){ |
| | | //自动开始任务 |
| | | autoStartActivity(split[1]); |
| | | }else if(DelayTaskEnum.ACTIVITY_END_TASK.getCode().equals(operation)){ |
| | | //自动结束任务 |
| | | autoEndActivity(split[1]); |
| | | }else if(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode().equals(operation)){ |
| | | //自动结束任务 |
| | | autoCancelOrder(split[1]); |
| | | } |
| | | |
| | | //删除失效的key |
| | | redisTemplate.delete(expiredKey); |
| | | } |
| | |
| | | remoteConfigService.deleteDelayTask(DelayTaskEnum.COUPON_SEND_DELAY_TASK.getCode()+"-"+couponId); |
| | | } |
| | | |
| | | private void autoStartActivity(String activityId){ |
| | | log.info("autoStartActivity scheduler task is running :" + activityId); |
| | | remoteActivityService.startActivity(activityId); |
| | | //删除定时任务 |
| | | remoteConfigService.deleteDelayTask(DelayTaskEnum.ACTIVITY_START_TASK.getCode()+"-"+activityId); |
| | | } |
| | | |
| | | private void autoEndActivity(String activityId){ |
| | | log.info("autoEndActivity scheduler task is running :" + activityId); |
| | | remoteActivityService.endActivity(activityId); |
| | | //删除定时任务 |
| | | remoteConfigService.deleteDelayTask(DelayTaskEnum.ACTIVITY_END_TASK.getCode()+"-"+activityId); |
| | | } |
| | | |
| | | private void autoCancelOrder(String orderId){ |
| | | log.info("autoCancelOrder scheduler task is running :" + orderId); |
| | | remoteOrderService.autoCancelOrder(orderId); |
| | | //删除定时任务 |
| | | remoteConfigService.deleteDelayTask(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode()+"-"+orderId); |
| | | } |
| | | } |