EventPublisher.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package com.genersoft.iot.vmp.gb28181.event;
  2. import com.genersoft.iot.vmp.gb28181.bean.*;
  3. import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent;
  4. import com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire.PlatformKeepaliveExpireEvent;
  5. import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformCycleRegisterEvent;
  6. import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent;
  7. import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEvent;
  8. import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
  9. import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
  10. import com.genersoft.iot.vmp.media.zlm.event.ZLMOnlineEvent;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.context.ApplicationEventPublisher;
  13. import org.springframework.scheduling.annotation.Async;
  14. import org.springframework.stereotype.Component;
  15. import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent;
  16. import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent;
  17. import java.util.ArrayList;
  18. import java.util.HashSet;
  19. import java.util.List;
  20. import java.util.Set;
  21. /**
  22. * @description:Event事件通知推送器,支持推送在线事件、离线事件
  23. * @author: swwheihei
  24. * @date: 2020年5月6日 上午11:30:50
  25. */
  26. @Component
  27. public class EventPublisher {
  28. @Autowired
  29. private ApplicationEventPublisher applicationEventPublisher;
  30. public void onlineEventPublish(Device device, String from, int expires) {
  31. OnlineEvent onEvent = new OnlineEvent(this);
  32. onEvent.setDevice(device);
  33. onEvent.setFrom(from);
  34. onEvent.setExpires(expires);
  35. applicationEventPublisher.publishEvent(onEvent);
  36. }
  37. public void onlineEventPublish(Device device, String from) {
  38. OnlineEvent onEvent = new OnlineEvent(this);
  39. onEvent.setDevice(device);
  40. onEvent.setFrom(from);
  41. applicationEventPublisher.publishEvent(onEvent);
  42. }
  43. public void outlineEventPublish(String deviceId, String from){
  44. OfflineEvent outEvent = new OfflineEvent(this);
  45. outEvent.setDeviceId(deviceId);
  46. outEvent.setFrom(from);
  47. applicationEventPublisher.publishEvent(outEvent);
  48. }
  49. /**
  50. * 平台心跳到期事件
  51. * @param platformGbId
  52. */
  53. public void platformKeepaliveExpireEventPublish(String platformGbId){
  54. PlatformKeepaliveExpireEvent platformNotRegisterEvent = new PlatformKeepaliveExpireEvent(this);
  55. platformNotRegisterEvent.setPlatformGbID(platformGbId);
  56. applicationEventPublisher.publishEvent(platformNotRegisterEvent);
  57. }
  58. /**
  59. * 平台未注册事件
  60. * @param platformGbId
  61. */
  62. public void platformNotRegisterEventPublish(String platformGbId){
  63. PlatformNotRegisterEvent platformNotRegisterEvent = new PlatformNotRegisterEvent(this);
  64. platformNotRegisterEvent.setPlatformGbID(platformGbId);
  65. applicationEventPublisher.publishEvent(platformNotRegisterEvent);
  66. }
  67. /**
  68. * 平台周期注册事件
  69. * @param paltformGbId
  70. */
  71. public void platformRegisterCycleEventPublish(String paltformGbId) {
  72. PlatformCycleRegisterEvent platformCycleRegisterEvent = new PlatformCycleRegisterEvent(this);
  73. platformCycleRegisterEvent.setPlatformGbID(paltformGbId);
  74. applicationEventPublisher.publishEvent(platformCycleRegisterEvent);
  75. }
  76. /**
  77. * 设备报警事件
  78. * @param deviceAlarm
  79. */
  80. public void deviceAlarmEventPublish(DeviceAlarm deviceAlarm) {
  81. AlarmEvent alarmEvent = new AlarmEvent(this);
  82. alarmEvent.setAlarmInfo(deviceAlarm);
  83. applicationEventPublisher.publishEvent(alarmEvent);
  84. }
  85. public void zlmOfflineEventPublish(String mediaServerId){
  86. ZLMOfflineEvent outEvent = new ZLMOfflineEvent(this);
  87. outEvent.setMediaServerId(mediaServerId);
  88. applicationEventPublisher.publishEvent(outEvent);
  89. }
  90. public void zlmOnlineEventPublish(String mediaServerId) {
  91. ZLMOnlineEvent outEvent = new ZLMOnlineEvent(this);
  92. outEvent.setMediaServerId(mediaServerId);
  93. applicationEventPublisher.publishEvent(outEvent);
  94. }
  95. public void catalogEventPublish(String platformId, DeviceChannel deviceChannel, String type) {
  96. List<DeviceChannel> deviceChannelList = new ArrayList<>();
  97. deviceChannelList.add(deviceChannel);
  98. catalogEventPublish(platformId, deviceChannelList, type);
  99. }
  100. /**
  101. *
  102. * @param platformId
  103. * @param deviceChannels
  104. * @param type
  105. */
  106. public void catalogEventPublish(String platformId, List<DeviceChannel> deviceChannels, String type) {
  107. CatalogEvent outEvent = new CatalogEvent(this);
  108. List<DeviceChannel> channels = new ArrayList<>();
  109. if (deviceChannels.size() > 1) {
  110. // 数据去重
  111. Set<String> gbIdSet = new HashSet<>();
  112. for (DeviceChannel deviceChannel : deviceChannels) {
  113. if (!gbIdSet.contains(deviceChannel.getChannelId())) {
  114. gbIdSet.add(deviceChannel.getChannelId());
  115. channels.add(deviceChannel);
  116. }
  117. }
  118. }else {
  119. channels = deviceChannels;
  120. }
  121. outEvent.setDeviceChannels(channels);
  122. outEvent.setType(type);
  123. outEvent.setPlatformId(platformId);
  124. applicationEventPublisher.publishEvent(outEvent);
  125. }
  126. public void catalogEventPublishForStream(String platformId, List<GbStream> gbStreams, String type) {
  127. CatalogEvent outEvent = new CatalogEvent(this);
  128. outEvent.setGbStreams(gbStreams);
  129. outEvent.setType(type);
  130. outEvent.setPlatformId(platformId);
  131. applicationEventPublisher.publishEvent(outEvent);
  132. }
  133. public void catalogEventPublishForStream(String platformId, GbStream gbStream, String type) {
  134. List<GbStream> gbStreamList = new ArrayList<>();
  135. gbStreamList.add(gbStream);
  136. catalogEventPublishForStream(platformId, gbStreamList, type);
  137. }
  138. public void recordEndEventPush(RecordInfo recordInfo) {
  139. RecordEndEvent outEvent = new RecordEndEvent(this);
  140. outEvent.setRecordInfo(recordInfo);
  141. applicationEventPublisher.publishEvent(outEvent);
  142. }
  143. }