diff --git a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java index e838cc8e..acd6092f 100644 --- a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java +++ b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java @@ -39,7 +39,7 @@ public class VManageBootstrap extends SpringBootServletInitializer { }else { log.info("构建版本: {}", gitUtil.getBuildVersion()); log.info("构建时间: {}", gitUtil.getBuildDate()); - log.info("GIT最后提交时间: {}", gitUtil.getCommitTime()); + log.info("GIT信息: 分支: {}, ID: {}, 时间: {}", gitUtil.getBranch(), gitUtil.getCommitIdShort(), gitUtil.getCommitTime()); } } // 项目重启 diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java index 37113416..10991aed 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java @@ -1,187 +1,272 @@ package com.genersoft.iot.vmp.gb28181.bean; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.HashSet; +import java.util.Set; /** * @author lin */ @Schema(description = "报警信息") +@Data public class DeviceAlarm { - /** - * 数据库id - */ - @Schema(description = "数据库id") - private String id; + /** + * 数据库id + */ + @Schema(description = "数据库id") + private String id; - /** - * 设备Id - */ - @Schema(description = "设备的国标编号") - private String deviceId; + /** + * 设备Id + */ + @Schema(description = "设备的国标编号") + private String deviceId; - /** - * 通道Id - */ - @Schema(description = "通道的国标编号") - private String channelId; + /** + * 通道Id + */ + @Schema(description = "通道的国标编号") + private String channelId; - /** - * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级警情 - */ - @Schema(description = "报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级警情") - private String alarmPriority; + /** + * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级警情 + */ + @Schema(description = "报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级警情") + private String alarmPriority; - /** - * 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警, - * 7其他报警;可以为直接组合如12为电话报警或 设备报警- - */ - @Schema(description = "报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警,\n" + - "\t * 7其他报警;可以为直接组合如12为电话报警或设备报警") - private String alarmMethod; + @Schema(description = "报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级警情") + private String alarmPriorityDescription; - /** - * 报警时间 - */ - @Schema(description = "报警时间") - private String alarmTime; + public String getAlarmPriorityDescription() { + switch (alarmPriority) { + case "1": + return "一级警情"; + case "2": + return "二级警情"; + case "3": + return "三级警情"; + case "4": + return "四级警情"; + default: + return alarmPriority; + } + } - /** - * 报警内容描述 - */ - @Schema(description = "报警内容描述") - private String alarmDescription; - - /** - * 经度 - */ - @Schema(description = "经度") - private double longitude; - - /** - * 纬度 - */ - @Schema(description = "纬度") - private double latitude; - - /** - * 报警类型, - * 报警方式为2时,不携带 AlarmType为默认的报警设备报警, - * 携带 AlarmType取值及对应报警类型如下: - * 1-视频丢失报警; - * 2-设备防拆报警; - * 3-存储设备磁盘满报警; - * 4-设备高温报警; - * 5-设备低温报警。 - * 报警方式为5时,取值如下: - * 1-人工视频报警; - * 2-运动目标检测报警; - * 3-遗留物检测报警; - * 4-物体移除检测报警; - * 5-绊线检测报警; - * 6-入侵检测报警; - * 7-逆行检测报警; - * 8-徘徊检测报警; - * 9-流量统计报警; - * 10-密度检测报警; - * 11-视频异常检测报警; - * 12-快速移动报警。 - * 报警方式为6时,取值下: - * 1-存储设备磁盘故障报警; - * 2-存储设备风扇故障报警。 - */ - @Schema(description = "报警类型") - private String alarmType; - - @Schema(description = "创建时间") - private String createTime; + /** + * 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警, + * 7其他报警;可以为直接组合如12为电话报警或 设备报警- + */ + @Schema(description = "报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警,\n" + + "\t * 7其他报警;可以为直接组合如12为电话报警或设备报警") + private String alarmMethod; - public String getId() { - return id; + private String alarmMethodDescription; + + public String getAlarmMethodDescription() { + StringBuilder stringBuilder = new StringBuilder(); + char[] charArray = alarmMethod.toCharArray(); + for (char c : charArray) { + switch (c) { + case '1': + stringBuilder.append("-电话报警"); + break; + case '2': + stringBuilder.append("-设备报警"); + break; + case '3': + stringBuilder.append("-短信报警"); + break; + case '4': + stringBuilder.append("-GPS报警"); + break; + case '5': + stringBuilder.append("-视频报警"); + break; + case '6': + stringBuilder.append("-设备故障报警"); + break; + case '7': + stringBuilder.append("-其他报警"); + break; + } + } + stringBuilder.delete(0, 1); + return stringBuilder.toString(); + } + + /** + * 报警时间 + */ + @Schema(description = "报警时间") + private String alarmTime; + + /** + * 报警内容描述 + */ + @Schema(description = "报警内容描述") + private String alarmDescription; + + /** + * 经度 + */ + @Schema(description = "经度") + private double longitude; + + /** + * 纬度 + */ + @Schema(description = "纬度") + private double latitude; + + /** + * 报警类型, + * 报警方式为2时,不携带 AlarmType为默认的报警设备报警, + * 携带 AlarmType取值及对应报警类型如下: + * 1-视频丢失报警; + * 2-设备防拆报警; + * 3-存储设备磁盘满报警; + * 4-设备高温报警; + * 5-设备低温报警。 + * 报警方式为5时,取值如下: + * 1-人工视频报警; + * 2-运动目标检测报警; + * 3-遗留物检测报警; + * 4-物体移除检测报警; + * 5-绊线检测报警; + * 6-入侵检测报警; + * 7-逆行检测报警; + * 8-徘徊检测报警; + * 9-流量统计报警; + * 10-密度检测报警; + * 11-视频异常检测报警; + * 12-快速移动报警。 + * 报警方式为6时,取值下: + * 1-存储设备磁盘故障报警; + * 2-存储设备风扇故障报警。 + */ + @Schema(description = "报警类型") + private String alarmType; + + public String getAlarmTypeDescription() { + if (alarmType == null) { + return ""; + } + char[] charArray = alarmMethod.toCharArray(); + Set alarmMethodSet = new HashSet<>(); + for (char c : charArray) { + alarmMethodSet.add(Character.toString(c)); + } + String result = alarmType; + if (alarmMethodSet.contains("2")) { + switch (alarmType) { + case "1": + result = "视频丢失报警"; + break; + case "2": + result = "设备防拆报警"; + break; + case "3": + result = "存储设备磁盘满报警"; + break; + case "4": + result = "设备高温报警"; + break; + case "5": + result = "设备低温报警"; + break; + } + } + if (alarmMethodSet.contains("5")) { + switch (alarmType) { + case "1": + result = "人工视频报警"; + break; + case "2": + result = "运动目标检测报警"; + break; + case "3": + result = "遗留物检测报警"; + break; + case "4": + result = "物体移除检测报警"; + break; + case "5": + result = "绊线检测报警"; + break; + case "6": + result = "入侵检测报警"; + break; + case "7": + result = "逆行检测报警"; + break; + case "8": + result = "徘徊检测报警"; + break; + case "9": + result = "流量统计报警"; + break; + case "10": + result = "密度检测报警"; + break; + case "11": + result = "视频异常检测报警"; + break; + case "12": + result = "快速移动报警"; + break; + } + } + if (alarmMethodSet.contains("6")) { + switch (alarmType) { + case "1": + result = "人工视频报警"; + break; + case "2": + result = "运动目标检测报警"; + break; + case "3": + result = "遗留物检测报警"; + break; + case "4": + result = "物体移除检测报警"; + break; + case "5": + result = "绊线检测报警"; + break; + case "6": + result = "入侵检测报警"; + break; + case "7": + result = "逆行检测报警"; + break; + case "8": + result = "徘徊检测报警"; + break; + case "9": + result = "流量统计报警"; + break; + case "10": + result = "密度检测报警"; + break; + case "11": + result = "视频异常检测报警"; + break; + case "12": + result = "快速移动报警"; + break; + } + } + return result; } - public void setId(String id) { - this.id = id; - } + @Schema(description = "报警类型描述") + private String alarmTypeDescription; - public String getDeviceId() { - return deviceId; - } + @Schema(description = "创建时间") + private String createTime; - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } - - public String getAlarmPriority() { - return alarmPriority; - } - - public void setAlarmPriority(String alarmPriority) { - this.alarmPriority = alarmPriority; - } - - public String getAlarmMethod() { - return alarmMethod; - } - - public void setAlarmMethod(String alarmMethod) { - this.alarmMethod = alarmMethod; - } - - public String getAlarmTime() { - return alarmTime; - } - - public void setAlarmTime(String alarmTime) { - this.alarmTime = alarmTime; - } - - public String getAlarmDescription() { - return alarmDescription; - } - - public void setAlarmDescription(String alarmDescription) { - this.alarmDescription = alarmDescription; - } - - public double getLongitude() { - return longitude; - } - - public void setLongitude(double longitude) { - this.longitude = longitude; - } - - public double getLatitude() { - return latitude; - } - - public void setLatitude(double latitude) { - this.latitude = latitude; - } - - public String getAlarmType() { - return alarmType; - } - - public void setAlarmType(String alarmType) { - this.alarmType = alarmType; - } - - public String getChannelId() { - return channelId; - } - - public void setChannelId(String channelId) { - this.channelId = channelId; - } - - public String getCreateTime() { - return createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SSEMessage.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SSEMessage.java new file mode 100644 index 00000000..eec5d2d0 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SSEMessage.java @@ -0,0 +1,21 @@ +package com.genersoft.iot.vmp.gb28181.bean; + +import com.alibaba.fastjson2.JSONObject; +import lombok.Data; + +@Data +public class SSEMessage { + private String event; + private T data; + + public static SSEMessage getInstance(String event, DeviceAlarm data) { + SSEMessage message = new SSEMessage<>(); + message.setEvent(event); + message.setData(data); + return message; + } + + public String ecode(){ + return String.format("event:%s\ndata:%s\n", event, JSONObject.toJSONString(data)); + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEventListener.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEventListener.java index 317683d6..3610c2a3 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEventListener.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEventListener.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.event.alarm; +import com.genersoft.iot.vmp.gb28181.bean.SSEMessage; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; import org.springframework.context.ApplicationListener; @@ -25,12 +26,12 @@ public class AlarmEventListener implements ApplicationListener { public void addSseEmitter(String browserId, PrintWriter writer) { SSE_CACHE.put(browserId, writer); - log.info("SSE 在线数量: {}", SSE_CACHE.size()); + log.info("[SSE推送] 连接已建立, 浏览器 ID: {}, 当前在线数: {}", browserId, SSE_CACHE.size()); } public void removeSseEmitter(String browserId, PrintWriter writer) { SSE_CACHE.remove(browserId, writer); - log.info("SSE 在线数量: {}", SSE_CACHE.size()); + log.info("[SSE推送] 连接已断开, 浏览器 ID: {}, 当前在线数: {}", browserId, SSE_CACHE.size()); } @Override @@ -39,14 +40,17 @@ public class AlarmEventListener implements ApplicationListener { log.debug("设备报警事件触发, deviceId: {}, {}", event.getAlarmInfo().getDeviceId(), event.getAlarmInfo().getAlarmDescription()); } - String msg = "设备编号: " + event.getAlarmInfo().getDeviceId() + "" + log.info("设备报警事件触发, deviceId: {}, {}", event.getAlarmInfo().getDeviceId(), event.getAlarmInfo().getAlarmDescription()); + + + String msg = "设备: " + event.getAlarmInfo().getDeviceId() + "" + "
通道编号: " + event.getAlarmInfo().getChannelId() + "" + "
报警描述: " + event.getAlarmInfo().getAlarmDescription() + "" + "
报警时间: " + event.getAlarmInfo().getAlarmTime() + ""; for (Iterator> it = SSE_CACHE.entrySet().iterator(); it.hasNext(); ) { Map.Entry response = it.next(); - log.info("推送到 SSE 连接, 浏览器 ID: {}", response.getKey()); + try { PrintWriter writer = response.getValue(); @@ -58,9 +62,13 @@ public class AlarmEventListener implements ApplicationListener { String sseMsg = "event:message\n" + "data:" + msg + "\n" + "\n"; - writer.write(sseMsg); + System.out.println( + SSEMessage.getInstance("message", event.getAlarmInfo()).ecode() + ); + writer.write(SSEMessage.getInstance("message", event.getAlarmInfo()).ecode()); writer.flush(); } catch (Exception e) { + log.error("[发送SSE] 失败", e); it.remove(); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java index 293f3e37..230f9039 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java @@ -20,8 +20,7 @@ import lombok.extern.slf4j.Slf4j; import org.dom4j.Element; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; @@ -30,6 +29,8 @@ import javax.sip.RequestEvent; import javax.sip.SipException; import javax.sip.message.Response; import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; @@ -64,12 +65,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme @Autowired private IDeviceChannelService deviceChannelService; - private ConcurrentLinkedQueue taskQueue = new ConcurrentLinkedQueue<>(); - - @Qualifier("taskExecutor") - @Autowired - private ThreadPoolTaskExecutor taskExecutor; - + private final ConcurrentLinkedQueue taskQueue = new ConcurrentLinkedQueue<>(); @Override public void afterPropertiesSet() throws Exception { @@ -78,118 +74,136 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme @Override public void handForDevice(RequestEvent evt, Device device, Element rootElement) { - boolean isEmpty = taskQueue.isEmpty(); - taskQueue.offer(new SipMsgInfo(evt, device, rootElement)); - // 回复200 OK - try { - responseAck((SIPRequest) evt.getRequest(), Response.OK); - } catch (SipException | InvalidArgumentException | ParseException e) { - log.error("[命令发送失败] 报警通知回复: {}", e.getMessage()); + if (taskQueue.size() >= userSetting.getMaxNotifyCountQueue()) { + log.error("[Alarm] 待处理消息队列已满 {},返回486 BUSY_HERE,消息不做处理", userSetting.getMaxNotifyCountQueue()); + return; } - if (isEmpty) { - taskExecutor.execute(() -> { - if (log.isDebugEnabled()) { - log.info("[处理报警通知]待处理数量:{}", taskQueue.size() ); + taskQueue.offer(new SipMsgInfo(evt, device, rootElement)); + } + + @Scheduled(fixedDelay = 200) + public void executeTaskQueue() { + if (taskQueue.isEmpty()) { + return; + } + List handlerCatchDataList = new ArrayList<>(); + int size = taskQueue.size(); + for (int i = 0; i < size; i++) { + SipMsgInfo poll = taskQueue.poll(); + if (poll != null) { + handlerCatchDataList.add(poll); + } + } + if (handlerCatchDataList.isEmpty()) { + return; + } + for (SipMsgInfo sipMsgInfo : handlerCatchDataList) { + if (sipMsgInfo == null) { + continue; + } + RequestEvent evt = sipMsgInfo.getEvt(); + System.out.println(evt.getRequest()); + // 回复200 OK + try { + responseAck((SIPRequest) evt.getRequest(), Response.OK); + } catch (SipException | InvalidArgumentException | ParseException e) { + log.error("[命令发送失败] 报警通知回复: {}", e.getMessage()); + } + try { + Device device = sipMsgInfo.getDevice(); + Element deviceIdElement = sipMsgInfo.getRootElement().element("DeviceID"); + String channelId = deviceIdElement.getText(); + + DeviceAlarm deviceAlarm = new DeviceAlarm(); + deviceAlarm.setCreateTime(DateUtil.getNow()); + deviceAlarm.setDeviceId(sipMsgInfo.getDevice().getDeviceId()); + deviceAlarm.setChannelId(channelId); + deviceAlarm.setAlarmPriority(getText(sipMsgInfo.getRootElement(), "AlarmPriority")); + deviceAlarm.setAlarmMethod(getText(sipMsgInfo.getRootElement(), "AlarmMethod")); + String alarmTime = XmlUtil.getText(sipMsgInfo.getRootElement(), "AlarmTime"); + if (alarmTime == null) { + continue; + } + deviceAlarm.setAlarmTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(alarmTime)); + String alarmDescription = getText(sipMsgInfo.getRootElement(), "AlarmDescription"); + if (alarmDescription == null) { + deviceAlarm.setAlarmDescription(""); + } else { + deviceAlarm.setAlarmDescription(alarmDescription); + } + String longitude = getText(sipMsgInfo.getRootElement(), "Longitude"); + if (longitude != null && NumericUtil.isDouble(longitude)) { + deviceAlarm.setLongitude(Double.parseDouble(longitude)); + } else { + deviceAlarm.setLongitude(0.00); + } + String latitude = getText(sipMsgInfo.getRootElement(), "Latitude"); + if (latitude != null && NumericUtil.isDouble(latitude)) { + deviceAlarm.setLatitude(Double.parseDouble(latitude)); + } else { + deviceAlarm.setLatitude(0.00); } - while (!taskQueue.isEmpty()) { - try { - SipMsgInfo sipMsgInfo = taskQueue.poll(); - Element deviceIdElement = sipMsgInfo.getRootElement().element("DeviceID"); - String channelId = deviceIdElement.getText().toString(); + if (!ObjectUtils.isEmpty(deviceAlarm.getAlarmMethod()) && deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.GPS.getVal() + "")) { + DeviceChannel deviceChannel = deviceChannelService.getOne(device.getDeviceId(), channelId); + if (deviceChannel == null) { + log.warn("[解析报警消息] 未找到通道:{}/{}", device.getDeviceId(), channelId); + } else { + MobilePosition mobilePosition = new MobilePosition(); + mobilePosition.setCreateTime(DateUtil.getNow()); + mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); + mobilePosition.setChannelId(deviceChannel.getId()); + mobilePosition.setTime(deviceAlarm.getAlarmTime()); + mobilePosition.setLongitude(deviceAlarm.getLongitude()); + mobilePosition.setLatitude(deviceAlarm.getLatitude()); + mobilePosition.setReportSource("GPS Alarm"); - DeviceAlarm deviceAlarm = new DeviceAlarm(); - deviceAlarm.setCreateTime(DateUtil.getNow()); - deviceAlarm.setDeviceId(sipMsgInfo.getDevice().getDeviceId()); - deviceAlarm.setChannelId(channelId); - deviceAlarm.setAlarmPriority(getText(sipMsgInfo.getRootElement(), "AlarmPriority")); - deviceAlarm.setAlarmMethod(getText(sipMsgInfo.getRootElement(), "AlarmMethod")); - String alarmTime = XmlUtil.getText(sipMsgInfo.getRootElement(), "AlarmTime"); - if (alarmTime == null) { - continue; - } - deviceAlarm.setAlarmTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(alarmTime)); - String alarmDescription = getText(sipMsgInfo.getRootElement(), "AlarmDescription"); - if (alarmDescription == null) { - deviceAlarm.setAlarmDescription(""); - } else { - deviceAlarm.setAlarmDescription(alarmDescription); - } - String longitude = getText(sipMsgInfo.getRootElement(), "Longitude"); - if (longitude != null && NumericUtil.isDouble(longitude)) { - deviceAlarm.setLongitude(Double.parseDouble(longitude)); - } else { - deviceAlarm.setLongitude(0.00); - } - String latitude = getText(sipMsgInfo.getRootElement(), "Latitude"); - if (latitude != null && NumericUtil.isDouble(latitude)) { - deviceAlarm.setLatitude(Double.parseDouble(latitude)); - } else { - deviceAlarm.setLatitude(0.00); - } + // 更新device channel 的经纬度 + deviceChannel.setLongitude(mobilePosition.getLongitude()); + deviceChannel.setLatitude(mobilePosition.getLatitude()); + deviceChannel.setGpsTime(mobilePosition.getTime()); - if (!ObjectUtils.isEmpty(deviceAlarm.getAlarmMethod()) && deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.GPS.getVal() + "")) { - DeviceChannel deviceChannel = deviceChannelService.getOne(device.getDeviceId(), channelId); - if (deviceChannel == null) { - log.warn("[解析报警消息] 未找到通道:{}/{}", device.getDeviceId(), channelId); - } else { - MobilePosition mobilePosition = new MobilePosition(); - mobilePosition.setCreateTime(DateUtil.getNow()); - mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); - mobilePosition.setChannelId(deviceChannel.getId()); - mobilePosition.setTime(deviceAlarm.getAlarmTime()); - mobilePosition.setLongitude(deviceAlarm.getLongitude()); - mobilePosition.setLatitude(deviceAlarm.getLatitude()); - mobilePosition.setReportSource("GPS Alarm"); - - // 更新device channel 的经纬度 - deviceChannel.setLongitude(mobilePosition.getLongitude()); - deviceChannel.setLatitude(mobilePosition.getLatitude()); - deviceChannel.setGpsTime(mobilePosition.getTime()); - - deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition); - } - } - if (!ObjectUtils.isEmpty(deviceAlarm.getDeviceId())) { - if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) { - deviceAlarm.setAlarmType(getText(sipMsgInfo.getRootElement().element("Info"), "AlarmType")); - } - } - if (log.isDebugEnabled()) { - log.debug("[收到报警通知]设备:{}, 内容:{}", device.getDeviceId(), JSON.toJSONString(deviceAlarm)); - } - // 作者自用判断,其他小伙伴需要此消息可以自行修改,但是不要提在pr里 - if (DeviceAlarmMethod.Other.getVal() == Integer.parseInt(deviceAlarm.getAlarmMethod())) { - // 发送给平台的报警信息。 发送redis通知 - log.info("[发送给平台的报警信息]内容:{}", JSONObject.toJSONString(deviceAlarm)); - AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage(); - if (deviceAlarm.getAlarmMethod() != null) { - alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod())); - } - alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription()); - if (deviceAlarm.getAlarmType() != null) { - alarmChannelMessage.setAlarmType(Integer.parseInt(deviceAlarm.getAlarmType())); - } - alarmChannelMessage.setGbId(channelId); - redisCatchStorage.sendAlarmMsg(alarmChannelMessage); - continue; - } - - log.debug("存储报警信息、报警分类"); - // 存储报警信息、报警分类 - if (sipConfig.isAlarm()) { - deviceAlarmService.add(deviceAlarm); - } - - if (redisCatchStorage.deviceIsOnline(sipMsgInfo.getDevice().getDeviceId())) { - publisher.deviceAlarmEventPublish(deviceAlarm); - } - }catch (Exception e) { - log.error("未处理的异常 ", e); - log.warn("[收到报警通知] 发现未处理的异常, {}\r\n{}",e.getMessage(), evt.getRequest()); + deviceChannelService.updateChannelGPS(device, deviceChannel, mobilePosition); } } - }); + if (!ObjectUtils.isEmpty(deviceAlarm.getDeviceId())) { + if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) { + deviceAlarm.setAlarmType(getText(sipMsgInfo.getRootElement().element("Info"), "AlarmType")); + } + } + if (log.isDebugEnabled()) { + log.debug("[收到报警通知]设备:{}, 内容:{}", device.getDeviceId(), JSON.toJSONString(deviceAlarm)); + } + // 作者自用判断,其他小伙伴需要此消息可以自行修改,但是不要提在pr里 + if (DeviceAlarmMethod.Other.getVal() == Integer.parseInt(deviceAlarm.getAlarmMethod())) { + // 发送给平台的报警信息。 发送redis通知 + log.info("[发送给平台的报警信息]内容:{}", JSONObject.toJSONString(deviceAlarm)); + AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage(); + if (deviceAlarm.getAlarmMethod() != null) { + alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod())); + } + alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription()); + if (deviceAlarm.getAlarmType() != null) { + alarmChannelMessage.setAlarmType(Integer.parseInt(deviceAlarm.getAlarmType())); + } + alarmChannelMessage.setGbId(channelId); + redisCatchStorage.sendAlarmMsg(alarmChannelMessage); + continue; + } + + log.debug("存储报警信息、报警分类"); + // 存储报警信息、报警分类 + if (sipConfig.isAlarm()) { + deviceAlarmService.add(deviceAlarm); + } + + if (redisCatchStorage.deviceIsOnline(sipMsgInfo.getDevice().getDeviceId())) { + publisher.deviceAlarmEventPublish(deviceAlarm); + } + } catch (Exception e) { + log.error("未处理的异常 ", e); + log.warn("[收到报警通知] 发现未处理的异常, {}\r\n{}", e.getMessage(), evt.getRequest()); + } } } @@ -203,7 +217,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme log.error("[命令发送失败] 国标级联 报警通知回复: {}", e.getMessage()); } Element deviceIdElement = rootElement.element("DeviceID"); - String channelId = deviceIdElement.getText().toString(); + String channelId = deviceIdElement.getText(); DeviceAlarm deviceAlarm = new DeviceAlarm(); diff --git a/web_src/src/layout/UiHeader.vue b/web_src/src/layout/UiHeader.vue index 623df322..6912c7fb 100755 --- a/web_src/src/layout/UiHeader.vue +++ b/web_src/src/layout/UiHeader.vue @@ -112,17 +112,25 @@ export default { let that = this; if (this.alarmNotify) { console.log("申请SSE推送API调用,浏览器ID: " + this.$browserId); - this.sseSource = new EventSource('/api/emit?browserId=' + this.$browserId); + let url = (process.env.NODE_ENV === 'development' ? "debug" : "") + 'api/emit?browserId=' + this.$browserId + this.sseSource = new EventSource(url); this.sseSource.addEventListener('message', function (evt) { + console.log("收到信息:" + evt.data); + let data = JSON.parse(evt.data) that.$notify({ title: '报警信息', dangerouslyUseHTMLString: true, - message: evt.data, + message: `设备: ${data.deviceId}` + + `
通道编号: ${ data.channelId}` + + `
报警级别: ${ data.alarmPriorityDescription}` + + `
报警方式: ${ data.alarmMethodDescription}` + + `
报警类型: ${ data.alarmTypeDescription}` + + `
报警时间: ${ data.alarmTime}`, type: 'warning', position: 'bottom-right', duration: 3000 }); - console.log("收到信息:" + evt.data); + }); this.sseSource.addEventListener('open', function (e) { console.log("SSE连接打开.");