diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/BaseEventHandler.java | 10 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 5 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java index 3c2016af0..fde57748c 100644 --- a/src/org/traccar/BaseEventHandler.java +++ b/src/org/traccar/BaseEventHandler.java @@ -1,5 +1,6 @@ package org.traccar; +import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -14,9 +15,12 @@ public abstract class BaseEventHandler extends BaseDataHandler { @Override protected Position handlePosition(Position position) { - Position lastPosition = Context.getConnectionManager().getLastPosition(position.getDeviceId()); - if (lastPosition == null || position.getFixTime().compareTo(lastPosition.getFixTime()) >= 0) { - isLastPosition = true; + Device device = Context.getDataManager().getDeviceById(position.getDeviceId()); + if (device != null) { + long lastPositionId = device.getPositionId(); + if (position.getId() == lastPositionId) { + isLastPosition = true; + } } Event event = analizePosition(position); diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 4e14f6c97..fcb8899bc 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -358,6 +358,9 @@ public class DataManager implements IdentityManager { QueryBuilder.create(dataSource, getQuery("database.updateDeviceStatus")) .setObject(device) .executeUpdate(); + Device cachedDevice = getDeviceById(device.getId()); + cachedDevice.setStatus(device.getStatus()); + cachedDevice.setMotion(device.getMotion()); } public void removeDevice(long deviceId) throws SQLException { @@ -466,6 +469,8 @@ public class DataManager implements IdentityManager { .setDate("now", new Date()) .setObject(position) .executeUpdate(); + Device device = getDeviceById(position.getDeviceId()); + device.setPositionId(position.getId()); } public Collection<Position> getLatestPositions() throws SQLException { |