From f26537e926d7ad2d725e059700142ba14c0c2b1f Mon Sep 17 00:00:00 2001
From: jiangqs <jiangqs>
Date: 星期三, 12 七月 2023 21:04:27 +0800
Subject: [PATCH] 定时任务延时任务

---
 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/RedisListener.java |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/RedisListener.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/RedisListener.java
index 3e539d5..6f84050 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/RedisListener.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/listener/RedisListener.java
@@ -3,6 +3,9 @@
 
 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.RemoteConfigService;
+import com.ruoyi.system.api.service.RemoteCouponService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.redis.connection.Message;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -13,12 +16,22 @@
 
 import java.util.Date;
 
+/**
+ * @author jqs34
+ * @ClassName RedisListener
+ * @description: redis监听
+ * @date 2023年06月06日
+ * @version: 1.0
+ */
 @Slf4j
 @Component
 public class RedisListener extends KeyExpirationEventMessageListener {
 
     private RedisTemplate<String, Object> redisTemplate;
 
+    private RemoteConfigService remoteConfigService;
+
+    private RemoteCouponService remoteCouponService;
 
     public RedisListener(RedisMessageListenerContainer listenerContainer,
                          RedisTemplate redisTemplate) {
@@ -37,7 +50,10 @@
                 if(expiredKey.contains("-")){
                     String[] split = expiredKey.split("-");
                     String operation=split[0];
-
+                    if(DelayTaskEnum.COUPON_SEND_DELAY_TASK.getCode().equals(operation)){
+                        //自动关闭订单
+                        autoTimeSendCoupon(split[1]);
+                    }
                     //删除失效的key
                     redisTemplate.delete(expiredKey);
                 }
@@ -59,8 +75,13 @@
     }
 
     //延时任务表
-
-
+    //自动定时发送优惠券
+    private void autoTimeSendCoupon(String couponId){
+        log.info("autoTimeSendCoupon scheduler task is running :" + couponId);
+        remoteCouponService.autoTimeSendCoupon(couponId);
+        //删除定时任务
+        remoteConfigService.deleteDelayTask(DelayTaskEnum.COUPON_SEND_DELAY_TASK.getCode()+"-"+couponId);
+    }
 
 
 }

--
Gitblit v1.7.1