From 2c47c8c86b0a685e92b0a605ae6f96901cf10555 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 21 一月 2021 09:24:32 +0800 Subject: [PATCH] Merge pull request #42 from lawrencehj/wvp-28181-2.0 --- web_src/src/main.js | 3 web_src/src/components/ParentPlatformList.vue | 2 src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java | 10 +- src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEvent.java | 26 ++++++ src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java | 32 ++++++++ web_src/src/components/UiHeader.vue | 58 +++++++++++++- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java | 40 +++++++-- README.md | 3 src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java | 14 +++ src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEventListener.java | 47 +++++++++++ 10 files changed, 214 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 5e5eb54..929e85e 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ 16. 鏀寔鐩存帴杈撳嚭RTSP銆丷TMP銆丠TTP-FLV銆乄ebsocket-FLV銆丠LS澶氱鍗忚娴佸湴鍧� 17. 鏀寔鍥芥爣缃戠粶鏍℃椂 18. 鏀寔鍏綉閮ㄧ讲, 鏀寔wvp涓巣lm鍒嗗紑閮ㄧ讲 -19. 鏀寔鎾斁h265, g.711鏍煎紡鐨勬祦(闇�瑕佸皢closeWaitRTPInfo璁句负false). +19. 鏀寔鎾斁h265, g.711鏍煎紡鐨勬祦(闇�瑕佸皢closeWaitRTPInfo璁句负false) +20. 鎶ヨ淇℃伅澶勭悊锛屾敮鎸佸悜鍓嶇鎺ㄩ�佹姤璀︿俊鎭� # 2.0 鏀寔鐗规�� - [ ] 鍥芥爣閫氶亾鍚戜笂绾ц仈 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 d91a1c7..35cb6bf 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 @@ -11,7 +11,7 @@ /** * 鎶ヨ绾у埆, 1涓轰竴绾ц鎯�, 2涓轰簩绾ц鎯�, 3涓轰笁绾ц鎯�, 4涓哄洓绾� 璀︽儏- */ - private String alarmPriorit; + private String alarmPriority; /** * 鎶ヨ鏂瑰紡 , 1涓虹數璇濇姤璀�, 2涓鸿澶囨姤璀�, 3涓虹煭淇℃姤璀�, 4涓� GPS鎶ヨ, 5涓鸿棰戞姤璀�, 6涓鸿澶囨晠闅滄姤璀�, @@ -53,12 +53,12 @@ this.deviceId = deviceId; } - public String getAlarmPriorit() { - return alarmPriorit; + public String getAlarmPriority() { + return alarmPriority; } - public void setAlarmPriorit(String alarmPriorit) { - this.alarmPriorit = alarmPriorit; + public void setAlarmPriority(String alarmPriority) { + this.alarmPriority = alarmPriority; } public String getAlarmMethod() { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java index 29f859d..c796a4a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java @@ -6,6 +6,8 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Component; +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; +import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent; import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent; import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent; @@ -52,5 +54,15 @@ PlatformNotRegisterEvent platformNotRegisterEvent = new PlatformNotRegisterEvent(this); platformNotRegisterEvent.setPlatformGbID(platformGbId); applicationEventPublisher.publishEvent(platformNotRegisterEvent); - } + } + + /** + * 璁惧鎶ヨ浜嬩欢 + * @param deviceAlarm + */ + public void deviceAlarmEventPublish(DeviceAlarm deviceAlarm) { + AlarmEvent alarmEvent = new AlarmEvent(this); + alarmEvent.setAlarmInfo(deviceAlarm); + applicationEventPublisher.publishEvent(alarmEvent); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEvent.java new file mode 100644 index 0000000..fecc8b1 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEvent.java @@ -0,0 +1,26 @@ +package com.genersoft.iot.vmp.gb28181.event.alarm; + +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; +import org.springframework.context.ApplicationEvent; + +/** + * @description: 鎶ヨ浜嬩欢 + * @author: lawrencehj + * @data: 2021-01-20 + */ + +public class AlarmEvent extends ApplicationEvent { + public AlarmEvent(Object source) { + super(source); + } + + private DeviceAlarm deviceAlarm; + + public DeviceAlarm getAlarmInfo() { + return deviceAlarm; + } + + public void setAlarmInfo(DeviceAlarm deviceAlarm) { + this.deviceAlarm = deviceAlarm; + } +} 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 new file mode 100644 index 0000000..1b2f672 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEventListener.java @@ -0,0 +1,47 @@ +package com.genersoft.iot.vmp.gb28181.event.alarm; + +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; +import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @description: 鎶ヨ浜嬩欢鐩戝惉 + * @author: lawrencehj + * @data: 2021-01-20 + */ + +@Component +public class AlarmEventListener implements ApplicationListener<AlarmEvent> { + + private final static Logger logger = LoggerFactory.getLogger(AlarmEventListener.class); + + private static SseEmitter emitter = new SseEmitter(); + + public void addSseEmitters(SseEmitter sseEmitter) { + emitter = sseEmitter; + } + + @Override + public void onApplicationEvent(AlarmEvent event) { + if (logger.isDebugEnabled()) { + logger.debug("璁惧鎶ヨ浜嬩欢瑙﹀彂锛宒eviceId锛�" + event.getAlarmInfo().getDeviceId() + ", " + + event.getAlarmInfo().getAlarmDescription()); + } + try { + String msg = "<strong>璁惧缂栫爜锛�</strong> <i>" + event.getAlarmInfo().getDeviceId() + "</i>" + + "<br><strong>鎶ヨ鎻忚堪锛�</strong> <i>" + event.getAlarmInfo().getAlarmDescription() + "</i>" + + "<br><strong>鎶ヨ鏃堕棿锛�</strong> <i>" + event.getAlarmInfo().getAlarmTime() + "</i>" + + "<br><strong>瀹氫綅缁忓害锛�</strong> <i>" + event.getAlarmInfo().getLongitude() + "</i>" + + "<br><strong>瀹氫綅绾害锛�</strong> <i>" + event.getAlarmInfo().getLatitude() + "</i>"; + emitter.send(msg); + } catch (IOException e) { + if (logger.isDebugEnabled()) { + logger.debug("SSE 閫氶亾宸插叧闂�"); + } + // e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java index 06c4d68..22ed34a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java @@ -174,7 +174,7 @@ SipUri uri = (SipUri) address.getURI(); String platformId = uri.getUser(); // if (deviceListElement == null) { // 瀛樺湪DeviceList鍒欎负鍝嶅簲 catalog锛� 涓嶅瓨鍦―eviceList鍒欎负鏌ヨ璇锋眰 - if (name == "Query") { // 鍖哄垎鏄疪esponse鈥斺�旀煡璇㈠搷搴旓紝杩樻槸Query鈥斺�旀煡璇㈣姹� + if (name.equalsIgnoreCase("Query")) { // 鍖哄垎鏄疪esponse鈥斺�旀煡璇㈠搷搴旓紝杩樻槸Query鈥斺�旀煡璇㈣姹� // TODO 鍚庣画灏嗕唬鐮佹媶鍒� ParentPlatform parentPlatform = storager.queryParentPlatById(platformId); if (parentPlatform == null) { @@ -324,19 +324,41 @@ // storager.queryChannel(deviceId) return; } - device.setName(XmlUtil.getText(rootElement, "DeviceName")); - device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer")); - device.setModel(XmlUtil.getText(rootElement, "Model")); - device.setFirmware(XmlUtil.getText(rootElement, "Firmware")); - if (StringUtils.isEmpty(device.getStreamMode())) { - device.setStreamMode("UDP"); + + DeviceAlarm deviceAlarm = new DeviceAlarm(); + deviceAlarm.setDeviceId(deviceId); + deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority")); + deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod")); + deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime")); + if (XmlUtil.getText(rootElement, "AlarmDescription") == null) { + deviceAlarm.setAlarmDescription(""); + } else { + deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription")); } - storager.updateDevice(device); + if (XmlUtil.getText(rootElement, "Longitude") == null || XmlUtil.getText(rootElement, "Longitude") == "") { + deviceAlarm.setLongitude(0.00); + } else { + deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude"))); + } + if (XmlUtil.getText(rootElement, "Latitude") == null || XmlUtil.getText(rootElement, "Latitude") =="") { + deviceAlarm.setLatitude(0.00); + } else { + deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude"))); + } + + // device.setName(XmlUtil.getText(rootElement, "DeviceName")); + // device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer")); + // device.setModel(XmlUtil.getText(rootElement, "Model")); + // device.setFirmware(XmlUtil.getText(rootElement, "Firmware")); + // if (StringUtils.isEmpty(device.getStreamMode())) { + // device.setStreamMode("UDP"); + // } + // storager.updateDevice(device); //cmder.catalogQuery(device, null); // 鍥炲200 OK responseAck(evt); if (offLineDetector.isOnline(deviceId)) { - publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); + publisher.deviceAlarmEventPublish(deviceAlarm); } } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { // } catch (DocumentException e) { diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java new file mode 100644 index 0000000..689b967 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java @@ -0,0 +1,32 @@ +package com.genersoft.iot.vmp.vmanager.SEEController; + +import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEventListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; + +/** + * @description: SSE鎺ㄩ�� + * @author: lawrencehj + * @data: 2021-01-20 + */ + +@Controller +@RequestMapping("/api") +public class SEEController { + @Autowired + AlarmEventListener alarmEventListener; + + //璁剧疆鍝嶅簲 + @RequestMapping("/emit") + public SseEmitter emit() { + SseEmitter sseEmitter = new SseEmitter(0L); + try { + alarmEventListener.addSseEmitters(sseEmitter); + }catch (Exception e){ + sseEmitter.completeWithError(e); + } + return sseEmitter; + } +} diff --git a/web_src/src/components/ParentPlatformList.vue b/web_src/src/components/ParentPlatformList.vue index 37b8b8f..298504b 100644 --- a/web_src/src/components/ParentPlatformList.vue +++ b/web_src/src/components/ParentPlatformList.vue @@ -137,7 +137,7 @@ }); }, chooseChannel: function(platform) { - this.$refs.chooseChannelDialog.openDialog(platform.deviceGBId, ()=>{ + this.$refs.chooseChannelDialog.openDialog(platform.serverGBId, ()=>{ this.initData() }) }, diff --git a/web_src/src/components/UiHeader.vue b/web_src/src/components/UiHeader.vue index fa57b26..17a6880 100644 --- a/web_src/src/components/UiHeader.vue +++ b/web_src/src/components/UiHeader.vue @@ -3,7 +3,8 @@ <el-menu router :default-active="this.$route.path" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" mode="horizontal"> <el-menu-item index="/">鎺у埗鍙�</el-menu-item> <el-menu-item index="/videoList">璁惧鍒楄〃</el-menu-item> - <el-menu-item index="/parentPlatformList/15/1">鍥芥爣绾ц仈</el-menu-item> + <el-menu-item index="/parentPlatformList/15/1">鍥芥爣绾ц仈</el-menu-item> + <el-switch v-model="alarmNotify" active-text="鎶ヨ淇℃伅鎺ㄩ��" style="display: block float: right" @change="sseControl"></el-switch> <el-menu-item style="float: right;" @click="loginout">閫�鍑�</el-menu-item> </el-menu> </div> @@ -12,14 +13,63 @@ <script> export default { name: "UiHeader", + components: { Notification }, + data() { + return { + alarmNotify: true, + sseSource: null, + }; + }, methods:{ - loginout(){ // 鍒犻櫎cookie锛屽洖鍒扮櫥褰曢〉闈� this.$cookies.remove("session"); this.$router.push('/login'); + this.sseSource.close(); }, - } -} + beforeunloadHandler() { + this.sseSource.close(); + }, + sseControl() { + let that = this; + if (this.alarmNotify) { + this.sseSource = new EventSource('/api/emit'); + this.sseSource.addEventListener('message', function(evt) { + that.$notify({ + title: '鏀跺埌鎶ヨ淇℃伅', + dangerouslyUseHTMLString: true, + message: evt.data, + type: 'warning' + }); + console.log("鏀跺埌淇℃伅锛�" + evt.data); + }); + this.sseSource.addEventListener('open', function(e) { + console.log("SSE杩炴帴鎵撳紑."); + }, false); + this.sseSource.addEventListener('error', function(e) { + if (e.target.readyState == EventSource.CLOSED) { + console.log("SSE杩炴帴鍏抽棴"); + } else { + console.log(e.target.readyState); + } + }, false); + } else { + this.sseSource.removeEventListener('open', null); + this.sseSource.removeEventListener('message', null); + this.sseSource.removeEventListener('error', null); + this.sseSource.close(); + } + } + }, + mounted() { + window.addEventListener('beforeunload', e => this.beforeunloadHandler(e)) + // window.addEventListener('unload', e => this.unloadHandler(e)) + this.sseControl(); + }, + destroyed() { + window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e)) + // window.removeEventListener('unload', e => this.unloadHandler(e)) + }, + } </script> diff --git a/web_src/src/main.js b/web_src/src/main.js index 6f88c2a..ae2baee 100644 --- a/web_src/src/main.js +++ b/web_src/src/main.js @@ -9,10 +9,13 @@ import echarts from 'echarts'; import VueClipboard from 'vue-clipboard2' +import { Notification } from 'element-ui'; + Vue.use(VueClipboard) Vue.use(ElementUI); Vue.use(VueCookies); Vue.prototype.$axios = axios; +Vue.prototype.$notify = Notification; axios.defaults.baseURL = (process.env.NODE_ENV === 'development') ? process.env.BASE_API : ""; -- Gitblit v1.8.0