fix:修改物理设备新增问题

hhk
HuangHuiKang 1 month ago
parent 340ae2f6f3
commit 02203d4527

@ -129,7 +129,7 @@ public class DeviceServiceImpl implements DeviceService {
@Override
@Transactional(rollbackFor = Exception.class)
// @Transactional(rollbackFor = Exception.class)
public DeviceDO createDevice(DeviceSaveReqVO createReqVO) {
// if(StringUtils.isNotBlank(createReqVO.getReadTopic())){
// DeviceDO temp = deviceMapper.selectByTopic(createReqVO.getReadTopic());
@ -184,7 +184,7 @@ public class DeviceServiceImpl implements DeviceService {
//新增规则点位
addNewRulePoints(createReqVO.getDeviceModelId(),device.getId());
tdengineService.createTdengineTable(device.getId(),contactModelList);
return device;
}

@ -742,13 +742,26 @@ public class TDengineService {
return;
}
// 1. 表名
// 1. 数据库名
String dbName = "besure_server";
// 2. 表名
String tableName = "d_" + deviceId;
// 2. 构建列SQLTDengine必须有 ts
// 3. 确保数据库存在
try {
String createDbSql = "CREATE DATABASE IF NOT EXISTS " + dbName;
jdbcTemplate.execute(createDbSql);
log.info("TDengine 数据库确保存在: {}", dbName);
} catch (Exception e) {
log.error("TDengine 数据库创建失败: {}", dbName, e);
throw exception(TABLE_CREATION_FAILED);
}
// 4. 构建列SQLTDengine必须有 ts
StringBuilder columnsSql = new StringBuilder("ts TIMESTAMP");
// 3. 遍历 contactModelList如果为空则不执行循环表只含 ts
// 5. 遍历 contactModelList 构建列
if (contactModelList != null && !contactModelList.isEmpty()) {
for (DeviceContactModelDO contact : contactModelList) {
String attributeCode = contact.getAttributeCode();
@ -769,17 +782,16 @@ public class TDengineService {
}
}
// 4. 构建完整 SQL
String createSql = "CREATE TABLE IF NOT EXISTS besure_server." + tableName + " ("
+ columnsSql.toString()
+ ")";
// 6. 构建完整 SQL
String createTableSql = "CREATE TABLE IF NOT EXISTS " + dbName + "." + tableName + " ("
+ columnsSql.toString() + ")";
// 5. 使用 JdbcTemplate 执行 SQL
// 7. 执行创建表
try {
jdbcTemplate.execute(createSql);
log.info("TDengine 表创建成功: {}", tableName);
jdbcTemplate.execute(createTableSql);
log.info("TDengine 表创建成功: {}.{}", dbName, tableName);
} catch (Exception e) {
log.error("TDengine 表创建失败: {}", tableName, e);
log.error("TDengine 表创建失败: {}.{}", dbName, tableName, e);
throw exception(TABLE_CREATION_FAILED);
}
}

Loading…
Cancel
Save