aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/schedule
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-01-26 15:19:47 -0800
committerAnton Tananaev <anton@traccar.org>2023-01-26 15:19:53 -0800
commit18387265cd9432a906cd16b7d71547be5bf46086 (patch)
tree609f87c7812eec90255906dc90f50f12ed3b8143 /src/main/java/org/traccar/schedule
parent7d1a4120ebe5304217d617e248125e9663bbbf50 (diff)
downloadtrackermap-server-18387265cd9432a906cd16b7d71547be5bf46086.tar.gz
trackermap-server-18387265cd9432a906cd16b7d71547be5bf46086.tar.bz2
trackermap-server-18387265cd9432a906cd16b7d71547be5bf46086.zip
Use period from calendar
Diffstat (limited to 'src/main/java/org/traccar/schedule')
-rw-r--r--src/main/java/org/traccar/schedule/TaskReports.java51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java
index 259eb10d4..c80b786e9 100644
--- a/src/main/java/org/traccar/schedule/TaskReports.java
+++ b/src/main/java/org/traccar/schedule/TaskReports.java
@@ -15,6 +15,7 @@
*/
package org.traccar.schedule;
+import net.fortuna.ical4j.model.component.VEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.model.BaseModel;
@@ -86,8 +87,15 @@ public class TaskReports implements ScheduleTask {
for (Report report : storage.getObjects(Report.class, new Request(new Columns.All()))) {
Calendar calendar = storage.getObject(Calendar.class, new Request(
new Columns.All(), new Condition.Equals("id", report.getCalendarId())));
- if (calendar.checkMoment(currentCheck) && !calendar.checkMoment(lastCheck)) {
- executeReport(report);
+
+ var lastEvents = calendar.findEvents(lastCheck);
+ var currentEvents = calendar.findEvents(currentCheck);
+
+ if (!lastEvents.isEmpty() && currentEvents.isEmpty()) {
+ VEvent event = lastEvents.iterator().next();
+ Date from = event.getStartDate().getDate();
+ Date to = event.getEndDate().getDate();
+ executeReport(report, from, to);
}
}
} catch (StorageException e) {
@@ -95,7 +103,8 @@ public class TaskReports implements ScheduleTask {
}
}
- private void executeReport(Report report) throws StorageException {
+ private void executeReport(Report report, Date from, Date to) throws StorageException {
+
var deviceIds = storage.getObjects(Device.class, new Request(
new Columns.Include("id"),
new Condition.Permission(Device.class, Report.class, report.getId())))
@@ -107,42 +116,28 @@ public class TaskReports implements ScheduleTask {
var users = storage.getObjects(User.class, new Request(
new Columns.Include("id"),
new Condition.Permission(User.class, Report.class, report.getId())));
+
for (User user : users) {
switch (report.getType()) {
case "events":
- reportMailer.sendAsync(user.getId(), stream -> {
- eventsReportProvider.getExcel(
- stream, user.getId(), deviceIds, groupIds,
- List.of(), report.getFrom(), report.getTo());
- });
+ reportMailer.sendAsync(user.getId(), stream -> eventsReportProvider.getExcel(
+ stream, user.getId(), deviceIds, groupIds, List.of(), from, to));
break;
case "route":
- reportMailer.sendAsync(user.getId(), stream -> {
- routeReportProvider.getExcel(
- stream, user.getId(), deviceIds, groupIds,
- report.getFrom(), report.getTo());
- });
+ reportMailer.sendAsync(user.getId(), stream -> routeReportProvider.getExcel(
+ stream, user.getId(), deviceIds, groupIds, from, to));
break;
case "summary":
- reportMailer.sendAsync(user.getId(), stream -> {
- summaryReportProvider.getExcel(
- stream, user.getId(), deviceIds, groupIds,
- report.getFrom(), report.getTo(), false);
- });
+ reportMailer.sendAsync(user.getId(), stream -> summaryReportProvider.getExcel(
+ stream, user.getId(), deviceIds, groupIds, from, to, false));
break;
case "trips":
- reportMailer.sendAsync(user.getId(), stream -> {
- tripsReportProvider.getExcel(
- stream, user.getId(), deviceIds, groupIds,
- report.getFrom(), report.getTo());
- });
+ reportMailer.sendAsync(user.getId(), stream -> tripsReportProvider.getExcel(
+ stream, user.getId(), deviceIds, groupIds, from, to));
break;
case "stops":
- reportMailer.sendAsync(user.getId(), stream -> {
- stopsReportProvider.getExcel(
- stream, user.getId(), deviceIds, groupIds,
- report.getFrom(), report.getTo());
- });
+ reportMailer.sendAsync(user.getId(), stream -> stopsReportProvider.getExcel(
+ stream, user.getId(), deviceIds, groupIds, from, to));
break;
default:
LOGGER.warn("Unsupported report type {}", report.getType());