perf: 动态eqmid类型

main
huangfeng 1 year ago
parent 062b038478
commit 671670e906

@ -20,16 +20,21 @@ public class DbsqlService {
private JdbcTemplate jdbcTemplate;
public List<Integer> getDistinctEqmids(String tableName, String field) {
public List<Object> getDistinctEqmids(String tableName, String field) {
String sql = "SELECT DISTINCT(" + field + ") FROM " + tableName;
List<Integer> list = jdbcTemplate.queryForList(sql, Integer.class);
List<Object> list = jdbcTemplate.queryForList(sql, Object.class);
return list;
}
public List<Map<String, Object>> getData(Integer eqmid, Date lasttime, SyncTablesInfo table) {
public List<Map<String, Object>> getData(Object eqmid, Date lasttime, SyncTablesInfo table) {
String sqlSelect = "SELECT * FROM " + table.getId().getTableName();
String sqlWhere = " WHERE " + table.getDevidFieldName() + "=" + eqmid;
String sqlWhere = " WHERE " + table.getDevidFieldName();
if (eqmid instanceof String) {
sqlWhere = sqlWhere + "='" + eqmid + "'";
} else {
sqlWhere = sqlWhere + "=" + eqmid;
}
if (lasttime != null) {
sqlWhere = sqlWhere + " AND " + table.getFieldName() + ">'" + DateUtil.format(lasttime) + "'";
}

@ -16,7 +16,13 @@ public class I2relationService {
@Resource
I2relationRepository repository;
public List<I2relation> getList(Integer eqmid) {
return repository.findAllByEqmid(eqmid);
public List<I2relation> getList(Object eqmid) {
Integer id;
if (eqmid instanceof String) {
id = Integer.parseInt((String) eqmid);
} else {
id = (Integer) eqmid;
}
return repository.findAllByEqmid(id);
}
}

@ -49,11 +49,11 @@ public class MqttService {
private void processOneTable(SyncTablesInfo table) throws Exception {
List<SyncFieldsInfo> fieldList = fieldsInfoService.findAll(table.getId().getClientId(), table.getId().getTableName());
if (!CollectionUtils.isEmpty(fieldList)) {
List<Integer> eqmidList = dbsqlService.getDistinctEqmids(table.getId().getTableName(), table.getDevidFieldName());
List<Object> eqmidList = dbsqlService.getDistinctEqmids(table.getId().getTableName(), table.getDevidFieldName());
log.info("表{},共{}个设备", table.getId().getTableName(), eqmidList.size());
if (!CollectionUtils.isEmpty(eqmidList)) {
mqttUtil.connect();
for (Integer eqmid : eqmidList) {
for (Object eqmid : eqmidList) {
this.processOneEqmid(eqmid, table, fieldList);
}
mqttUtil.disconnect();
@ -64,7 +64,7 @@ public class MqttService {
}
// 处理单个设备
private void processOneEqmid(Integer eqmid, SyncTablesInfo table, List<SyncFieldsInfo> fieldList) {
private void processOneEqmid(Object eqmid, SyncTablesInfo table, List<SyncFieldsInfo> fieldList) {
List<I2relation> relationList = i2relationService.getList(eqmid);
@ -84,7 +84,7 @@ public class MqttService {
}
// 查询并上传单个设备的数据
private int uploadOneBlock(Integer eqmid, SyncRecords record,
private int uploadOneBlock(Object eqmid, SyncRecords record,
SyncTablesInfo table, List<SyncFieldsInfo> fieldList, List<I2relation> relationList) throws Exception {
if (record == null) {
@ -122,7 +122,8 @@ public class MqttService {
log.debug("表{}设备{}推送成功{}条数据,最后时间{}", table.getId().getTableName(), eqmid, count, DateUtil.format(date));
if (count >= 1000) {
count += uploadOneBlock(eqmid, record, table, fieldList, relationList);
count += uploadOneBlock(eqmid, record,
table, fieldList, relationList);
}
return count;
}

Loading…
Cancel
Save