From ac1a4a027a7bd88efb32e9da666bdba4b5fa166f Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 14 一月 2022 17:04:26 +0800
Subject: [PATCH] 支持国标级联的目录订阅功能

---
 src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java |   74 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
index 21c666f..35c262f 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
@@ -1,7 +1,14 @@
 package com.genersoft.iot.vmp.service.impl;
 
+import com.genersoft.iot.vmp.conf.SipConfig;
+import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
+import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
+import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
+import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
+import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
 import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
+import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
 import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
 import com.genersoft.iot.vmp.service.IGbStreamService;
 import com.github.pagehelper.PageHelper;
@@ -14,6 +21,7 @@
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -33,6 +41,15 @@
     @Autowired
     private PlatformGbStreamMapper platformGbStreamMapper;
 
+    @Autowired
+    private ParentPlatformMapper platformMapper;
+
+    @Autowired
+    private SipConfig sipConfig;
+
+    @Autowired
+    private EventPublisher eventPublisher;
+
     @Override
     public PageInfo<GbStream> getAll(Integer page, Integer count) {
         PageHelper.startPage(page, count);
@@ -51,32 +68,62 @@
         // 鏀惧湪浜嬪姟鍐呮墽琛�
         boolean result = false;
         TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
+        ParentPlatform parentPlatform = platformMapper.getParentPlatByServerGBId(platformId);
         try {
+            List<DeviceChannel> deviceChannelList = new ArrayList<>();
             for (GbStream gbStream : gbStreams) {
                 gbStream.setCatalogId(catalogId);
                 gbStream.setPlatformId(platformId);
                 // TODO 淇敼涓烘壒閲忔彁浜�
                 platformGbStreamMapper.add(gbStream);
+                DeviceChannel deviceChannelListByStream = getDeviceChannelListByStream(gbStream, catalogId, parentPlatform.getDeviceGBId());
+                deviceChannelList.add(deviceChannelListByStream);
             }
             dataSourceTransactionManager.commit(transactionStatus);     //鎵嬪姩鎻愪氦
+            eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
             result = true;
         }catch (Exception e) {
             logger.error("鎵归噺淇濆瓨娴佷笌骞冲彴鐨勫叧绯绘椂閿欒", e);
             dataSourceTransactionManager.rollback(transactionStatus);
         }
         return result;
-
     }
 
     @Override
-    public boolean delPlatformInfo(List<GbStream> gbStreams) {
+    public DeviceChannel getDeviceChannelListByStream(GbStream gbStream, String catalogId, String deviceGBId) {
+        DeviceChannel deviceChannel = new DeviceChannel();
+        deviceChannel.setChannelId(gbStream.getGbId());
+        deviceChannel.setName(gbStream.getName());
+        deviceChannel.setLongitude(gbStream.getLongitude());
+        deviceChannel.setLatitude(gbStream.getLatitude());
+        deviceChannel.setDeviceId(deviceGBId);
+        deviceChannel.setManufacture("wvp-pro");
+        deviceChannel.setStatus(gbStream.isStatus()?1:0);
+        deviceChannel.setParentId(catalogId ==null?gbStream.getCatalogId():catalogId);
+        deviceChannel.setRegisterWay(1);
+        deviceChannel.setCivilCode(sipConfig.getDomain());
+        deviceChannel.setModel("live");
+        deviceChannel.setOwner("wvp-pro");
+        deviceChannel.setParental(0);
+        deviceChannel.setSecrecy("0");
+        return deviceChannel;
+    }
+
+    @Override
+    public boolean delPlatformInfo(String platformId, List<GbStream> gbStreams) {
         // 鏀惧湪浜嬪姟鍐呮墽琛�
         boolean result = false;
         TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
         try {
+            List<DeviceChannel> deviceChannelList = new ArrayList<>();
             for (GbStream gbStream : gbStreams) {
                 platformGbStreamMapper.delByAppAndStream(gbStream.getApp(), gbStream.getStream());
+                DeviceChannel deviceChannel = new DeviceChannel();
+                deviceChannel.setChannelId(gbStream.getGbId());
+                deviceChannelList.add(deviceChannel);
+                eventPublisher.catalogEventPublish(platformId, deviceChannel, CatalogEvent.DEL);
             }
+
             dataSourceTransactionManager.commit(transactionStatus);     //鎵嬪姩鎻愪氦
             result = true;
         }catch (Exception e) {
@@ -85,4 +132,27 @@
         }
         return result;
     }
+
+    @Override
+    public void sendCatalogMsg(GbStream gbStream, String type) {
+        List<GbStream> gbStreams = new ArrayList<>();
+        if (gbStream.getGbId() != null) {
+            gbStreams.add(gbStream);
+        }else {
+            StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(gbStream.getApp(), gbStream.getStream());
+            if (streamProxyItem != null && streamProxyItem.getGbId() != null){
+                gbStreams.add(streamProxyItem);
+            }
+        }
+        if (gbStreams.size() > 0) {
+            for (GbStream gs : gbStreams) {
+                List<ParentPlatform> parentPlatforms = platformGbStreamMapper.selectByAppAndStream(gs.getApp(), gs.getStream());
+                if (parentPlatforms.size() > 0) {
+                    for (ParentPlatform parentPlatform : parentPlatforms) {
+                        eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), gs, type);
+                    }
+                }
+            }
+        }
+    }
 }

--
Gitblit v1.8.0