实现目录订阅的相关接口

结构优化
648540858 2023-12-19 16:50:47 +08:00
parent 31ab6eb174
commit 36c641c467
5 changed files with 62 additions and 116 deletions

View File

@ -286,9 +286,6 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
ArrayList<DeviceChannel> deviceChannels = new ArrayList<>(addChannelMap.values());
addChannelMap.clear();
deviceChannelService.batchAddChannel(deviceChannels);
if (device.isAutoSyncChannel()) {
commonGbChannelService.addChannelFromGb28181DeviceInList(device, deviceChannels);
}
}
}
@ -305,9 +302,6 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
private void executeSaveForOnline(Device device){
if (!updateChannelOnlineList.isEmpty()) {
deviceChannelService.channelsOnline(updateChannelOnlineList);
if (device.isAutoSyncChannel()) {
commonGbChannelService.channelsOnlineFromList(deleteChannelList);
}
updateChannelOnlineList.clear();
}
}
@ -315,9 +309,6 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
private void executeSaveForOffline(Device device){
if (!updateChannelOfflineList.isEmpty()) {
deviceChannelService.channelsOffline(updateChannelOfflineList);
if (device.isAutoSyncChannel()) {
commonGbChannelService.channelsOfflineFromList(deleteChannelList);
}
updateChannelOfflineList.clear();
}
}

View File

