|
@@ -2,11 +2,11 @@ package com.wsm.admin.handle;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
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.IDeviceStatusService;
|
|
|
+import com.wsm.admin.service.IDeviceEventService;
|
|
|
import com.wsm.admin.service.impl.DeviceServiceImpl;
|
|
|
-import com.wsm.admin.service.impl.DeviceStatusServiceImpl;
|
|
|
+import com.wsm.admin.service.impl.DeviceEventServiceImpl;
|
|
|
import com.wsm.common.util.DeviceUtil;
|
|
|
import com.wsm.common.util.ByteUtil;
|
|
|
import com.wsm.common.util.SpringContext;
|
|
@@ -37,7 +37,7 @@ public class UdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket
|
|
|
|
|
|
private static final Logger log= LoggerFactory.getLogger(UdpServerHandler.class);
|
|
|
|
|
|
- private IDeviceStatusService deviceStatusService;
|
|
|
+ private IDeviceEventService deviceEventService;
|
|
|
private IDeviceService deviceService;
|
|
|
private SimpMessagingTemplate messagingTemplate;
|
|
|
|
|
@@ -45,8 +45,8 @@ public class UdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket
|
|
|
if (deviceService == null){
|
|
|
deviceService = SpringContext.getBean(DeviceServiceImpl.class);
|
|
|
}
|
|
|
- if (deviceStatusService == null){
|
|
|
- deviceStatusService = SpringContext.getBean(DeviceStatusServiceImpl.class);
|
|
|
+ if (deviceEventService == null){
|
|
|
+ deviceEventService = SpringContext.getBean(DeviceEventServiceImpl.class);
|
|
|
}
|
|
|
if (messagingTemplate == null){
|
|
|
messagingTemplate = SpringContext.getBean(SimpMessagingTemplate.class);
|
|
@@ -55,7 +55,10 @@ public class UdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket
|
|
|
|
|
|
private static final Map<String, String> jgDeviceStatusMap = new HashMap<>();
|
|
|
|
|
|
+ private static final String LOW_PRESSURE_CODE = "ERC40";
|
|
|
+
|
|
|
static {
|
|
|
+ jgDeviceStatusMap.put(LOW_PRESSURE_CODE, "电池电压");
|
|
|
jgDeviceStatusMap.put("ERC52", "水浸事件");
|
|
|
jgDeviceStatusMap.put("ERC51", "井盖掀翻");
|
|
|
jgDeviceStatusMap.put("ERC50", "井盖倾斜/抬起");
|
|
@@ -130,21 +133,40 @@ public class UdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket
|
|
|
log.warn("=======时间"+dateTime.toDate()+"=======\n");
|
|
|
|
|
|
Device device = deviceService.findByDeviceId(deviceId);
|
|
|
+ String content = jgDeviceStatusMap.get(type);
|
|
|
+ boolean needEvent = false;
|
|
|
if (device != null){
|
|
|
- DeviceStatus status = new DeviceStatus();
|
|
|
- status.setContent(jgDeviceStatusMap.get(type));
|
|
|
- status.setDevice(device);
|
|
|
- status.setStatus((byte)1);
|
|
|
- status.setCreateTime(dateTime.toDate());
|
|
|
- status.setUpdateTime(dateTime.toDate());
|
|
|
- deviceStatusService.save(status);
|
|
|
- log.warn(device.getDeviceId() + ":"+ status.getContent());
|
|
|
-
|
|
|
- JSONObject result = new JSONObject();
|
|
|
- result.put("id", device.getDeviceId());
|
|
|
- result.put("deviceType", device.getDeviceType());
|
|
|
- result.put("status", "ERC"+type);
|
|
|
- messagingTemplate.convertAndSend("/topic/device", result.toJSONString());
|
|
|
+ if (LOW_PRESSURE_CODE.equals(type)){
|
|
|
+ String pressure = eventStrArr[11];
|
|
|
+ // 低压
|
|
|
+ if (Integer.valueOf(pressure) <= 20){
|
|
|
+ device.setStatus((byte)2);
|
|
|
+ needEvent = true;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ // 报警
|
|
|
+ device.setStatus((byte)1);
|
|
|
+ needEvent = true;
|
|
|
+ }
|
|
|
+ deviceService.update(device);
|
|
|
+
|
|
|
+ if (needEvent){
|
|
|
+ DeviceEvent event = new DeviceEvent();
|
|
|
+ event.setDevice(device);
|
|
|
+ event.setContent(content);
|
|
|
+ event.setHandleStatus((byte)0);
|
|
|
+ event.setCreateTime(dateTime.toDate());
|
|
|
+ event.setUpdateTime(dateTime.toDate());
|
|
|
+ deviceEventService.save(event);
|
|
|
+ log.warn(device.getDeviceId() + ":"+ event.getContent());
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("id", device.getDeviceId());
|
|
|
+ result.put("deviceType", device.getDeviceType());
|
|
|
+ result.put("status", type);
|
|
|
+ // 推送信息到前端
|
|
|
+ messagingTemplate.convertAndSend("/topic/device", result.toJSONString());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -166,8 +188,6 @@ public class UdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket
|
|
|
return feedback.toString().toUpperCase();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public void channelReadComplete(ChannelHandlerContext ctx) {
|
|
|
ctx.flush();
|