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