diff options
-rw-r--r-- | src/main/java/org/traccar/reports/Events.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/reports/Events.java b/src/main/java/org/traccar/reports/Events.java index 66d9e708d..be4dbc6b1 100644 --- a/src/main/java/org/traccar/reports/Events.java +++ b/src/main/java/org/traccar/reports/Events.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; +import java.util.Optional; import org.apache.poi.ss.util.WorkbookUtil; import org.traccar.Context; @@ -34,6 +35,7 @@ import org.traccar.model.Event; import org.traccar.model.Geofence; import org.traccar.model.Group; import org.traccar.model.Maintenance; +import org.traccar.model.Position; import org.traccar.reports.model.DeviceReport; public final class Events { @@ -72,15 +74,18 @@ public final class Events { ArrayList<String> sheetNames = new ArrayList<>(); HashMap<Long, String> geofenceNames = new HashMap<>(); HashMap<Long, String> maintenanceNames = new HashMap<>(); + HashMap<Long, Position> positionObjects = new HashMap<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to); + Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to); boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS); for (Iterator<Event> iterator = events.iterator(); iterator.hasNext();) { Event event = iterator.next(); if (all || types.contains(event.getType())) { long geofenceId = event.getGeofenceId(); long maintenanceId = event.getMaintenanceId(); + long positionId = event.getPositionId(); if (geofenceId != 0) { if (Context.getGeofenceManager().checkItemPermission(userId, geofenceId)) { Geofence geofence = Context.getGeofenceManager().getById(geofenceId); @@ -89,8 +94,10 @@ public final class Events { } } else { iterator.remove(); + continue; } - } else if (maintenanceId != 0) { + } + if (maintenanceId != 0) { if (Context.getMaintenancesManager().checkItemPermission(userId, maintenanceId)) { Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId); if (maintenance != null) { @@ -98,6 +105,14 @@ public final class Events { } } else { iterator.remove(); + continue; + } + } + if (positionId != 0) { + // Position checks not implemented + Optional<Position> position = positions.stream().filter(pos -> pos.getId() == positionId).findFirst(); + if (position.isPresent()) { + positionObjects.put(positionId, position.get()); } } } else { @@ -125,9 +140,10 @@ public final class Events { jxlsContext.putVar("sheetNames", sheetNames); jxlsContext.putVar("geofenceNames", geofenceNames); jxlsContext.putVar("maintenanceNames", maintenanceNames); + jxlsContext.putVar("positions", positionObjects); jxlsContext.putVar("from", from); jxlsContext.putVar("to", to); ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext); } } -} +}
\ No newline at end of file |