From 98b09eae533537dc9a5277aa6374bd7d35cfe5c4 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 19 六月 2025 09:20:03 +0800
Subject: [PATCH] 修改bug和定时任务

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/task/TaskUtil.java |   62 +++++++++++++++++++------------
 1 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/task/TaskUtil.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/task/TaskUtil.java
index f9c97c4..0d693ea 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/task/TaskUtil.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/task/TaskUtil.java
@@ -5,6 +5,8 @@
 import com.ruoyi.account.api.model.TAppUserVipDetail;
 import com.ruoyi.account.service.TAppUserService;
 import com.ruoyi.account.service.TAppUserVipDetailService;
+import org.springframework.boot.web.context.WebServerInitializedEvent;
+import org.springframework.context.ApplicationListener;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -18,7 +20,7 @@
  * 定时任务工具类
  */
 @Component
-public class TaskUtil {
+public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> {
 	
 	@Resource
 	private TAppUserVipDetailService tAppUserVipDetailService;
@@ -26,26 +28,30 @@
 	@Resource
 	private TAppUserService appUserService;
 	
+	private Integer port = null;
+	
 	
 	/**
 	 * 每隔一分钟去处理的定时任务
 	 */
 	@Scheduled(fixedRate = 1000 * 60)
 	public void sendVipCoupon() {
-		try {
-			//会员优惠次数使用完后重新续次数
-			LocalDateTime currentDate = LocalDateTime.now();
-			List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery()
-					.le(TAppUserVipDetail::getStartTime, currentDate)
-					.ge(TAppUserVipDetail::getEndTime, currentDate)
-					.ne(TAppUserVipDetail::getVipType, 1)
-					.le(TAppUserVipDetail::getMonthEndTime, currentDate)
-					.orderByDesc(TAppUserVipDetail::getStartTime).list();
-			for (TAppUserVipDetail recentDetail : recentDetails) {
-				tAppUserVipDetailService.giveVipCoupun(recentDetail);
+		if(null != port && port == 5200){
+			try {
+				//会员优惠次数使用完后重新续次数
+				LocalDateTime currentDate = LocalDateTime.now();
+				List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery()
+						.le(TAppUserVipDetail::getStartTime, currentDate)
+						.ge(TAppUserVipDetail::getEndTime, currentDate)
+						.ne(TAppUserVipDetail::getVipType, 1)
+						.le(TAppUserVipDetail::getMonthEndTime, currentDate)
+						.orderByDesc(TAppUserVipDetail::getStartTime).list();
+				for (TAppUserVipDetail recentDetail : recentDetails) {
+					tAppUserVipDetailService.giveVipCoupun(recentDetail);
+				}
+			} catch (Exception e) {
+				e.printStackTrace();
 			}
-		} catch (Exception e) {
-			e.printStackTrace();
 		}
 		
 		
@@ -53,20 +59,28 @@
 	
 	@Scheduled(fixedRate = 1000 * 60)
 	public void changeVipId() {
-		LocalDateTime currentDate = LocalDateTime.now();
-		List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery()
-				.le(TAppUserVipDetail::getStartTime, currentDate)
-				.ge(TAppUserVipDetail::getEndTime, currentDate)
-				.orderByDesc(TAppUserVipDetail::getStartTime).list();
-		for (TAppUserVipDetail recentDetail : recentDetails) {
-			TAppUser byId = appUserService.getById(recentDetail.getAppUserId());
-			if (byId != null) {
-				byId.setVipId(recentDetail.getVipId());
-				appUserService.updateById(byId);
+		if(null != port && port == 5200){
+			LocalDateTime currentDate = LocalDateTime.now();
+			List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery()
+					.le(TAppUserVipDetail::getStartTime, currentDate)
+					.ge(TAppUserVipDetail::getEndTime, currentDate)
+					.orderByDesc(TAppUserVipDetail::getStartTime).list();
+			for (TAppUserVipDetail recentDetail : recentDetails) {
+				TAppUser byId = appUserService.getById(recentDetail.getAppUserId());
+				if (byId != null) {
+					byId.setVipId(recentDetail.getVipId());
+					appUserService.updateById(byId);
+				}
 			}
 		}
+		
 		
 	}
 	
 	
+	@Override
+	public void onApplicationEvent(WebServerInitializedEvent event) {
+		port = event.getWebServer().getPort();
+		System.out.println("端口号:" + port);
+	}
 }

--
Gitblit v1.7.1