From 6011b014ae65b7a1bea456c02af4e2cd3596d8a1 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期一, 14 七月 2025 14:30:11 +0800
Subject: [PATCH] Merge branch 'dev' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/task/TaskUtil.java |  123 +++++++++++++++++++++-------------------
 1 files changed, 65 insertions(+), 58 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 578e04a..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,62 +20,67 @@
  * 定时任务工具类
  */
 @Component
-public class TaskUtil {
-
-    @Resource
-    private TAppUserVipDetailService tAppUserVipDetailService;
-
-    @Resource
-    private TAppUserService appUserService;
-
-
-    /**
-     * 每隔一分钟去处理的定时任务
-     */
-    @Scheduled(fixedRate = 1000 * 60)
-    public void sendVipCoupon(){
-        try {
-            //首先获取当前的月份,用int类型标识
-            LocalDate currentDate = LocalDate.now();
-            int monthNum = currentDate.getMonthValue();
-            //获取在当前时间内生效的vipDetail
-            List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery()
-                    .ge(TAppUserVipDetail::getStartTime, currentDate)
-                    .le(TAppUserVipDetail::getEndTime, currentDate)
-                    .orderByDesc(TAppUserVipDetail::getStartTime).list();
-            //判断sendNum是否包括当前月份
-            for (TAppUserVipDetail recentDetail : recentDetails) {
-
-                    //赠送优惠卷
-                    tAppUserVipDetailService.giveVipCoupun(recentDetail.getAppUserId(), recentDetail.getVipId(),recentDetail.getId(),monthNum);
-
-
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-
-
-
-    }
-
-    @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);
-            }
-        }
-
-    }
-
-
+public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> {
+	
+	@Resource
+	private TAppUserVipDetailService tAppUserVipDetailService;
+	
+	@Resource
+	private TAppUserService appUserService;
+	
+	private Integer port = null;
+	
+	
+	/**
+	 * 每隔一分钟去处理的定时任务
+	 */
+	@Scheduled(fixedRate = 1000 * 60)
+	public void sendVipCoupon() {
+		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();
+			}
+		}
+		
+		
+	}
+	
+	@Scheduled(fixedRate = 1000 * 60)
+	public void changeVipId() {
+		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