修复数据中心页面排序比较器违反契约的问题:处理null值情况

This commit is contained in:
Your Name 2026-01-23 10:38:49 +08:00
parent e2feece96b
commit 3fcc41855a

View File

@ -1008,8 +1008,21 @@ public class AnalyticsService {
BigDecimal netB = b.getNetScore() != null ? b.getNetScore() : BigDecimal.ZERO;
return netB.compareTo(netA);
});
// 按当前负载排序
workloadStats.sort((a, b) -> b.getCurrentLoad().compareTo(a.getCurrentLoad()));
// 按当前负载排序(null 值排在最后)
workloadStats.sort((a, b) -> {
Integer loadA = a.getCurrentLoad();
Integer loadB = b.getCurrentLoad();
if (loadA == null && loadB == null) {
return 0;
}
if (loadA == null) {
return 1; // a 排在后面
}
if (loadB == null) {
return -1; // b 排在后面
}
return loadB.compareTo(loadA); // 降序排序
});
// 构建汇总数据
DesignerPerformanceVO.Summary summary = DesignerPerformanceVO.Summary.builder()
@ -1302,9 +1315,28 @@ public class AnalyticsService {
// 按预警级别排序(紧急在前)
warnings.sort((a, b) -> {
int levelCompare = "urgent".equals(a.getWarningLevel()) ? -1 : ("urgent".equals(b.getWarningLevel()) ? 1 : 0);
if (levelCompare != 0) return levelCompare;
return b.getHoursInfo().compareTo(a.getHoursInfo());
// 先按预警级别排序:urgent 在前
boolean aIsUrgent = "urgent".equals(a.getWarningLevel());
boolean bIsUrgent = "urgent".equals(b.getWarningLevel());
if (aIsUrgent && !bIsUrgent) {
return -1; // a 排在前面
}
if (!aIsUrgent && bIsUrgent) {
return 1; // b 排在前面
}
// 如果级别相同,按 hoursInfo 降序排序(null 值排在最后)
Double hoursA = a.getHoursInfo();
Double hoursB = b.getHoursInfo();
if (hoursA == null && hoursB == null) {
return 0;
}
if (hoursA == null) {
return 1; // a 排在后面
}
if (hoursB == null) {
return -1; // b 排在后面
}
return Double.compare(hoursB, hoursA); // 降序排序
});
return warnings;