|
|
@@ -468,6 +468,9 @@ public class MonitoringServiceImpl implements MonitoringService {
|
|
|
boolean hasAny = false;
|
|
|
LocalDateTime latestTime = null;
|
|
|
for (Map<String, Object> m : agg) {
|
|
|
+ if (m == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
String day = String.valueOf(m.get("day"));
|
|
|
Double a = toBig(m.get("avg_val"));
|
|
|
Double pk = toBig(m.get("max_val"));
|
|
|
@@ -547,7 +550,7 @@ public class MonitoringServiceImpl implements MonitoringService {
|
|
|
if (conditions.isEmpty()) {
|
|
|
return 0L;
|
|
|
}
|
|
|
- String caseSql = "SUM(CASE WHEN " + String.join(" OR ", conditions) + " THEN 1 ELSE 0 END) AS cnt";
|
|
|
+ String caseSql = "COALESCE(SUM(CASE WHEN " + String.join(" OR ", conditions) + " THEN 1 ELSE 0 END), 0) AS cnt";
|
|
|
List<Map<String, Object>> result;
|
|
|
if ("WARN-INSTANT-FLOW-SUPPLY".equals(warningCode) || "WARN-PRESSURE".equals(warningCode)) {
|
|
|
result = telemetryDataMapper.selectMaps(new QueryWrapper<TelemetryData>().select(caseSql)
|
|
|
@@ -559,7 +562,7 @@ public class MonitoringServiceImpl implements MonitoringService {
|
|
|
result = noiseInfoMapper.selectMaps(new QueryWrapper<NoiseInfo>().select(caseSql)
|
|
|
.ge(start != null, "create_time", start).le(endTime != null, "create_time", endTime));
|
|
|
}
|
|
|
- if (result.isEmpty()) {
|
|
|
+ if (result == null || result.isEmpty() || result.get(0) == null) {
|
|
|
return 0L;
|
|
|
}
|
|
|
Object value = result.get(0).get("cnt");
|
|
|
@@ -764,7 +767,7 @@ public class MonitoringServiceImpl implements MonitoringService {
|
|
|
*/
|
|
|
private <T> LocalDateTime latestCreateTime(BaseMapper<T> mapper, Class<T> clazz) {
|
|
|
List<Map<String, Object>> rows = mapper.selectMaps(new QueryWrapper<T>().select("MAX(create_time) AS mx"));
|
|
|
- if (rows != null && !rows.isEmpty()) {
|
|
|
+ if (rows != null && !rows.isEmpty() && rows.get(0) != null) {
|
|
|
return toLdt(rows.get(0).get("mx"));
|
|
|
}
|
|
|
return null;
|
|
|
@@ -1129,6 +1132,15 @@ public class MonitoringServiceImpl implements MonitoringService {
|
|
|
g.groupBy(deviceCol);
|
|
|
List<Map<String, Object>> groups = mapper.selectMaps(g);
|
|
|
|
|
|
+ long safePageNum = Math.max(pageNum, 1);
|
|
|
+ long safePageSize = Math.max(pageSize, 1);
|
|
|
+ Page<T> result = new Page<>(safePageNum, safePageSize, 0);
|
|
|
+ if (CollUtil.isEmpty(groups)) {
|
|
|
+ result.setRecords(new ArrayList<>());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ groups = new ArrayList<>(groups);
|
|
|
+ groups.removeIf(Objects::isNull);
|
|
|
groups.sort((a, b) -> {
|
|
|
LocalDateTime ta = toLdt(a.get("latest"));
|
|
|
LocalDateTime tb = toLdt(b.get("latest"));
|
|
|
@@ -1139,31 +1151,40 @@ public class MonitoringServiceImpl implements MonitoringService {
|
|
|
});
|
|
|
|
|
|
long total = groups.size();
|
|
|
- long safePageNum = Math.max(pageNum, 1);
|
|
|
- long safePageSize = Math.max(pageSize, 1);
|
|
|
+ result.setTotal(total);
|
|
|
long from = (safePageNum - 1) * safePageSize;
|
|
|
long to = Math.min(from + safePageSize, total);
|
|
|
List<Map<String, Object>> pagePairs = from < total
|
|
|
? new ArrayList<>(groups.subList((int) from, (int) to))
|
|
|
: new ArrayList<>();
|
|
|
|
|
|
- Page<T> result = new Page<>(safePageNum, safePageSize, total);
|
|
|
if (pagePairs.isEmpty()) {
|
|
|
result.setRecords(new ArrayList<>());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
QueryWrapper<T> q = new QueryWrapper<T>();
|
|
|
- for (int i = 0; i < pagePairs.size(); i++) {
|
|
|
- Map<String, Object> p = pagePairs.get(i);
|
|
|
- String dev = (String) p.get(deviceCol);
|
|
|
+ boolean firstCondition = true;
|
|
|
+ for (Map<String, Object> p : pagePairs) {
|
|
|
+ if (p == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Object devValue = p.get(deviceCol);
|
|
|
LocalDateTime lt = toLdt(p.get("latest"));
|
|
|
- if (i == 0) {
|
|
|
- q.eq(deviceCol, dev).eq("create_time", lt);
|
|
|
+ if (devValue == null || lt == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (firstCondition) {
|
|
|
+ q.eq(deviceCol, String.valueOf(devValue)).eq("create_time", lt);
|
|
|
+ firstCondition = false;
|
|
|
} else {
|
|
|
- q.or().eq(deviceCol, dev).eq("create_time", lt);
|
|
|
+ q.or().eq(deviceCol, String.valueOf(devValue)).eq("create_time", lt);
|
|
|
}
|
|
|
}
|
|
|
+ if (firstCondition) {
|
|
|
+ result.setRecords(new ArrayList<>());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
result.setRecords(mapper.selectList(q));
|
|
|
return result;
|
|
|
}
|