diff options
-rw-r--r-- | src/org/traccar/notification/NotificationFormatter.java | 7 | ||||
-rw-r--r-- | src/org/traccar/reports/ReportUtils.java | 17 | ||||
-rw-r--r-- | src/org/traccar/reports/model/TripReport.java | 10 | ||||
-rw-r--r-- | templates/mail/driverUnauthorized.vm | 10 | ||||
-rw-r--r-- | templates/sms/driverUnauthorized.vm | 6 |
5 files changed, 44 insertions, 6 deletions
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java index 96337ecaa..a30023fdc 100644 --- a/src/org/traccar/notification/NotificationFormatter.java +++ b/src/org/traccar/notification/NotificationFormatter.java @@ -30,6 +30,7 @@ import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; +import org.traccar.model.User; import org.traccar.reports.ReportUtils; public final class NotificationFormatter { @@ -38,9 +39,11 @@ public final class NotificationFormatter { } public static VelocityContext prepareContext(long userId, Event event, Position position) { + User user = Context.getPermissionsManager().getUser(userId); Device device = Context.getIdentityManager().getDeviceById(event.getDeviceId()); VelocityContext velocityContext = new VelocityContext(); + velocityContext.put("user", user); velocityContext.put("device", device); velocityContext.put("event", event); if (position != null) { @@ -50,6 +53,10 @@ public final class NotificationFormatter { if (event.getGeofenceId() != 0) { velocityContext.put("geofence", Context.getGeofenceManager().getGeofence(event.getGeofenceId())); } + String driverUniqueId = event.getString(Position.KEY_DRIVER_UNIQUE_ID); + if (driverUniqueId != null) { + velocityContext.put("driver", Context.getDriversManager().getDriverByUniqueId(driverUniqueId)); + } velocityContext.put("webUrl", Context.getVelocityEngine().getProperty("web.url")); velocityContext.put("dateTool", new DateTool()); velocityContext.put("numberTool", new NumberTool()); diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index 92918b861..3a177300b 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -102,16 +102,19 @@ public final class ReportUtils { return 0; } - public static String findDriverName(Position firstPosition, Position lastPosition) { - String driverUniqueId = null; + public static String findDriver(Position firstPosition, Position lastPosition) { if (firstPosition.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) { - driverUniqueId = firstPosition.getString(Position.KEY_DRIVER_UNIQUE_ID); + return 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); + return lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID); } + return null; + } + + public static String findDriverName(String driverUniqueId) { if (driverUniqueId != null && Context.getDriversManager() != null) { Driver driver = Context.getDriversManager().getDriverByUniqueId(driverUniqueId); - return driver != null ? driver.getName() : null; + return driver != null ? driver.getName() : driverUniqueId; } return null; } @@ -190,7 +193,9 @@ public final class ReportUtils { trip.setAverageSpeed(speedSum / (endIndex - startIndex)); trip.setMaxSpeed(speedMax); trip.setSpentFuel(calculateFuel(startTrip, endTrip)); - trip.setDriverName(findDriverName(startTrip, endTrip)); + + trip.setDriverUniqueId(findDriver(startTrip, endTrip)); + trip.setDriverName(findDriverName(trip.getDriverUniqueId())); return trip; } diff --git a/src/org/traccar/reports/model/TripReport.java b/src/org/traccar/reports/model/TripReport.java index 0f23581b2..42a4240b7 100644 --- a/src/org/traccar/reports/model/TripReport.java +++ b/src/org/traccar/reports/model/TripReport.java @@ -146,6 +146,16 @@ public class TripReport extends BaseReport { this.duration = duration; } + private String driverUniqueId; + + public String getDriverUniqueId() { + return driverUniqueId; + } + + public void setDriverUniqueId(String driverUniqueId) { + this.driverUniqueId = driverUniqueId; + } + private String driverName; public String getDriverName() { diff --git a/templates/mail/driverUnauthorized.vm b/templates/mail/driverUnauthorized.vm new file mode 100644 index 000000000..3d28266cd --- /dev/null +++ b/templates/mail/driverUnauthorized.vm @@ -0,0 +1,10 @@ +#set($subject = "$device.name: driver unauthorized") +<!DOCTYPE html> +<html> +<body> +Device: $device.name<br> +Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone)<br> +Point: <a href="$webUrl?eventId=$event.id">#{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}</a><br> +Driver: #{if}($driver)$driver.name#{else}$event.getString("driverUniqueId")#{end} +</body> +</html> diff --git a/templates/sms/driverUnauthorized.vm b/templates/sms/driverUnauthorized.vm new file mode 100644 index 000000000..52c819eb8 --- /dev/null +++ b/templates/sms/driverUnauthorized.vm @@ -0,0 +1,6 @@ +#if($driver) +#set($driverName = $driver.name) +#else +#set($driverName = $event.getString("driverUniqueId")) +#end +$driverName is unauthorized for $device.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone) |