aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-28 07:39:33 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-28 07:39:33 -0700
commit9e07a009a3da41cd3cdd21809e9588e1ed133d6f (patch)
tree870e65c2519c77943e11623763c514575a6903c0 /src/main
parent3c48c66cf55705274ff482cf3deefee11196ddfe (diff)
downloadtrackermap-server-9e07a009a3da41cd3cdd21809e9588e1ed133d6f.tar.gz
trackermap-server-9e07a009a3da41cd3cdd21809e9588e1ed133d6f.tar.bz2
trackermap-server-9e07a009a3da41cd3cdd21809e9588e1ed133d6f.zip
Fix device name in reports
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/reports/StopsReportProvider.java10
-rw-r--r--src/main/java/org/traccar/reports/SummaryReportProvider.java20
-rw-r--r--src/main/java/org/traccar/reports/TripsReportProvider.java15
-rw-r--r--src/main/java/org/traccar/reports/common/ReportUtils.java27
4 files changed, 32 insertions, 40 deletions
diff --git a/src/main/java/org/traccar/reports/StopsReportProvider.java b/src/main/java/org/traccar/reports/StopsReportProvider.java
index 6e4cd74d6..ba61ef6a1 100644
--- a/src/main/java/org/traccar/reports/StopsReportProvider.java
+++ b/src/main/java/org/traccar/reports/StopsReportProvider.java
@@ -55,10 +55,10 @@ public class StopsReportProvider {
this.storage = storage;
}
- private Collection<StopReportItem> detectStops(long deviceId, Date from, Date to) throws StorageException {
+ private Collection<StopReportItem> detectStops(Device device, Date from, Date to) throws StorageException {
boolean ignoreOdometer = config.getBoolean(Keys.REPORT_IGNORE_ODOMETER);
- return reportUtils.detectTripsAndStops(
- PositionUtil.getPositions(storage, deviceId, from, to), ignoreOdometer, StopReportItem.class);
+ var positions = PositionUtil.getPositions(storage, device.getId(), from, to);
+ return reportUtils.detectTripsAndStops(device, positions, ignoreOdometer, StopReportItem.class);
}
public Collection<StopReportItem> getObjects(
@@ -68,7 +68,7 @@ public class StopsReportProvider {
ArrayList<StopReportItem> result = new ArrayList<>();
for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
- result.addAll(detectStops(device.getId(), from, to));
+ result.addAll(detectStops(device, from, to));
}
return result;
}
@@ -81,7 +81,7 @@ public class StopsReportProvider {
ArrayList<DeviceReportSection> devicesStops = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
- Collection<StopReportItem> stops = detectStops(device.getId(), from, to);
+ Collection<StopReportItem> stops = detectStops(device, from, to);
DeviceReportSection deviceStops = new DeviceReportSection();
deviceStops.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceStops.getDeviceName()));
diff --git a/src/main/java/org/traccar/reports/SummaryReportProvider.java b/src/main/java/org/traccar/reports/SummaryReportProvider.java
index 26d79c899..02033b9e5 100644
--- a/src/main/java/org/traccar/reports/SummaryReportProvider.java
+++ b/src/main/java/org/traccar/reports/SummaryReportProvider.java
@@ -58,11 +58,10 @@ public class SummaryReportProvider {
this.storage = storage;
}
- private SummaryReportItem calculateSummaryResult(
- long deviceId, Collection<Position> positions) throws StorageException {
+ private SummaryReportItem calculateSummaryResult(Device device, Collection<Position> positions) {
SummaryReportItem result = new SummaryReportItem();
- result.setDeviceId(deviceId);
- result.setDeviceName(reportUtils.getDevice(deviceId).getName());
+ result.setDeviceId(device.getId());
+ result.setDeviceName(device.getName());
if (positions != null && !positions.isEmpty()) {
Position firstPosition = null;
Position previousPosition = null;
@@ -119,9 +118,9 @@ public class SummaryReportProvider {
}
private Collection<SummaryReportItem> calculateSummaryResults(
- long userId, long deviceId, Date from, Date to, boolean daily) throws StorageException {
+ long userId, Device device, Date from, Date to, boolean daily) throws StorageException {
- var positions = PositionUtil.getPositions(storage, deviceId, from, to);
+ var positions = PositionUtil.getPositions(storage, device.getId(), from, to);
var results = new ArrayList<SummaryReportItem>();
if (daily && !positions.isEmpty()) {
int startIndex = 0;
@@ -129,14 +128,14 @@ public class SummaryReportProvider {
for (int i = 0; i < positions.size(); i++) {
int currentDay = getDay(userId, positions.get(i).getFixTime());
if (currentDay != startDay) {
- results.add(calculateSummaryResult(deviceId, positions.subList(startIndex, i)));
+ results.add(calculateSummaryResult(device, positions.subList(startIndex, i)));
startIndex = i;
startDay = currentDay;
}
}
- results.add(calculateSummaryResult(deviceId, positions.subList(startIndex, positions.size())));
+ results.add(calculateSummaryResult(device, positions.subList(startIndex, positions.size())));
} else {
- results.add(calculateSummaryResult(deviceId, positions));
+ results.add(calculateSummaryResult(device, positions));
}
return results;
@@ -149,8 +148,7 @@ public class SummaryReportProvider {
ArrayList<SummaryReportItem> result = new ArrayList<>();
for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
- Collection<SummaryReportItem> deviceResults =
- calculateSummaryResults(userId, device.getId(), from, to, daily);
+ Collection<SummaryReportItem> deviceResults = calculateSummaryResults(userId, device, from, to, daily);
for (SummaryReportItem summaryReport : deviceResults) {
if (summaryReport.getStartTime() != null && summaryReport.getEndTime() != null) {
result.add(summaryReport);
diff --git a/src/main/java/org/traccar/reports/TripsReportProvider.java b/src/main/java/org/traccar/reports/TripsReportProvider.java
index 7d10879b7..2d9bcdfbf 100644
--- a/src/main/java/org/traccar/reports/TripsReportProvider.java
+++ b/src/main/java/org/traccar/reports/TripsReportProvider.java
@@ -55,19 +55,20 @@ public class TripsReportProvider {
this.storage = storage;
}
- private Collection<TripReportItem> detectTrips(long deviceId, Date from, Date to) throws StorageException {
+ private Collection<TripReportItem> detectTrips(Device device, Date from, Date to) throws StorageException {
boolean ignoreOdometer = config.getBoolean(Keys.REPORT_IGNORE_ODOMETER);
- return reportUtils.detectTripsAndStops(
- PositionUtil.getPositions(storage, deviceId, from, to), ignoreOdometer, TripReportItem.class);
+ var positions = PositionUtil.getPositions(storage, device.getId(), from, to);
+ return reportUtils.detectTripsAndStops(device, positions, ignoreOdometer, TripReportItem.class);
}
- public Collection<TripReportItem> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws StorageException {
+ public Collection<TripReportItem> getObjects(
+ long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ Date from, Date to) throws StorageException {
reportUtils.checkPeriodLimit(from, to);
ArrayList<TripReportItem> result = new ArrayList<>();
for (Device device: reportUtils.getAccessibleDevices(userId, deviceIds, groupIds)) {
- result.addAll(detectTrips(device.getId(), from, to));
+ 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)) {
- Collection<TripReportItem> trips = detectTrips(device.getId(), from, to);
+ Collection<TripReportItem> trips = detectTrips(device, from, to);
DeviceReportSection deviceTrips = new DeviceReportSection();
deviceTrips.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceTrips.getDeviceName()));
diff --git a/src/main/java/org/traccar/reports/common/ReportUtils.java b/src/main/java/org/traccar/reports/common/ReportUtils.java
index f5f2cd3df..cd6b6ffd5 100644
--- a/src/main/java/org/traccar/reports/common/ReportUtils.java
+++ b/src/main/java/org/traccar/reports/common/ReportUtils.java
@@ -99,12 +99,6 @@ public class ReportUtils {
new Condition.Permission(User.class, userId, clazz))));
}
- public Device getDevice(long deviceId) throws StorageException {
- return storage.getObject(Device.class, new Request(
- new Columns.Include("id"),
- new Condition.Equals("id", "id", deviceId)));
- }
-
public void checkPeriodLimit(Date from, Date to) {
long limit = config.getLong(Keys.REPORT_PERIOD_LIMIT) * 1000;
if (limit > 0 && to.getTime() - from.getTime() > limit) {
@@ -211,7 +205,7 @@ public class ReportUtils {
}
private TripReportItem calculateTrip(
- ArrayList<Position> positions, int startIndex, int endIndex,
+ Device device, ArrayList<Position> positions, int startIndex, int endIndex,
boolean ignoreOdometer) throws StorageException {
Position startTrip = positions.get(startIndex);
@@ -230,7 +224,7 @@ public class ReportUtils {
long tripDuration = endTrip.getFixTime().getTime() - startTrip.getFixTime().getTime();
long deviceId = startTrip.getDeviceId();
trip.setDeviceId(deviceId);
- trip.setDeviceName(getDevice(deviceId).getName());
+ trip.setDeviceName(device.getName());
trip.setStartPositionId(startTrip.getId());
trip.setStartLat(startTrip.getLatitude());
@@ -277,8 +271,7 @@ public class ReportUtils {
}
private StopReportItem calculateStop(
- ArrayList<Position> positions, int startIndex, int endIndex,
- boolean ignoreOdometer) throws StorageException {
+ Device device, ArrayList<Position> positions, int startIndex, int endIndex, boolean ignoreOdometer) {
Position startStop = positions.get(startIndex);
Position endStop = positions.get(endIndex);
@@ -287,7 +280,7 @@ public class ReportUtils {
long deviceId = startStop.getDeviceId();
stop.setDeviceId(deviceId);
- stop.setDeviceName(getDevice(deviceId).getName());
+ stop.setDeviceName(device.getName());
stop.setPositionId(startStop.getId());
stop.setLatitude(startStop.getLatitude());
@@ -326,13 +319,13 @@ public class ReportUtils {
@SuppressWarnings("unchecked")
private <T extends BaseReportItem> T calculateTripOrStop(
- ArrayList<Position> positions, int startIndex, int endIndex,
+ Device device, ArrayList<Position> positions, int startIndex, int endIndex,
boolean ignoreOdometer, Class<T> reportClass) throws StorageException {
if (reportClass.equals(TripReportItem.class)) {
- return (T) calculateTrip(positions, startIndex, endIndex, ignoreOdometer);
+ return (T) calculateTrip(device, positions, startIndex, endIndex, ignoreOdometer);
} else {
- return (T) calculateStop(positions, startIndex, endIndex, ignoreOdometer);
+ return (T) calculateStop(device, positions, startIndex, endIndex, ignoreOdometer);
}
}
@@ -357,7 +350,7 @@ public class ReportUtils {
}
public <T extends BaseReportItem> Collection<T> detectTripsAndStops(
- Collection<Position> positionCollection, boolean ignoreOdometer,
+ Device device, Collection<Position> positionCollection, boolean ignoreOdometer,
Class<T> reportClass) throws StorageException {
Collection<T> result = new ArrayList<>();
@@ -392,14 +385,14 @@ public class ReportUtils {
if (startEventIndex != -1 && startNoEventIndex != -1 && event != null
&& trips != deviceState.getMotionState()) {
result.add(calculateTripOrStop(
- positions, startEventIndex, startNoEventIndex, ignoreOdometer, reportClass));
+ device, positions, startEventIndex, startNoEventIndex, ignoreOdometer, reportClass));
startEventIndex = -1;
}
}
if (startEventIndex != -1 && (startNoEventIndex != -1 || !trips)) {
int endIndex = startNoEventIndex != -1 ? startNoEventIndex : positions.size() - 1;
result.add(calculateTripOrStop(
- positions, startEventIndex, endIndex, ignoreOdometer, reportClass));
+ device, positions, startEventIndex, endIndex, ignoreOdometer, reportClass));
}
}