|
@ -30,6 +30,8 @@ import org.springframework.stereotype.Service; |
|
|
import javax.annotation.PostConstruct; |
|
|
import javax.annotation.PostConstruct; |
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.time.Instant; |
|
|
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@ -123,9 +125,18 @@ public class DcTrafficStatisticsServiceImpl |
|
|
LambdaQueryWrapper<DcTrafficSectionData> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<DcTrafficSectionData> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
queryWrapper.between(DcTrafficSectionData::getStatisticalDate, request.getStartTime(), request.getEndTime()); |
|
|
queryWrapper.between(DcTrafficSectionData::getStatisticalDate, request.getStartTime(), request.getEndTime()); |
|
|
queryWrapper.eq(DcTrafficSectionData::getPeriodType, request.getPeriodType()); |
|
|
queryWrapper.eq(DcTrafficSectionData::getPeriodType, request.getPeriodType()); |
|
|
queryWrapper.eq(DcTrafficSectionData::getDirection, request.getDirection()); |
|
|
|
|
|
queryWrapper.eq(DcTrafficSectionData::getDeviceType, request.getDeviceType()); |
|
|
if (request.getDirection() != null) { |
|
|
queryWrapper.eq(DcTrafficSectionData::getDeviceId, request.getDeviceId()); |
|
|
queryWrapper.eq(DcTrafficSectionData::getDirection, request.getDirection()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.getDeviceType() != null) { |
|
|
|
|
|
queryWrapper.eq(DcTrafficSectionData::getDeviceType, request.getDeviceType()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (request.getDeviceId() != null) { |
|
|
|
|
|
queryWrapper.eq(DcTrafficSectionData::getDeviceId, request.getDeviceId()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return list(queryWrapper); |
|
|
return list(queryWrapper); |
|
|
} |
|
|
} |
|
@ -143,6 +154,9 @@ public class DcTrafficStatisticsServiceImpl |
|
|
// 从Redis缓存中获取指定方向的交通路段数据列表
|
|
|
// 从Redis缓存中获取指定方向的交通路段数据列表
|
|
|
List<DcTrafficSectionData> dcTrafficSectionDataCaches = getDcTrafficSectionDataRedisCache(request.getDirection()); |
|
|
List<DcTrafficSectionData> dcTrafficSectionDataCaches = getDcTrafficSectionDataRedisCache(request.getDirection()); |
|
|
|
|
|
|
|
|
|
|
|
// 过滤掉时间错误的交通数据
|
|
|
|
|
|
processStaleTrafficSectionData(dcTrafficSectionDataCaches); |
|
|
|
|
|
|
|
|
// 根据请求过滤交通数据
|
|
|
// 根据请求过滤交通数据
|
|
|
List<DcTrafficSectionData> trafficSectionDataList = filterTrafficDataByRequest(request, dcTrafficSectionDataCaches); |
|
|
List<DcTrafficSectionData> trafficSectionDataList = filterTrafficDataByRequest(request, dcTrafficSectionDataCaches); |
|
|
|
|
|
|
|
@ -180,7 +194,10 @@ public class DcTrafficStatisticsServiceImpl |
|
|
LambdaQueryWrapper<DcTrafficSectionData> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<DcTrafficSectionData> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
queryWrapper.between(DcTrafficSectionData::getStatisticalDate, request.getStartTime(), request.getEndTime()); |
|
|
queryWrapper.between(DcTrafficSectionData::getStatisticalDate, request.getStartTime(), request.getEndTime()); |
|
|
queryWrapper.eq(DcTrafficSectionData::getPeriodType, request.getPeriodType()); |
|
|
queryWrapper.eq(DcTrafficSectionData::getPeriodType, request.getPeriodType()); |
|
|
queryWrapper.eq(DcTrafficSectionData::getDirection, request.getDirection()); |
|
|
|
|
|
|
|
|
if (request.getDirection() != null) { |
|
|
|
|
|
queryWrapper.eq(DcTrafficSectionData::getDirection, request.getDirection()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 根据请求获取所属路段ID,并进一步筛选路段范围内的数据
|
|
|
// 根据请求获取所属路段ID,并进一步筛选路段范围内的数据
|
|
|
Long roadSectionId = request.getRoadSectionId(); |
|
|
Long roadSectionId = request.getRoadSectionId(); |
|
@ -320,6 +337,36 @@ public class DcTrafficStatisticsServiceImpl |
|
|
return new ArrayList<>(dcTrafficSectionDataMap.values()); |
|
|
return new ArrayList<>(dcTrafficSectionDataMap.values()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 过滤掉时间错误的交通路段数据,并更新数据的统计时间为当前时间。 |
|
|
|
|
|
* 该方法会遍历交通路段数据列表,移除统计时间早于20分钟前的数据,并将其它数据的统计时间更新为当前时间。 |
|
|
|
|
|
* |
|
|
|
|
|
* @param dcTrafficSectionDataList 交通路段数据列表,列表中每一项包含一个交通路段的统计数据。 |
|
|
|
|
|
*/ |
|
|
|
|
|
public void processStaleTrafficSectionData(List<DcTrafficSectionData> dcTrafficSectionDataList) { |
|
|
|
|
|
// 计算20分钟前的时间戳
|
|
|
|
|
|
Instant twentyMinutesAgo = Instant.now().minus(20, ChronoUnit.MINUTES); |
|
|
|
|
|
// 获取当前时间
|
|
|
|
|
|
Instant currentTime = Instant.now(); |
|
|
|
|
|
|
|
|
|
|
|
// 遍历交通路段数据列表
|
|
|
|
|
|
dcTrafficSectionDataList.removeIf(data -> { |
|
|
|
|
|
// 获取数据的统计时间
|
|
|
|
|
|
Instant dataStatisticalTime = data.getStatisticalDate().toInstant(); |
|
|
|
|
|
|
|
|
|
|
|
// 如果数据的统计时间早于20分钟前,则移除该数据,并记录日志
|
|
|
|
|
|
if (dataStatisticalTime.isBefore(twentyMinutesAgo)) { |
|
|
|
|
|
logger.error("过滤掉时间错误的交通路段数据,已移除:" + data); |
|
|
|
|
|
return true; // 移除该元素
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 更新数据的统计时间为当前时间
|
|
|
|
|
|
data.setStatisticalDate(Date.from(currentTime)); // 直接使用Instant对象
|
|
|
|
|
|
return false; // 保留该元素
|
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 根据方向获取交通数据 |
|
|
* 根据方向获取交通数据 |
|
|
* |
|
|
* |
|
|