Commit 7831941b authored by wujiang's avatar wujiang

提交

parent 34102153
...@@ -34,9 +34,7 @@ import java.net.HttpURLConnection; ...@@ -34,9 +34,7 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -62,6 +60,8 @@ public class JxiopCarIotListerServiceImpl { ...@@ -62,6 +60,8 @@ public class JxiopCarIotListerServiceImpl {
private EmqKeeper emqkeeper; private EmqKeeper emqkeeper;
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Autowired
private static Map<String,Object> cache = new HashMap<>();
// @Async("equipAsyncExecutor") // @Async("equipAsyncExecutor")
...@@ -72,9 +72,11 @@ public class JxiopCarIotListerServiceImpl { ...@@ -72,9 +72,11 @@ public class JxiopCarIotListerServiceImpl {
String iotCode = measurement + deviceName; String iotCode = measurement + deviceName;
JSONObject jsonObject = JSONObject.parseObject(message.toString()); 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 wlCarMileage = new WlCarMileage();
wlCarMileage.setIotCode(iotCode); wlCarMileage.setIotCode(iotCode);
wlCarMileage.setDate(new Date()); wlCarMileage.setDate(new Date());
...@@ -97,15 +99,16 @@ public class JxiopCarIotListerServiceImpl { ...@@ -97,15 +99,16 @@ public class JxiopCarIotListerServiceImpl {
e.printStackTrace(); e.printStackTrace();
iWlCarMileageService.save(wlCarMileage); iWlCarMileageService.save(wlCarMileage);
} }
cache.remove(iotCode);
} }
this.updateCarLocation(jsonObject, iotCode); this.updateCarLocation(jsonObject, iotCode);
String coordinate = jsonObject.getString("FireCar_Longitude") + "," + jsonObject.getString("FireCar_Latitude"); String coordinate = jsonObject.getString("FireCar_Longitude") + "," + jsonObject.getString("FireCar_Latitude");
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get(iotCode))) { if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get(iotCode))) {
redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES); redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES);
logger.info("首次入库redis:{}", iotCode); //logger.info("首次入库redis:{}", iotCode);
} else { } else {
if (!String.valueOf(redisTemplate.opsForValue().get(iotCode)).equals(coordinate)) { 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); redisTemplate.opsForValue().set(iotCode, coordinate, 5, TimeUnit.MINUTES);
} }
} }
......
...@@ -55,6 +55,7 @@ import java.text.DateFormat; ...@@ -55,6 +55,7 @@ import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -317,6 +318,7 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC ...@@ -317,6 +318,7 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
@Scheduled(cron = "${mileage.segmentation.cron}") @Scheduled(cron = "${mileage.segmentation.cron}")
@Async @Async
public void mileageSegmentation() { public void mileageSegmentation() {
CarIotNewListener.pooledExecutor.submit(()->{
log.info("轨迹切分定时任务开始执行时间.............{}", LocalDateTime.now()); log.info("轨迹切分定时任务开始执行时间.............{}", LocalDateTime.now());
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(new Date()); cal.setTime(new Date());
...@@ -324,11 +326,11 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC ...@@ -324,11 +326,11 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
String nowDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); String nowDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
log.info("轨迹切分定时任务数据过滤时间.............{}", nowDate); log.info("轨迹切分定时任务数据过滤时间.............{}", nowDate);
List<WlCarMileage> list = this.baseMapper.list(nowDate); List<WlCarMileage> list = this.baseMapper.list(nowDate);
log.info("需要切分数据, {}", list); // log.info("需要切分数据, {}", list);
log.info("销毁所有坐标信息成功"); // log.info("销毁所有坐标信息成功");
log.info("------------------跨天轨迹切分任开始切分里程-------------------------------"); log.info("------------------跨天轨迹切分任开始切分里程-------------------------------");
list.forEach(item -> { list.forEach(item -> {
redisTemplate.delete(item.getIotCode()); //redisTemplate.delete(item.getIotCode());
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(item.getDate()); calendar.setTime(item.getDate());
calendar.add(Calendar.DATE, 1); calendar.add(Calendar.DATE, 1);
...@@ -404,16 +406,28 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC ...@@ -404,16 +406,28 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
Date endTime = DateUtil.offsetDay(new Date(),-15); Date endTime = DateUtil.offsetDay(new Date(),-15);
String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:00"); String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:00");
wlCarSpeedWaringRecordMapper.delete(new QueryWrapper<CarSpeedWarningRecord>().le("waring_date",endTimeStr)); wlCarSpeedWaringRecordMapper.delete(new QueryWrapper<CarSpeedWarningRecord>().le("waring_date",endTimeStr));
});
} }
@Scheduled(cron = "${mileage.splitmileage.cron}") @Scheduled(cron = "${mileage.splitmileage.cron}")
@Async @Async
public void endCarMileageTask() { 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<WlCarMileage> list = wlCarMileageMapper.selectList(new QueryWrapper<WlCarMileage>().isNull("end_time").isNotNull("start_time"));
list.forEach(item -> { list.forEach(item -> {
log.info("1获取code:{}", item.getIotCode()); //log.info("1获取code:{}", item.getIotCode());
log.info("2获取结果:{}", ObjectUtils.isEmpty(redisTemplate.opsForValue().get(item.getIotCode()))); //log.info("2获取结果:{}", ObjectUtils.isEmpty(redisTemplate.opsForValue().get(item.getIotCode())));
if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get(item.getIotCode()))) { if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get(item.getIotCode()))) {
if (!ObjectUtils.isEmpty(item.getIotCode()) && item.getIotCode().length() > 8) { if (!ObjectUtils.isEmpty(item.getIotCode()) && item.getIotCode().length() > 8) {
log.info("3处理结束坐标轨迹iocCode:{}", item.getIotCode()); log.info("3处理结束坐标轨迹iocCode:{}", item.getIotCode());
...@@ -485,12 +499,14 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC ...@@ -485,12 +499,14 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
} }
} }
}); });
log.info("轨迹切分任务执行完成..............");
log.info("轨迹切分任务执行完成..............");
log.info("轨迹切分任务执行完成.............."); log.info("轨迹切分任务执行完成..............");
//删除无效的告警数据 //删除无效的告警数据
Date endTime = DateUtil.offsetMinute(new Date(),-10); Date endTime = DateUtil.offsetMinute(new Date(),-10);
String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:00"); 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)); wlCarSpeedWaringRecordMapper.delete(new QueryWrapper<CarSpeedWarningRecord>().le("waring_date",endTimeStr).lt("over_speed_count",5));
});
} }
@Override @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