模拟量数据上报更新tdengine
This commit is contained in:
parent
5c3b2e95a5
commit
364500bcb8
@ -87,7 +87,6 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
private DataServiceImpl dataService;
|
||||
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
//初始化高性能队列
|
||||
@ -110,6 +109,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
disruptor.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public void pushMessage(TerminalMessage msg) {
|
||||
RingBuffer<TerminalMessage> ringBuffer = disruptor.getRingBuffer();
|
||||
if (ringBuffer == null) {
|
||||
@ -233,7 +233,13 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
JsonNode jsonNode = data.getData();
|
||||
String deviceId = jsonNode.get("deviceId").asText();
|
||||
JsonNode values = jsonNode.get("values");
|
||||
Long dataTime = jsonNode.get("dataTime").asLong();
|
||||
Map<String, Object> keyValueMap = new HashMap<>();
|
||||
DeviceInfoCache deviceInfoCacheById = cacheService.getEquipmentCache().getDeviceInfoCacheById(Long.valueOf(deviceId));
|
||||
Set<String> highKey = dataService.highIotFieldMap.get(deviceInfoCacheById.getDeviceCode()).keySet();
|
||||
Set<String> lowKey = dataService.lowIotFieldMap.get(deviceInfoCacheById.getDeviceCode()).keySet();
|
||||
Map<String, Object> highSpeedValueMap = new HashMap<>();
|
||||
Map<String, Object> lowSpeedValueMap = new HashMap<>();
|
||||
|
||||
//数据入redis
|
||||
Iterator<String> keysHigh = values.fieldNames();
|
||||
@ -241,8 +247,30 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
String fieldName = keysHigh.next();
|
||||
String key = String.format("RT:%s:%s", deviceId, fieldName.toLowerCase());
|
||||
keyValueMap.put(key, values.get(fieldName));
|
||||
if (highKey.contains(fieldName)){
|
||||
highSpeedValueMap.put(fieldName,values.get(fieldName));
|
||||
}
|
||||
if (lowKey.contains(fieldName)){
|
||||
lowSpeedValueMap.put(fieldName,values.get(fieldName));
|
||||
}
|
||||
}
|
||||
adminRedisTemplate.mSet(keyValueMap);
|
||||
if (jsonNode.get("isStore").asBoolean()) {
|
||||
//更新td
|
||||
if (!highSpeedValueMap.isEmpty()){
|
||||
List<RTData> highSpeedData = new ArrayList<>();
|
||||
RTData rtHighData = RTData.builder().dataTime(dataTime).deviceId(Long.valueOf(deviceId)).values(highSpeedValueMap).build();
|
||||
highSpeedData.add(rtHighData);
|
||||
tdEngineService.updateYCHighValues(highSpeedData,deviceInfoCacheById.getDeviceCode());
|
||||
}
|
||||
|
||||
if (!lowSpeedValueMap.isEmpty()){
|
||||
List<RTData> lowSpeedData = new ArrayList<>();
|
||||
RTData rtLowData = RTData.builder().dataTime(dataTime).deviceId(Long.valueOf(deviceId)).values(lowSpeedValueMap).build();
|
||||
lowSpeedData.add(rtLowData);
|
||||
tdEngineService.updateYCLowValues(lowSpeedData,deviceInfoCacheById.getDeviceCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -336,8 +364,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
} else {
|
||||
deviceEventInfo.setEventText(fieldName + " 动作");
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
deviceEventInfo.setEventText(fieldName + eventType + ",属性值为:" + item.getAttrValue() + ",越限值为:" + item.getLimitValue());
|
||||
}
|
||||
valueList.add(deviceEventInfo);
|
||||
@ -392,6 +419,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
|
||||
/**
|
||||
* 收到节点Websocket报文回调函数
|
||||
*
|
||||
* @param session websocket session
|
||||
* @param message 报文内容
|
||||
* @throws Exception
|
||||
@ -406,8 +434,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
//如果是应答报文,跳过队列,直接异步返回
|
||||
if (responseCallback.contains(msg.getCmdId())) {
|
||||
responseCallback.get(msg.getCmdId()).complete(msg);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
//如果是主动请求报文,加入队列,等待处理
|
||||
String nodeId = session.getAttributes().get(NodeConstant.NODE_ID).toString();
|
||||
String cmd = msg.getCmd();
|
||||
@ -465,25 +492,27 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
|
||||
/**
|
||||
* 发送ping消息
|
||||
*
|
||||
* @param session
|
||||
*/
|
||||
private void SendPingMessage(ConcurrentWebSocketSessionDecorator session) {
|
||||
try {
|
||||
session.sendMessage(new PingMessage());
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
catch (Exception ignore){}
|
||||
}
|
||||
|
||||
private void closeSession(WebSocketSession session) {
|
||||
try {
|
||||
session.close(CloseStatus.NO_CLOSE_FRAME);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
catch (Exception ignore){}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定采集节点发送指令(无返回值)
|
||||
*
|
||||
* @param nodeId 节点ID
|
||||
* @param message 指令
|
||||
*/
|
||||
@ -493,8 +522,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
try {
|
||||
session.sendMessage(new TextMessage(message.toJsonString()));
|
||||
log.info("发送的消息为:{}", message.toJsonString());
|
||||
}
|
||||
catch (Exception exception){
|
||||
} catch (Exception exception) {
|
||||
log.error(String.format("发送消息失败: NodeId: %s", nodeId), exception);
|
||||
closeSession(session);
|
||||
}
|
||||
@ -503,6 +531,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
|
||||
/**
|
||||
* 向指定采集节点发送指令(无返回值)
|
||||
*
|
||||
* @param nodeId 节点ID
|
||||
* @param message 指令
|
||||
* @return
|
||||
@ -517,6 +546,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node
|
||||
|
||||
/**
|
||||
* 向指定采集节点发送指令(有返回值)
|
||||
*
|
||||
* @param nodeId 节点ID
|
||||
* @param message 指令
|
||||
* @param timeout 超时时间(秒)
|
||||
|
Loading…
Reference in New Issue
Block a user