Commit 7831941b authored by wujiang's avatar wujiang

提交

parent 34102153
......@@ -34,9 +34,7 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
......@@ -62,6 +60,8 @@ public class JxiopCarIotListerServiceImpl {
private EmqKeeper emqkeeper;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private static Map<String,Object> cache = new HashMap<>();
// @Async("equipAsyncExecutor")
......@@ -72,9 +72,11 @@ public class JxiopCarIotListerServiceImpl {
String iotCode = measurement + deviceName;
JSONObject jsonObject = JSONObject.parseObject(message.toString());
//判断是否有效坐标
if (!ObjectUtils.isEmpty(jsonObject.get("FireCar_Longitude")) && !ObjectUtils.isEmpty(jsonObject.get("FireCar_Latitude"))) {
if (!ObjectUtils.isEmpty(jsonObject.get("FireCar_Longitude")) && !ObjectUtils.isEmpty(jsonObject.get("FireCar_Latitude"))
&&cache.get(iotCode)==null) {
//判断是否存在未结束进程,如果不存在,则进入判断插入开始节点
if (iWlCarMileageService.getUncompleteMileagByIotCode(iotCode)) {
if (iWlCarMileageService.getUncompleteMileagByIotCode(iotCode)&&cache.get(iotCode)==null) {
cache.put(iotCode,iotCode);
WlCarMileage wlCarMileage = new WlCarMileage();
wlCarMileage.setIotCode(iotCode);
wlCarMileage.setDate(new Date());
......@@ -97,15 +99,16 @@ public class JxiopCarIotListerServiceImpl {
e.printStackTrace();
iWlCarMileageService.save(wlCarMileage);
}
cache.remove(iotCode);
}
this.updateCarLocation(jsonObject, iotCode);
String coordinate = jsonObject.getString("FireCar_Longitude") + "," + jsonObject.getString("FireCar_Latitude");
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get(iotCode))) {
redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES);
logger.info("首次入库redis:{}", iotCode);
//logger.info("首次入库redis:{}", iotCode);
} else {
if (!String.valueOf(redisTemplate.opsForValue().get(iotCode)).equals(coordinate)) {
logger.info("更新入库redis:{},旧:{},新:{}", iotCode, redisTemplate.opsForValue().get(iotCode), coordinate);
// logger.info("更新入库redis:{},旧:{},新:{}", iotCode, redisTemplate.opsForValue().get(iotCode), coordinate);
redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES);
}
}
......
......@@ -55,6 +55,7 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
......@@ -317,103 +318,116 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
@Scheduled(cron = "${mileage.segmentation.cron}")
@Async
public void mileageSegmentation() {
log.info("轨迹切分定时任务开始执行时间.............{}", LocalDateTime.now());
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -1);
String nowDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
log.info("轨迹切分定时任务数据过滤时间.............{}", nowDate);
List<WlCarMileage> list = this.baseMapper.list(nowDate);
log.info("需要切分数据, {}", list);
log.info("销毁所有坐标信息成功");
log.info("------------------跨天轨迹切分任开始切分里程-------------------------------");
list.forEach(item -> {
redisTemplate.delete(item.getIotCode());
Calendar calendar = Calendar.getInstance();
calendar.setTime(item.getDate());
calendar.add(Calendar.DATE, 1);
Date date = calendar.getTime();
//iotcode有效
if (!ObjectUtils.isEmpty(item.getIotCode()) && item.getIotCode().length() > 8) {
// 查询车辆上报信息
ResponseModel<List<Object>> result = iotFeign.getLiveData(item.getIotCode().substring(0, 8), item.getIotCode().substring(8),
item.getStartTime(), new Date(new Date().getTime() + 2000));
List<Object> list1 = result.getResult();
// 获取最后一个有坐标的数据
JSONObject lastObj = null;
// 过滤空坐标
List<Object> filterList = new ArrayList<Object>();
for (int i = 0; i < list1.size(); i++) {
JSONObject Obj = JSONObject.parseObject(JSONObject.toJSONString(list1.get(i)));
if (Obj.get("FireCar_Longitude") != null && Obj.get("FireCar_Latitude") != null
&& Obj.getDoubleValue("FireCar_Longitude") != 0
&& Obj.getDoubleValue("FireCar_Latitude") != 0) {
filterList.add(list1.get(i));
// 获取第一个不为空的坐标
if (lastObj == null) {
lastObj = Obj;
CarIotNewListener.pooledExecutor.submit(()->{
log.info("轨迹切分定时任务开始执行时间.............{}", LocalDateTime.now());
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -1);
String nowDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
log.info("轨迹切分定时任务数据过滤时间.............{}", nowDate);
List<WlCarMileage> list = this.baseMapper.list(nowDate);
// log.info("需要切分数据, {}", list);
// log.info("销毁所有坐标信息成功");
log.info("------------------跨天轨迹切分任开始切分里程-------------------------------");
list.forEach(item -> {
//redisTemplate.delete(item.getIotCode());
Calendar calendar = Calendar.getInstance();
calendar.setTime(item.getDate());
calendar.add(Calendar.DATE, 1);
Date date = calendar.getTime();
//iotcode有效
if (!ObjectUtils.isEmpty(item.getIotCode()) && item.getIotCode().length() > 8) {
// 查询车辆上报信息
ResponseModel<List<Object>> result = iotFeign.getLiveData(item.getIotCode().substring(0, 8), item.getIotCode().substring(8),
item.getStartTime(), new Date(new Date().getTime() + 2000));
List<Object> list1 = result.getResult();
// 获取最后一个有坐标的数据
JSONObject lastObj = null;
// 过滤空坐标
List<Object> filterList = new ArrayList<Object>();
for (int i = 0; i < list1.size(); i++) {
JSONObject Obj = JSONObject.parseObject(JSONObject.toJSONString(list1.get(i)));
if (Obj.get("FireCar_Longitude") != null && Obj.get("FireCar_Latitude") != null
&& Obj.getDoubleValue("FireCar_Longitude") != 0
&& Obj.getDoubleValue("FireCar_Latitude") != 0) {
filterList.add(list1.get(i));
// 获取第一个不为空的坐标
if (lastObj == null) {
lastObj = Obj;
}
}
}
}
if (lastObj == null) {
lastObj = new JSONObject();
lastObj.put("FireCar_Longitude", 0.0);
lastObj.put("FireCar_Latitude", 0.0);
lastObj.put("time", 0);
lastObj.put("FireCar_Speed", 0);
}
// 当前坐标
double startLongitude = lastObj.getDoubleValue("FireCar_Longitude");
double startLatitude = lastObj.getDoubleValue("FireCar_Latitude");
// 当前速度
Double v = lastObj.getDoubleValue("FireCar_Speed");
item.setStartSpeed(v.intValue());
double travel = 0.0;
// 获取里程
for (int i = 0; i < filterList.size() - 1; i++) {
JSONObject start = JSONObject.parseObject(JSONObject.toJSONString(filterList.get(i)));
JSONObject end = JSONObject.parseObject(JSONObject.toJSONString(filterList.get(i + 1)));
travel += CoordinateUtil.distance(start.getDoubleValue("FireCar_Latitude"),
start.getDoubleValue("FireCar_Longitude"), end.getDoubleValue("FireCar_Latitude"),
end.getDoubleValue("FireCar_Longitude"));
}
if (lastObj == null) {
lastObj = new JSONObject();
lastObj.put("FireCar_Longitude", 0.0);
lastObj.put("FireCar_Latitude", 0.0);
lastObj.put("time", 0);
lastObj.put("FireCar_Speed", 0);
}
// 当前坐标
double startLongitude = lastObj.getDoubleValue("FireCar_Longitude");
double startLatitude = lastObj.getDoubleValue("FireCar_Latitude");
// 当前速度
Double v = lastObj.getDoubleValue("FireCar_Speed");
item.setStartSpeed(v.intValue());
double travel = 0.0;
// 获取里程
for (int i = 0; i < filterList.size() - 1; i++) {
JSONObject start = JSONObject.parseObject(JSONObject.toJSONString(filterList.get(i)));
JSONObject end = JSONObject.parseObject(JSONObject.toJSONString(filterList.get(i + 1)));
travel += CoordinateUtil.distance(start.getDoubleValue("FireCar_Latitude"),
start.getDoubleValue("FireCar_Longitude"), end.getDoubleValue("FireCar_Latitude"),
end.getDoubleValue("FireCar_Longitude"));
}
// 里程耗时
long takeTime = (date.getTime()) - (item.getStartTime().getTime());
// 里程耗时
long takeTime = (date.getTime()) - (item.getStartTime().getTime());
// 查询车辆最新位置
// 查询车辆最新位置
// 修改0点未结束里程记录
item.setEndSpeed(v.intValue());
item.setEndTime(date);
item.setEndLatitude(startLatitude);
item.setEndLongitude(startLongitude);
item.setEndName("无效坐标");
if (travel > 0.5) {
String address = getAddress(startLongitude, startLatitude);
item.setEndName(address);
// 修改0点未结束里程记录
item.setEndSpeed(v.intValue());
item.setEndTime(date);
item.setEndLatitude(startLatitude);
item.setEndLongitude(startLongitude);
item.setEndName("无效坐标");
if (travel > 0.5) {
String address = getAddress(startLongitude, startLatitude);
item.setEndName(address);
}
item.setTravel(new BigDecimal(travel / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
item.setTakeTime(takeTime);
this.getBaseMapper().updateById(item);
log.info("-----------跨天轨迹切分任更新车辆坐标成功:::" + JSONObject.toJSONString(item) + "-----------------");
}
item.setTravel(new BigDecimal(travel / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
item.setTakeTime(takeTime);
this.getBaseMapper().updateById(item);
log.info("-----------跨天轨迹切分任更新车辆坐标成功:::" + JSONObject.toJSONString(item) + "-----------------");
}
});
log.info("-------------------跨天轨迹切分任务执行完成..............");
//删除过期的告警数据
Date endTime = DateUtil.offsetDay(new Date(),-15);
String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:00");
wlCarSpeedWaringRecordMapper.delete(new QueryWrapper<CarSpeedWarningRecord>().le("waring_date",endTimeStr));
});
log.info("-------------------跨天轨迹切分任务执行完成..............");
//删除过期的告警数据
Date endTime = DateUtil.offsetDay(new Date(),-15);
String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:00");
wlCarSpeedWaringRecordMapper.delete(new QueryWrapper<CarSpeedWarningRecord>().le("waring_date",endTimeStr));
}
@Scheduled(cron = "${mileage.splitmileage.cron}")
@Async
public void endCarMileageTask() {
log.info("========开始轨迹切分任务===========");
CarIotNewListener.pooledExecutor.submit(()->{
// 获取当前的日期和时间
LocalDateTime now = LocalDateTime.now();
// 定义日期时间格式化器
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 格式化当前日期时间并打印
String formattedDateTime = now.format(formatter);
log.info("========开始轨迹切分任务==========="+formattedDateTime);
log.info("========开始轨迹切分任务==========="+formattedDateTime);
log.info("========开始轨迹切分任务==========="+formattedDateTime);
log.info("========开始轨迹切分任务==========="+formattedDateTime);
log.info("========开始轨迹切分任务==========="+formattedDateTime);
List<WlCarMileage> list = wlCarMileageMapper.selectList(new QueryWrapper<WlCarMileage>().isNull("end_time").isNotNull("start_time"));
list.forEach(item -> {
log.info("1获取code:{}", item.getIotCode());
log.info("2获取结果:{}", ObjectUtils.isEmpty(redisTemplate.opsForValue().get(item.getIotCode())));
//log.info("1获取code:{}", item.getIotCode());
//log.info("2获取结果:{}", ObjectUtils.isEmpty(redisTemplate.opsForValue().get(item.getIotCode())));
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get(item.getIotCode()))) {
if (!ObjectUtils.isEmpty(item.getIotCode()) && item.getIotCode().length() > 8) {
log.info("3处理结束坐标轨迹iocCode:{}", item.getIotCode());
......@@ -485,12 +499,14 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
}
}
});
log.info("轨迹切分任务执行完成..............");
log.info("轨迹切分任务执行完成..............");
log.info("轨迹切分任务执行完成..............");
//删除无效的告警数据
Date endTime = DateUtil.offsetMinute(new Date(),-10);
String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:00");
wlCarSpeedWaringRecordMapper.delete(new QueryWrapper<CarSpeedWarningRecord>().le("waring_date",endTimeStr).lt("over_speed_count",5));
});
}
@Override
......
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