From c8c77b0c3396f9dff8637a757f54c9c4320f4b25 Mon Sep 17 00:00:00 2001 From: Fai Luk Date: Thu, 16 Apr 2026 13:25:47 +0800 Subject: [PATCH] handle the special case of syn DO2 for sunday --- .../scheduler/service/SchedulerService.kt | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ffii/fpsms/modules/common/scheduler/service/SchedulerService.kt b/src/main/java/com/ffii/fpsms/modules/common/scheduler/service/SchedulerService.kt index eacdf67..fe3a746 100644 --- a/src/main/java/com/ffii/fpsms/modules/common/scheduler/service/SchedulerService.kt +++ b/src/main/java/com/ffii/fpsms/modules/common/scheduler/service/SchedulerService.kt @@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory import org.springframework.scheduling.TaskScheduler import org.springframework.scheduling.support.CronTrigger import org.springframework.stereotype.Service +import java.time.DayOfWeek import java.time.LocalDate import java.time.LocalDateTime import java.time.format.DateTimeFormatter @@ -449,22 +450,37 @@ open class SchedulerService( val currentTime = LocalDateTime.now() // .atStartOfDay() results in 00:00:00 - val today = currentTime.toLocalDate().atStartOfDay() + val runDate = currentTime.toLocalDate() + val today = runDate.atStartOfDay() val ysd = today.minusDays(1L) val tmr = today.plusDays(1L) - // Set to 19:00:00 of yesterday - val ysdNight = ysd.withHour(19).withMinute(0).withSecond(0) + // Default: lastModified from yesterday 19:00 (aligns with nightly DO2 expectation). + // On Sunday, yesterday is Saturday: use 03:00 instead so we include DO changed after Sat 03:10 DO1 + // (otherwise Sat 03:00–18:59 would be skipped until a much later sync). + val isSundayDo2 = runDate.dayOfWeek == DayOfWeek.SUNDAY + val modifiedFromStart = if (isSundayDo2) { + ysd.withHour(3).withMinute(0).withSecond(0) + } else { + ysd.withHour(19).withMinute(0).withSecond(0) + } // Set to 11:00:00 of today - val todayEleven = today.withHour(11).withMinute(0).withSecond(0) + val todayEleven = today.withHour(11).withMinute(0).withSecond(0) + + logger.info( + "DO2 modifiedDateFrom={} ({}), modifiedDateTo={}", + modifiedFromStart.format(dateTimeStringFormat), + if (isSundayDo2) "Sunday window from Sat 03:00" else "from yesterday 19:00", + todayEleven.format(dateTimeStringFormat), + ) val requestDO = M18CommonRequest( // These will now produce "yyyy-MM-dd HH:mm:ss" dDateTo = tmr.format(dateTimeStringFormat), // e.g. 2026-01-19 00:00:00 dDateFrom = tmr.format(dateTimeStringFormat), // e.g. 2026-01-19 00:00:00 modifiedDateTo = todayEleven.format(dateTimeStringFormat), // 2026-01-18 11:00:00 - modifiedDateFrom = ysdNight.format(dateTimeStringFormat) // 2026-01-17 19:00:00 + modifiedDateFrom = modifiedFromStart.format(dateTimeStringFormat), ) val result = m18DeliveryOrderService.saveDeliveryOrders(requestDO)