[国标级联] 优化catalog推送代码
parent
b37c0e264c
commit
cb7c41c3c1
|
@ -58,8 +58,8 @@ public interface PlatformChannelMapper {
|
|||
"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);
|
||||
|
||||
@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}")
|
||||
List<Integer> queryParentPlatformByChannelId(@Param("channelId") String 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<Platform> queryParentPlatformByChannelId(@Param("channelId") String channelId);
|
||||
|
||||
@Select("<script>" +
|
||||
" select " +
|
||||
|
|
|
@ -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) {
|
||||
RequestTimeoutEvent requestTimeoutEvent = new RequestTimeoutEvent(this);
|
||||
requestTimeoutEvent.setTimeoutEvent(timeoutEvent);
|
||||
applicationEventPublisher.publishEvent(requestTimeoutEvent);
|
||||
}
|
||||
|
||||
public void catalogEventPublish(Platform platform, CommonGBChannel deviceChannel, String type) {
|
||||
List<CommonGBChannel> deviceChannelList = new ArrayList<>();
|
||||
deviceChannelList.add(deviceChannel);
|
||||
catalogEventPublish(platform, deviceChannelList, type);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param platformId
|
||||
* @param deviceChannels
|
||||
* @param type
|
||||
*/
|
||||
public void catalogEventPublish(Integer platformId, List<CommonGBChannel> deviceChannels, String type) {
|
||||
public void catalogEventPublish(Platform platform, List<CommonGBChannel> deviceChannels, String type) {
|
||||
CatalogEvent outEvent = new CatalogEvent(this);
|
||||
List<CommonGBChannel> channels = new ArrayList<>();
|
||||
if (deviceChannels.size() > 1) {
|
||||
|
@ -90,11 +82,10 @@ public class EventPublisher {
|
|||
}
|
||||
outEvent.setChannels(channels);
|
||||
outEvent.setType(type);
|
||||
outEvent.setPlatformId(platformId);
|
||||
outEvent.setPlatform(platform);
|
||||
applicationEventPublisher.publishEvent(outEvent);
|
||||
}
|
||||
|
||||
|
||||
public void mobilePositionEventPublish(MobilePosition mobilePosition) {
|
||||
MobilePositionEvent event = new MobilePositionEvent(this);
|
||||
event.setMobilePosition(mobilePosition);
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package com.genersoft.iot.vmp.gb28181.event.subscribe.catalog;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Platform;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class CatalogEvent extends ApplicationEvent {
|
||||
|
||||
public CatalogEvent(Object source) {
|
||||
|
@ -48,16 +51,10 @@ public class CatalogEvent extends ApplicationEvent {
|
|||
*/
|
||||
public static final String UPDATE = "UPDATE";
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private List<CommonGBChannel> channels;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private String type;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private Integer platformId;
|
||||
private Platform platform;
|
||||
|
||||
}
|
||||
|
|
|
@ -46,11 +46,8 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
|
|||
|
||||
Map<String, List<Platform>> parentPlatformMap = new HashMap<>();
|
||||
Map<String, CommonGBChannel> channelMap = new HashMap<>();
|
||||
if (event.getPlatformId() != null) {
|
||||
parentPlatform = platformService.queryOne(event.getPlatformId());
|
||||
if (parentPlatform == null) {
|
||||
return;
|
||||
}
|
||||
if (event.getPlatform() != null) {
|
||||
parentPlatform = event.getPlatform();
|
||||
subscribe = subscribeHolder.getCatalogSubscribe(parentPlatform.getServerGBId());
|
||||
if (subscribe == null) {
|
||||
return;
|
||||
|
|
|
@ -7,10 +7,7 @@ import com.genersoft.iot.vmp.common.InviteSessionType;
|
|||
import com.genersoft.iot.vmp.common.enums.ChannelDataType;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
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.bean.*;
|
||||
import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce;
|
||||
import com.genersoft.iot.vmp.gb28181.dao.DeviceChannelMapper;
|
||||
import com.genersoft.iot.vmp.gb28181.dao.DeviceMapper;
|
||||
|
@ -507,10 +504,10 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
|||
deviceChannel.setHasAudio(channelInDb.isHasAudio());
|
||||
deviceChannel.setId(channelInDb.getId());
|
||||
if (channelInDb.getStatus() != null && channelInDb.getStatus().equalsIgnoreCase(deviceChannel.getStatus())){
|
||||
List<Integer> ids = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getDeviceId());
|
||||
if (!CollectionUtils.isEmpty(ids)){
|
||||
ids.forEach(platformId->{
|
||||
eventPublisher.catalogEventPublish(platformId, deviceChannel, deviceChannel.getStatus().equals("ON")? CatalogEvent.ON:CatalogEvent.OFF);
|
||||
List<Platform> platformList = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getDeviceId());
|
||||
if (!CollectionUtils.isEmpty(platformList)){
|
||||
platformList.forEach(platform->{
|
||||
eventPublisher.catalogEventPublish(platform, deviceChannel, deviceChannel.getStatus().equals("ON")? CatalogEvent.ON:CatalogEvent.OFF);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ public class GroupServiceImpl implements IGroupService {
|
|||
for (Platform platform : platformList) {
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platform.getId(), channel, CatalogEvent.DEL);
|
||||
eventPublisher.catalogEventPublish(platform, channel, CatalogEvent.DEL);
|
||||
}catch (Exception e) {
|
||||
log.warn("[业务分组/虚拟组织删除] 发送失败,{}", groupForDelete.getDeviceId(), e);
|
||||
}
|
||||
|
|
|
@ -215,6 +215,10 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
|
||||
@Transactional
|
||||
public int addChannelList(Integer platformId, List<CommonGBChannel> channelList) {
|
||||
Platform platform = platformMapper.query(platformId);
|
||||
if (platform == null) {
|
||||
return 0;
|
||||
}
|
||||
int result = platformChannelMapper.addChannels(platformId, channelList);
|
||||
if (result > 0) {
|
||||
// 查询通道相关的行政区划信息是否共享,如果没共享就添加
|
||||
|
@ -244,7 +248,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platformId, channelList, CatalogEvent.ADD);
|
||||
eventPublisher.catalogEventPublish(platform, channelList, CatalogEvent.ADD);
|
||||
} catch (Exception e) {
|
||||
log.warn("[关联通道] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
|
@ -254,6 +258,11 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
|
||||
@Override
|
||||
public int removeAllChannel(Integer platformId) {
|
||||
Platform platform = platformMapper.query(platformId);
|
||||
if (platform == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<CommonGBChannel> channelListShare = platformChannelMapper.queryShare(platformId, null);
|
||||
Assert.notEmpty(channelListShare, "未共享任何通道");
|
||||
int result = platformChannelMapper.removeChannelsWithPlatform(platformId, channelListShare);
|
||||
|
@ -278,7 +287,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platformId, channelListShare, CatalogEvent.DEL);
|
||||
eventPublisher.catalogEventPublish(platform, channelListShare, CatalogEvent.DEL);
|
||||
} catch (Exception e) {
|
||||
log.warn("[移除全部关联通道] 发送失败,数量:{}", channelListShare.size(), e);
|
||||
}
|
||||
|
@ -302,6 +311,10 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
|
||||
@Transactional
|
||||
public int removeChannelList(Integer platformId, List<CommonGBChannel> channelList) {
|
||||
Platform platform = platformMapper.query(platformId);
|
||||
if (platform == null) {
|
||||
return 0;
|
||||
}
|
||||
int result = platformChannelMapper.removeChannelsWithPlatform(platformId, channelList);
|
||||
if (result > 0) {
|
||||
// 查询通道相关的分组信息
|
||||
|
@ -324,7 +337,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platformId, channelList, CatalogEvent.DEL);
|
||||
eventPublisher.catalogEventPublish(platform, channelList, CatalogEvent.DEL);
|
||||
} catch (Exception e) {
|
||||
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
|
@ -425,11 +438,12 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
@Override
|
||||
public void updateCustomChannel(PlatformChannel channel) {
|
||||
platformChannelMapper.updateCustomChannel(channel);
|
||||
Platform platform = platformMapper.query(channel.getPlatformId());
|
||||
CommonGBChannel commonGBChannel = platformChannelMapper.queryShareChannel(channel.getPlatformId(), channel.getGbId());
|
||||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(channel.getPlatformId(), commonGBChannel, CatalogEvent.UPDATE);
|
||||
eventPublisher.catalogEventPublish(platform, commonGBChannel, CatalogEvent.UPDATE);
|
||||
} catch (Exception e) {
|
||||
log.warn("[自定义通道信息] 发送失败, 平台ID: {}, 通道: {}({})", channel.getPlatformId(),
|
||||
channel.getGbName(), channel.getId(), e);
|
||||
|
@ -468,7 +482,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.DEL);
|
||||
eventPublisher.catalogEventPublish(platform, channelListForEvent, CatalogEvent.DEL);
|
||||
} catch (Exception e) {
|
||||
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
|
@ -506,7 +520,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.DEL);
|
||||
eventPublisher.catalogEventPublish(platform, channelListForEvent, CatalogEvent.DEL);
|
||||
} catch (Exception e) {
|
||||
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
|
@ -537,7 +551,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.ADD);
|
||||
eventPublisher.catalogEventPublish(platform, channelListForEvent, CatalogEvent.ADD);
|
||||
} catch (Exception e) {
|
||||
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
|
@ -567,7 +581,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
|||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.ADD);
|
||||
eventPublisher.catalogEventPublish(platform, channelListForEvent, CatalogEvent.ADD);
|
||||
} catch (Exception e) {
|
||||
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue