Commit 62636a3e authored by caotao's avatar caotao

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

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