Commit 62636a3e authored by caotao's avatar caotao

车辆初始化时里程切割坐标结束坐标错误问题修复

parent 26dba690
This diff is collapsed.
...@@ -70,7 +70,31 @@ public class CarIotNewListener extends EmqxListener { ...@@ -70,7 +70,31 @@ public class CarIotNewListener extends EmqxListener {
this.updateEquipBattery(jsonObject, iotCode); this.updateEquipBattery(jsonObject, iotCode);
logger.info("当前设备信息info" + JSON.toJSONString(deviceInfo)); logger.info("当前设备信息info" + JSON.toJSONString(deviceInfo));
//判断是否有效数据 //判断是否有效数据
if (!ObjectUtils.isEmpty(jsonObject.containsKey("FireCar_Longitude"))&&!ObjectUtils.isEmpty(jsonObject.containsKey("FireCar_Latitude"))) { if (!ObjectUtils.isEmpty(jsonObject.get("FireCar_Longitude")) || !ObjectUtils.isEmpty(jsonObject.get("FireCar_Latitude"))) {
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();
//时间值被mysql自动转换
Date startTime = new Date((jsonObject.getLong("time") / 1000) * 1000);
wlCarMileage.setStartTime(startTime);
wlCarMileage.setStartName(getAddress(startLongitude, startLatitude));
wlCarMileage.setStartSpeed(Double.valueOf(jsonObject.getDoubleValue("FireCar_Speed")).intValue());
logger.info("新增数据信息如下::" + JSONObject.toJSONString(wlCarMileage));
try {
iWlCarMileageService.save(wlCarMileage);
} catch (Exception e) {
e.printStackTrace();
iWlCarMileageService.save(wlCarMileage);
}
}
this.updateCarLocation(jsonObject, iotCode); this.updateCarLocation(jsonObject, iotCode);
//如果map中已经存在该设备或者该设备有但是线程已经执行了 //如果map中已经存在该设备或者该设备有但是线程已经执行了
//存储上报上来的经纬度信息 //存储上报上来的经纬度信息
...@@ -102,32 +126,9 @@ public class CarIotNewListener extends EmqxListener { ...@@ -102,32 +126,9 @@ public class CarIotNewListener extends EmqxListener {
//更新车辆的最新坐标数据 //更新车辆的最新坐标数据
deviceLastInfo.put(iotCode, coordinate); deviceLastInfo.put(iotCode, coordinate);
threadCar.start(); 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();
//时间值被mysql自动转换
Date startTime = new Date((jsonObject.getLong("time") / 1000) * 1000);
wlCarMileage.setStartTime(startTime);
wlCarMileage.setStartName(getAddress(startLongitude, startLatitude));
wlCarMileage.setStartSpeed(Double.valueOf(jsonObject.getDoubleValue("FireCar_Speed")).intValue());
logger.info("新增数据信息如下::"+JSONObject.toJSONString(wlCarMileage));
try {
iWlCarMileageService.save(wlCarMileage);
} catch (Exception e) {
e.printStackTrace();
iWlCarMileageService.save(wlCarMileage);
}
}
} }
} }
} }
public String getAddress(double longitude, double lantitude) { public String getAddress(double longitude, double lantitude) {
......
package com.yeejoin.equipmanage.thread; package com.yeejoin.equipmanage.thread;
import ch.qos.logback.core.joran.conditional.ElseAction;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...@@ -15,6 +16,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; ...@@ -15,6 +16,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.jfree.util.Log; import org.jfree.util.Log;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.emq.EmqKeeper; import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
...@@ -44,6 +46,7 @@ ThreadCar extends Thread { ...@@ -44,6 +46,7 @@ ThreadCar extends Thread {
this.iCarService = iCarService; this.iCarService = iCarService;
this.clippingTime = clippingTime; this.clippingTime = clippingTime;
} }
@Override @Override
public void run() { public void run() {
//toDo //toDo
...@@ -88,6 +91,7 @@ ThreadCar extends Thread { ...@@ -88,6 +91,7 @@ ThreadCar extends Thread {
lastObj.put("FireCar_Latitude", last.getEndLatitude()); lastObj.put("FireCar_Latitude", last.getEndLatitude());
lastObj.put("time", 0); lastObj.put("time", 0);
lastObj.put("FireCar_Speed", 0); lastObj.put("FireCar_Speed", 0);
logger.info("---过滤后last信息为null时的数据::" + JSONObject.toJSONString(last));
} }
double endLongitude = lastObj.getDoubleValue("FireCar_Longitude"); double endLongitude = lastObj.getDoubleValue("FireCar_Longitude");
double endLatitude = lastObj.getDoubleValue("FireCar_Latitude"); double endLatitude = lastObj.getDoubleValue("FireCar_Latitude");
...@@ -95,15 +99,25 @@ ThreadCar extends Thread { ...@@ -95,15 +99,25 @@ ThreadCar extends Thread {
Date endTime = new Date(); Date endTime = new Date();
//实时库中的时间虽然坐标与记录的一致,但是更新时间可能最新,故可能会有记录的结束时间早于开始时间 //实时库中的时间虽然坐标与记录的一致,但是更新时间可能最新,故可能会有记录的结束时间早于开始时间
long takeTime = (endTime.getTime() / 1000 * 1000) - (last.getStartTime().getTime() / 1000 * 1000); long takeTime = (endTime.getTime() / 1000 * 1000) - (last.getStartTime().getTime() / 1000 * 1000);
if(takeTime<0){ if (takeTime < 0) {
takeTime = 0-takeTime; takeTime = 0 - takeTime;
} }
last.setTakeTime(takeTime);
last.setEndLongitude(endLongitude); last.setEndLongitude(endLongitude);
last.setEndLatitude(endLatitude); last.setEndLatitude(endLatitude);
last.setEndTime(endTime); last.setEndTime(endTime);
last.setEndName(CarUtils.getAddress(endLongitude, endLatitude)); last.setEndName(CarUtils.getAddress(endLongitude, endLatitude));
last.setEndSpeed(lastObj.getIntValue("FireCar_Speed")); //原来的写法不够健壮,如果上报的数据为double写法则会直接报凑错
last.setTakeTime(takeTime); try {
Double.valueOf(jsonObject.getDoubleValue("FireCar_Speed")).intValue();
if (ObjectUtils.isEmpty(lastObj.containsKey("FireCar_Speed"))) {
last.setEndSpeed(0);
} else {
last.setEndSpeed(Double.valueOf(jsonObject.getString("FireCar_Speed")).intValue());
}
} catch (Exception exception) {
last.setEndSpeed(0);
}
double travel = 0.0; double travel = 0.0;
// 获取里程 // 获取里程
for (int i = 0; i < filterList.size() - 1; i++) { for (int i = 0; i < filterList.size() - 1; i++) {
...@@ -113,19 +127,23 @@ ThreadCar extends Thread { ...@@ -113,19 +127,23 @@ ThreadCar extends Thread {
start.getDoubleValue("FireCar_Longitude"), end.getDoubleValue("FireCar_Latitude"), start.getDoubleValue("FireCar_Longitude"), end.getDoubleValue("FireCar_Latitude"),
end.getDoubleValue("FireCar_Longitude")); end.getDoubleValue("FireCar_Longitude"));
} }
last.setTravel(new BigDecimal(travel / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); Double travle =new BigDecimal(travel / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
logger.info("---------------------本次里程::"+travle+"---------------------------------------");
last.setTravel(travle);
iWlCarMileageService.updateById(last); iWlCarMileageService.updateById(last);
Long lastTime = System.currentTimeMillis(); Long lastTime = System.currentTimeMillis();
logger.info("--------------"+topic+"结束坐标成功::花费时间===="+String.valueOf((lastTime-startTime)/60000)+"-------------------------"); logger.info("---正常时获取到的获取last信息::" + JSONObject.toJSONString(last));
logger.info("============================================================更新结束坐标成功==============================================:"+topic); logger.info("--------------" + topic + "结束坐标成功::花费时间====" + String.valueOf((lastTime - startTime) / 60000) + "分钟-------------------------");
logger.info("============================================================更新结束坐标成功==============================================:" + topic);
} }
} catch (Exception exception) { } catch (Exception exception) {
if (last != null) { if (last != null) {
logger.info("---异常时获取到的获取last信息::"+JSONObject.toJSONString(last)); logger.info("---异常时获取到的获取last信息::" + JSONObject.toJSONString(last));
iWlCarMileageService.updateById(last); iWlCarMileageService.updateById(last);
} }
}finally { } finally {
logger.info("销毁车辆倒计时线程::topic_"+topic); logger.info("销毁车辆倒计时线程::topic_" + topic);
this.interrupt(); this.interrupt();
} }
} }
......
...@@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory; ...@@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.emq.EmqKeeper; import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
...@@ -100,12 +101,22 @@ public class ThreadCarMileageTreatment extends Thread { ...@@ -100,12 +101,22 @@ public class ThreadCarMileageTreatment extends Thread {
if(takeTime<0){ if(takeTime<0){
takeTime = 0-takeTime; takeTime = 0-takeTime;
} }
last.setTakeTime(takeTime);
last.setEndLongitude(endLongitude); last.setEndLongitude(endLongitude);
last.setEndLatitude(endLatitude); last.setEndLatitude(endLatitude);
last.setEndTime(endTime); last.setEndTime(endTime);
last.setEndName(CarUtils.getAddress(endLongitude, endLatitude)); last.setEndName(CarUtils.getAddress(endLongitude, endLatitude));
last.setEndSpeed(lastObj.getIntValue("FireCar_Speed")); //原来的写法不够健壮,如果上报的数据为double写法则会直接报凑错
last.setTakeTime(takeTime); try {
Double.valueOf(lastObj.getDoubleValue("FireCar_Speed")).intValue();
if (ObjectUtils.isEmpty(lastObj.containsKey("FireCar_Speed"))) {
last.setEndSpeed(0);
} else {
last.setEndSpeed(Double.valueOf(lastObj.getString("FireCar_Speed")).intValue());
}
} catch (Exception exception) {
last.setEndSpeed(0);
}
double travel = 0.0; double travel = 0.0;
// 获取里程 // 获取里程
for (int k = 0; k < filterList.size() - 1; k++) { for (int k = 0; k < filterList.size() - 1; k++) {
...@@ -115,14 +126,17 @@ public class ThreadCarMileageTreatment extends Thread { ...@@ -115,14 +126,17 @@ public class ThreadCarMileageTreatment extends Thread {
start.getDoubleValue("FireCar_Longitude"), end.getDoubleValue("FireCar_Latitude"), start.getDoubleValue("FireCar_Longitude"), end.getDoubleValue("FireCar_Latitude"),
end.getDoubleValue("FireCar_Longitude")); end.getDoubleValue("FireCar_Longitude"));
} }
last.setTravel(new BigDecimal(travel / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); Double travle =new BigDecimal(travel / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
logger.info("---------------------本次里程::"+travle+"---------------------------------------");
last.setTravel(travle);
logger.info("----------------------------------------last----------------------"+lastObj.toJSONString()); logger.info("----------------------------------------last----------------------"+lastObj.toJSONString());
// wlCarMileageServiceImpl.updateById(last); wlCarMileageServiceImpl.updateById(last);
} }
} }
} }
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); logger.info(exception.getMessage());
wlCarMileageServiceImpl.updateById(last);
} }
} }
......
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