Commit e89c404f authored by caotao's avatar caotao

对于收到的消息进行坐标校验,避免大量的无效坐标

parent 6597a33e
...@@ -65,20 +65,21 @@ public class CarIotNewListener extends EmqxListener { ...@@ -65,20 +65,21 @@ public class CarIotNewListener extends EmqxListener {
String deviceName = topic.split("/")[1]; String deviceName = topic.split("/")[1];
String iotCode = measurement + deviceName; String iotCode = measurement + deviceName;
JSONObject jsonObject = JSONObject.parseObject(message.toString()); JSONObject jsonObject = JSONObject.parseObject(message.toString());
if (jsonObject.containsKey("FireCar_Longitude")) {
//如果map中已经存在该设备或者该设备有但是线程已经执行了 //如果map中已经存在该设备或者该设备有但是线程已经执行了
if ((!deviceInfo.containsKey(topic)) || (deviceInfo.containsKey(topic) && deviceInfo.get(topic) == null)) { if ((!deviceInfo.containsKey(topic)) || (deviceInfo.containsKey(topic) && deviceInfo.get(topic) == null)) {
ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, this.emqkeeper, clipping_time); ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, this.emqkeeper, clipping_time);
deviceInfo.put(topic, threadCar); deviceInfo.put(topic, threadCar);
threadCar.start(); threadCar.start();
} }
String coordinate = jsonObject.getDoubleValue("FireCar_Longitude") +String.valueOf(jsonObject.getDoubleValue("FireCar_Latitude")); String coordinate = jsonObject.getDoubleValue("FireCar_Longitude") + String.valueOf(jsonObject.getDoubleValue("FireCar_Latitude"));
if(!deviceLastInfo.containsKey(topic)){ if (!deviceLastInfo.containsKey(topic)) {
deviceLastInfo.put(topic,coordinate); deviceLastInfo.put(topic, coordinate);
} }
Long currentTime = new Date().getTime(); Long currentTime = new Date().getTime();
Long endTime = jsonObject.getLong("time"); Long endTime = jsonObject.getLong("time");
// if ((startTime - endTime) <= 600000) { // if ((startTime - endTime) <= 600000) {
if (((currentTime - endTime) <= clipping_time)&&(!deviceLastInfo.get(topic).equals(coordinate))) { if (((currentTime - endTime) <= clipping_time) && (!deviceLastInfo.get(topic).equals(coordinate))) {
try { try {
deviceInfo.get(topic).interrupt(); deviceInfo.get(topic).interrupt();
} catch (Exception e) { } catch (Exception e) {
...@@ -86,7 +87,7 @@ public class CarIotNewListener extends EmqxListener { ...@@ -86,7 +87,7 @@ public class CarIotNewListener extends EmqxListener {
ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, this.emqkeeper, clipping_time); ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, this.emqkeeper, clipping_time);
deviceInfo.put(topic, threadCar); deviceInfo.put(topic, threadCar);
//更新车辆的最新坐标数据 //更新车辆的最新坐标数据
deviceLastInfo.put(topic,coordinate); deviceLastInfo.put(topic, coordinate);
threadCar.start(); threadCar.start();
} }
if (iWlCarMileageService.getUncompleteMileagByIotCode(iotCode)) { if (iWlCarMileageService.getUncompleteMileagByIotCode(iotCode)) {
...@@ -112,6 +113,7 @@ public class CarIotNewListener extends EmqxListener { ...@@ -112,6 +113,7 @@ public class CarIotNewListener extends EmqxListener {
} }
} }
} }
}
public String getAddress(double longitude, double lantitude) { public String getAddress(double longitude, double lantitude) {
StringBuilder api = new StringBuilder(GUIDE_URL); StringBuilder api = new StringBuilder(GUIDE_URL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment