|
@@ -66,10 +66,21 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
*/
|
|
|
private static final Integer CHECK_DATA_LENGTH = 162;
|
|
|
|
|
|
- private static final double JG_ERC40 = 10;
|
|
|
+ private static final double JG_ERC40 = 18;
|
|
|
|
|
|
private static final double JG_ERC90 = 70;
|
|
|
|
|
|
+ /**
|
|
|
+ * 心跳
|
|
|
+ */
|
|
|
+ private static final int CODE_HEARTBEAT = 85;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 报警
|
|
|
+ */
|
|
|
+ private static final int CODE_ALARM = 0;
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -122,16 +133,27 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
if (StringUtils.isNotEmpty(inString) && inString.length() == CHECK_DATA_LENGTH){
|
|
|
|
|
|
- // 这应该是心跳,直接结束
|
|
|
-// if (inString.contains(JG_HEARTBEAT)) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
|
|
|
ConvertData cd = new ConvertData();
|
|
|
Map<String, Object> hm = cd.convert(inString);
|
|
|
|
|
|
|
|
|
log.info("解析json: {}", JSON.toJSONString(hm));
|
|
|
+
|
|
|
+ int type = (int)hm.get("type");
|
|
|
+ // 设备id
|
|
|
+ String sn2 = hm.get("sn2").toString();
|
|
|
+
|
|
|
+
|
|
|
+ // 心跳检测
|
|
|
+ if (type == CODE_HEARTBEAT) {
|
|
|
+ redisUtil.set(sn2,"heartbeat", Long.parseLong("25"));
|
|
|
+ log.warn("heartbeat device id: {}", sn2);
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
String status = hm.get("status").toString();
|
|
|
|
|
|
// 计算井盖角度
|
|
@@ -140,8 +162,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
double angle = angle(Double.parseDouble(ox), Double.parseDouble(oy));
|
|
|
log.info("井盖开启角度: {} 度", Math.round(angle));
|
|
|
|
|
|
- // 设备id
|
|
|
- String sn2 = hm.get("sn2").toString();
|
|
|
+
|
|
|
Device device = deviceService.findByDeviceId(sn2);
|
|
|
log.warn("JG设备号: {}", sn2);
|
|
|
|
|
@@ -163,31 +184,43 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
//报警开关
|
|
|
boolean needEvent = false;
|
|
|
String content = "";
|
|
|
+ Integer devideStatus = null;
|
|
|
|
|
|
+
|
|
|
+ // 状态类型:0-正常 1-报警 2-低压 3-故障
|
|
|
if (device != null) {
|
|
|
+
|
|
|
+ needEvent = true;
|
|
|
+
|
|
|
// 低电压
|
|
|
if (JG_LOW_PRESSURE_CODE.equals(status)) {
|
|
|
device.setStatus((byte)2);
|
|
|
+ devideStatus = 2;
|
|
|
+ content = deviceStatusMap.get(JG_LOW_PRESSURE_CODE);
|
|
|
|
|
|
// 故障
|
|
|
} else if (JG_LOW_PRESSURE_OFF.equals(status)) {
|
|
|
device.setStatus((byte)3);
|
|
|
+ devideStatus = 3;
|
|
|
+ content = deviceStatusMap.get(JG_LOW_PRESSURE_OFF);
|
|
|
|
|
|
// 报警
|
|
|
} else if (JG_NORMAL.equals(status)) {
|
|
|
device.setStatus((byte)1);
|
|
|
- needEvent = true;
|
|
|
|
|
|
//处理报警类型
|
|
|
+ devideStatus = 1;
|
|
|
// 大于40度
|
|
|
|
|
|
if (angle > JG_ERC40) {
|
|
|
// 报警
|
|
|
content = deviceStatusMap.get("ERC40");
|
|
|
|
|
|
+
|
|
|
}
|
|
|
if (angle > JG_ERC90) {
|
|
|
content = deviceStatusMap.get("ERC90");
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
device.setUpdateTime(new Date());
|
|
@@ -200,13 +233,14 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
// 记录报警详情
|
|
|
if (needEvent) {
|
|
|
- DeviceEvent event = new DeviceEvent();
|
|
|
-// DeviceEvent event = deviceEventService.findByDeviceIdTop(device.getId());
|
|
|
-// if (event == null) {
|
|
|
+ DeviceEvent event = deviceEventService.findByStatusAndDeviceId(device.getId(), devideStatus);
|
|
|
+ if (event == null) {
|
|
|
event = new DeviceEvent();
|
|
|
event.setDevice(device);
|
|
|
event.setCreateTime(new Date());
|
|
|
-// }
|
|
|
+ }
|
|
|
+ event.setStatus(devideStatus);
|
|
|
+ // 处理状态:0-待解决, 1-已立案,2-出警中,3-已解决
|
|
|
event.setHandleStatus((byte)0);
|
|
|
event.setContent(content);
|
|
|
event.setUpdateTime(new Date());
|