|
@@ -2,11 +2,12 @@ package com.wsm.admin.init;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.wsm.admin.model.Device;
|
|
import com.wsm.admin.model.Device;
|
|
-import com.wsm.admin.model.DeviceStatus;
|
|
|
|
|
|
+import com.wsm.admin.model.DeviceEvent;
|
|
import com.wsm.admin.service.IDeviceService;
|
|
import com.wsm.admin.service.IDeviceService;
|
|
-import com.wsm.admin.service.IDeviceStatusService;
|
|
|
|
|
|
+import com.wsm.admin.service.IDeviceEventService;
|
|
import com.wsm.common.util.ByteUtil;
|
|
import com.wsm.common.util.ByteUtil;
|
|
import com.wsm.common.util.DeviceUtil;
|
|
import com.wsm.common.util.DeviceUtil;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -41,12 +42,15 @@ public class TcpServer {
|
|
private static Selector selector;
|
|
private static Selector selector;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private IDeviceStatusService deviceStatusService;
|
|
|
|
|
|
+ private IDeviceEventService deviceEventService;
|
|
@Autowired
|
|
@Autowired
|
|
private IDeviceService deviceService;
|
|
private IDeviceService deviceService;
|
|
@Autowired
|
|
@Autowired
|
|
private SimpMessagingTemplate messagingTemplate;
|
|
private SimpMessagingTemplate messagingTemplate;
|
|
|
|
|
|
|
|
+ private static final String LOW_PRESSURE_CODE = "384";
|
|
|
|
+ private static final String SMOKE_CODE = "111";
|
|
|
|
+
|
|
private static final Map<String, String> deviceStatusMap = new HashMap<>();
|
|
private static final Map<String, String> deviceStatusMap = new HashMap<>();
|
|
|
|
|
|
static {
|
|
static {
|
|
@@ -60,8 +64,8 @@ public class TcpServer {
|
|
deviceStatusMap.put("3801", "消防手报状态:弹起");
|
|
deviceStatusMap.put("3801", "消防手报状态:弹起");
|
|
deviceStatusMap.put("3E01", "喷淋状态:打开");
|
|
deviceStatusMap.put("3E01", "喷淋状态:打开");
|
|
|
|
|
|
- deviceStatusMap.put("111", "烟雾报警");
|
|
|
|
- deviceStatusMap.put("384", "低压报警");
|
|
|
|
|
|
+ deviceStatusMap.put(SMOKE_CODE, "烟雾报警");
|
|
|
|
+ deviceStatusMap.put(LOW_PRESSURE_CODE, "低压报警");
|
|
deviceStatusMap.put("993", "底座上的烟感低压");
|
|
deviceStatusMap.put("993", "底座上的烟感低压");
|
|
deviceStatusMap.put("992", "NB 底座低压报警 ");
|
|
deviceStatusMap.put("992", "NB 底座低压报警 ");
|
|
deviceStatusMap.put("991", "燃气报警");
|
|
deviceStatusMap.put("991", "燃气报警");
|
|
@@ -178,13 +182,17 @@ public class TcpServer {
|
|
break;
|
|
break;
|
|
// 状态
|
|
// 状态
|
|
case "04":
|
|
case "04":
|
|
- int total = Integer.valueOf(str[16]);
|
|
|
|
|
|
+ log.warn("======心跳信息,推送状态信息======");
|
|
|
|
+ /*int total = Integer.valueOf(str[16]);
|
|
for (int i = 0, length = 3; i < total; i++){
|
|
for (int i = 0, length = 3; i < total; i++){
|
|
String a = str[17 + i * length];
|
|
String a = str[17 + i * length];
|
|
//String b = str[18 + i * length];
|
|
//String b = str[18 + i * length];
|
|
String c = str[19 + i * length];
|
|
String c = str[19 + i * length];
|
|
// 状态异常
|
|
// 状态异常
|
|
- if (!org.springframework.util.StringUtils.isEmpty(deviceStatusMap.get(a+c)) && device != null){
|
|
|
|
|
|
+ if (!StringUtils.isEmpty(deviceStatusMap.get(a+c)) && device != null){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
DeviceStatus status = new DeviceStatus();
|
|
DeviceStatus status = new DeviceStatus();
|
|
status.setContent(deviceStatusMap.get(a+c));
|
|
status.setContent(deviceStatusMap.get(a+c));
|
|
status.setDevice(device);
|
|
status.setDevice(device);
|
|
@@ -199,24 +207,34 @@ public class TcpServer {
|
|
|
|
|
|
messagingTemplate.convertAndSend("/topic/device", result.toJSONString());
|
|
messagingTemplate.convertAndSend("/topic/device", result.toJSONString());
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
break;
|
|
break;
|
|
// 报警
|
|
// 报警
|
|
case "09":
|
|
case "09":
|
|
// 报警
|
|
// 报警
|
|
String hex = ByteUtil.hexStringToString(str[24]+str[25]+str[26]);
|
|
String hex = ByteUtil.hexStringToString(str[24]+str[25]+str[26]);
|
|
- if (!org.springframework.util.StringUtils.isEmpty(deviceStatusMap.get(hex)) && device != null){
|
|
|
|
- DeviceStatus status = new DeviceStatus();
|
|
|
|
- status.setContent(deviceStatusMap.get(hex));
|
|
|
|
- status.setDevice(device);
|
|
|
|
- status.setStatus((byte)1);
|
|
|
|
- deviceStatusService.save(status);
|
|
|
|
- log.warn(device.getDeviceId() + ":"+ status.getContent());
|
|
|
|
|
|
+ if (!StringUtils.isEmpty(deviceStatusMap.get(hex)) && device != null){
|
|
|
|
+
|
|
|
|
+ if (LOW_PRESSURE_CODE.equals(hex)){
|
|
|
|
+ device.setStatus((byte)2);
|
|
|
|
+ }else if (SMOKE_CODE.equals(hex)){
|
|
|
|
+ device.setStatus((byte)1);
|
|
|
|
+ }
|
|
|
|
+ deviceService.update(device);
|
|
|
|
+
|
|
|
|
+ DeviceEvent event = new DeviceEvent();
|
|
|
|
+ event.setContent(deviceStatusMap.get(hex));
|
|
|
|
+ event.setDevice(device);
|
|
|
|
+ event.setHandleStatus((byte)0);
|
|
|
|
+ deviceEventService.save(event);
|
|
|
|
+ log.warn(device.getDeviceId() + ":"+ event.getContent());
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
JSONObject result = new JSONObject();
|
|
result.put("id", device.getDeviceId());
|
|
result.put("id", device.getDeviceId());
|
|
result.put("deviceType", device.getDeviceType());
|
|
result.put("deviceType", device.getDeviceType());
|
|
result.put("status", hex);
|
|
result.put("status", hex);
|
|
|
|
+
|
|
|
|
+ // 推送报警事件给前端
|
|
messagingTemplate.convertAndSend("/topic/device", result.toJSONString());
|
|
messagingTemplate.convertAndSend("/topic/device", result.toJSONString());
|
|
}
|
|
}
|
|
break;
|
|
break;
|