perf: 动态eqmid类型

main
huangfeng 1 year ago
parent 062b038478
commit 671670e906

@ -20,16 +20,21 @@ public class DbsqlService {
private JdbcTemplate jdbcTemplate; 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; 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; 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 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) { if (lasttime != null) {
sqlWhere = sqlWhere + " AND " + table.getFieldName() + ">'" + DateUtil.format(lasttime) + "'"; sqlWhere = sqlWhere + " AND " + table.getFieldName() + ">'" + DateUtil.format(lasttime) + "'";
} }

@ -16,7 +16,13 @@ public class I2relationService {
@Resource @Resource
I2relationRepository repository; I2relationRepository repository;
public List<I2relation> getList(Integer eqmid) { public List<I2relation> getList(Object eqmid) {
return repository.findAllByEqmid(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 { private void processOneTable(SyncTablesInfo table) throws Exception {
List<SyncFieldsInfo> fieldList = fieldsInfoService.findAll(table.getId().getClientId(), table.getId().getTableName()); List<SyncFieldsInfo> fieldList = fieldsInfoService.findAll(table.getId().getClientId(), table.getId().getTableName());
if (!CollectionUtils.isEmpty(fieldList)) { 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()); log.info("表{},共{}个设备", table.getId().getTableName(), eqmidList.size());
if (!CollectionUtils.isEmpty(eqmidList)) { if (!CollectionUtils.isEmpty(eqmidList)) {
mqttUtil.connect(); mqttUtil.connect();
for (Integer eqmid : eqmidList) { for (Object eqmid : eqmidList) {
this.processOneEqmid(eqmid, table, fieldList); this.processOneEqmid(eqmid, table, fieldList);
} }
mqttUtil.disconnect(); 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); 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 { SyncTablesInfo table, List<SyncFieldsInfo> fieldList, List<I2relation> relationList) throws Exception {
if (record == null) { if (record == null) {
@ -122,7 +122,8 @@ public class MqttService {
log.debug("表{}设备{}推送成功{}条数据,最后时间{}", table.getId().getTableName(), eqmid, count, DateUtil.format(date)); log.debug("表{}设备{}推送成功{}条数据,最后时间{}", table.getId().getTableName(), eqmid, count, DateUtil.format(date));
if (count >= 1000) { if (count >= 1000) {
count += uploadOneBlock(eqmid, record, table, fieldList, relationList); count += uploadOneBlock(eqmid, record,
table, fieldList, relationList);
} }
return count; return count;
} }

Loading…
Cancel
Save