diff options
Diffstat (limited to 'src/org/traccar/reports')
-rw-r--r-- | src/org/traccar/reports/ReportUtils.java | 16 | ||||
-rw-r--r-- | src/org/traccar/reports/model/TripReport.java | 10 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index 71c567c29..92918b861 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -26,6 +26,7 @@ import org.jxls.transform.Transformer; import org.jxls.transform.poi.PoiTransformer; import org.jxls.util.TransformerFactory; import org.traccar.Context; +import org.traccar.model.Driver; import org.traccar.model.Position; import org.traccar.reports.model.BaseReport; import org.traccar.reports.model.StopReport; @@ -101,6 +102,20 @@ public final class ReportUtils { return 0; } + public static String findDriverName(Position firstPosition, Position lastPosition) { + String driverUniqueId = null; + if (firstPosition.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) { + driverUniqueId = firstPosition.getString(Position.KEY_DRIVER_UNIQUE_ID); + } else if (lastPosition.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) { + driverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID); + } + if (driverUniqueId != null && Context.getDriversManager() != null) { + Driver driver = Context.getDriversManager().getDriverByUniqueId(driverUniqueId); + return driver != null ? driver.getName() : null; + } + return null; + } + public static org.jxls.common.Context initializeContext(long userId) { org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); jxlsContext.putVar("distanceUnit", getDistanceUnit(userId)); @@ -175,6 +190,7 @@ public final class ReportUtils { trip.setAverageSpeed(speedSum / (endIndex - startIndex)); trip.setMaxSpeed(speedMax); trip.setSpentFuel(calculateFuel(startTrip, endTrip)); + trip.setDriverName(findDriverName(startTrip, endTrip)); return trip; } diff --git a/src/org/traccar/reports/model/TripReport.java b/src/org/traccar/reports/model/TripReport.java index efe556f79..0f23581b2 100644 --- a/src/org/traccar/reports/model/TripReport.java +++ b/src/org/traccar/reports/model/TripReport.java @@ -145,4 +145,14 @@ public class TripReport extends BaseReport { public void setDuration(long duration) { this.duration = duration; } + + private String driverName; + + public String getDriverName() { + return driverName; + } + + public void setDriverName(String driverName) { + this.driverName = driverName; + } } |