Commit 22f17c7e authored by caotao's avatar caotao

车辆里程分割新增兼容处理无效坐标的数据

parent c38ce76d
......@@ -119,6 +119,7 @@ public class CarIotNewListener extends EmqxListener {
deviceInfo.get(iotCode).interrupt();
deviceInfo.remove(iotCode);
} catch (Exception e) {
deviceInfo.remove(iotCode);
}
logger.info("topic---------------------" + topic + "开启计时线程");
ThreadCar threadCar = new ThreadCar(topic, jsonObject, this.iWlCarMileageService, this.iotFeign, this.iCarService, clipping_time);
......
......@@ -3,7 +3,6 @@ package com.yeejoin.equipmanage.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -27,8 +26,10 @@ import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
......@@ -66,6 +67,9 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
@Value("${mileage.parameter}")
private Double mileageParameter;
@Resource
private EmqKeeper emqKeeper;
private static final Logger log = LoggerFactory.getLogger(HttpUtil.class);
private final String GUIDE_KEY = "813684495d9a3981dd2c7694916fe404";
......@@ -89,7 +93,7 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
double speed = 0;
WlCarMileage wlCarMileage = this.getById(id);
String iotCode = wlCarMileage.getIotCode();
String measurement = "0THMcLKR";
String measurement = iotCode.substring(0,8);
String deviceName = iotCode.replace(measurement, "");
// 由于iot存在毫秒故结束时间要+1秒 iot+1秒有bug还是查不到 +2秒
ResponseModel<List<Object>> result = iotFeign.getLiveData(measurement, deviceName, wlCarMileage.getStartTime(),
......@@ -337,9 +341,8 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
double startLongitude = lastObj.getDoubleValue("FireCar_Longitude");
double startLatitude = lastObj.getDoubleValue("FireCar_Latitude");
// 当前速度
double v = Double.parseDouble(String.valueOf(lastObj.get("FireCar_Speed")));
int ceil = (int) Math.ceil(v);
item.setStartSpeed(ceil);
Double v = Double.parseDouble(String.valueOf(lastObj.get("FireCar_Speed")));
item.setStartSpeed(v.intValue());
double travel = 0.0;
// 获取里程
for (int i = 0; i < filterList.size() - 1; i++) {
......@@ -354,7 +357,7 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
// 里程耗时
long takeTime = (date.getTime()) - (item.getStartTime().getTime());
// 修改0点未结束里程记录
item.setEndSpeed(ceil);
item.setEndSpeed(v.intValue());
item.setEndTime(date);
item.setEndLatitude(startLatitude);
item.setEndLongitude(startLongitude);
......@@ -374,12 +377,22 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
item.setEndName(null);
item.setTravel(null);
item.setTakeTime(null);
item.setStartSpeed(ceil);
item.setStartSpeed(v.intValue());
item.setStartTime(item.getDate());
item.setStartLongitude(startLongitude);
item.setStartLatitude(startLatitude);
this.baseMapper.insert(item);
HashMap<String,String> messageMap = new HashMap<>();
messageMap.put("FireCar_Latitude", String.valueOf(startLatitude));
messageMap.put("FireCar_Longitude", String.valueOf(startLongitude));
messageMap.put("FireCar_Speed",String.valueOf(v.intValue()));
messageMap.put("time",String.valueOf(item.getDate().getTime()));
messageMap.put("name","轨迹切分消息!!!");
log.info("-----------新增开始里程成功:::"+JSONObject.toJSONString(item)+"-----------------");
try {
emqKeeper.getMqttClient().publish(item.getIotCode().substring(0, 8)+"/"+item.getIotCode().substring(8)+"/property",JSON.toJSON(messageMap).toString().getBytes("UTF-8"),1,false);
} catch (Exception e) {
}
//根据iotcode获取车辆并且同步经纬度到车辆
Car car = iCarService.getOne(new QueryWrapper<Car>().eq("iot_code", item.getIotCode()));
car.setLongitude(startLongitude);
......@@ -390,7 +403,7 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
});
log.info("轨迹切分任务执行完成..............");
log.info("-------------------对于切割完成的数据进行倒计时操作----------------------------------");
ThreadCarMileageTreatment threadCarMileageTreatment = new ThreadCarMileageTreatment();
ThreadCarMileageTreatment threadCarMileageTreatment = new ThreadCarMileageTreatment(this,iCarService , iotFeign);
log.info("-------------------对于切割完成的数据进行倒计时开始----------------------------------");
threadCarMileageTreatment.start();
log.info("-------------------对于切割完成的数据进行倒计时结束----------------------------------");
......
......@@ -8,19 +8,14 @@ import com.yeejoin.equipmanage.common.entity.WlCarMileage;
import com.yeejoin.equipmanage.common.utils.CoordinateUtil;
import com.yeejoin.equipmanage.fegin.IotFeign;
import com.yeejoin.equipmanage.service.ICarService;
import com.yeejoin.equipmanage.service.IWlCarMileageService;
import com.yeejoin.equipmanage.service.impl.CarServiceImpl;
import com.yeejoin.equipmanage.service.impl.WlCarMileageServiceImpl;
import com.yeejoin.equipmanage.utils.CarUtils;
import liquibase.pro.packaged.E;
import org.jfree.util.Log;
import org.slf4j.Logger;
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;
import java.math.BigDecimal;
......@@ -28,20 +23,21 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@Component
public class ThreadCarMileageTreatment extends Thread {
Logger logger = LoggerFactory.getLogger(ThreadCarMileageTreatment.class);
@Autowired
private WlCarMileageServiceImpl wlCarMileageServiceImpl;
@Autowired
CarServiceImpl carServiceImpl;
@Autowired
private IotFeign iotFeign;
private final WlCarMileageServiceImpl wlCarMileageServiceImpl;
private final ICarService iCarService;
private final IotFeign iotFeign;
@Value("${mileage.clippingtime}")
private Long clipping_time;
public ThreadCarMileageTreatment(WlCarMileageServiceImpl wlCarMileageServiceImpl, ICarService iCarService, IotFeign iotFeign) {
this.wlCarMileageServiceImpl = wlCarMileageServiceImpl;
this.iCarService = iCarService;
this.iotFeign = iotFeign;
}
@Override
public void run() {
logger.info("----------------------------------------------------开始处理未结束里程---------------------------------");
......@@ -52,19 +48,21 @@ public class ThreadCarMileageTreatment extends Thread {
Car car =null;
List<WlCarMileage> wlCarMileageList = wlCarMileageServiceImpl.list(new QueryWrapper<WlCarMileage>().isNull("end_time"));
for (int i = 0; i < wlCarMileageList.size(); i++) {
car = carServiceImpl.getOne(new QueryWrapper<Car>().eq("iot_code", wlCarMileageList.get(i).getIotCode()));
car = iCarService.getOne(new QueryWrapper<Car>().eq("iot_code", wlCarMileageList.get(i).getIotCode()));
String coordinateSting = String.valueOf(car.getLongitude()) + String.valueOf(car.getLatitude());
hashMap.put(car.getIotCode(), coordinateSting);
}
logger.info("----------------获取到的未处理的车辆坐标信息::"+JSONObject.toJSONString(hashMap));
try {
Thread.sleep(clipping_time);
for (int i = 0; i < wlCarMileageList.size(); i++) {
WlCarMileage wlCarMileage =wlCarMileageList.get(i);
car = carServiceImpl.getOne(new QueryWrapper<Car>().eq("iot_code", wlCarMileage.getIotCode()));
car = iCarService.getOne(new QueryWrapper<Car>().eq("iot_code", wlCarMileage.getIotCode()));
String coordinateSting = String.valueOf(car.getLongitude()) + String.valueOf(car.getLatitude());
if (coordinateSting.equals(hashMap.get(car.getIotCode()))) {
//增加对于无效坐标的兼容处理,由于无效坐标的存储精度不一样 可能会导致0的位数发生差异从而到时无法判断生效
if (coordinateSting.equals(hashMap.get(car.getIotCode()))||(handlerUnActiveCoodinate(coordinateSting).equals(handlerUnActiveCoodinate(hashMap.get(car.getIotCode()))))) {
String iotCode = car.getIotCode();
String measurement = "0THMcLKR";
String measurement = iotCode.substring(0,8);
String deviceName = iotCode.replace(measurement, "");
last = wlCarMileageServiceImpl
.getOne(new LambdaQueryWrapper<WlCarMileage>().eq(WlCarMileage::getIotCode, iotCode)
......@@ -139,6 +137,8 @@ public class ThreadCarMileageTreatment extends Thread {
wlCarMileageServiceImpl.updateById(last);
}
}
public String handlerUnActiveCoodinate(String coodeinateString){
return coodeinateString.replace("0","").replace(".","");
}
}
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