修复通道共享的BUG以及增加通道手动推送的功能
This commit is contained in:
@@ -30,8 +30,6 @@ public interface IGbChannelService {
|
||||
|
||||
void updateStatus(List<CommonGBChannel> channelList);
|
||||
|
||||
List<CommonGBChannel> queryByPlatform(Platform platform);
|
||||
|
||||
CommonGBChannel getOne(int id);
|
||||
|
||||
List<IndustryCodeType> getIndustryCodeList();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.service;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Platform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.PlatformChannel;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
@@ -22,5 +23,11 @@ public interface IPlatformChannelService {
|
||||
|
||||
int removeChannels(Integer platformId, List<Integer> channelIds);
|
||||
|
||||
void removeChannels(List<CommonGBChannel> channelList);
|
||||
void removeChannels(List<Integer> ids);
|
||||
|
||||
void removeChannel(int gbId);
|
||||
|
||||
List<CommonGBChannel> queryByPlatform(Platform platform);
|
||||
|
||||
void pushChannel(Integer platformId);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ 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;
|
||||
@@ -538,6 +537,16 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||
|
||||
}
|
||||
if (!deleteChannels.isEmpty()) {
|
||||
try {
|
||||
// 这些通道可能关联了,上级平台需要删除同时发送消息
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
deleteChannels.stream().forEach(deviceChannel -> {
|
||||
ids.add(deviceChannel.getId());
|
||||
});
|
||||
platformChannelService.removeChannels(ids);
|
||||
}catch (Exception e) {
|
||||
log.error("[移除通道国标级联共享失败]", e);
|
||||
}
|
||||
if (deleteChannels.size() > limitCount) {
|
||||
for (int i = 0; i < deleteChannels.size(); i += limitCount) {
|
||||
int toIndex = i + limitCount;
|
||||
@@ -549,17 +558,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
|
||||
}else {
|
||||
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 true;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.gb28181.dao.RegionMapper;
|
||||
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.IGbChannelService;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IPlatformChannelService;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
@@ -35,6 +36,9 @@ public class GbChannelServiceImpl implements IGbChannelService {
|
||||
@Autowired
|
||||
private PlatformChannelMapper platformChannelMapper;
|
||||
|
||||
@Autowired
|
||||
private IPlatformChannelService platformChannelService;
|
||||
|
||||
@Autowired
|
||||
private RegionMapper regionMapper;
|
||||
|
||||
@@ -66,7 +70,15 @@ public class GbChannelServiceImpl implements IGbChannelService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int delete(int gbId) {
|
||||
// 移除国标级联关联的信息
|
||||
try {
|
||||
platformChannelService.removeChannel(gbId);
|
||||
}catch (Exception e) {
|
||||
log.error("[移除通道国标级联共享失败]", e);
|
||||
}
|
||||
|
||||
CommonGBChannel channel = commonGBChannelMapper.queryById(gbId);
|
||||
if (channel != null) {
|
||||
commonGBChannelMapper.delete(gbId);
|
||||
@@ -81,18 +93,19 @@ public class GbChannelServiceImpl implements IGbChannelService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(Collection<Integer> ids) {
|
||||
// 移除国标级联关联的信息
|
||||
try {
|
||||
platformChannelService.removeChannels(new ArrayList<>(ids));
|
||||
}catch (Exception e) {
|
||||
log.error("[移除通道国标级联共享失败]", e);
|
||||
}
|
||||
List<CommonGBChannel> channelListInDb = commonGBChannelMapper.queryByIds(ids);
|
||||
if (channelListInDb.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
commonGBChannelMapper.batchDelete(channelListInDb);
|
||||
try {
|
||||
// 发送通知
|
||||
eventPublisher.catalogEventPublish(null, channelListInDb, CatalogEvent.DEL);
|
||||
} catch (Exception e) {
|
||||
log.warn("[通道移除通知] 发送失败,{}条", channelListInDb.size(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,40 +322,7 @@ public class GbChannelServiceImpl implements IGbChannelService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommonGBChannel> queryByPlatform(Platform platform) {
|
||||
if (platform == null) {
|
||||
return null;
|
||||
}
|
||||
List<CommonGBChannel> commonGBChannelList = commonGBChannelMapper.queryWithPlatform(platform.getId());
|
||||
if (commonGBChannelList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<CommonGBChannel> channelList = new ArrayList<>();
|
||||
// 是否包含平台信息
|
||||
if (platform.getCatalogWithPlatform()) {
|
||||
CommonGBChannel channel = CommonGBChannel.build(platform);
|
||||
channelList.add(channel);
|
||||
}
|
||||
// 关联的行政区划信息
|
||||
if (platform.getCatalogWithRegion()) {
|
||||
// 查询关联平台的行政区划信息
|
||||
List<CommonGBChannel> regionChannelList = regionMapper.queryByPlatform(platform.getId());
|
||||
if (!regionChannelList.isEmpty()) {
|
||||
channelList.addAll(regionChannelList);
|
||||
}
|
||||
}
|
||||
if (platform.getCatalogWithGroup()) {
|
||||
// 关联的分组信息
|
||||
List<CommonGBChannel> groupChannelList = groupMapper.queryForPlatform(platform.getId());
|
||||
if (!groupChannelList.isEmpty()) {
|
||||
channelList.addAll(groupChannelList);
|
||||
}
|
||||
}
|
||||
|
||||
channelList.addAll(commonGBChannelList);
|
||||
return channelList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonGBChannel getOne(int id) {
|
||||
|
||||
@@ -2,13 +2,11 @@ package com.genersoft.iot.vmp.gb28181.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
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;
|
||||
import com.genersoft.iot.vmp.gb28181.dao.RegionMapper;
|
||||
import com.genersoft.iot.vmp.gb28181.dao.*;
|
||||
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.IPlatformChannelService;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -16,7 +14,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.beans.Transient;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -43,6 +44,12 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
||||
@Autowired
|
||||
private CommonGBChannelMapper commonGBChannelMapper;
|
||||
|
||||
@Autowired
|
||||
private PlatformMapper platformMapper;
|
||||
|
||||
@Autowired
|
||||
private ISIPCommanderForPlatform sipCommanderFroPlatform;
|
||||
|
||||
|
||||
@Override
|
||||
public PageInfo<PlatformChannel> queryChannelList(int page, int count, String query, Boolean online, Integer platformId, Boolean hasShare) {
|
||||
@@ -336,44 +343,82 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChannels(List<CommonGBChannel> channelList) {
|
||||
List<Platform> platformList = platformChannelMapper.queryPlatFormListByChannelList(channelList);
|
||||
@Transient
|
||||
public void removeChannels(List<Integer> ids) {
|
||||
List<Platform> platformList = platformChannelMapper.queryPlatFormListByChannelList(ids);
|
||||
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));
|
||||
}
|
||||
}
|
||||
removeChannels(platform.getId(), ids);
|
||||
}
|
||||
}
|
||||
|
||||
// 查询通道相关的分组信息
|
||||
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));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void removeChannel(int channelId) {
|
||||
List<Platform> platformList = platformChannelMapper.queryPlatFormListByChannelId(channelId);
|
||||
if (platformList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Platform platform : platformList) {
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
ids.add(channelId);
|
||||
removeChannels(platform.getId(), ids);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommonGBChannel> queryByPlatform(Platform platform) {
|
||||
if (platform == null) {
|
||||
return null;
|
||||
}
|
||||
List<CommonGBChannel> commonGBChannelList = commonGBChannelMapper.queryWithPlatform(platform.getId());
|
||||
if (commonGBChannelList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<CommonGBChannel> channelList = new ArrayList<>();
|
||||
// 是否包含平台信息
|
||||
if (platform.getCatalogWithPlatform()) {
|
||||
CommonGBChannel channel = CommonGBChannel.build(platform);
|
||||
channelList.add(channel);
|
||||
}
|
||||
// 关联的行政区划信息
|
||||
if (platform.getCatalogWithRegion()) {
|
||||
// 查询关联平台的行政区划信息
|
||||
List<CommonGBChannel> regionChannelList = regionMapper.queryByPlatform(platform.getId());
|
||||
if (!regionChannelList.isEmpty()) {
|
||||
channelList.addAll(regionChannelList);
|
||||
}
|
||||
// 发送消息
|
||||
try {
|
||||
// 发送catalog
|
||||
eventPublisher.catalogEventPublish(platform.getId(), channelList, CatalogEvent.DEL);
|
||||
} catch (Exception e) {
|
||||
log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
|
||||
}
|
||||
if (platform.getCatalogWithGroup()) {
|
||||
// 关联的分组信息
|
||||
List<CommonGBChannel> groupChannelList = groupMapper.queryForPlatform(platform.getId());
|
||||
if (!groupChannelList.isEmpty()) {
|
||||
channelList.addAll(groupChannelList);
|
||||
}
|
||||
}
|
||||
|
||||
channelList.addAll(commonGBChannelList);
|
||||
return channelList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushChannel(Integer platformId) {
|
||||
Platform platform = platformMapper.query(platformId);
|
||||
Assert.notNull(platform, "平台不存在");
|
||||
List<CommonGBChannel> channelList = queryByPlatform(platform);
|
||||
if (channelList.isEmpty()){
|
||||
return;
|
||||
}
|
||||
SubscribeInfo subscribeInfo = SubscribeInfo.buildSimulated(platform.getServerGBId(), platform.getServerIp());
|
||||
|
||||
try {
|
||||
sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(CatalogEvent.UPDATE, platform, channelList, subscribeInfo, null);
|
||||
} catch (InvalidArgumentException | ParseException | NoSuchFieldException |
|
||||
SipException | IllegalAccessException e) {
|
||||
log.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.ResponseEvent;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
@@ -329,16 +328,8 @@ public class PlatformServiceImpl implements IPlatformService {
|
||||
@Override
|
||||
public void addSimulatedSubscribeInfo(Platform platform) {
|
||||
// 自动添加一条模拟的订阅信息
|
||||
SubscribeInfo subscribeInfo = new SubscribeInfo();
|
||||
subscribeInfo.setId(platform.getServerGBId());
|
||||
subscribeInfo.setExpires(-1);
|
||||
subscribeInfo.setEventType("Catalog");
|
||||
int random = (int) Math.floor(Math.random() * 10000);
|
||||
subscribeInfo.setEventId(random + "");
|
||||
subscribeInfo.setSimulatedCallId(UUID.randomUUID().toString().replace("-", "") + "@" + platform.getServerIp());
|
||||
subscribeInfo.setSimulatedFromTag(UUID.randomUUID().toString().replace("-", ""));
|
||||
subscribeInfo.setSimulatedToTag(UUID.randomUUID().toString().replace("-", ""));
|
||||
subscribeHolder.putCatalogSubscribe(platform.getServerGBId(), subscribeInfo);
|
||||
subscribeHolder.putCatalogSubscribe(platform.getServerGBId(),
|
||||
SubscribeInfo.buildSimulated(platform.getServerGBId(), platform.getServerIp()));
|
||||
}
|
||||
|
||||
private void registerTask(Platform platform, SipTransactionInfo sipTransactionInfo){
|
||||
|
||||
Reference in New Issue
Block a user