|
|
@ -151,7 +151,44 @@ public class DashboardAlertDao { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 检查是否需要合并告警。如果最新告警记录的 merge_alarm_flag = 1, |
|
|
|
|
|
* 则插入 alert_handle_history 并返回 true。 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean tryMergeAlert(String deviceId) { |
|
|
|
|
|
String queryLatestSql = "SELECT id, merge_alarm_flag FROM alert_history WHERE device_id = ? ORDER BY id DESC LIMIT 1"; |
|
|
|
|
|
List<AlertHistoryDTO> latestList = jdbcTemplate.query(queryLatestSql, |
|
|
|
|
|
(rs, rowNum) -> { |
|
|
|
|
|
AlertHistoryDTO dto = new AlertHistoryDTO(); |
|
|
|
|
|
dto.setId(rs.getLong("id")); |
|
|
|
|
|
dto.setMergeAlarmFlag(rs.getInt("merge_alarm_flag")); |
|
|
|
|
|
return dto; |
|
|
|
|
|
}, |
|
|
|
|
|
deviceId |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!latestList.isEmpty() && latestList.get(0).getMergeAlarmFlag() == 1) { |
|
|
|
|
|
AlertHistoryDTO latest = latestList.get(0); |
|
|
|
|
|
String insertHandleSql = "INSERT INTO alert_handle_history (" + |
|
|
|
|
|
"alert_history_id, device_id, alert_status, handle_at, detail_title, detail_content" + |
|
|
|
|
|
") VALUES (?, ?, 0, ?, ?, ?)"; |
|
|
|
|
|
jdbcTemplate.update(insertHandleSql, |
|
|
|
|
|
latest.getId(), |
|
|
|
|
|
deviceId, |
|
|
|
|
|
System.currentTimeMillis(), |
|
|
|
|
|
"重複アラーム", |
|
|
|
|
|
"重複アラーム" |
|
|
|
|
|
); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public void insertAlertHistory(DynamodbEntity entity) { |
|
|
public void insertAlertHistory(DynamodbEntity entity) { |
|
|
|
|
|
if (tryMergeAlert(entity.getDeviceId())) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String sql = "INSERT INTO alert_history (" + |
|
|
String sql = "INSERT INTO alert_history (" + |
|
|
"device_id, receive_ts, retain_alert, block_flag " + |
|
|
"device_id, receive_ts, retain_alert, block_flag " + |
|
|
") VALUES (?, ?, ?, ?)"; |
|
|
") VALUES (?, ?, ?, ?)"; |
|
|
@ -166,6 +203,10 @@ public class DashboardAlertDao { |
|
|
|
|
|
|
|
|
public Long insertAlertHistory(DynamodbEntity entity, int sourceType) { |
|
|
public Long insertAlertHistory(DynamodbEntity entity, int sourceType) { |
|
|
|
|
|
|
|
|
|
|
|
if (tryMergeAlert(entity.getDeviceId())) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String sql = "INSERT INTO alert_history (" + |
|
|
String sql = "INSERT INTO alert_history (" + |
|
|
"device_id, receive_ts, source_type, block_flag " + |
|
|
"device_id, receive_ts, source_type, block_flag " + |
|
|
") VALUES (?, ?, ?, ?)"; |
|
|
") VALUES (?, ?, ?, ?)"; |
|
|
|