临时提交

This commit is contained in:
648540858
2024-08-27 17:56:49 +08:00
parent b2b7426871
commit dd794d4868
23 changed files with 552 additions and 1257 deletions

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.service;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.PlatformChannel;
import com.github.pagehelper.PageInfo;
@@ -20,4 +21,6 @@ public interface IPlatformChannelService {
int addChannels(Integer platformId, List<Integer> channelIds);
int removeChannels(Integer platformId, List<Integer> channelIds);
void removeChannels(List<CommonGBChannel> channelList);
}

View File

@@ -6,9 +6,11 @@ import com.genersoft.iot.vmp.common.InviteInfo;
import com.genersoft.iot.vmp.common.InviteSessionType;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
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;
import com.genersoft.iot.vmp.gb28181.dao.DeviceMobilePositionMapper;
@@ -17,11 +19,11 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService;
import com.genersoft.iot.vmp.gb28181.service.IInviteStreamService;
import com.genersoft.iot.vmp.gb28181.service.IPlatformChannelService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
import com.genersoft.iot.vmp.gb28181.controller.bean.ChannelReduce;
import com.genersoft.iot.vmp.web.gb28181.dto.DeviceChannelExtend;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -68,6 +70,10 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private IPlatformChannelService platformChannelService;
@Override
public void updateChannel(String deviceId, DeviceChannel channel) {
String channelId = channel.getDeviceId();
@@ -503,7 +509,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
return false;
}
int limitCount = 50;
boolean result = false;
if (!addChannels.isEmpty()) {
if (addChannels.size() > limitCount) {
for (int i = 0; i < addChannels.size(); i += limitCount) {
@@ -511,39 +516,52 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
if (i + limitCount > addChannels.size()) {
toIndex = addChannels.size();
}
result = result || channelMapper.batchAdd(addChannels.subList(i, toIndex)) > 0;
channelMapper.batchAdd(addChannels.subList(i, toIndex));
}
}else {
result = channelMapper.batchAdd(addChannels) > 0;
channelMapper.batchAdd(addChannels);
}
}
if (!result && !updateChannels.isEmpty()) {
if (!updateChannels.isEmpty()) {
if (updateChannels.size() > limitCount) {
for (int i = 0; i < updateChannels.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > updateChannels.size()) {
toIndex = updateChannels.size();
}
result = result || channelMapper.batchUpdate(updateChannels.subList(i, toIndex)) > 0;
channelMapper.batchUpdate(updateChannels.subList(i, toIndex));
}
}else {
result = channelMapper.batchUpdate(updateChannels) > 0;
channelMapper.batchUpdate(updateChannels);
}
// 不对收到的通道做比较,已确定是否真的发生变化,所以不发送更新通知
}
if (!result && !deleteChannels.isEmpty()) {
if (!deleteChannels.isEmpty()) {
if (deleteChannels.size() > limitCount) {
for (int i = 0; i < deleteChannels.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > deleteChannels.size()) {
toIndex = deleteChannels.size();
}
result = result || channelMapper.batchDel(deleteChannels.subList(i, toIndex)) < 0;
channelMapper.batchDel(deleteChannels.subList(i, toIndex));
}
}else {
result = channelMapper.batchDel(deleteChannels) < 0;
channelMapper.batchDel(deleteChannels);
}
// 这些通道可能关联了,上级平台需要删除同时发送消息
List<CommonGBChannel> channelList = new ArrayList<>();
deleteChannels.stream().forEach(deviceChannel -> {
CommonGBChannel commonGBChannel = new CommonGBChannel();
commonGBChannel.setGbId(deviceChannel.getId());
commonGBChannel.setGbDeviceId(deviceChannel.getDeviceId());
commonGBChannel.setGbName(deviceChannel.getName());
channelList.add(commonGBChannel);
});
platformChannelService.removeChannels(channelList);
}
return result;
return true;
}

View File

@@ -536,6 +536,7 @@ public class GbChannelServiceImpl implements IGbChannelService {
return;
}
commonGBChannelMapper.removeParentIdByChannels(channelList);
// TODO 可能需要发送通道更新通知
}
@Override

View File

