|
|
@ -2,6 +2,7 @@ package com.qyft.gd.device.handler; |
|
|
|
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.qyft.gd.device.common.constant.TcpMessageType; |
|
|
|
import com.qyft.gd.device.model.bo.DeviceStatus; |
|
|
|
import com.qyft.gd.device.service.DeviceStateService; |
|
|
|
import io.netty.channel.ChannelHandler; |
|
|
@ -25,13 +26,19 @@ public class DeviceMessageHandler extends SimpleChannelInboundHandler<String> { |
|
|
|
try { |
|
|
|
// 解析 JSON |
|
|
|
JSONObject json = JSONUtil.parseObj(msg); |
|
|
|
DeviceStatus deviceStatus = json.toBean(DeviceStatus.class); |
|
|
|
// 更新设备状态 |
|
|
|
deviceStateService.updateDeviceStatus(deviceStatus); |
|
|
|
String type = json.getStr("type"); |
|
|
|
|
|
|
|
log.info("设备状态已更新: {}", json.toStringPretty()); |
|
|
|
if(TcpMessageType.STATUS.equals(type)){//设备状态 |
|
|
|
DeviceStatus deviceStatus = json.toBean(DeviceStatus.class); |
|
|
|
deviceStateService.updateDeviceStatus(deviceStatus); // 更新设备状态 |
|
|
|
log.info("设备状态已更新: {}", json.toStringPretty()); |
|
|
|
}else if(TcpMessageType.ALARM.equals(type)){//设备报警 |
|
|
|
|
|
|
|
}else if(TcpMessageType.FEEDBACK.equals(type)){//设备指令反馈 |
|
|
|
|
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("设备状态更新错误: {}, error: {}", msg, e.getMessage(), e); |
|
|
|
log.error("TCP数据处理错误: {}, error: {}", msg, e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |