Browse Source

bug处理

jwy_category
review512jwy@163.com 1 month ago
parent
commit
58fe68a9ab
  1. 69
      src/main/java/com/techsor/datacenter/sender/dao/DashboardAlertDao.java
  2. 4
      src/main/java/com/techsor/datacenter/sender/dto/DeviceAlertInfo.java
  3. 4
      src/main/java/com/techsor/datacenter/sender/dto/DeviceInfoVO.java

69
src/main/java/com/techsor/datacenter/sender/dao/DashboardAlertDao.java

@ -1,5 +1,6 @@
package com.techsor.datacenter.sender.dao;
import com.techsor.datacenter.sender.config.DataSourceContextHolder;
import com.techsor.datacenter.sender.disruptor.AlertEvent;
import com.techsor.datacenter.sender.entitiy.AlertHistoryDTO;
import com.techsor.datacenter.sender.entitiy.DynamodbEntity;
@ -9,6 +10,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
@ -63,49 +66,61 @@ public class DashboardAlertDao {
}
public void batchUpsertRawData(List<AlertEvent> list) {
// 按 companyId 分组
Map<Long, List<AlertEvent>> grouped = list.stream()
.filter(e -> e.getEntity() != null && e.getEntity().getCompanyId() != null)
.collect(Collectors.groupingBy(e -> e.getEntity().getCompanyId()));
grouped.forEach((companyId, subList) -> {
String dsKey = "dataSourceForCompany_" + companyId;
try {
DataSourceContextHolder.setCurrentDataSourceKey(dsKey);
// 批量执行 upsert
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) " +
"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), " +
"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()));
DynamodbEntity entity = subList.get(i).getEntity();
ps.setString(1, entity.getDeviceId());
ps.setLong(2, entity.getDbBuildingId());
ps.setString(3, entity.getStatus());
ps.setLong(4, entity.getReceive_ts());
ps.setString(5, entity.getAlertTitle());
ps.setString(6, entity.getAlertContent());
ps.setString(7, entity.getAlertCancelTitle());
ps.setString(8, entity.getAlertCancelContent());
ps.setString(9, entity.getRawData());
ps.setInt(10, Integer.parseInt(entity.getYearKey()));
ps.setInt(11, Integer.parseInt(entity.getMonthKey()));
ps.setInt(12, Integer.parseInt(entity.getDayKey()));
}
@Override
public int getBatchSize() {
return list.size();
return subList.size();
}
}
);
} finally {
DataSourceContextHolder.clearCurrentDataSourceKey();
}
});
}
public void insertAlertHistory(DynamodbEntity entity) {

4
src/main/java/com/techsor/datacenter/sender/dto/DeviceAlertInfo.java

@ -3,8 +3,10 @@ package com.techsor.datacenter.sender.dto;
import lombok.Data;
import java.io.Serializable;
@Data
public class DeviceAlertInfo {
public class DeviceAlertInfo implements Serializable {
private Integer id;
private Long deviceConfigId;

4
src/main/java/com/techsor/datacenter/sender/dto/DeviceInfoVO.java

@ -2,12 +2,14 @@ package com.techsor.datacenter.sender.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author Mr.Jiang
* @time 2022年7月21日 下午8:50:31
*/
@Data
public class DeviceInfoVO{
public class DeviceInfoVO implements Serializable {
private String deviceId;

Loading…
Cancel
Save