aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/reports
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/reports')
-rw-r--r--src/main/java/org/traccar/reports/CombinedReportProvider.java3
-rw-r--r--src/main/java/org/traccar/reports/EventsReportProvider.java5
-rw-r--r--src/main/java/org/traccar/reports/RouteReportProvider.java5
-rw-r--r--src/main/java/org/traccar/reports/StopsReportProvider.java5
-rw-r--r--src/main/java/org/traccar/reports/SummaryReportProvider.java3
-rw-r--r--src/main/java/org/traccar/reports/TripsReportProvider.java5
-rw-r--r--src/main/java/org/traccar/reports/common/ReportUtils.java40
7 files changed, 16 insertions, 50 deletions
diff --git a/src/main/java/org/traccar/reports/CombinedReportProvider.java b/src/main/java/org/traccar/reports/CombinedReportProvider.java
index 923fd12b4..63d6a9830 100644
--- a/src/main/java/org/traccar/reports/CombinedReportProvider.java
+++ b/src/main/java/org/traccar/reports/CombinedReportProvider.java
@@ -15,6 +15,7 @@
*/
package org.traccar.reports;
+import org.traccar.helper.model.DeviceUtil;
import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Device;
import org.traccar.model.Event;
@@ -53,7 +54,7 @@ public class CombinedReportProvider {
reportUtils.checkPeriodLimit(from, to);
ArrayList<CombinedReportItem> result = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
CombinedReportItem item = new CombinedReportItem();
item.setDeviceId(device.getId());
var positions = PositionUtil.getPositions(storage, device.getId(), from, to);
diff --git a/src/main/java/org/traccar/reports/EventsReportProvider.java b/src/main/java/org/traccar/reports/EventsReportProvider.java
index 30f55ba80..ff7bc8e2f 100644
--- a/src/main/java/org/traccar/reports/EventsReportProvider.java
+++ b/src/main/java/org/traccar/reports/EventsReportProvider.java
@@ -19,6 +19,7 @@ package org.traccar.reports;
import org.apache.poi.ss.util.WorkbookUtil;
import org.traccar.config.Config;
import org.traccar.config.Keys;
+import org.traccar.helper.model.DeviceUtil;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
@@ -76,7 +77,7 @@ public class EventsReportProvider {
reportUtils.checkPeriodLimit(from, to);
ArrayList<Event> result = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
Collection<Event> events = getEvents(device.getId(), from, to);
boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS);
for (Event event : events) {
@@ -104,7 +105,7 @@ public class EventsReportProvider {
HashMap<Long, String> geofenceNames = new HashMap<>();
HashMap<Long, String> maintenanceNames = new HashMap<>();
HashMap<Long, Position> positions = new HashMap<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
Collection<Event> events = getEvents(device.getId(), from, to);
boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS);
for (Iterator<Event> iterator = events.iterator(); iterator.hasNext();) {
diff --git a/src/main/java/org/traccar/reports/RouteReportProvider.java b/src/main/java/org/traccar/reports/RouteReportProvider.java
index 3ee651619..6d44259e6 100644
--- a/src/main/java/org/traccar/reports/RouteReportProvider.java
+++ b/src/main/java/org/traccar/reports/RouteReportProvider.java
@@ -19,6 +19,7 @@ package org.traccar.reports;
import org.apache.poi.ss.util.WorkbookUtil;
import org.traccar.config.Config;
import org.traccar.config.Keys;
+import org.traccar.helper.model.DeviceUtil;
import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Device;
import org.traccar.model.Group;
@@ -60,7 +61,7 @@ public class RouteReportProvider {
reportUtils.checkPeriodLimit(from, to);
ArrayList<Position> result = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
result.addAll(PositionUtil.getPositions(storage, device.getId(), from, to));
}
return result;
@@ -73,7 +74,7 @@ public class RouteReportProvider {
ArrayList<DeviceReportSection> devicesRoutes = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
var positions = PositionUtil.getPositions(storage, device.getId(), from, to);
DeviceReportSection deviceRoutes = new DeviceReportSection();
deviceRoutes.setDeviceName(device.getName());
diff --git a/src/main/java/org/traccar/reports/StopsReportProvider.java b/src/main/java/org/traccar/reports/StopsReportProvider.java
index ec3fd2215..a23cee48b 100644
--- a/src/main/java/org/traccar/reports/StopsReportProvider.java
+++ b/src/main/java/org/traccar/reports/StopsReportProvider.java
@@ -19,6 +19,7 @@ package org.traccar.reports;
import org.apache.poi.ss.util.WorkbookUtil;
import org.traccar.config.Config;
import org.traccar.config.Keys;
+import org.traccar.helper.model.DeviceUtil;
import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Device;
import org.traccar.model.Group;
@@ -67,7 +68,7 @@ public class StopsReportProvider {
reportUtils.checkPeriodLimit(from, to);
ArrayList<StopReportItem> result = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
result.addAll(detectStops(device, from, to));
}
return result;
@@ -80,7 +81,7 @@ public class StopsReportProvider {
ArrayList<DeviceReportSection> devicesStops = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
Collection<StopReportItem> stops = detectStops(device, from, to);
DeviceReportSection deviceStops = new DeviceReportSection();
deviceStops.setDeviceName(device.getName());
diff --git a/src/main/java/org/traccar/reports/SummaryReportProvider.java b/src/main/java/org/traccar/reports/SummaryReportProvider.java
index 9415f3e81..f7d9f0325 100644
--- a/src/main/java/org/traccar/reports/SummaryReportProvider.java
+++ b/src/main/java/org/traccar/reports/SummaryReportProvider.java
@@ -21,6 +21,7 @@ import org.traccar.api.security.PermissionsService;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.helper.UnitsConverter;
+import org.traccar.helper.model.DeviceUtil;
import org.traccar.helper.model.PositionUtil;
import org.traccar.helper.model.UserUtil;
import org.traccar.model.Device;
@@ -146,7 +147,7 @@ public class SummaryReportProvider {
reportUtils.checkPeriodLimit(from, to);
ArrayList<SummaryReportItem> result = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
Collection<SummaryReportItem> deviceResults = calculateSummaryResults(userId, device, from, to, daily);
for (SummaryReportItem summaryReport : deviceResults) {
if (summaryReport.getStartTime() != null && summaryReport.getEndTime() != null) {
diff --git a/src/main/java/org/traccar/reports/TripsReportProvider.java b/src/main/java/org/traccar/reports/TripsReportProvider.java
index 265811354..2d8989b7a 100644
--- a/src/main/java/org/traccar/reports/TripsReportProvider.java
+++ b/src/main/java/org/traccar/reports/TripsReportProvider.java
@@ -19,6 +19,7 @@ package org.traccar.reports;
import org.apache.poi.ss.util.WorkbookUtil;
import org.traccar.config.Config;
import org.traccar.config.Keys;
+import org.traccar.helper.model.DeviceUtil;
import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Device;
import org.traccar.model.Group;
@@ -67,7 +68,7 @@ public class TripsReportProvider {
reportUtils.checkPeriodLimit(from, to);
ArrayList<TripReportItem> result = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
result.addAll(detectTrips(device, from, to));
}
return result;
@@ -80,7 +81,7 @@ public class TripsReportProvider {
ArrayList<DeviceReportSection> devicesTrips = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
- for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
+ for (Device device: DeviceUtil.getAccessibleDevices(storage, userId, deviceIds, groupIds)) {
Collection<TripReportItem> trips = detectTrips(device, from, to);
DeviceReportSection deviceTrips = new DeviceReportSection();
deviceTrips.setDeviceName(device.getName());
diff --git a/src/main/java/org/traccar/reports/common/ReportUtils.java b/src/main/java/org/traccar/reports/common/ReportUtils.java
index 35faa9c8b..f1a2f7d54 100644
--- a/src/main/java/org/traccar/reports/common/ReportUtils.java
+++ b/src/main/java/org/traccar/reports/common/ReportUtils.java
@@ -36,7 +36,6 @@ import org.traccar.helper.model.UserUtil;
import org.traccar.model.BaseModel;
import org.traccar.model.Device;
import org.traccar.model.Driver;
-import org.traccar.model.Group;
import org.traccar.model.Position;
import org.traccar.model.User;
import org.traccar.reports.model.BaseReportItem;
@@ -60,13 +59,9 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
-import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
-import java.util.Objects;
-import java.util.stream.Collectors;
@Singleton
public class ReportUtils {
@@ -106,41 +101,6 @@ public class ReportUtils {
}
}
- public Collection<Device> getAccessibleDevices(
- long userId, Collection<Long> deviceIds, Collection<Long> groupIds) throws StorageException {
-
- var devices = storage.getObjects(Device.class, new Request(
- new Columns.All(),
- new Condition.Permission(User.class, userId, Device.class)));
- var deviceById = devices.stream()
- .collect(Collectors.toUnmodifiableMap(Device::getId, x -> x));
- var devicesByGroup = devices.stream()
- .filter(x -> x.getGroupId() > 0)
- .collect(Collectors.groupingBy(Device::getGroupId));
-
- var groups = storage.getObjects(Group.class, new Request(
- new Columns.All(),
- new Condition.Permission(User.class, userId, Group.class)));
- var groupsByGroup = groups.stream()
- .filter(x -> x.getGroupId() > 0)
- .collect(Collectors.groupingBy(Group::getGroupId));
-
- var results = deviceIds.stream()
- .map(deviceById::get)
- .filter(Objects::nonNull)
- .collect(Collectors.toSet());
-
- var groupQueue = new LinkedList<>(groupIds);
- while (!groupQueue.isEmpty()) {
- long groupId = groupQueue.pop();
- results.addAll(devicesByGroup.getOrDefault(groupId, Collections.emptyList()));
- groupQueue.addAll(groupsByGroup.getOrDefault(groupId, Collections.emptyList())
- .stream().map(Group::getId).collect(Collectors.toUnmodifiableList()));
- }
-
- return results;
- }
-
public double calculateFuel(Position firstPosition, Position lastPosition) {
if (firstPosition.getAttributes().get(Position.KEY_FUEL_LEVEL) != null