gongfuzhu 1 gadu atpakaļ
vecāks
revīzija
69301b6e61

+ 3 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/boot/SpringBatchApplication.java

@@ -6,10 +6,13 @@ import org.springframework.batch.core.configuration.annotation.EnableBatchProces
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
 
 /**
  * @author Wy
  */
+@EnableScheduling
 @SpringBootApplication
 @EnableApplicationClient
 @EnableBatchProcessing

+ 3 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/job/standard/StandardOrderJob.java

@@ -112,6 +112,9 @@ public class StandardOrderJob {
                             GoodsInfoVo goodsInfoVo = detail.getContent();
                             SharePlatformVo sharePlatformVo = goodsInfoVo.getSharePlatformVo();
 
+                            // 设置有效期
+                            createOrder2Model.setValidDay(goodsInfoVo.getValidDay());
+
 
                             goods.setTransferType(sharePlatformVo.getShareType() == 1 ? TransferType.RATIO : TransferType.FIXED);
                             CreateOrder2Model.Owner platform = new CreateOrder2Model.Owner();

+ 43 - 0
SpringBatchServiceServer/src/main/java/com/zswl/cloud/springBtach/server/core/timer/DelayTimer.java

@@ -0,0 +1,43 @@
+package com.zswl.cloud.springBtach.server.core.timer;
+
+import com.github.microservice.auth.client.content.ResultContent;
+import com.zhongshu.payment.client.model.order.v2.GoodsResultModel;
+import com.zhongshu.payment.client.service.v2.OrderService2;
+import com.zhongshu.payment.client.service.v2.PaymentService2;
+import com.zhongshu.payment.client.type.RedisEventType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.Set;
+
+@Component
+public class DelayTimer {
+
+    @Autowired
+    PaymentService2 paymentService2;
+
+    @Autowired
+    OrderService2 orderService2;
+
+
+    RedisTemplate<String, String> redisTemplate;
+
+    @Scheduled(fixedRate = 1000) // 每秒执行一次
+    public void processDelayedQueue() {
+        long currentTimestamp = System.currentTimeMillis();
+        Set<String> orderTmp = redisTemplate.opsForZSet().rangeByScore(RedisEventType.ORDER_TMPE.name(), 0, currentTimestamp);
+
+        for (String orderNo : orderTmp) {
+            ResultContent<GoodsResultModel> goodsResultModelResultContent = orderService2.orderInfo(orderNo);
+            GoodsResultModel content = goodsResultModelResultContent.getContent();
+            paymentService2.close(orderNo,content.getUserId());
+            redisTemplate.opsForZSet().remove(RedisEventType.ORDER_TMPE.name(), orderNo);
+        }
+    }
+
+
+
+
+}

+ 1 - 1
SpringBatchServiceServer/src/main/resources/application-dev.yml

@@ -21,7 +21,7 @@ spring:
   redis:
     host: 192.168.110.241
     port: 6379
-    database: 5
+    database: 6
 
 swagger:
   packageName: "com.zswl.cloud.springBtach.server.core.controller"