diff --git a/src/main/java/com/xydl/service/DbsqlService.java b/src/main/java/com/xydl/service/DbsqlService.java index 46c1bdf..22997e5 100644 --- a/src/main/java/com/xydl/service/DbsqlService.java +++ b/src/main/java/com/xydl/service/DbsqlService.java @@ -20,16 +20,21 @@ public class DbsqlService { private JdbcTemplate jdbcTemplate; - public List getDistinctEqmids(String tableName, String field) { + public List getDistinctEqmids(String tableName, String field) { String sql = "SELECT DISTINCT(" + field + ") FROM " + tableName; - List list = jdbcTemplate.queryForList(sql, Integer.class); + List list = jdbcTemplate.queryForList(sql, Object.class); return list; } - public List> getData(Integer eqmid, Date lasttime, SyncTablesInfo table) { + public List> 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) + "'"; } diff --git a/src/main/java/com/xydl/service/I2relationService.java b/src/main/java/com/xydl/service/I2relationService.java index a525186..bf24e02 100644 --- a/src/main/java/com/xydl/service/I2relationService.java +++ b/src/main/java/com/xydl/service/I2relationService.java @@ -16,7 +16,13 @@ public class I2relationService { @Resource I2relationRepository repository; - public List getList(Integer eqmid) { - return repository.findAllByEqmid(eqmid); + public List getList(Object eqmid) { + Integer id; + if (eqmid instanceof String) { + id = Integer.parseInt((String) eqmid); + } else { + id = (Integer) eqmid; + } + return repository.findAllByEqmid(id); } } diff --git a/src/main/java/com/xydl/service/MqttService.java b/src/main/java/com/xydl/service/MqttService.java index f3ad6aa..9f5e168 100644 --- a/src/main/java/com/xydl/service/MqttService.java +++ b/src/main/java/com/xydl/service/MqttService.java @@ -49,11 +49,11 @@ public class MqttService { private void processOneTable(SyncTablesInfo table) throws Exception { List fieldList = fieldsInfoService.findAll(table.getId().getClientId(), table.getId().getTableName()); if (!CollectionUtils.isEmpty(fieldList)) { - List eqmidList = dbsqlService.getDistinctEqmids(table.getId().getTableName(), table.getDevidFieldName()); + List 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 fieldList) { + private void processOneEqmid(Object eqmid, SyncTablesInfo table, List fieldList) { List 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 fieldList, List 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; }