From 8e4e92f84f149ec9f9da6dd601fab06ed55c544c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 20 Apr 2024 09:36:05 -0700 Subject: Improve report schedules logic --- src/main/java/org/traccar/model/Calendar.java | 3 ++- src/main/java/org/traccar/schedule/TaskReports.java | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/model/Calendar.java b/src/main/java/org/traccar/model/Calendar.java index feef7286f..76c9a2cc1 100644 --- a/src/main/java/org/traccar/model/Calendar.java +++ b/src/main/java/org/traccar/model/Calendar.java @@ -34,6 +34,7 @@ import java.time.Duration; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; @StorageName("tc_calendars") @@ -78,7 +79,7 @@ public class Calendar extends ExtendedModel { } } - public Collection findPeriods(Date date) { + public Set findPeriods(Date date) { return findEvents(date).stream() .flatMap((e) -> e.calculateRecurrenceSet(new Period(new DateTime(date), Duration.ZERO)).stream()) .collect(Collectors.toSet()); diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java index 3989cd6a0..1d074214c 100644 --- a/src/main/java/org/traccar/schedule/TaskReports.java +++ b/src/main/java/org/traccar/schedule/TaskReports.java @@ -43,7 +43,9 @@ import org.traccar.storage.query.Request; import jakarta.inject.Inject; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -81,8 +83,9 @@ public class TaskReports implements ScheduleTask { var lastEvents = calendar.findPeriods(lastCheck); var currentEvents = calendar.findPeriods(currentCheck); - if (!lastEvents.isEmpty() && !currentEvents.equals(lastEvents)) { - Period period = lastEvents.iterator().next(); + Set finishedEvents = new HashSet<>(lastEvents); + finishedEvents.removeAll(currentEvents); + for (Period period : finishedEvents) { RequestScoper scope = ServletScopes.scopeRequest(Collections.emptyMap()); try (RequestScoper.CloseableScope ignored = scope.open()) { executeReport(report, period.getStart(), period.getEnd()); -- cgit v1.2.3