瀏覽代碼

修复行政区划未移除的问题

648540858 1 年之前
父節點
當前提交
7d669f74ec

+ 8 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformChannelMapper.java

@@ -540,4 +540,12 @@ public interface PlatformChannelMapper {
             " </script>")
     Set<Group> queryShareGroup(@Param("platformId") Integer platformId);
 
+    @Select(" <script>" +
+            " SELECT wcr.* " +
+            " from wvp_common_region wcr" +
+            " left join wvp_platform_region wpr on wpr.region_id = wcr.id " +
+            " where wpr.platform_id = #{platformId}" +
+            " order by wcr.id DESC" +
+            " </script>")
+    Set<Region> queryShareRegion(Integer id);
 }

+ 3 - 4
src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java

@@ -1,9 +1,6 @@
 package com.genersoft.iot.vmp.gb28181.service;
 
-import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
-import com.genersoft.iot.vmp.gb28181.bean.Group;
-import com.genersoft.iot.vmp.gb28181.bean.Platform;
-import com.genersoft.iot.vmp.gb28181.bean.PlatformChannel;
+import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.github.pagehelper.PageInfo;
 
 import java.util.List;
@@ -47,4 +44,6 @@ public interface IPlatformChannelService {
     CommonGBChannel queryChannelByPlatformIdAndChannelId(Integer platformId, Integer channelId);
 
     void checkRegionAdd(List<CommonGBChannel> channelList);
+
+    void checkRegionRemove(List<CommonGBChannel> channelList, List<Region> regionList);
 }

+ 11 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java

@@ -442,6 +442,14 @@ public class GbChannelServiceImpl implements IGbChannelService {
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
         }
         int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList);
+        Region region = regionMapper.queryByDeviceId(civilCode);
+        if (region == null) {
+            platformChannelService.checkRegionRemove(channelList, null);
+        }else {
+            List<Region> regionList = new ArrayList<>();
+            regionList.add(region);
+            platformChannelService.checkRegionRemove(channelList, regionList);
+        }
         // TODO 发送通知
 //        if (result > 0) {
 //            try {
@@ -460,6 +468,8 @@ public class GbChannelServiceImpl implements IGbChannelService {
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
         }
         int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList);
+
+        platformChannelService.checkRegionRemove(channelList, null);
         // TODO 发送通知
 //        if (result > 0) {
 //            try {
@@ -499,6 +509,7 @@ public class GbChannelServiceImpl implements IGbChannelService {
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在");
         }
         int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList);
+        platformChannelService.checkRegionRemove(channelList, null);
     }
 
     @Override

+ 38 - 4
src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java

@@ -52,8 +52,6 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
     private ISIPCommanderForPlatform sipCommanderFroPlatform;
 
 
-
-
     @Override
     public PageInfo<PlatformChannel> queryChannelList(int page, int count, String query, Integer channelType, Boolean online, Integer platformId, Boolean hasShare) {
         PageHelper.startPage(page, count);
@@ -94,8 +92,6 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
         return regionMapper.queryNotShareRegionForPlatformByRegionList(allRegion, platformId);
     }
 
-
-
     /**
      * 移除空的共享,并返回移除的分组
      */
@@ -474,6 +470,44 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
         }
     }
 
+    @Override
+    @Transactional
+    public void checkRegionRemove(List<CommonGBChannel> channelList, List<Region> regionList) {
+        List<Integer> channelIds = new ArrayList<>();
+        channelList.stream().forEach(commonGBChannel -> {
+            channelIds.add(commonGBChannel.getGbId());
+        });
+        // 获取关联这些通道的平台
+        List<Platform> platformList = platformChannelMapper.queryPlatFormListByChannelList(channelIds);
+        if (platformList.isEmpty()) {
+            return;
+        }
+        for (Platform platform : platformList) {
+            Set<Region> regionSet;
+            if (regionList == null || regionList.isEmpty()) {
+                regionSet = platformChannelMapper.queryShareRegion(platform.getId());
+            }else {
+                regionSet = new HashSet<>(regionList);
+            }
+            // 清理空的分组并发送消息
+            Set<Region> deleteRegion = deleteEmptyRegion(regionSet, platform.getId());
+
+            List<CommonGBChannel> channelListForEvent = new ArrayList<>();
+            if (!deleteRegion.isEmpty()) {
+                for (Region region : deleteRegion) {
+                    channelListForEvent.add(0, CommonGBChannel.build(region));
+                }
+            }
+            // 发送消息
+            try {
+                // 发送catalog
+                eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.DEL);
+            } catch (Exception e) {
+                log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e);
+            }
+        }
+    }
+
     @Override
     @Transactional
     public void checkGroupAdd(List<CommonGBChannel> channelList) {