Commit e89c404f authored by caotao's avatar caotao

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

parent 6597a33e
...@@ -65,50 +65,52 @@ public class CarIotNewListener extends EmqxListener { ...@@ -65,50 +65,52 @@ 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());
//如果map中已经存在该设备或者该设备有但是线程已经执行了 if (jsonObject.containsKey("FireCar_Longitude")) {
if ((!deviceInfo.containsKey(topic)) || (deviceInfo.containsKey(topic) && deviceInfo.get(topic) == null)) { //如果map中已经存在该设备或者该设备有但是线程已经执行了
ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, this.emqkeeper, clipping_time); if ((!deviceInfo.containsKey(topic)) || (deviceInfo.containsKey(topic) && deviceInfo.get(topic) == null)) {
deviceInfo.put(topic, threadCar); ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, this.emqkeeper, clipping_time);
threadCar.start(); deviceInfo.put(topic, threadCar);
} threadCar.start();
String coordinate = jsonObject.getDoubleValue("FireCar_Longitude") +String.valueOf(jsonObject.getDoubleValue("FireCar_Latitude")); }
if(!deviceLastInfo.containsKey(topic)){ String coordinate = jsonObject.getDoubleValue("FireCar_Longitude") + String.valueOf(jsonObject.getDoubleValue("FireCar_Latitude"));
deviceLastInfo.put(topic,coordinate); if (!deviceLastInfo.containsKey(topic)) {
} deviceLastInfo.put(topic, coordinate);
Long currentTime = new Date().getTime(); }
Long endTime = jsonObject.getLong("time"); Long currentTime = new Date().getTime();
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) {
}
ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, this.emqkeeper, clipping_time);
deviceInfo.put(topic, threadCar);
//更新车辆的最新坐标数据
deviceLastInfo.put(topic, coordinate);
threadCar.start();
} }
ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, this.emqkeeper, clipping_time); if (iWlCarMileageService.getUncompleteMileagByIotCode(iotCode)) {
deviceInfo.put(topic, threadCar); WlCarMileage wlCarMileage = new WlCarMileage();
//更新车辆的最新坐标数据 wlCarMileage.setIotCode(iotCode);
deviceLastInfo.put(topic,coordinate); wlCarMileage.setDate(new Date());
threadCar.start(); // 获取开始坐标
} double startLongitude = jsonObject.getDoubleValue("FireCar_Longitude");
if (iWlCarMileageService.getUncompleteMileagByIotCode(iotCode)) { double startLatitude = jsonObject.getDoubleValue("FireCar_Latitude");
WlCarMileage wlCarMileage = new WlCarMileage(); // String currentTime = "20"+jsonObject.getString("currentTime");
wlCarMileage.setIotCode(iotCode); wlCarMileage.setStartLongitude(startLongitude);
wlCarMileage.setDate(new Date()); wlCarMileage.setStartLatitude(startLatitude);
// 获取开始坐标 // Date startTime = UTCToCST();
double startLongitude = jsonObject.getDoubleValue("FireCar_Longitude"); Date startTime = new Date(jsonObject.getLong("time"));
double startLatitude = jsonObject.getDoubleValue("FireCar_Latitude"); wlCarMileage.setStartTime(startTime);
// String currentTime = "20"+jsonObject.getString("currentTime"); wlCarMileage.setStartName(getAddress(startLongitude, startLatitude));
wlCarMileage.setStartLongitude(startLongitude); wlCarMileage.setStartSpeed(jsonObject.getIntValue("FireCar_Speed"));
wlCarMileage.setStartLatitude(startLatitude); try {
// Date startTime = UTCToCST(); iWlCarMileageService.save(wlCarMileage);
Date startTime = new Date(jsonObject.getLong("time")); } catch (Exception e) {
wlCarMileage.setStartTime(startTime); e.printStackTrace();
wlCarMileage.setStartName(getAddress(startLongitude, startLatitude)); iWlCarMileageService.save(wlCarMileage);
wlCarMileage.setStartSpeed(jsonObject.getIntValue("FireCar_Speed")); }
try {
iWlCarMileageService.save(wlCarMileage);
} catch (Exception e) {
e.printStackTrace();
iWlCarMileageService.save(wlCarMileage);
} }
} }
} }
......
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