Commit e0922755 authored by caotao's avatar caotao

车辆轨迹按照10分钟划分逻辑优化提交

parent 359d290c
...@@ -30,6 +30,7 @@ public interface IWlCarMileageService extends IService<WlCarMileage> { ...@@ -30,6 +30,7 @@ public interface IWlCarMileageService extends IService<WlCarMileage> {
* 里程切分(0点若里程未结束,自动切分设置结束信息,并开始新里程) * 里程切分(0点若里程未结束,自动切分设置结束信息,并开始新里程)
*/ */
void mileageSegmentation(); void mileageSegmentation();
//根据iot编码查询是否有未结束里程
Boolean getUncompleteMileagByIotCode(String iotCode);
} }
...@@ -3,6 +3,7 @@ package com.yeejoin.equipmanage.service.impl; ...@@ -3,6 +3,7 @@ package com.yeejoin.equipmanage.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
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.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -384,6 +385,12 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC ...@@ -384,6 +385,12 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
log.info("轨迹切分任务执行完成.............."); log.info("轨迹切分任务执行完成..............");
} }
@Override
public Boolean getUncompleteMileagByIotCode(String iotCode) {
Integer integer = this.count(new QueryWrapper<WlCarMileage>().select("1").lambda().eq(WlCarMileage::getIotCode,iotCode).isNull(WlCarMileage::getEndTime));
return integer <= 0 ;
}
private String getAddress(double longitude, double lantitude) { private String getAddress(double longitude, double lantitude) {
StringBuilder api = new StringBuilder(GUIDE_ADDRESS_URL); StringBuilder api = new StringBuilder(GUIDE_ADDRESS_URL);
......
package com.yeejoin.equipmanage.thread; package com.yeejoin.equipmanage.thread;
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;
import com.yeejoin.equipmanage.common.entity.Car;
import com.yeejoin.equipmanage.common.entity.WlCarMileage; import com.yeejoin.equipmanage.common.entity.WlCarMileage;
import com.yeejoin.equipmanage.common.utils.CoordinateUtil; import com.yeejoin.equipmanage.common.utils.CoordinateUtil;
import com.yeejoin.equipmanage.fegin.IotFeign; import com.yeejoin.equipmanage.fegin.IotFeign;
import com.yeejoin.equipmanage.service.ICarService;
import com.yeejoin.equipmanage.service.IWlCarMileageService; import com.yeejoin.equipmanage.service.IWlCarMileageService;
import com.yeejoin.equipmanage.utils.CarUtils; import com.yeejoin.equipmanage.utils.CarUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Timer;
import java.util.concurrent.TimeUnit;
public class ThreadCar extends Thread { public class ThreadCar extends Thread {
@Autowired
private IWlCarMileageService iWlCarMileageService; private IWlCarMileageService iWlCarMileageService;
@Autowired
private IotFeign iotFeign; private IotFeign iotFeign;
private String topic; private String topic;
private Long clippingTime;
ICarService iCarService;
private EmqKeeper emqkeeper;
private JSONObject jsonObject; private JSONObject jsonObject;
public ThreadCar(String topic, JSONObject jsonObject){
public ThreadCar(String topic, JSONObject jsonObject, IWlCarMileageService iWlCarMileageService, IotFeign iotFeign, ICarService iCarService, EmqKeeper emqkeeper, Long clippingTime) {
this.topic = topic; this.topic = topic;
this.jsonObject = jsonObject; this.jsonObject = jsonObject;
this.iWlCarMileageService = iWlCarMileageService;
this.iotFeign = iotFeign;
this.iCarService = iCarService;
this.emqkeeper = emqkeeper;
this.clippingTime = clippingTime;
} }
@Override @Override
public void run() { public void run() {
//toDo //toDo
// 获取最后一个有坐标的数据 // 获取最后一个有坐标的数据
JSONObject lastObj = null; JSONObject lastObj = null;
WlCarMileage last= null; WlCarMileage last = null;
try { try {
Thread.sleep(600000); TimeUnit.MILLISECONDS.sleep(Long.valueOf((long) (clippingTime)));
//业务处理 //业务处理
//如果十分钟没有坐标,则需要设置结束标记 //如果十分钟没有坐标,则需要设置结束标记
// 获取结束坐标 // 获取结束坐标
...@@ -79,7 +94,7 @@ public class ThreadCar extends Thread { ...@@ -79,7 +94,7 @@ public class ThreadCar extends Thread {
// 230215180624 // 230215180624
// Date endTime =UTCToCST(lastObj.getString("time")); // Date endTime =UTCToCST(lastObj.getString("time"));
Date endTime = new Date(jsonObject.getLong("time")); 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);
last.setEndLongitude(endLongitude); last.setEndLongitude(endLongitude);
last.setEndLatitude(endLatitude); last.setEndLatitude(endLatitude);
...@@ -98,10 +113,44 @@ public class ThreadCar extends Thread { ...@@ -98,10 +113,44 @@ public class ThreadCar extends Thread {
} }
last.setTravel(new BigDecimal(travel / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue()); last.setTravel(new BigDecimal(travel / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
iWlCarMileageService.updateById(last); iWlCarMileageService.updateById(last);
this.pushCarInfoToMap(jsonObject, topic);
this.interrupt(); this.interrupt();
} }
} catch (Exception exception) { } catch (Exception exception) {
iWlCarMileageService.updateById(last);
}
}
public void pushCarInfoToMap(JSONObject jsonObject, String iotCode) {
if (jsonObject.containsKey("FireCar_Longitude") && jsonObject.containsKey("FireCar_Latitude")) {
// 获取开始坐标
double startLongitude = jsonObject.getDoubleValue("FireCar_Longitude");
double startLatitude = jsonObject.getDoubleValue("FireCar_Latitude");
int direction = jsonObject.getIntValue("direction");
// 地图推送消息
Car car = iCarService.getOne(new LambdaQueryWrapper<Car>().eq(Car::getIotCode, iotCode));
if (car != null && startLongitude != 0 && startLatitude != 0) {
JSONArray sendArr = new JSONArray();
JSONObject sendObj = new JSONObject();
sendObj.put("id", String.valueOf(car.getId()));
sendObj.put("direction", direction);
sendObj.put("longitude", String.valueOf(startLongitude));
sendObj.put("latitude", String.valueOf(startLatitude));
sendObj.put("carNum", car.getCarNum());
sendObj.put("bizOrgName", car.getBizOrgName());
sendArr.add(sendObj);
MqttMessage mqttMessage = new MqttMessage();
mqttMessage.setPayload(sendArr.toJSONString().getBytes());
car.setLongitude(startLongitude);
car.setLatitude(startLatitude);
iCarService.updateById(car);
try {
emqkeeper.getMqttClient().publish("car/location", mqttMessage);
} catch (MqttException e) {
throw new RuntimeException(e);
}
}
} }
} }
} }
......
package com.yeejoin.equipmanage.utils; package com.yeejoin.equipmanage.utils;
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.yeejoin.equipmanage.common.entity.Car;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
......
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