forked from dyf/fys-Multi-tenant
如果经纬度不变就不去调用地图api
This commit is contained in:
@ -336,8 +336,8 @@ public class AppDeviceBizService {
|
|||||||
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
||||||
if(StringUtils.isNotBlank(locationInfo)){
|
if(StringUtils.isNotBlank(locationInfo)){
|
||||||
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
||||||
vo.setLongitude((String)jsonObject.get("longitude"));
|
vo.setLongitude(jsonObject.get("longitude").toString());
|
||||||
vo.setLatitude((String)jsonObject.get("latitude"));
|
vo.setLatitude(jsonObject.get("latitude").toString());
|
||||||
vo.setAddress((String)jsonObject.get("address"));
|
vo.setAddress((String)jsonObject.get("address"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.fuyuanshen.global.mqtt.rule;
|
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.constant.GlobalConstants;
|
||||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||||
import com.fuyuanshen.common.json.utils.JsonUtils;
|
import com.fuyuanshen.common.json.utils.JsonUtils;
|
||||||
@ -108,6 +110,29 @@ public class LocationDataRule implements MqttMessageRule {
|
|||||||
if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){
|
if(StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude)){
|
||||||
return;
|
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<String, Object> locationInfo = new LinkedHashMap<>();
|
Map<String, Object> locationInfo = new LinkedHashMap<>();
|
||||||
double[] doubles = LngLonUtil.gps84_To_Gcj02(Double.parseDouble(latitude), Double.parseDouble(longitude));
|
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());
|
locationInfo.put("timestamp", System.currentTimeMillis());
|
||||||
|
|
||||||
|
|
||||||
// 将位置信息存储到Redis中
|
|
||||||
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX + deviceImei;
|
|
||||||
String locationJson = JsonUtils.toJsonString(locationInfo);
|
String locationJson = JsonUtils.toJsonString(locationInfo);
|
||||||
|
|
||||||
// 存储到Redis
|
// 存储到Redis
|
||||||
|
Reference in New Issue
Block a user