@@ -1,9 +1,6 @@
package com.genersoft.iot.vmp.gb28181.service.impl;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.GbCode;
import com.genersoft.iot.vmp.gb28181.bean.Group;
import com.genersoft.iot.vmp.gb28181.bean.GroupTree;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper;
import com.genersoft.iot.vmp.gb28181.dao.GroupMapper;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
@@ -202,14 +199,22 @@ public class GroupServiceImpl implements IGroupService {
gbChannelService.removeParentIdByGroupList(groupListForDelete);
}
groupManager.batchDelete(groupListForDelete);
for (Group groupForDelete : groupListForDelete) {
// 将变化信息发送通知
CommonGBChannel channel = CommonGBChannel.build(groupForDelete);
try {
// 发送catalog
eventPublisher.catalogEventPublish(null, channel, CatalogEvent.DEL);
}catch (Exception e) {
log.warn("[业务分组/虚拟组织删除] 发送失败,{}", groupForDelete.getDeviceId(), e);
// 删除平台关联的分组信息。同时发送通知
List<Platform> platformList = groupManager.queryForPlatformByGroupId(groupForDelete.getId());
if ( !platformList.isEmpty()) {
groupManager.deletePlatformGroup(groupForDelete.getId());
// 将变化信息发送通知
CommonGBChannel channel = CommonGBChannel.build(groupForDelete);
for (Platform platform : platformList) {
try {
// 发送catalog
eventPublisher.catalogEventPublish(platform.getId(), channel, CatalogEvent.DEL);
}catch (Exception e) {
log.warn("[业务分组/虚拟组织删除] 发送失败,{}", groupForDelete.getDeviceId(), e);
}
}
}
}
return true;

View File

@@ -1,10 +1,7 @@
package com.genersoft.iot.vmp.gb28181.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.Group;
import com.genersoft.iot.vmp.gb28181.bean.PlatformChannel;
import com.genersoft.iot.vmp.gb28181.bean.Region;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper;
import com.genersoft.iot.vmp.gb28181.dao.GroupMapper;
import com.genersoft.iot.vmp.gb28181.dao.PlatformChannelMapper;
@@ -273,7 +270,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
public int removeAllChannel(Integer platformId) {
List<CommonGBChannel> channelListShare = platformChannelMapper.queryShare(platformId, null);
Assert.notEmpty(channelListShare, "未共享任何通道");
int result = platformChannelMapper.removeChannels(platformId, channelListShare);
int result = platformChannelMapper.removeChannelsWithPlatform(platformId, channelListShare);
if (result > 0) {
// 查询通道相关的分组信息
Set<Region> regionSet = regionMapper.queryByChannelList(channelListShare);
@@ -308,7 +305,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
public int removeChannels(Integer platformId, List<Integer> channelIds) {
List<CommonGBChannel> channelList = platformChannelMapper.queryShare(platformId, channelIds);
Assert.notEmpty(channelList, "所选通道未共享");
int result = platformChannelMapper.removeChannels(platformId, channelList);
int result = platformChannelMapper.removeChannelsWithPlatform(platformId, channelList);
if (result > 0) {
// 查询通道相关的分组信息
Set<Region> regionSet = regionMapper.queryByChannelList(channelList);
@@ -337,4 +334,46 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
}
return result;
}
@Override
public void removeChannels(List<CommonGBChannel> channelList) {
List<Platform> platformList = platformChannelMapper.queryPlatFormListByChannelList(channelList);
if (platformList.isEmpty()) {
return;
}
// TODO 不对呀
for (Platform platform : platformList) {
int result = platformChannelMapper.removeChannelsWithPlatform(platform.getId(), channelList);
if (result > 0) {
// 查询通道相关的分组信息
Set<Region> regionSet = regionMapper.queryByChannelList(channelList);
Set<Region> deleteRegion = deleteEmptyRegion(regionSet, platform.getId());
if (!deleteRegion.isEmpty()) {
for (Region region : deleteRegion) {
channelList.add(0, CommonGBChannel.build(region));
}
}
// 查询通道相关的分组信息
Set<Group> groupSet = groupMapper.queryByChannelList(channelList);
Set<Group> deleteGroup = deleteEmptyGroup(groupSet, platform.getId());
if (!deleteGroup.isEmpty()) {
for (Group group : deleteGroup) {
channelList.add(0, CommonGBChannel.build(group));
}
}
}
// 发送消息
try {
// 发送catalog
eventPublisher.catalogEventPublish(platform.getId(), channelList, CatalogEvent.DEL);
} catch (Exception e) {
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
}
}
}
}