diff options
author | Aaron Donnelly <126603683+Aaron-Donnelly@users.noreply.github.com> | 2023-05-03 14:27:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 14:27:45 +0100 |
commit | 442806299eb328b5b41882d04c3dd65650715647 (patch) | |
tree | ce471e548ade4a971ce1569ffa07661b49533e57 /src/main/java/org/traccar/handler/events/GeofenceEventHandler.java | |
parent | beb43ba371de5862a7ca6579daef20c8ffd83f2d (diff) | |
parent | bb6964f03867d039a547c103cd16390f78688022 (diff) | |
download | trackermap-server-442806299eb328b5b41882d04c3dd65650715647.tar.gz trackermap-server-442806299eb328b5b41882d04c3dd65650715647.tar.bz2 trackermap-server-442806299eb328b5b41882d04c3dd65650715647.zip |
Merge branch 'traccar:master' into Teltonika-io30-faultCount
Diffstat (limited to 'src/main/java/org/traccar/handler/events/GeofenceEventHandler.java')
-rw-r--r-- | src/main/java/org/traccar/handler/events/GeofenceEventHandler.java | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java index 9414f4b31..0ab9ca217 100644 --- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java +++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2023 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +17,14 @@ package org.traccar.handler.events; import io.netty.channel.ChannelHandler; import org.traccar.config.Config; -import org.traccar.helper.model.GeofenceUtil; import org.traccar.helper.model.PositionUtil; import org.traccar.model.Calendar; -import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Geofence; import org.traccar.model.Position; import org.traccar.session.ConnectionManager; import org.traccar.session.cache.CacheManager; import org.traccar.storage.Storage; -import org.traccar.storage.StorageException; -import org.traccar.storage.query.Columns; -import org.traccar.storage.query.Condition; -import org.traccar.storage.query.Request; import javax.inject.Inject; import javax.inject.Singleton; @@ -59,36 +53,21 @@ public class GeofenceEventHandler extends BaseEventHandler { @Override protected Map<Event, Position> analyzePosition(Position position) { - Device device = cacheManager.getObject(Device.class, position.getDeviceId()); - if (device == null) { - return null; - } - if (!PositionUtil.isLatest(cacheManager, position) || !position.getValid()) { + if (!PositionUtil.isLatest(cacheManager, position)) { return null; } - List<Long> currentGeofences = GeofenceUtil.getCurrentGeofences(config, cacheManager, position); List<Long> oldGeofences = new ArrayList<>(); - if (device.getGeofenceIds() != null) { - oldGeofences.addAll(device.getGeofenceIds()); + Position lastPosition = cacheManager.getPosition(position.getDeviceId()); + if (lastPosition != null && lastPosition.getGeofenceIds() != null) { + oldGeofences.addAll(lastPosition.getGeofenceIds()); } - List<Long> newGeofences = new ArrayList<>(currentGeofences); - newGeofences.removeAll(oldGeofences); - oldGeofences.removeAll(currentGeofences); - - - if (!oldGeofences.isEmpty() || !newGeofences.isEmpty()) { - device.setGeofenceIds(currentGeofences.isEmpty() ? null : currentGeofences); - - try { - storage.updateObject(device, new Request( - new Columns.Include("geofenceIds"), - new Condition.Equals("id", device.getId()))); - } catch (StorageException e) { - throw new RuntimeException("Update device geofences error", e); - } - connectionManager.updateDevice(true, device); + List<Long> newGeofences = new ArrayList<>(); + if (position.getGeofenceIds() != null) { + newGeofences.addAll(position.getGeofenceIds()); + newGeofences.removeAll(oldGeofences); + oldGeofences.removeAll(position.getGeofenceIds()); } Map<Event, Position> events = new HashMap<>(); |