fix:报警统计-趋势柱状图为0问题

master
HuangHuiKang 1 month ago
parent 4671bdbcab
commit c84dc559f7

@ -6,5 +6,5 @@ import lombok.Data;
@Data
public class WarningTrendPointRespDTO {
private String timeKey;
private Long count;
private Long cnt;
}

@ -287,8 +287,9 @@ public class DeviceWarinningRecordServiceImpl implements DeviceWarinningRecordSe
List<WarningTrendPointRespDTO> rows = iotDeviceMapper.selectWarningTrendByHour(start, end);
for (WarningTrendPointRespDTO row : rows) {
if (bucket.containsKey(row.getTimeKey())) {
bucket.put(row.getTimeKey(), row.getCount() == null ? 0L : row.getCount());
String key = normalizeHourKey(row.getTimeKey()); // 按小时分支
if (bucket.containsKey(key)) {
bucket.put(key, row.getCnt() == null ? 0L : row.getCnt());
}
}
} else {
@ -303,8 +304,9 @@ public class DeviceWarinningRecordServiceImpl implements DeviceWarinningRecordSe
List<WarningTrendPointRespDTO> rows = iotDeviceMapper.selectWarningTrendByDay(start, end);
for (WarningTrendPointRespDTO row : rows) {
if (bucket.containsKey(row.getTimeKey())) {
bucket.put(row.getTimeKey(), row.getCount() == null ? 0L : row.getCount());
String key = normalizeDayKey(row.getTimeKey()); // 按天分支
if (bucket.containsKey(key)) {
bucket.put(key, row.getCnt() == null ? 0L : row.getCnt());
}
}
}
@ -315,6 +317,23 @@ public class DeviceWarinningRecordServiceImpl implements DeviceWarinningRecordSe
return resp;
}
private String normalizeHourKey(String raw) {
if (raw == null) return null;
String s = raw.trim().replace('T', ' ');
if (s.length() >= 16) { // yyyy-MM-dd HH:mm...
return s.substring(0, 13) + ":00";
}
return s;
}
private String normalizeDayKey(String raw) {
if (raw == null) return null;
String s = raw.trim().replace('T', ' ');
if (s.length() >= 10) { // yyyy-MM-dd...
return s.substring(0, 10);
}
return s;
}
}
Loading…
Cancel
Save