|
|
|
@ -74,12 +74,25 @@ public class DashboardAlertDao { |
|
|
|
.filter(e -> e.getEntity() != null && e.getEntity().getCompanyId() != null) |
|
|
|
.collect(Collectors.groupingBy(e -> e.getEntity().getCompanyId())); |
|
|
|
|
|
|
|
grouped.forEach((companyId, subList) -> { |
|
|
|
grouped.forEach((companyId, companyList) -> { |
|
|
|
long topCompanyId = companyInfoDao.getTopCompanyId(String.valueOf(companyId)); |
|
|
|
String dsKey = "dataSourceForCompany_" + topCompanyId; |
|
|
|
try { |
|
|
|
DataSourceContextHolder.setCurrentDataSourceKey(dsKey); |
|
|
|
|
|
|
|
// 再按 retainAlert 分组(关键)
|
|
|
|
Map<Integer, List<AlertEvent>> retainGroup = |
|
|
|
companyList.stream() |
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
e -> e.getEntity().getRetainAlert() |
|
|
|
)); |
|
|
|
|
|
|
|
// 每个 retainAlert 执行一次 batch upsert
|
|
|
|
retainGroup.forEach((retainAlert, subList) -> { |
|
|
|
if (subList.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 批量执行 upsert
|
|
|
|
StringBuilder sql = new StringBuilder( |
|
|
|
"INSERT INTO device_rawdata_realtime (" + |
|
|
|
@ -109,9 +122,8 @@ public class DashboardAlertDao { |
|
|
|
params.add(Integer.parseInt(entity.getYearKey())); |
|
|
|
params.add(Integer.parseInt(entity.getMonthKey())); |
|
|
|
params.add(Integer.parseInt(entity.getDayKey())); |
|
|
|
//给下面dashboard_status = IF(? = 1 里的?用
|
|
|
|
params.add(entity.getRetainAlert()); |
|
|
|
} |
|
|
|
// ON DUPLICATE KEY UPDATE(retainAlert 只绑定一次)
|
|
|
|
sql.append(" ON DUPLICATE KEY UPDATE ") |
|
|
|
.append("building_id = VALUES(building_id), ") |
|
|
|
.append("status = VALUES(status), ") |
|
|
|
@ -125,7 +137,10 @@ public class DashboardAlertDao { |
|
|
|
.append("upload_month = VALUES(upload_month), ") |
|
|
|
.append("upload_day = VALUES(upload_day), ") |
|
|
|
.append("dashboard_status = IF(? = 1 AND VALUES(status) = 'alert_cancel' AND dashboard_status = 'alert', dashboard_status, VALUES(status))"); |
|
|
|
//retainAlert 分组了,只加一次
|
|
|
|
params.add(retainAlert); |
|
|
|
jdbcTemplate.update(sql.toString(), params.toArray()); |
|
|
|
}); |
|
|
|
|
|
|
|
} finally { |
|
|
|
DataSourceContextHolder.clearCurrentDataSourceKey(); |
|
|
|
|