临时提交

This commit is contained in:
lin
2025-10-17 15:19:21 +08:00
parent dd0a760d8a
commit 87afbe3f89
6 changed files with 183 additions and 8 deletions

View File

@@ -0,0 +1,99 @@
package com.genersoft.iot.vmp.gb28181.event.channel;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.ApplicationEvent;
import java.io.Serial;
import java.util.Collections;
import java.util.List;
/**
* 通道事件
*/
@Setter
@Getter
public class ChannelEvent extends ApplicationEvent {
@Serial
private static final long serialVersionUID = 1L;
public ChannelEvent(Object source) {
super(source);
}
private List<CommonGBChannel> channels;
private ChannelEventMessageType messageType;
enum ChannelEventMessageType {
ADD, UPDATE, DELETE, ONLINE, OFFLINE, OFFLINE_LIST
}
public static ChannelEvent getInstanceForAdd(Object source, CommonGBChannel channel) {
return getInstance(source, ChannelEventMessageType.ADD, channel);
}
public static ChannelEvent getInstanceForAddList(Object source, List<CommonGBChannel> channels) {
ChannelEvent channelEvent = new ChannelEvent(source);
channelEvent.setMessageType(ChannelEventMessageType.ADD);
channelEvent.setChannels(channels);
return channelEvent;
}
public static ChannelEvent getInstanceForUpdate(Object source, CommonGBChannel channel) {
return getInstance(source, ChannelEventMessageType.UPDATE, channel);
}
public static ChannelEvent getInstanceForUpdateList(Object source, List<CommonGBChannel> channels) {
ChannelEvent channelEvent = new ChannelEvent(source);
channelEvent.setMessageType(ChannelEventMessageType.UPDATE);
channelEvent.setChannels(channels);
return channelEvent;
}
public static ChannelEvent getInstanceForDelete(Object source, CommonGBChannel channel) {
return getInstance(source, ChannelEventMessageType.DELETE, channel);
}
public static ChannelEvent getInstanceForOnline(Object source, CommonGBChannel channel) {
return getInstance(source, ChannelEventMessageType.ONLINE, channel);
}
public static ChannelEvent getInstanceForOnlineList(Object source, List<CommonGBChannel> channels) {
ChannelEvent channelEvent = new ChannelEvent(source);
channelEvent.setMessageType(ChannelEventMessageType.ONLINE);
channelEvent.setChannels(channels);
return channelEvent;
}
public static ChannelEvent getInstanceForOffline(Object source, CommonGBChannel channel) {
return getInstance(source, ChannelEventMessageType.OFFLINE, channel);
}
public static ChannelEvent getInstanceForOfflineList(Object source, List<CommonGBChannel> channel) {
ChannelEvent channelEvent = new ChannelEvent(source);
channelEvent.setMessageType(ChannelEventMessageType.OFFLINE);
channelEvent.setChannels(channel);
return channelEvent;
}
public static Object getInstanceForDeleteList(Object source, List<CommonGBChannel> commonGBChannels) {
ChannelEvent channelEvent = new ChannelEvent(source);
channelEvent.setMessageType(ChannelEventMessageType.DELETE);
channelEvent.setChannels(commonGBChannels);
return channelEvent;
}
private static ChannelEvent getInstance(Object source, ChannelEventMessageType messageType, CommonGBChannel channel) {
ChannelEvent channelEvent = new ChannelEvent(source);
channelEvent.setMessageType(messageType);
channelEvent.setChannels(Collections.singletonList(channel));
return channelEvent;
}
}

View File

