Merge remote-tracking branch 'origin/main'

This commit is contained in:
谷成伟 2024-11-28 17:00:49 +08:00
commit 7e4ee1323f
6 changed files with 94 additions and 2 deletions

View File

@ -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);
}
}
}

View File

@ -25,6 +25,7 @@ import org.springframework.util.StopWatch;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
@ -71,6 +72,10 @@ public class DataServiceImpl implements DataService {
public ConcurrentHashMap<String, Map<String, Integer>> eventLevelMap = new ConcurrentHashMap<>(10000);
public ConcurrentHashMap<String, Map<String, String>> stateDescMap = new ConcurrentHashMap<>(10000);
/**
* 读取实时数据快照
* @param paramList 设备id及设备属性列表
@ -234,6 +239,7 @@ public class DataServiceImpl implements DataService {
Map<String, String> calculateFieldList = allIotModelField.stream().filter(field -> field.getAttributeType() == 199).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getDataType, (value1, value2) -> value1));
Map<String, String> fieldCodeNameList = allIotModelField.stream().collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getAttributeName, (value1, value2) -> value1));
Map<String, Integer> eventLevelList = allIotModelField.stream().collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getLevel, (value1, value2) -> value1));
Map<String, String> stateDescList = allIotModelField.stream().filter(field -> field.getStateDesc() != null).collect(Collectors.toMap(SysIotModelField::getAttributeCode, SysIotModelField::getStateDesc, (value1, value2) -> value1));
Map<String, Object> map = new HashMap<>();
for (String field : HighModelFieldList.keySet()) {
map.put(field, HighModelFieldList.get(field));
@ -247,6 +253,8 @@ public class DataServiceImpl implements DataService {
eventLevelMap.put(item.getIotModelCode(),eventLevelList);
fieldCodeNameMap.put(item.getIotModelCode(),fieldCodeNameList);
calculateIotFieldMap.put(item.getIotModelCode(), calculateFieldList);
stateDescMap.put(item.getIotModelCode(),stateDescList);
}
tdEngineService.initIotModel(allIotModel, highIotFieldMap, lowIotFieldMap, calculateIotFieldMap);
}

View File

@ -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)) {

View File

@ -635,6 +635,16 @@ public class SysIotModelServiceImpl implements SysIotModelService {
}
}
if (sysIotModelField.getStateDesc() != null){
Map<String, String> stateDescMap = dataService.stateDescMap.get(modelCode);
if (stateDescMap == null) {
Map<String, String> calMap = new HashMap<>();
calMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getStateDesc());
dataService.stateDescMap.put(modelCode, calMap);
} else {
stateDescMap.put(sysIotModelField.getAttributeCode(), sysIotModelField.getStateDesc());
}
}
if (sysIotModelField.getAttributeType() == 199) {
Map<String, String> map = dataService.calculateIotFieldMap.get(modelCode);
if (map == null) {
@ -686,6 +696,9 @@ public class SysIotModelServiceImpl implements SysIotModelService {
if (sysIotModelField.getLevel() != null){
dataService.eventLevelMap.remove(sysIotModelField.getAttributeCode());
}
if (sysIotModelField.getStateDesc() != null){
dataService.stateDescMap.remove(sysIotModelField.getAttributeCode());
}
if (sysIotModelField.getAttributeType() == 199) {
Map<String, String> map = dataService.calculateIotFieldMap.get(modelCode);
map.remove(sysIotModelField.getAttributeCode());

View File

@ -369,12 +369,20 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
deviceEventInfo.setEventType(item.getEventType());
deviceEventInfo.setConfirmed(0);
if (!StringUtils.isEmpty(eventType) && eventType.equals("遥信变位")) {
String stateDesc = dataService.stateDescMap.get(model).get(item.getAttrCode());
if (item.getAttrValue().equals(0)) {
deviceEventInfo.setEventText(item.getAttrCode()+fieldName + " 复归");
if (StringUtils.isNotEmpty(stateDesc)){
List<String> descList = Arrays.stream(stateDesc.split("\\|")).toList();
deviceEventInfo.setEventText(item.getAttrCode()+fieldName + descList.get(0));
}
deviceEventInfo.setEventLevel(0);
} else {
deviceEventInfo.setEventText(item.getAttrCode()+fieldName + " 动作");
if (StringUtils.isNotEmpty(stateDesc)){
List<String> descList = Arrays.stream(stateDesc.split("\\|")).toList();
deviceEventInfo.setEventText(item.getAttrCode()+fieldName + descList.get(1));
}
Integer level = dataService.eventLevelMap.get(model).get(item.getAttrCode());
log.info("level:{}",level);
log.info("fieldname{}",fieldName);

View File

@ -78,7 +78,7 @@
where se.id = #{id}
</select>
<select id="getAllIotModelField" resultType="com.das.modules.equipment.entity.SysIotModelField">
select simf.attribute_name as attributeName, simf.attribute_code as attributeCode,simf.highspeed as highSpeed,simf.datatype as dataType,simf.attribute_type as attributeType,simf.level as level from sys_iot_model_field simf where simf.iot_model_id = #{id} order by simf.attribute_code
select simf.attribute_name as attributeName, simf.attribute_code as attributeCode,simf.highspeed as highSpeed,simf.datatype as dataType,simf.attribute_type as attributeType,simf.level as level,simf.stateDesc as stateDesc from sys_iot_model_field simf where simf.iot_model_id = #{id} order by simf.attribute_code
</select>