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 5574ecbc1..84b3b1fce 100755 --- 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,7 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; import com.genersoft.iot.vmp.gb28181.bean.MobilePosition; import com.genersoft.iot.vmp.gb28181.bean.Platform; import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent; +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.event.subscribe.mobilePosition.MobilePositionEvent; import com.genersoft.iot.vmp.media.bean.MediaServer; @@ -17,10 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @description:Event事件通知推送器,支持推送在线事件、离线事件 @@ -62,11 +60,18 @@ public class EventPublisher { applicationEventPublisher.publishEvent(outEvent); } + public void channelEventPublish(CommonGBChannel deviceChannel, ChannelEvent.ChannelEventMessageType type) { + catalogEventPublish(Collections.singletonList(deviceChannel), type); + } + + private void catalogEventPublish(List channelList, ChannelEvent.ChannelEventMessageType type) { + ChannelEvent channelEvent = ChannelEvent.getInstance(this, type, channelList); + applicationEventPublisher.publishEvent(channelEvent); + } + public void catalogEventPublish(Platform platform, CommonGBChannel deviceChannel, String type) { - List deviceChannelList = new ArrayList<>(); - deviceChannelList.add(deviceChannel); - catalogEventPublish(platform, deviceChannelList, type); + catalogEventPublish(platform, Collections.singletonList(deviceChannel), type); } public void catalogEventPublish(Platform platform, List deviceChannels, String type) { if (platform != null && !userSetting.getServerId().equals(platform.getServerId())) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/channel/ChannelEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/channel/ChannelEvent.java index 9bcdd6139..275ef39e9 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/channel/ChannelEvent.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/channel/ChannelEvent.java @@ -30,69 +30,14 @@ public class ChannelEvent extends ApplicationEvent { - enum ChannelEventMessageType { - ADD, UPDATE, DELETE, ONLINE, OFFLINE, OFFLINE_LIST + public enum ChannelEventMessageType { + ADD, UPDATE, DELETE, ONLINE, OFFLINE, VLOST, DEFECT } - public static ChannelEvent getInstanceForAdd(Object source, CommonGBChannel channel) { - return getInstance(source, ChannelEventMessageType.ADD, channel); - } - - public static ChannelEvent getInstanceForAddList(Object source, List 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 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 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 channel) { - ChannelEvent channelEvent = new ChannelEvent(source); - channelEvent.setMessageType(ChannelEventMessageType.OFFLINE); - channelEvent.setChannels(channel); - return channelEvent; - } - - public static Object getInstanceForDeleteList(Object source, List 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) { + public static ChannelEvent getInstance(Object source, ChannelEventMessageType messageType, List channelList) { ChannelEvent channelEvent = new ChannelEvent(source); channelEvent.setMessageType(messageType); - channelEvent.setChannels(Collections.singletonList(channel)); + channelEvent.setChannels(channelList); return channelEvent; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java index 472370144..261d71281 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java @@ -135,7 +135,8 @@ public class GbChannelServiceImpl implements IGbChannelService { return 0; } // 确定编号是否重复 - if (commonGBChannelMapper.queryByDeviceId(commonGBChannel.getGbDeviceId()).size() > 1) { + List channels = commonGBChannelMapper.queryByDeviceId(commonGBChannel.getGbDeviceId()); + if (channels.size() > 1) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "国标编号重复,请修改编号后保存"); } commonGBChannel.setUpdateTime(DateUtil.getNow()); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java index f0669c8b0..3d66a169b 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java @@ -242,7 +242,6 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { } } } - // 发送消息 try { // 发送catalog