|
|
|
|
@ -472,7 +472,7 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
|
|
|
|
|
|
|
|
|
|
List<Long> deviceIds = parseIds(pageReqVO.getIds());
|
|
|
|
|
List<Map<String, Object>> hourlyRows = tDengineService.queryDeviceHourTrend(deviceIds, pageReqVO.getStartTime(), pageReqVO.getEndTime());
|
|
|
|
|
respVO.setHourlyStatus(buildHourlyStatus(hourlyRows));
|
|
|
|
|
respVO.setHourlyStatus(buildHourlyStatus(hourlyRows, pageReqVO.getStartTime(), pageReqVO.getEndTime()));
|
|
|
|
|
//设备运行轨迹
|
|
|
|
|
List<DeviceOperationOverviewRespVO.TimelineRowItem> timelineRows =
|
|
|
|
|
buildTimelineRows(records, deviceIds, pageReqVO.getStartTime(), pageReqVO.getEndTime());
|
|
|
|
|
@ -500,19 +500,13 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DeviceOperationOverviewRespVO.HourlyStatusItem> buildHourlyStatus(List<Map<String, Object>> hourlyRows) {
|
|
|
|
|
Map<String, HourBucket> bucketMap = new LinkedHashMap<>();
|
|
|
|
|
for (int i = 0; i < 24; i++) {
|
|
|
|
|
String hour = String.format("%02d:00", i);
|
|
|
|
|
bucketMap.put(hour, new HourBucket(hour));
|
|
|
|
|
}
|
|
|
|
|
private List<DeviceOperationOverviewRespVO.HourlyStatusItem> buildHourlyStatus(List<Map<String, Object>> hourlyRows,
|
|
|
|
|
String startTime,
|
|
|
|
|
String endTime) {
|
|
|
|
|
Map<String, HourBucket> bucketMap = buildLast24HourBuckets(startTime, endTime);
|
|
|
|
|
|
|
|
|
|
for (Map<String, Object> row : hourlyRows) {
|
|
|
|
|
Integer hourValue = getIntValue(row, "hourValue");
|
|
|
|
|
if (hourValue == null || hourValue < 0 || hourValue > 23) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String hour = String.format("%02d:00", hourValue);
|
|
|
|
|
String hour = resolveHourBucketKey(row);
|
|
|
|
|
HourBucket bucket = bucketMap.get(hour);
|
|
|
|
|
if (bucket == null) {
|
|
|
|
|
continue;
|
|
|
|
|
@ -535,6 +529,49 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, HourBucket> buildLast24HourBuckets(String startTime, String endTime) {
|
|
|
|
|
Map<String, HourBucket> bucketMap = new LinkedHashMap<>();
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
|
|
|
|
|
try {
|
|
|
|
|
LocalDateTime end = LocalDateTime.parse(endTime, formatter).withMinute(0).withSecond(0).withNano(0);
|
|
|
|
|
LocalDateTime firstBucketEnd = end.minusHours(23);
|
|
|
|
|
for (int i = 0; i < 24; i++) {
|
|
|
|
|
String hour = firstBucketEnd.plusHours(i).format(formatter);
|
|
|
|
|
bucketMap.put(hour, new HourBucket(hour));
|
|
|
|
|
}
|
|
|
|
|
return bucketMap;
|
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
|
for (int i = 0; i < 24; i++) {
|
|
|
|
|
String hour = String.format("%02d:00", i);
|
|
|
|
|
bucketMap.put(hour, new HourBucket(hour));
|
|
|
|
|
}
|
|
|
|
|
return bucketMap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String resolveHourBucketKey(Map<String, Object> row) {
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
|
|
|
|
|
String hourTime = getStringValue(row, "hourTime");
|
|
|
|
|
if (StringUtils.isNotBlank(hourTime)) {
|
|
|
|
|
try {
|
|
|
|
|
return LocalDateTime.parse(hourTime, formatter)
|
|
|
|
|
.plusHours(1)
|
|
|
|
|
.withMinute(0)
|
|
|
|
|
.withSecond(0)
|
|
|
|
|
.withNano(0)
|
|
|
|
|
.format(formatter);
|
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
|
// Fallback to hourValue for old TDengine format compatibility.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Integer hourValue = getIntValue(row, "hourValue");
|
|
|
|
|
if (hourValue == null || hourValue < 0 || hourValue > 23) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return String.format("%02d:00", hourValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double toPercent(double numerator, double denominator) {
|
|
|
|
|
return denominator > 0 ? round2(numerator / denominator * 100) : 0D;
|
|
|
|
|
}
|
|
|
|
|
@ -738,6 +775,14 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getStringValue(Map<String, Object> map, String key) {
|
|
|
|
|
Object value = map.get(key);
|
|
|
|
|
if (value == null) {
|
|
|
|
|
value = map.get(key.toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
return value == null ? null : String.valueOf(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class HourBucket {
|
|
|
|
|
private final String hour;
|
|
|
|
|
private double running;
|
|
|
|
|
|