| @@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory | |||||
| import org.springframework.scheduling.TaskScheduler | import org.springframework.scheduling.TaskScheduler | ||||
| import org.springframework.scheduling.support.CronTrigger | import org.springframework.scheduling.support.CronTrigger | ||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| import java.time.DayOfWeek | |||||
| import java.time.LocalDate | import java.time.LocalDate | ||||
| import java.time.LocalDateTime | import java.time.LocalDateTime | ||||
| import java.time.format.DateTimeFormatter | import java.time.format.DateTimeFormatter | ||||
| @@ -449,22 +450,37 @@ open class SchedulerService( | |||||
| val currentTime = LocalDateTime.now() | val currentTime = LocalDateTime.now() | ||||
| // .atStartOfDay() results in 00:00:00 | // .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 ysd = today.minusDays(1L) | ||||
| val tmr = today.plusDays(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 | // 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( | val requestDO = M18CommonRequest( | ||||
| // These will now produce "yyyy-MM-dd HH:mm:ss" | // These will now produce "yyyy-MM-dd HH:mm:ss" | ||||
| dDateTo = tmr.format(dateTimeStringFormat), // e.g. 2026-01-19 00:00:00 | dDateTo = tmr.format(dateTimeStringFormat), // e.g. 2026-01-19 00:00:00 | ||||
| dDateFrom = 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 | 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) | val result = m18DeliveryOrderService.saveDeliveryOrders(requestDO) | ||||