|
|
|
@ -1,15 +1,18 @@ |
|
|
|
package com.techsor.datacenter.sender.dao; |
|
|
|
|
|
|
|
import com.techsor.datacenter.sender.disruptor.AlertEvent; |
|
|
|
import com.techsor.datacenter.sender.entitiy.AlertHistoryDTO; |
|
|
|
import com.techsor.datacenter.sender.entitiy.DynamodbEntity; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import java.sql.PreparedStatement; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.jdbc.core.RowMapper; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
@ -59,6 +62,52 @@ public class DashboardAlertDao { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void batchUpsertRawData(List<AlertEvent> list) { |
|
|
|
jdbcTemplate.batchUpdate( |
|
|
|
"INSERT INTO device_rawdata_realtime (" + |
|
|
|
"device_id, building_id, status, receive_ts, alert_title, alert_content, " + |
|
|
|
"alert_cancel_title, alert_cancel_content, raw_data, upload_year, upload_month, upload_day) " + |
|
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) " + |
|
|
|
"ON DUPLICATE KEY UPDATE " + |
|
|
|
"building_id = VALUES(building_id), " + |
|
|
|
"status = VALUES(status), " + |
|
|
|
"receive_ts = VALUES(receive_ts), " + |
|
|
|
"alert_title = VALUES(alert_title), " + |
|
|
|
"alert_content = VALUES(alert_content), " + |
|
|
|
"alert_cancel_title = VALUES(alert_cancel_title), " + |
|
|
|
"alert_cancel_content = VALUES(alert_cancel_content), " + |
|
|
|
"raw_data = VALUES(raw_data), " + |
|
|
|
"upload_year = VALUES(upload_year), " + |
|
|
|
"upload_month = VALUES(upload_month), " + |
|
|
|
"upload_day = VALUES(upload_day)", |
|
|
|
new BatchPreparedStatementSetter() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void setValues(PreparedStatement ps, int i) throws SQLException { |
|
|
|
AlertEvent e = list.get(i); |
|
|
|
|
|
|
|
ps.setString(1, e.getEntity().getDeviceId()); |
|
|
|
ps.setLong(2, e.getEntity().getDbBuildingId()); |
|
|
|
ps.setString(3, e.getEntity().getStatus()); |
|
|
|
ps.setLong(4, e.getEntity().getReceive_ts()); |
|
|
|
ps.setString(5, e.getEntity().getAlertTitle()); |
|
|
|
ps.setString(6, e.getEntity().getAlertContent()); |
|
|
|
ps.setString(7, e.getEntity().getAlertCancelTitle()); |
|
|
|
ps.setString(8, e.getEntity().getAlertCancelContent()); |
|
|
|
ps.setString(9, e.getEntity().getRawData()); |
|
|
|
ps.setInt(10, Integer.parseInt(e.getEntity().getYearKey())); |
|
|
|
ps.setInt(11, Integer.parseInt(e.getEntity().getMonthKey())); |
|
|
|
ps.setInt(12, Integer.parseInt(e.getEntity().getDayKey())); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int getBatchSize() { |
|
|
|
return list.size(); |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public void insertAlertHistory(DynamodbEntity entity) { |
|
|
|
String sql = "INSERT INTO alert_history (" + |
|
|
|
"device_id, receive_ts, retain_alert" + |
|
|
|
@ -112,5 +161,4 @@ public class DashboardAlertDao { |
|
|
|
String updateHandleHistorySql = "UPDATE alert_handle_history SET status = 4, alert_status = 1 WHERE alert_history_id = ? and status != 3"; |
|
|
|
jdbcTemplate.update(updateHandleHistorySql, alertHistoryId); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|