diff options
Diffstat (limited to 'src/main/java/org/traccar/schedule/TaskReports.java')
-rw-r--r-- | src/main/java/org/traccar/schedule/TaskReports.java | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java index 070fa9d2b..32f6fea87 100644 --- a/src/main/java/org/traccar/schedule/TaskReports.java +++ b/src/main/java/org/traccar/schedule/TaskReports.java @@ -41,6 +41,8 @@ import org.traccar.storage.query.Condition; import org.traccar.storage.query.Request; import jakarta.inject.Inject; + +import java.time.Instant; import java.util.Collections; import java.util.Date; import java.util.HashSet; @@ -50,7 +52,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -public class TaskReports implements ScheduleTask { +public class TaskReports extends SingleScheduleTask { private static final Logger LOGGER = LoggerFactory.getLogger(TaskReports.class); @@ -83,12 +85,12 @@ public class TaskReports implements ScheduleTask { var lastEvents = calendar.findPeriods(lastCheck); var currentEvents = calendar.findPeriods(currentCheck); - Set<Period> finishedEvents = new HashSet<>(lastEvents); + Set<Period<Instant>> finishedEvents = new HashSet<>(lastEvents); finishedEvents.removeAll(currentEvents); - for (Period period : finishedEvents) { + for (Period<Instant> period : finishedEvents) { RequestScoper scope = ServletScopes.scopeRequest(Collections.emptyMap()); try (RequestScoper.CloseableScope ignored = scope.open()) { - executeReport(report, period.getStart(), period.getEnd()); + executeReport(report, Date.from(period.getStart()), Date.from(period.getEnd())); } } } @@ -116,34 +118,32 @@ public class TaskReports implements ScheduleTask { for (User user : users) { LogAction.report(user.getId(), true, report.getType(), from, to, deviceIds, groupIds); switch (report.getType()) { - case "events": + case "events" -> { var eventsReportProvider = injector.getInstance(EventsReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> eventsReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, List.of(), from, to)); - break; - case "route": + } + case "route" -> { var routeReportProvider = injector.getInstance(RouteReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> routeReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, from, to)); - break; - case "summary": + } + case "summary" -> { var summaryReportProvider = injector.getInstance(SummaryReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> summaryReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, from, to, false)); - break; - case "trips": + } + case "trips" -> { var tripsReportProvider = injector.getInstance(TripsReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> tripsReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, from, to)); - break; - case "stops": + } + case "stops" -> { var stopsReportProvider = injector.getInstance(StopsReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> stopsReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, from, to)); - break; - default: - LOGGER.warn("Unsupported report type {}", report.getType()); - break; + } + default -> LOGGER.warn("Unsupported report type {}", report.getType()); } } } |