tdengine event子表修改TAG(device_code,device_name)
This commit is contained in:
parent
8a345f178e
commit
41763b2f7b
@ -806,4 +806,53 @@ public class TDEngineService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Boolean checkTableExist(String tableName){
|
||||
StringBuffer sb = new StringBuffer(256);
|
||||
sb.append("select count(*) from information_schema.ins_tables where table_name = '");
|
||||
sb.append(tableName);
|
||||
sb.append("'");
|
||||
Integer result = null;
|
||||
try (Connection conn = hikariDataSource.getConnection();
|
||||
Statement smt = conn.createStatement();
|
||||
ResultSet rs = smt.executeQuery(sb.toString())) {
|
||||
if (rs.next()) {
|
||||
result = rs.getInt("count");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("检查td表是否存在失败", e);
|
||||
}
|
||||
return result != null && result == 1;
|
||||
}
|
||||
|
||||
public void updateTagDeviceName(String tableName,String deviceName){
|
||||
|
||||
StringBuffer sb = new StringBuffer(256);
|
||||
sb.append("ALTER table ");
|
||||
sb.append(tableName);
|
||||
sb.append(" SET TAG device_name = '").append(deviceName).append("'");
|
||||
|
||||
try (Connection conn = hikariDataSource.getConnection();
|
||||
Statement pstmt = conn.createStatement()) {
|
||||
pstmt.executeUpdate(sb.toString());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("修改Tag值失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTagDeviceCode(String tableName,String deviceCode){
|
||||
StringBuffer sb = new StringBuffer(256);
|
||||
sb.append("ALTER table ");
|
||||
sb.append(tableName);
|
||||
sb.append(" SET TAG device_code = '").append(deviceCode).append("'");
|
||||
|
||||
try (Connection conn = hikariDataSource.getConnection();
|
||||
Statement pstmt = conn.createStatement()) {
|
||||
pstmt.executeUpdate(sb.toString());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("修改Tag值失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import com.das.common.utils.SequenceUtils;
|
||||
import com.das.modules.auth.domain.vo.SysUserVo;
|
||||
import com.das.modules.auth.mapper.SysOrgMapper;
|
||||
import com.das.modules.cache.service.CacheService;
|
||||
import com.das.modules.data.service.TDEngineService;
|
||||
import com.das.modules.data.service.impl.DataServiceImpl;
|
||||
import com.das.modules.equipment.domain.dto.SysEquipmentDto;
|
||||
import com.das.modules.equipment.domain.excel.SysEquipmentExcel;
|
||||
@ -66,6 +67,9 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
|
||||
@Autowired
|
||||
private CacheService cacheService;
|
||||
|
||||
@Autowired
|
||||
private TDEngineService tdEngineService;
|
||||
|
||||
@Override
|
||||
public SysEquipmentVo creatSysEquipment(SysEquipmentDto sysEquipmentDto) {
|
||||
//去除空格
|
||||
@ -119,6 +123,10 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
|
||||
}
|
||||
//更新设备缓存
|
||||
cacheService.getEquipmentCache().refreshDeviceCache(sysEquipment.getId());
|
||||
if (tdEngineService.checkTableExist("e_"+sysEquipment.getId())){
|
||||
tdEngineService.updateTagDeviceCode("e_"+sysEquipment.getId(),sysEquipment.getCode());
|
||||
tdEngineService.updateTagDeviceName("e_"+sysEquipment.getId(),sysEquipment.getName());
|
||||
}
|
||||
SysEquipmentVo sysEquipmentVo = new SysEquipmentVo();
|
||||
BeanCopyUtils.copy(sysEquipment, sysEquipmentVo);
|
||||
return sysEquipmentVo;
|
||||
@ -319,6 +327,12 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
|
||||
}
|
||||
//更新设备缓存
|
||||
cacheService.getEquipmentCache().refreshDeviceCache(item.getId());
|
||||
|
||||
//更新td表TAG
|
||||
if (tdEngineService.checkTableExist("e_"+item.getId())){
|
||||
tdEngineService.updateTagDeviceCode("e_"+item.getId(),item.getCode());
|
||||
tdEngineService.updateTagDeviceName("e_"+item.getId(),item.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(delSysEquipmentList)) {
|
||||
|
Loading…
Reference in New Issue
Block a user