Commit e89c404f authored by caotao's avatar caotao

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

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