aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/events/MaintenanceEventHandler.java26
-rw-r--r--src/org/traccar/model/Maintenance.java10
2 files changed, 23 insertions, 13 deletions
diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java
index 001b414c0..b556e1003 100644
--- a/src/org/traccar/events/MaintenanceEventHandler.java
+++ b/src/org/traccar/events/MaintenanceEventHandler.java
@@ -34,25 +34,25 @@ public class MaintenanceEventHandler extends BaseEventHandler {
return null;
}
- double oldTotalDistance = 0.0;
- double newTotalDistance = 0.0;
-
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
- if (lastPosition != null) {
- oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE);
+ if (lastPosition == null) {
+ return null;
}
- newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE);
Map<Event, Position> events = new HashMap<>();
for (long maintenanceId : Context.getMaintenancesManager().getAllDeviceItems(position.getDeviceId())) {
Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId);
- if (maintenance.getLapse() != 0
- && (long) ((oldTotalDistance - maintenance.getStart()) / maintenance.getLapse())
- < (long) ((newTotalDistance - maintenance.getStart()) / maintenance.getLapse())) {
- Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
- event.setMaintenanceId(maintenanceId);
- event.set(Position.KEY_TOTAL_DISTANCE, newTotalDistance);
- events.put(event, position);
+ if (maintenance.getLapse() != 0) {
+ double oldValue = lastPosition.getDouble(maintenance.getType());
+ double newValue = position.getDouble(maintenance.getType());
+ if (oldValue != 0.0 && newValue != 0.0
+ && (long) ((oldValue - maintenance.getStart()) / maintenance.getLapse())
+ < (long) ((newValue - maintenance.getStart()) / maintenance.getLapse())) {
+ Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
+ event.setMaintenanceId(maintenanceId);
+ event.set(maintenance.getType(), newValue);
+ events.put(event, position);
+ }
}
}
diff --git a/src/org/traccar/model/Maintenance.java b/src/org/traccar/model/Maintenance.java
index 827fd3b85..82052e160 100644
--- a/src/org/traccar/model/Maintenance.java
+++ b/src/org/traccar/model/Maintenance.java
@@ -28,6 +28,16 @@ public class Maintenance extends ExtendedModel {
this.name = name;
}
+ private String type;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
private double start;
public double getStart() {