From 0ad100a7a5d7fa9b51161480cbf191ad47b98742 Mon Sep 17 00:00:00 2001 From: chenyouting <514333061@qq.com> Date: Fri, 1 Aug 2025 16:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=BB=8F=E7=BA=AC=E5=BA=A6?= =?UTF-8?q?=E4=B8=8D=E5=8F=98=E5=B0=B1=E4=B8=8D=E5=8E=BB=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=9C=B0=E5=9B=BEapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/AppDeviceBizService.java | 4 +-- .../global/mqtt/rule/LocationDataRule.java | 28 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java index 1815dcf0..c1063f73 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java +++ b/fys-admin/src/main/java/com/fuyuanshen/app/service/AppDeviceBizService.java @@ -336,8 +336,8 @@ public class AppDeviceBizService { String locationInfo = RedisUtils.getCacheObject(locationKey); if(StringUtils.isNotBlank(locationInfo)){ JSONObject jsonObject = JSONObject.parseObject(locationInfo); - vo.setLongitude((String)jsonObject.get("longitude")); - vo.setLatitude((String)jsonObject.get("latitude")); + vo.setLongitude(jsonObject.get("longitude").toString()); + vo.setLatitude(jsonObject.get("latitude").toString()); vo.setAddress((String)jsonObject.get("address")); } diff --git a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java index 94499cf4..238d244e 100644 --- a/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java +++ b/fys-admin/src/main/java/com/fuyuanshen/global/mqtt/rule/LocationDataRule.java @@ -1,5 +1,7 @@ package com.fuyuanshen.global.mqtt.rule; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.fuyuanshen.common.core.constant.GlobalConstants; import com.fuyuanshen.common.core.utils.StringUtils; import com.fuyuanshen.common.json.utils.JsonUtils; @@ -108,6 +110,29 @@ public class LocationDataRule implements MqttMessageRule { if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){ return; } + String[] latArr = latitude.split("\\."); + String[] lonArr = longitude.split("\\."); + // 将位置信息存储到Redis中 + String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + deviceImei; + String redisObj = RedisUtils.getCacheObject(redisKey); + JSONObject jsonOBj = JSONObject.parseObject(redisObj); + if(jsonOBj != null){ + String str1 = latArr[0] +"."+ latArr[1].substring(0,4); + String str2 = lonArr[0] +"."+ lonArr[1].substring(0,4); + + String cacheLatitude = jsonOBj.getString("latitude"); + String cacheLongitude = jsonOBj.getString("longitude"); + String[] latArr1 = cacheLatitude.split("\\."); + String[] lonArr1 = cacheLongitude.split("\\."); + + String cacheStr1 = latArr1[0] +"."+ latArr1[1].substring(0,4); + String cacheStr2 = lonArr1[0] +"."+ lonArr1[1].substring(0,4); + if(str1.equals(cacheStr1) && str2.equals(cacheStr2)){ + log.info("位置信息未发生变化: device={}, lat={}, lon={}", deviceImei, latitude, longitude); + return; + } + } + // 构造位置信息对象 Map locationInfo = new LinkedHashMap<>(); double[] doubles = LngLonUtil.gps84_To_Gcj02(Double.parseDouble(latitude), Double.parseDouble(longitude)); @@ -119,8 +144,7 @@ public class LocationDataRule implements MqttMessageRule { locationInfo.put("timestamp", System.currentTimeMillis()); - // 将位置信息存储到Redis中 - String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + deviceImei; + String locationJson = JsonUtils.toJsonString(locationInfo); // 存储到Redis