diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java index 60f0e195..ef0e4ecb 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java @@ -286,9 +286,6 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent ArrayList 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(); } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java index 5192e9f1..091adb71 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java @@ -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 getChannelsInRegion(String regionDeviceId, String query, int page, int count); - List getChannelsInBusinessGroup(String businessGroupID); - - void updateChannelFromGb28181DeviceInList(Device device, List deviceChannels); - - void addChannelFromGb28181DeviceInList(Device device, List deviceChannels); - void deleteGbChannelsFromList(List deleteChannelList); - void channelsOnlineFromList(List deleteChannelList); - - void channelsOfflineFromList(List deleteChannelList); PageInfo queryChannelListInGroup(int page, int count, String query, String groupDeviceId, String regionDeviceId, Boolean inGroup, Boolean inRegion, diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java index 85559de5..6d446a52 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java @@ -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 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 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 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 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 getChannelsInBusinessGroup(String businessGroupID) { - return null; - } - - @Override - public void updateChannelFromGb28181DeviceInList(Device device, List deviceChannels) { - - } - - @Override - public void addChannelFromGb28181DeviceInList(Device device, List deviceChannels) { - - } - @Override public void deleteGbChannelsFromList(List channelList) { if (channelList.isEmpty()) { @@ -183,16 +126,6 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { } - @Override - public void channelsOnlineFromList(List channelList) { - commonGbChannelMapper.channelsOnlineFromList(channelList); - } - - @Override - public void channelsOfflineFromList(List channelList) { - commonGbChannelMapper.channelsOfflineFromList(channelList); - } - @Override public PageInfo 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 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 commonChannelIdList) { - commonGbChannelMapper.deleteByIdList(commonChannelIdList); - // TODO 向国标级联发送catalog + List commonGbChannelList = commonGbChannelMapper.queryInIdList(commonChannelIdList); + if (commonGbChannelList.isEmpty()) { + return; + } + commonGbChannelMapper.batchDelete(commonGbChannelList); + sendCatalogEvent(commonGbChannelList, CatalogEventType.DEL); } @Override - public void offlineForList(List onlinePushers) { - - - // TODO 向国标级联发送catalog + public void offlineForList(List commonChannelIdList) { + List commonGbChannelList = commonGbChannelMapper.queryInIdList(commonChannelIdList); + if (commonGbChannelList.isEmpty()) { + return; + } + commonGbChannelMapper.channelsOfflineFromList(commonGbChannelList); + sendCatalogEvent(commonGbChannelList, CatalogEventType.OFF); } @Override public void onlineForList(List commonChannelIdList) { - // TODO 向国标级联发送catalog + List commonGbChannelList = commonGbChannelMapper.queryInIdList(commonChannelIdList); + if (commonGbChannelList.isEmpty()) { + return; + } + commonGbChannelMapper.channelsOnlineFromList(commonGbChannelList); + sendCatalogEvent(commonGbChannelList, CatalogEventType.ON); } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java index 2bf183d0..157e09a2 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java @@ -240,11 +240,25 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @Override public int channelsOnline(List channels) { + List 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 channels) { + List 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) { diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonChannelMapper.java index 4f0435f8..237977d9 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonChannelMapper.java @@ -295,16 +295,16 @@ public interface CommonChannelMapper { @Update("") - void channelsOnlineFromList(List channelList); + void channelsOnlineFromList(List channelList); @Update("") - void channelsOfflineFromList(List channelList); + void channelsOfflineFromList(List channelList); @Update(""}) - int batchDelete(@Param("ids") List ids); + int batchDelete(@Param("commonGbChannels") List 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" + " #{item}" + "") - void deleteByIdList(List commonChannelIdList); + void deleteByIdList(@Param("commonChannelIdList") List commonChannelIdList); @Select("") List getAll(); + @Select("SELECT common_gb_id FROM wvp_common_channel WHERE common_gb_id = #{commonGbChannelId}") + CommonGbChannel getOne(@Param("commonGbChannelId") int commonGbChannelId); }