[国标级联] 优化catalog推送代码

master
648540858 2025-01-03 15:10:02 +08:00
parent b37c0e264c
commit cb7c41c3c1
7 changed files with 43 additions and 47 deletions

View File

@ -58,8 +58,8 @@ public interface PlatformChannelMapper {
"where dc.channel_type = 0 and dc.channel_id = #{channelId} and pgc.platform_id=#{platformId}") "where dc.channel_type = 0 and dc.channel_id = #{channelId} and pgc.platform_id=#{platformId}")
List<Device> queryDeviceInfoByPlatformIdAndChannelId(@Param("platformId") String platformId, @Param("channelId") String channelId); List<Device> queryDeviceInfoByPlatformIdAndChannelId(@Param("platformId") String platformId, @Param("channelId") String channelId);
@Select("SELECT pgc.platform_id from wvp_platform_channel pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE dc.channel_type = 0 and dc.device_id=#{channelId}") @Select("SELECT pgc.* from wvp_platform_channel pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE dc.channel_type = 0 and dc.device_id=#{channelId}")
List<Integer> queryParentPlatformByChannelId(@Param("channelId") String channelId); List<Platform> queryParentPlatformByChannelId(@Param("channelId") String channelId);
@Select("<script>" + @Select("<script>" +
" select " + " select " +

View File

@ -53,27 +53,19 @@ public class EventPublisher {
} }
public void catalogEventPublish(Integer platformId, CommonGBChannel deviceChannel, String type) {
List<CommonGBChannel> deviceChannelList = new ArrayList<>();
deviceChannelList.add(deviceChannel);
catalogEventPublish(platformId, deviceChannelList, type);
}
public void requestTimeOut(TimeoutEvent timeoutEvent) { public void requestTimeOut(TimeoutEvent timeoutEvent) {
RequestTimeoutEvent requestTimeoutEvent = new RequestTimeoutEvent(this); RequestTimeoutEvent requestTimeoutEvent = new RequestTimeoutEvent(this);
requestTimeoutEvent.setTimeoutEvent(timeoutEvent); requestTimeoutEvent.setTimeoutEvent(timeoutEvent);
applicationEventPublisher.publishEvent(requestTimeoutEvent); applicationEventPublisher.publishEvent(requestTimeoutEvent);
} }
public void catalogEventPublish(Platform platform, CommonGBChannel deviceChannel, String type) {
List<CommonGBChannel> deviceChannelList = new ArrayList<>();
deviceChannelList.add(deviceChannel);
catalogEventPublish(platform, deviceChannelList, type);
}
/** public void catalogEventPublish(Platform platform, List<CommonGBChannel> deviceChannels, String type) {
*
* @param platformId
* @param deviceChannels
* @param type
*/
public void catalogEventPublish(Integer platformId, List<CommonGBChannel> deviceChannels, String type) {
CatalogEvent outEvent = new CatalogEvent(this); CatalogEvent outEvent = new CatalogEvent(this);
List<CommonGBChannel> channels = new ArrayList<>(); List<CommonGBChannel> channels = new ArrayList<>();
if (deviceChannels.size() > 1) { if (deviceChannels.size() > 1) {
@ -90,11 +82,10 @@ public class EventPublisher {
} }
outEvent.setChannels(channels); outEvent.setChannels(channels);
outEvent.setType(type); outEvent.setType(type);
outEvent.setPlatformId(platformId); outEvent.setPlatform(platform);
applicationEventPublisher.publishEvent(outEvent); applicationEventPublisher.publishEvent(outEvent);
} }
public void mobilePositionEventPublish(MobilePosition mobilePosition) { public void mobilePositionEventPublish(MobilePosition mobilePosition) {
MobilePositionEvent event = new MobilePositionEvent(this); MobilePositionEvent event = new MobilePositionEvent(this);
event.setMobilePosition(mobilePosition); event.setMobilePosition(mobilePosition);

View File

@ -1,12 +1,15 @@
package com.genersoft.iot.vmp.gb28181.event.subscribe.catalog; package com.genersoft.iot.vmp.gb28181.event.subscribe.catalog;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.Platform;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import java.util.List; import java.util.List;
@Setter
@Getter
public class CatalogEvent extends ApplicationEvent { public class CatalogEvent extends ApplicationEvent {
public CatalogEvent(Object source) { public CatalogEvent(Object source) {
@ -48,16 +51,10 @@ public class CatalogEvent extends ApplicationEvent {
*/ */
public static final String UPDATE = "UPDATE"; public static final String UPDATE = "UPDATE";
@Setter
@Getter
private List<CommonGBChannel> channels; private List<CommonGBChannel> channels;
@Setter
@Getter
private String type; private String type;
@Setter private Platform platform;
@Getter
private Integer platformId;
} }

View File

@ -46,11 +46,8 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
Map<String, List<Platform>> parentPlatformMap = new HashMap<>(); Map<String, List<Platform>> parentPlatformMap = new HashMap<>();
Map<String, CommonGBChannel> channelMap = new HashMap<>(); Map<String, CommonGBChannel> channelMap = new HashMap<>();
if (event.getPlatformId() != null) { if (event.getPlatform() != null) {
parentPlatform = platformService.queryOne(event.getPlatformId()); parentPlatform = event.getPlatform();
if (parentPlatform == null) {
return;
}
subscribe = subscribeHolder.getCatalogSubscribe(parentPlatform.getServerGBId()); subscribe = subscribeHolder.getCatalogSubscribe(parentPlatform.getServerGBId());
if (subscribe == null) { if (subscribe == null) {
return; return;

View File

@ -7,10 +7,7 @@ import com.genersoft.iot.vmp.common.InviteSessionType;
import com.genersoft.iot.vmp.common.enums.ChannelDataType; import com.genersoft.iot.vmp.common.enums.ChannelDataType;
import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.GbCode;
import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce; import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce;
import com.genersoft.iot.vmp.gb28181.dao.DeviceChannelMapper; import com.genersoft.iot.vmp.gb28181.dao.DeviceChannelMapper;
import com.genersoft.iot.vmp.gb28181.dao.DeviceMapper; import com.genersoft.iot.vmp.gb28181.dao.DeviceMapper;
@ -507,10 +504,10 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
deviceChannel.setHasAudio(channelInDb.isHasAudio()); deviceChannel.setHasAudio(channelInDb.isHasAudio());
deviceChannel.setId(channelInDb.getId()); deviceChannel.setId(channelInDb.getId());
if (channelInDb.getStatus() != null && channelInDb.getStatus().equalsIgnoreCase(deviceChannel.getStatus())){ if (channelInDb.getStatus() != null && channelInDb.getStatus().equalsIgnoreCase(deviceChannel.getStatus())){
List<Integer> ids = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getDeviceId()); List<Platform> platformList = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getDeviceId());
if (!CollectionUtils.isEmpty(ids)){ if (!CollectionUtils.isEmpty(platformList)){
ids.forEach(platformId->{ platformList.forEach(platform->{
eventPublisher.catalogEventPublish(platformId, deviceChannel, deviceChannel.getStatus().equals("ON")? CatalogEvent.ON:CatalogEvent.OFF); eventPublisher.catalogEventPublish(platform, deviceChannel, deviceChannel.getStatus().equals("ON")? CatalogEvent.ON:CatalogEvent.OFF);
}); });
} }
} }

View File

@ -209,7 +209,7 @@ public class GroupServiceImpl implements IGroupService {
for (Platform platform : platformList) { for (Platform platform : platformList) {
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(platform.getId(), channel, CatalogEvent.DEL); eventPublisher.catalogEventPublish(platform, channel, CatalogEvent.DEL);
}catch (Exception e) { }catch (Exception e) {
log.warn("[业务分组/虚拟组织删除] 发送失败,{}", groupForDelete.getDeviceId(), e); log.warn("[业务分组/虚拟组织删除] 发送失败,{}", groupForDelete.getDeviceId(), e);
} }

View File

@ -215,6 +215,10 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
@Transactional @Transactional
public int addChannelList(Integer platformId, List<CommonGBChannel> channelList) { public int addChannelList(Integer platformId, List<CommonGBChannel> channelList) {
Platform platform = platformMapper.query(platformId);
if (platform == null) {
return 0;
}
int result = platformChannelMapper.addChannels(platformId, channelList); int result = platformChannelMapper.addChannels(platformId, channelList);
if (result > 0) { if (result > 0) {
// 查询通道相关的行政区划信息是否共享,如果没共享就添加 // 查询通道相关的行政区划信息是否共享,如果没共享就添加
@ -244,7 +248,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
// 发送消息 // 发送消息
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(platformId, channelList, CatalogEvent.ADD); eventPublisher.catalogEventPublish(platform, channelList, CatalogEvent.ADD);
} catch (Exception e) { } catch (Exception e) {
log.warn("[关联通道] 发送失败,数量:{}", channelList.size(), e); log.warn("[关联通道] 发送失败,数量:{}", channelList.size(), e);
} }
@ -254,6 +258,11 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
@Override @Override
public int removeAllChannel(Integer platformId) { public int removeAllChannel(Integer platformId) {
Platform platform = platformMapper.query(platformId);
if (platform == null) {
return 0;
}
List<CommonGBChannel> channelListShare = platformChannelMapper.queryShare(platformId, null); List<CommonGBChannel> channelListShare = platformChannelMapper.queryShare(platformId, null);
Assert.notEmpty(channelListShare, "未共享任何通道"); Assert.notEmpty(channelListShare, "未共享任何通道");
int result = platformChannelMapper.removeChannelsWithPlatform(platformId, channelListShare); int result = platformChannelMapper.removeChannelsWithPlatform(platformId, channelListShare);
@ -278,7 +287,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
// 发送消息 // 发送消息
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(platformId, channelListShare, CatalogEvent.DEL); eventPublisher.catalogEventPublish(platform, channelListShare, CatalogEvent.DEL);
} catch (Exception e) { } catch (Exception e) {
log.warn("[移除全部关联通道] 发送失败,数量:{}", channelListShare.size(), e); log.warn("[移除全部关联通道] 发送失败,数量:{}", channelListShare.size(), e);
} }
@ -302,6 +311,10 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
@Transactional @Transactional
public int removeChannelList(Integer platformId, List<CommonGBChannel> channelList) { public int removeChannelList(Integer platformId, List<CommonGBChannel> channelList) {
Platform platform = platformMapper.query(platformId);
if (platform == null) {
return 0;
}
int result = platformChannelMapper.removeChannelsWithPlatform(platformId, channelList); int result = platformChannelMapper.removeChannelsWithPlatform(platformId, channelList);
if (result > 0) { if (result > 0) {
// 查询通道相关的分组信息 // 查询通道相关的分组信息
@ -324,7 +337,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
// 发送消息 // 发送消息
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(platformId, channelList, CatalogEvent.DEL); eventPublisher.catalogEventPublish(platform, channelList, CatalogEvent.DEL);
} catch (Exception e) { } catch (Exception e) {
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e); log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
} }
@ -425,11 +438,12 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
@Override @Override
public void updateCustomChannel(PlatformChannel channel) { public void updateCustomChannel(PlatformChannel channel) {
platformChannelMapper.updateCustomChannel(channel); platformChannelMapper.updateCustomChannel(channel);
Platform platform = platformMapper.query(channel.getPlatformId());
CommonGBChannel commonGBChannel = platformChannelMapper.queryShareChannel(channel.getPlatformId(), channel.getGbId()); CommonGBChannel commonGBChannel = platformChannelMapper.queryShareChannel(channel.getPlatformId(), channel.getGbId());
// 发送消息 // 发送消息
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(channel.getPlatformId(), commonGBChannel, CatalogEvent.UPDATE); eventPublisher.catalogEventPublish(platform, commonGBChannel, CatalogEvent.UPDATE);
} catch (Exception e) { } catch (Exception e) {
log.warn("[自定义通道信息] 发送失败, 平台ID {} 通道: {}{}", channel.getPlatformId(), log.warn("[自定义通道信息] 发送失败, 平台ID {} 通道: {}{}", channel.getPlatformId(),
channel.getGbName(), channel.getId(), e); channel.getGbName(), channel.getId(), e);
@ -468,7 +482,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
// 发送消息 // 发送消息
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.DEL); eventPublisher.catalogEventPublish(platform, channelListForEvent, CatalogEvent.DEL);
} catch (Exception e) { } catch (Exception e) {
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e); log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
} }
@ -506,7 +520,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
// 发送消息 // 发送消息
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.DEL); eventPublisher.catalogEventPublish(platform, channelListForEvent, CatalogEvent.DEL);
} catch (Exception e) { } catch (Exception e) {
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e); log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
} }
@ -537,7 +551,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
// 发送消息 // 发送消息
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.ADD); eventPublisher.catalogEventPublish(platform, channelListForEvent, CatalogEvent.ADD);
} catch (Exception e) { } catch (Exception e) {
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e); log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
} }
@ -567,7 +581,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
// 发送消息 // 发送消息
try { try {
// 发送catalog // 发送catalog
eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.ADD); eventPublisher.catalogEventPublish(platform, channelListForEvent, CatalogEvent.ADD);
} catch (Exception e) { } catch (Exception e) {
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e); log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
} }