@@ -11,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.dao.DeviceChannelMapper;
import com.genersoft.iot.vmp.gb28181.dao.DeviceMapper;
import com.genersoft.iot.vmp.gb28181.dao.PlatformChannelMapper;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.event.channel.ChannelEvent;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.gb28181.service.IDeviceService;
import com.genersoft.iot.vmp.gb28181.service.IInviteStreamService;
@@ -43,6 +44,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@@ -120,6 +122,9 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
@Autowired
private DeviceStatusTaskRunner deviceStatusTaskRunner;
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
private Device getDeviceByDeviceIdFromDb(String deviceId) {
return deviceMapper.getDeviceByDeviceId(deviceId);
}
@@ -356,7 +361,6 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
// 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, true);
}
}else {
deviceMapper.update(device);
redisCatchStorage.updateDevice(device);
@@ -424,6 +428,8 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
deviceChannelMapper.offlineByDeviceId(device.getId());
// 发送通道离线通知
eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.OFF);
// 发送离线通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOfflineList(this, channelList));
}
private boolean isDevice(String deviceId) {
@@ -824,6 +830,10 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
if (deviceStatusTaskRunner.containsKey(deviceId)) {
deviceStatusTaskRunner.removeTask(deviceId);
}
List<CommonGBChannel> commonGBChannels = commonGBChannelMapper.queryByGbDeviceIds(1, List.of(device.getId()));
// 发送删除通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForDeleteList(this, commonGBChannels));
platformChannelMapper.delChannelForDeviceId(deviceId);
deviceChannelMapper.cleanChannelsByDeviceId(device.getId());
deviceMapper.del(deviceId);

View File

@@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.gb28181.dao.GroupMapper;
import com.genersoft.iot.vmp.gb28181.dao.PlatformChannelMapper;
import com.genersoft.iot.vmp.gb28181.dao.RegionMapper;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.event.channel.ChannelEvent;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.gb28181.service.IGbChannelService;
import com.genersoft.iot.vmp.gb28181.service.IPlatformChannelService;
@@ -20,6 +21,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
@@ -51,6 +53,9 @@ public class GbChannelServiceImpl implements IGbChannelService {
@Autowired
private GroupMapper groupMapper;
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
@Override
public CommonGBChannel queryByDeviceId(String gbDeviceId) {
return commonGBChannelMapper.queryByDeviceId(gbDeviceId);
@@ -69,7 +74,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
commonGBChannel.setUpdateTime(DateUtil.getNow());
int result = commonGBChannelMapper.insert(commonGBChannel);
// 发送通道新增通知
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForAdd(this, commonGBChannel));
return result;
}
@@ -92,6 +98,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
} catch (Exception e) {
log.warn("[通道移除通知] 发送失败,{}", channel.getGbDeviceId(), e);
}
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForDelete(this, channel));
}
return 1;
}
@@ -109,6 +117,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
if (channelListInDb.isEmpty()) {
return;
}
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForDeleteList(this, channelListInDb));
commonGBChannelMapper.batchDelete(channelListInDb);
}
@@ -123,6 +133,9 @@ public class GbChannelServiceImpl implements IGbChannelService {
int result = commonGBChannelMapper.update(commonGBChannel);
if (result > 0) {
try {
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForUpdate(this, commonGBChannel));
// 发送通知
eventPublisher.catalogEventPublish(null, commonGBChannel, CatalogEvent.UPDATE);
} catch (Exception e) {
@@ -141,6 +154,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
int result = commonGBChannelMapper.updateStatusById(commonGBChannel.getGbId(), "OFF");
if (result > 0) {
try {
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOffline(this, commonGBChannel));
// 发送通知
eventPublisher.catalogEventPublish(null, commonGBChannel, CatalogEvent.OFF);
} catch (Exception e) {
@@ -158,6 +173,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
return 0;
}
log.info("[通道离线] 共 {} 个", commonGBChannelList.size());
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOfflineList(this, commonGBChannelList));
int limitCount = 1000;
int result = 0;
if (commonGBChannelList.size() > limitCount) {
@@ -191,6 +208,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
int result = commonGBChannelMapper.updateStatusById(commonGBChannel.getGbId(), "ON");
if (result > 0) {
try {
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOnline(this, commonGBChannel));
// 发送通知
eventPublisher.catalogEventPublish(null, commonGBChannel, CatalogEvent.ON);
} catch (Exception e) {
@@ -222,6 +241,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
result += commonGBChannelMapper.updateStatusForListById(commonGBChannelList, "ON");
}
try {
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOnlineList(this, commonGBChannelList));
// 发送catalog
eventPublisher.catalogEventPublish(null, commonGBChannelList, CatalogEvent.ON);
} catch (Exception e) {
@@ -252,6 +273,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
} else {
result += commonGBChannelMapper.batchAdd(commonGBChannels);
}
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForAddList(this, commonGBChannels));
log.warn("[新增多个通道] 通道数量为{},成功保存:{}", commonGBChannels.size(), result);
}
@@ -278,6 +301,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
log.info("[更新多个通道] 通道数量为{},成功保存:{}", commonGBChannels.size(), result);
// 发送通过更新通知
try {
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForUpdateList(this, commonGBChannels));
// 发送通知
eventPublisher.catalogEventPublish(null, commonGBChannels, CatalogEvent.UPDATE);
} catch (Exception e) {
@@ -308,6 +333,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
log.warn("[更新多个通道状态] 通道数量为{},成功保存:{}", commonGBChannels.size(), result);
// 发送通过更新通知
try {
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForUpdateList(this, commonGBChannels));
// 发送通知
eventPublisher.catalogEventPublish(null, commonGBChannels, CatalogEvent.UPDATE);
} catch (Exception e) {
@@ -372,6 +399,10 @@ public class GbChannelServiceImpl implements IGbChannelService {
CommonGBChannel channelNew = getOne(id);
// 发送通过更新通知
try {
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForUpdate(this, channelNew));
// 发送通知
eventPublisher.catalogEventPublish(null, channelNew, CatalogEvent.UPDATE);
} catch (Exception e) {
@@ -558,6 +589,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
}
// 发送catalog
try {
// 发送通知
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForUpdateList(this, channelList));
eventPublisher.catalogEventPublish(null, channelList, CatalogEvent.UPDATE);
} catch (Exception e) {
log.warn("[多个通道业务分组] 发送失败,数量:{}", channelList.size(), e);

View File

@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.event.channel.ChannelEvent;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
@@ -14,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -50,6 +52,9 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
@Autowired
private IDeviceChannelService deviceChannelService;
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
// @Scheduled(fixedRate = 2000) //每400毫秒执行一次
// public void showSize(){
// log.warn("[notify-目录订阅] 待处理消息数量: {}", taskQueue.size() );
@@ -145,6 +150,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
log.info("[收到通道上线通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
channel.setStatus("ON");
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.STATUS_CHANGED, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOnline(this, channel));
if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), true);
@@ -158,6 +167,9 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
} else {
channel.setStatus("OFF");
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.STATUS_CHANGED, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOffline(this, channel));
if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), false);
@@ -172,6 +184,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
} else {
channel.setStatus("OFF");
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.STATUS_CHANGED, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOffline(this, channel));
if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), false);
@@ -186,6 +202,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
} else {
channel.setStatus("OFF");
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.STATUS_CHANGED, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForOffline(this, channel));
if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), false);
@@ -203,10 +223,17 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
channel.setHasAudio(deviceChannel.isHasAudio());
channel.setUpdateTime(DateUtil.getNow());
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.UPDATE, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForUpdate(this, channel));
} else {
catalogChannelEvent.getChannel().setUpdateTime(DateUtil.getNow());
catalogChannelEvent.getChannel().setCreateTime(DateUtil.getNow());
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.ADD, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForAdd(this, channel));
if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息
redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), true);
@@ -218,6 +245,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
// 删除
log.info("[收到删除通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.DELETE, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForDelete(this, channel));
if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息
redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), false);
@@ -234,10 +265,17 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
channel.setUpdateTime(DateUtil.getNow());
channel.setUpdateTime(DateUtil.getNow());
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.UPDATE, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForUpdate(this, channel));
} else {
catalogChannelEvent.getChannel().setCreateTime(DateUtil.getNow());
catalogChannelEvent.getChannel().setUpdateTime(DateUtil.getNow());
channelList.add(NotifyCatalogChannel.getInstance(NotifyCatalogChannel.Type.ADD, channel));
// 发送通道修改消息
applicationEventPublisher.publishEvent(ChannelEvent.getInstanceForAdd(this, channel));
if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息
redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), true);

View File

@@ -18,9 +18,4 @@ public class CameraChannel extends CommonGBChannel {
@Setter
@Schema(description = "图标路径")
private String icon;
@Getter
@Setter
@Schema(description = "移动设备唯一编号")
private Long unitNo;
}

View File

@@ -295,7 +295,7 @@ export default {
}
}
cameraList.push(cameraData)
if (item.mapLevel) {
if (item.mapLevel) {
if (cameraListForLevelMap.has(item.mapLevel)) {
let list = cameraListForLevelMap.get(item.mapLevel)
list.push(cameraData)