From 54ea586ece304ef2569a345c9b26b2a9b9702c8a Mon Sep 17 00:00:00 2001
From: shikeying <pxzsky@163.com>
Date: 星期五, 19 一月 2024 11:11:40 +0800
Subject: [PATCH] 定时任务,修改启动不执行(当过期)

---
 walker-scheduler/src/main/java/com/walker/scheduler/Option.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/walker-scheduler/src/main/java/com/walker/scheduler/Option.java b/walker-scheduler/src/main/java/com/walker/scheduler/Option.java
index c8830fb..0a5abf7 100644
--- a/walker-scheduler/src/main/java/com/walker/scheduler/Option.java
+++ b/walker-scheduler/src/main/java/com/walker/scheduler/Option.java
@@ -56,6 +56,18 @@
 	private int currentTaskMonth = 0;			// 鍛ㄦ湡鎬э紝褰撳墠鎵ц鍒扮殑鏈堬紝璁板綍
 	private int currentTaskYear = 0;				// 鍛ㄦ湡鎬э紝褰撳墠鎵ц鍒扮殑骞达紝璁板綍
 
+	public int getCurrentTaskDay() {
+		return currentTaskDay;
+	}
+
+	public int getCurrentTaskMonth() {
+		return currentTaskMonth;
+	}
+
+	public int getCurrentTaskYear() {
+		return currentTaskYear;
+	}
+
 	public String getTimeRangesValue() {
 		StringBuilder s = new StringBuilder();
 		for(Integer[] vals : timeRanges){
@@ -110,6 +122,43 @@
 		this.currentTaskMonth = month;
 		this.currentTaskDay = day;
 //		this.currentTaskHour = hour;
+
+		// 2024-01-18锛屼慨澶嶏細濡傛灉宸茬粡杩囦簡浠婂ぉ鏃堕棿鐐圭殑浠诲姟锛屽锛氬噷鏅�2鐐癸紝鍒欓渶瑕佽嚜鍔ㄥ垏鎹㈠埌涓嬩竴涓椂闂淬��
+		// 鍚﹀垯鍑虹幇浠诲姟姘歌繙鏃犳硶鎵ц鎯呭喌銆�
+		if(this.isCycleTask){
+			Option.TimeObject timeObj = this.isAvailableTime(System.currentTimeMillis());
+			int currentHour = DateUtils.getCurrentHour();
+			int currentDay = DateUtils.getCurrentYearMonthDay()[2];
+			if(this.periodType == PeriodType.DAY){
+				if(currentHour > hour){
+					// 浠婂ぉ宸茬粡杩囦簡鏃堕棿鐐癸紝鑷姩鍒囨崲鍒颁笅涓�娆�
+					this.scheduleToNext(timeObj);
+					logger.info("浠婂ぉ宸茬粡杩囦簡鏃堕棿鐐癸紝鑷姩鍒囨崲鍒颁笅涓�娆★紝option={}", this);
+				}
+
+			} else if (this.periodType == PeriodType.MONTH) {
+				if(currentDay > day){
+					this.scheduleToNext(timeObj);
+					logger.info("鏈湀褰撳墠鏃ユ湡{}宸茶秴杩囪缃棩鏈焮}锛岃嚜鍔ㄥ垏鎹㈠埌涓嬩竴娆★紝option={}", currentDay, day, this);
+				} else if(currentDay == day && (currentHour > hour)){
+					this.scheduleToNext(timeObj);
+					logger.info("鏈湀鏃ユ湡宸插埌杈撅紝浣嗙敱浜庢椂闂村凡杩囨湡锛屽洜姝や换鍔′細鍦ㄤ笅涓湀鎵ц锛宱ption={}", this);
+				}
+
+			} else if (this.periodType == PeriodType.YEAR) {
+				int currentMonth = DateUtils.getCurrentYearMonthDay()[1];
+				if(currentMonth > month){
+					this.scheduleToNext(timeObj);
+					logger.info("鏈勾褰撳墠鏈堜唤{}宸茶秴杩囪缃湀浠絳}锛岃嚜鍔ㄥ垏鎹㈠埌涓嬩竴娆★紝option={}", currentMonth, month, this);
+				} else if (currentMonth == month && (currentDay > day)) {
+					this.scheduleToNext(timeObj);
+					logger.info("鏈勾褰撳墠鏈堜唤鐩稿悓锛屼絾褰撳墠鏃ユ湡{}宸茶秴杩囪缃棩鏈焮}锛岃嚜鍔ㄥ垏鎹㈠埌涓嬩竴娆★紝option={}", currentDay, day, this);
+				} else if(currentMonth == month && (currentDay == day) && currentHour > hour){
+					this.scheduleToNext(timeObj);
+					logger.info("鏈勾褰撳墠鏈堜唤鏃ユ湡鐩稿悓锛屼絾褰撳墠鏃堕棿{}宸茶秴杩囪缃椂闂磠}锛岃嚜鍔ㄥ垏鎹㈠埌涓嬩竴娆★紝option={}", currentHour, hour, this);
+				}
+			}
+		}
 	}
 
 	/**
@@ -454,6 +503,17 @@
 		}
 	}
 
+	@Override
+	public String toString(){
+		return new StringBuilder("[periodType=").append(this.periodType)
+				.append(", timeType=").append(this.timeType)
+				.append(", timeRanges=").append(this.timeRanges)
+				.append(", isCycleTask=").append(this.isCycleTask)
+				.append(", setYearMonthDayHour=").append(this.year).append("-").append(this.month).append("-").append(this.day).append("-").append(this.hour)
+				.append(", nextTime=").append(this.currentTaskYear).append("-").append(this.currentTaskMonth).append("-").append(this.currentTaskDay)
+				.append("]").toString();
+	}
+
 	public static void main(String[] args){
 		/**
 		long test = System.currentTimeMillis();

--
Gitblit v1.9.1