Merge branch 'master' into dev/数据库统合

dev/数据库统合
648540858 2025-01-03 15:10:23 +08:00
commit 3903bc31b5
7 changed files with 42 additions and 43 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}")
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 " +

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) {
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);

View File

@ -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;
}

View File

@ -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;

View File

@ -531,10 +531,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);
});
}
}

View File

@ -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);
}

View File

@ -213,6 +213,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) {
// 查询通道相关的行政区划信息是否共享,如果没共享就添加
@ -242,7 +246,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);
}
@ -252,6 +256,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);
@ -276,7 +285,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);
}
@ -300,6 +309,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) {
// 查询通道相关的分组信息
@ -322,7 +335,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);
}
@ -423,11 +436,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);
@ -466,7 +480,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);
}
@ -504,7 +518,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);
}
@ -535,7 +549,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);
}
@ -565,7 +579,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);
}