|
|
@@ -78,7 +78,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
String topic = nettyMessage.getTopic();
|
|
|
String deviceNo = nettyMessage.getDeviceNo();
|
|
|
String messageId = nettyMessage.getMessageId();
|
|
|
- String commandType = nettyMessage.getCommandType();
|
|
|
|
|
|
// 将会话与会话管理器关联
|
|
|
if (deviceNo != null && !deviceNo.isEmpty()) {
|
|
|
@@ -100,9 +99,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
handleDeviceActiveReport(ctx, nettyMessage);
|
|
|
break;
|
|
|
case COMMAND_DOWNLOAD_RESPONSE:
|
|
|
- if(commandType.equals(DEVICE_INFO_REPORT.getCode())){
|
|
|
- handleDeviceInfoResponse(ctx, nettyMessage);
|
|
|
- }
|
|
|
break;
|
|
|
case COMMON_RESPONSE:
|
|
|
handleCommonResponse(ctx, nettyMessage);
|
|
|
@@ -113,6 +109,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
sendResponse(ctx, messageId, deviceNo, 1, "未支持的消息主题", null,NettyTopic.COMMON_RESPONSE.getCode());
|
|
|
break;
|
|
|
}
|
|
|
+ handleDeviceInfoResponse(ctx, nettyMessage);
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
logger.error("处理消息异常: {}", e.getMessage());
|
|
|
sendResponse(ctx, messageId, deviceNo, 2, "处理消息异常: " + e.getMessage(), null,NettyTopic.COMMON_RESPONSE.getCode());
|
|
|
@@ -278,37 +275,32 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
* 处理设备信息响应,计算通信延迟
|
|
|
*/
|
|
|
private void handleDeviceInfoResponse(ChannelHandlerContext ctx, NettyMessage message) {
|
|
|
- Long sendTime = ctx.channel().attr(NettyAttributes.REQUEST_SEND_TIME).get();
|
|
|
- if (sendTime != null) {
|
|
|
- long delay = System.currentTimeMillis() - sendTime;
|
|
|
- ctx.channel().attr(NettyAttributes.COMMUNICATION_DELAY).set(delay);
|
|
|
- logger.info("设备信息响应延迟: {}ms,消息ID: {}", delay, message.getMessageId());
|
|
|
-
|
|
|
- // 获取设备ID
|
|
|
- String deviceId = message.getDeviceNo();
|
|
|
- if (deviceId != null) {
|
|
|
- try {
|
|
|
- // 查询设备是否存在
|
|
|
- Record device = Db.findFirst("select * from t_jz_device where device_no = ?", deviceId);
|
|
|
- if (device != null) {
|
|
|
- // 查询设备详细信息
|
|
|
- Record deviceDetail = Db.findFirst("select * from t_device_detail where device_id = ?", WxUtil.getInt("id", device));
|
|
|
- if (deviceDetail != null) {
|
|
|
- // 更新设备延迟信息
|
|
|
- deviceDetail.set("network_delay", delay);
|
|
|
- deviceDetail.set("updated_time", new Date());
|
|
|
- Db.update("t_device_detail", "device_id", deviceDetail);
|
|
|
- }
|
|
|
+ // 获取设备ID
|
|
|
+ String deviceId = message.getDeviceNo();
|
|
|
+ long timestamp = message.getTimestamp();
|
|
|
+ //如何判断timestamp 时间有没有值
|
|
|
+ if (timestamp == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ long delay = System.currentTimeMillis()-timestamp;
|
|
|
+ if (deviceId != null) {
|
|
|
+ try {
|
|
|
+ // 查询设备是否存在
|
|
|
+ Record device = Db.findFirst("select * from t_jz_device where device_no = ?", deviceId);
|
|
|
+ if (device != null) {
|
|
|
+ // 查询设备详细信息
|
|
|
+ Record deviceDetail = Db.findFirst("select * from t_device_detail where device_id = ?", WxUtil.getInt("id", device));
|
|
|
+ if (deviceDetail != null) {
|
|
|
+ // 更新设备延迟信息
|
|
|
+ deviceDetail.set("network_delay", delay);
|
|
|
+ deviceDetail.set("updated_time", new Date());
|
|
|
+ Db.update("t_device_detail", "device_id", deviceDetail);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("保存通信延迟信息失败: {}", e.getMessage());
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("保存通信延迟信息失败: {}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 发送响应
|
|
|
- sendResponse(ctx, message.getMessageId(), message.getDeviceNo(),
|
|
|
- 0, "设备信息接收成功", null, NettyTopic.COMMON_RESPONSE.getCode());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -337,7 +329,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
Record deviceDetail = Db.findFirst("select * from t_device_detail where device_id = ?", deviceId);
|
|
|
Record deviceDetailDb = new Record();
|
|
|
deviceDetailDb.set("device_id", deviceId);
|
|
|
- deviceDetailDb.set("product_id", data.getProductId());
|
|
|
+ deviceDetailDb.set("product_sku", data.getProductSku());
|
|
|
deviceDetailDb.set("cpu_usage", data.getCpuUsage());
|
|
|
deviceDetailDb.set("memory_usage", data.getMemoryUsage());
|
|
|
deviceDetailDb.set("disk_free", data.getDiskFreeSpace());
|