@ -22,25 +22,12 @@ public interface ICommonGbChannelService {
int add(CommonGbChannel channel);
int delete(String channelId);
int update(CommonGbChannel channel);
boolean checkChannelInPlatform(String channelId, String platformServerId);
PageInfo<CommonGbChannel> getChannelsInRegion(String regionDeviceId, String query, int page, int count);
List<CommonGbChannel> getChannelsInBusinessGroup(String businessGroupID);
void updateChannelFromGb28181DeviceInList(Device device, List<DeviceChannel> deviceChannels);
void addChannelFromGb28181DeviceInList(Device device, List<DeviceChannel> deviceChannels);
void deleteGbChannelsFromList(List<DeviceChannel> deleteChannelList);
void channelsOnlineFromList(List<DeviceChannel> deleteChannelList);
void channelsOfflineFromList(List<DeviceChannel> deleteChannelList);
PageInfo<CommonGbChannel> queryChannelListInGroup(int page, int count, String query, String groupDeviceId,
String regionDeviceId, Boolean inGroup, Boolean inRegion,

View File

@ -1,35 +1,23 @@
package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.common.BatchLimit;
import com.genersoft.iot.vmp.common.CivilCodePo;
import com.genersoft.iot.vmp.common.CommonGbChannel;
import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEventType;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.service.*;
import com.genersoft.iot.vmp.service.bean.*;
import com.genersoft.iot.vmp.storager.dao.CommonChannelMapper;
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
import com.genersoft.iot.vmp.storager.dao.GroupMapper;
import com.genersoft.iot.vmp.storager.dao.RegionMapper;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup;
import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToRegion;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
@ -44,24 +32,6 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
@Autowired
private CommonChannelMapper commonGbChannelMapper;
@Autowired
private DeviceChannelMapper deviceChannelMapper;
@Autowired
private GroupMapper groupMapper;
@Autowired
private RegionMapper regionMapper;
@Autowired
private DataSourceTransactionManager dataSourceTransactionManager;
@Autowired
private TransactionDefinition transactionDefinition;
@Autowired
private CivilCodeFileConf civilCodeFileConf;
@Autowired
private IPlatformService platformService;
@ -114,25 +84,19 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
}
}
private void sendCatalogEvent(CommonGbChannel channel, CatalogEventType catalogEventType) {
List<CommonGbChannel> commonGbChannelList = new ArrayList<>();
commonGbChannelList.add(channel);
sendCatalogEvent(commonGbChannelList, catalogEventType);
}
@Override
public int add(CommonGbChannel channel) {
int result = commonGbChannelMapper.add(channel);
if (result == 0) {
return 0;
}
List<CommonGbChannel> channelList = new ArrayList<>();
sendCatalogEvent(channelList, CatalogEventType.ADD);
return result;
}
@Override
public int delete(String channelId) {
int result = commonGbChannelMapper.deleteByDeviceID(channelId);
if (result == 0) {
return 0;
}
List<CommonGbChannel> channelList = new ArrayList<>();
sendCatalogEvent(channelList, CatalogEventType.DEL);
sendCatalogEvent(channel, CatalogEventType.ADD);
return result;
}
@ -145,31 +109,10 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
if (result == 0) {
return 0;
}
List<CommonGbChannel> channelList = new ArrayList<>();
sendCatalogEvent(channelList, CatalogEventType.UPDATE);
sendCatalogEvent(channel, CatalogEventType.UPDATE);
return result;
}
@Override
public boolean checkChannelInPlatform(String channelId, String platformServerId) {
return commonGbChannelMapper.checkChannelInPlatform(channelId, platformServerId) > 0;
}
@Override
public List<CommonGbChannel> getChannelsInBusinessGroup(String businessGroupID) {
return null;
}
@Override
public void updateChannelFromGb28181DeviceInList(Device device, List<DeviceChannel> deviceChannels) {
}
@Override
public void addChannelFromGb28181DeviceInList(Device device, List<DeviceChannel> deviceChannels) {
}
@Override
public void deleteGbChannelsFromList(List<DeviceChannel> channelList) {
if (channelList.isEmpty()) {
@ -183,16 +126,6 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
}
@Override
public void channelsOnlineFromList(List<DeviceChannel> channelList) {
commonGbChannelMapper.channelsOnlineFromList(channelList);
}
@Override
public void channelsOfflineFromList(List<DeviceChannel> channelList) {
commonGbChannelMapper.channelsOfflineFromList(channelList);
}
@Override
public PageInfo<CommonGbChannel> getChannelsInRegion(String regionDeviceId, String query, int page, int count) {
assert regionDeviceId != null;
@ -350,45 +283,65 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
if (channelsForDelete.isEmpty()) {
return;
}
List<CommonGbChannel> channelList = commonGbChannelMapper.queryInIdList(channelsForDelete);
if (channelList.isEmpty()) {
return;
}
if (channelsForDelete.size() > BatchLimit.count) {
for (int i = 0; i < channelsForDelete.size(); i += BatchLimit.count) {
int toIndex = i + BatchLimit.count;
if (i + BatchLimit.count > channelsForDelete.size()) {
toIndex = channelsForDelete.size();
}
if (commonGbChannelMapper.batchDelete(channelsForDelete.subList(i, toIndex)) < 0) {
if (commonGbChannelMapper.batchDelete(channelList.subList(i, toIndex)) < 0) {
throw new RuntimeException("batch update commonGbChannel fail");
}
}
}else {
if (commonGbChannelMapper.batchDelete(channelsForDelete) < 0) {
if (commonGbChannelMapper.batchDelete(channelList) < 0) {
throw new RuntimeException("batch update commonGbChannel fail");
}
}
// TODO 向国标级联发送catalog
sendCatalogEvent(channelList, CatalogEventType.DEL);
}
@Override
public void deleteById(int commonGbChannelId) {
CommonGbChannel commonGbChannel = commonGbChannelMapper.getOne(commonGbChannelId);
if (commonGbChannel == null) {
return;
}
commonGbChannelMapper.delete(commonGbChannelId);
// TODO 向国标级联发送catalog
sendCatalogEvent(commonGbChannel, CatalogEventType.DEL);
}
@Override
public void deleteByIdList(List<Integer> commonChannelIdList) {
commonGbChannelMapper.deleteByIdList(commonChannelIdList);
// TODO 向国标级联发送catalog
List<CommonGbChannel> commonGbChannelList = commonGbChannelMapper.queryInIdList(commonChannelIdList);
if (commonGbChannelList.isEmpty()) {
return;
}
commonGbChannelMapper.batchDelete(commonGbChannelList);
sendCatalogEvent(commonGbChannelList, CatalogEventType.DEL);
}
@Override
public void offlineForList(List<Integer> onlinePushers) {
// TODO 向国标级联发送catalog
public void offlineForList(List<Integer> commonChannelIdList) {
List<CommonGbChannel> commonGbChannelList = commonGbChannelMapper.queryInIdList(commonChannelIdList);
if (commonGbChannelList.isEmpty()) {
return;
}
commonGbChannelMapper.channelsOfflineFromList(commonGbChannelList);
sendCatalogEvent(commonGbChannelList, CatalogEventType.OFF);
}
@Override
public void onlineForList(List<Integer> commonChannelIdList) {
// TODO 向国标级联发送catalog
List<CommonGbChannel> commonGbChannelList = commonGbChannelMapper.queryInIdList(commonChannelIdList);
if (commonGbChannelList.isEmpty()) {
return;
}
commonGbChannelMapper.channelsOnlineFromList(commonGbChannelList);
sendCatalogEvent(commonGbChannelList, CatalogEventType.ON);
}
}

View File

@ -240,11 +240,25 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
@Override
public int channelsOnline(List<DeviceChannel> channels) {
List<Integer> ids = new ArrayList<>();
for (DeviceChannel channel : channels) {
ids.add(channel.getCommonGbChannelId());
}
if (!ids.isEmpty()) {
commonGbChannelService.onlineForList(ids);
}
return channelMapper.batchOnline(channels);
}
@Override
public int channelsOffline(List<DeviceChannel> channels) {
List<Integer> ids = new ArrayList<>();
for (DeviceChannel channel : channels) {
ids.add(channel.getCommonGbChannelId());
}
if (!ids.isEmpty()) {
commonGbChannelService.offlineForList(ids);
}
return channelMapper.batchOffline(channels);
}
@ -279,7 +293,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
commonGbChannelList.add(CommonGbChannel.getInstance(null, channel));
});
commonGbChannelService.batchAdd(commonGbChannelList);
channelMapper.batchAdd(channels);
for (DeviceChannel channel : channels) {
if (channel.getParentId() != null) {

View File

@ -295,16 +295,16 @@ public interface CommonChannelMapper {
@Update("<script> "+
"UPDATE wvp_common_channel SET commonGbStatus = true WHERE common_gb_id in" +
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbChannelId}</foreach>" +
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbId}</foreach>" +
"</script>")
void channelsOnlineFromList(List<DeviceChannel> channelList);
void channelsOnlineFromList(List<CommonGbChannel> channelList);
@Update("<script> "+
"UPDATE wvp_common_channel SET commonGbStatus = false WHERE common_gb_id in" +
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbChannelId}</foreach>" +
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbId}</foreach>" +
"</script>")
void channelsOfflineFromList(List<DeviceChannel> channelList);
void channelsOfflineFromList(List<CommonGbChannel> channelList);
@Update("<script> "+
"UPDATE wvp_common_channel SET common_gb_parent_id = null WHERE common_gb_id in" +
@ -570,9 +570,9 @@ public interface CommonChannelMapper {
"from " +
"wvp_common_channel " +
"WHERE common_gb_id IN " +
"<foreach collection='ids' item='item' open='(' separator=',' close=')' >#{item}</foreach>" +
"<foreach collection='commonGbChannels' item='item' open='(' separator=',' close=')' >#{item.commonGbId}</foreach>" +
" </script>"})
int batchDelete(@Param("ids") List<Integer> ids);
int batchDelete(@Param("commonGbChannels") List<CommonGbChannel> commonGbChannels);
@MapKey("commonGbDeviceID")
@Select("select * from wvp_common_channel")
@ -599,11 +599,13 @@ public interface CommonChannelMapper {
"delete from wvp_common_channel WHERE common_gb_id in" +
"<foreach collection='commonChannelIdList' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
"</script>")
void deleteByIdList(List<Integer> commonChannelIdList);
void deleteByIdList(@Param("commonChannelIdList") List<Integer> commonChannelIdList);
@Select("<script> "+
"SELECT * FROM wvp_common_channel" +
"</script>")
List<CommonGbChannel> getAll();
@Select("SELECT common_gb_id FROM wvp_common_channel WHERE common_gb_id = #{commonGbChannelId}")
CommonGbChannel getOne(@Param("commonGbChannelId") int commonGbChannelId);
}