From b444585ebe70764117fd0433183b7bcd63c430f3 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 22 三月 2023 15:20:48 +0800
Subject: [PATCH]  优化国标级联中的通道全部导入

---
 /dev/null                                                                        |    4 -
 web_src/src/components/dialog/chooseChannel.vue                                  |   14 ++--
 sql/2.6.6-2.6.7更新.sql                                                            |    6 ++
 src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java |   64 +++++++++++++++++----
 src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java        |   14 ++++
 web_src/src/components/dialog/chooseChannelForGb.vue                             |   15 ++++
 web_src/src/components/dialog/chooseChannelForStream.vue                         |   11 +++
 7 files changed, 100 insertions(+), 28 deletions(-)

diff --git "a/sql/2.6.6-2.6.7\346\233\264\346\226\260.sql" "b/sql/2.6.6-2.6.7\346\233\264\346\226\260.sql"
index df595a8..09732b3 100755
--- "a/sql/2.6.6-2.6.7\346\233\264\346\226\260.sql"
+++ "b/sql/2.6.6-2.6.7\346\233\264\346\226\260.sql"
@@ -4,3 +4,9 @@
 alter table parent_platform
     add asMessageChannel int default 0;
 
+alter table device
+    add mediaServerId varchar(50) default null;
+
+
+
+
diff --git "a/sql/2.6.7-2.6.8\346\233\264\346\226\260.sql" "b/sql/2.6.7-2.6.8\346\233\264\346\226\260.sql"
deleted file mode 100755
index 208f0bf..0000000
--- "a/sql/2.6.7-2.6.8\346\233\264\346\226\260.sql"
+++ /dev/null
@@ -1,4 +0,0 @@
-alter table device
-    add mediaServerId varchar(50) default null;
-
-
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 89acb06..37e3b9e 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
@@ -41,6 +41,9 @@
     private PlatformGbStreamMapper platformGbStreamMapper;
 
     @Autowired
+    private SubscribeHolder subscribeHolder;
+
+    @Autowired
     private ParentPlatformMapper platformMapper;
 
     @Autowired
@@ -73,16 +76,23 @@
         }
         try {
             List<DeviceChannel> deviceChannelList = new ArrayList<>();
-            for (GbStream gbStream : gbStreams) {
+
+
+            for (int i = 0; i < gbStreams.size(); i++) {
+                GbStream gbStream = gbStreams.get(i);
                 gbStream.setCatalogId(catalogId);
                 gbStream.setPlatformId(platformId);
                 // TODO 淇敼涓烘壒閲忔彁浜�
                 platformGbStreamMapper.add(gbStream);
+                logger.info("[鍏宠仈閫氶亾]鐩存挱娴侀�氶亾 骞冲彴锛歿}, 鍏遍渶鍏宠仈閫氶亾鏁�:{}, 宸插叧鑱旓細{}", platformId, gbStreams.size(), i + 1);
                 DeviceChannel deviceChannelListByStream = getDeviceChannelListByStreamWithStatus(gbStream, catalogId, parentPlatform);
                 deviceChannelList.add(deviceChannelListByStream);
             }
             dataSourceTransactionManager.commit(transactionStatus);     //鎵嬪姩鎻愪氦
-            eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
+            if (subscribeHolder.getCatalogSubscribe(platformId) != null) {
+                eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
+            }
+
             result = true;
         }catch (Exception e) {
             logger.error("鎵归噺淇濆瓨娴佷笌骞冲彴鐨勫叧绯绘椂閿欒", e);
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
index 601ff5d..7d827d7 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
@@ -1,9 +1,6 @@
 package com.genersoft.iot.vmp.service.impl;
 
-import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
-import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog;
-import com.genersoft.iot.vmp.gb28181.bean.TreeType;
+import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
 import com.genersoft.iot.vmp.service.IPlatformChannelService;
@@ -15,7 +12,10 @@
 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 org.springframework.util.ObjectUtils;
 
 import java.util.ArrayList;
@@ -33,6 +33,16 @@
 
     @Autowired
     private PlatformChannelMapper platformChannelMapper;
+
+    @Autowired
+    TransactionDefinition transactionDefinition;
+
+    @Autowired
+    DataSourceTransactionManager dataSourceTransactionManager;
+
+    @Autowired
+    private SubscribeHolder subscribeHolder;
+
 
     @Autowired
     private DeviceChannelMapper deviceChannelMapper;
@@ -69,17 +79,47 @@
         }
         List<ChannelReduce> channelReducesToAdd = new ArrayList<>(deviceAndChannels.values());
         // 瀵瑰墿涓嬬殑鏁版嵁杩涜瀛樺偍
-        int result = 0;
+        int allCount = 0;
+        boolean result = false;
+        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
+        int limitCount = 300;
         if (channelReducesToAdd.size() > 0) {
-            result = platformChannelMapper.addChannels(platformId, channelReducesToAdd);
-            // TODO 鍚庣画缁欏钩鍙板鍔犳帶鍒跺紑鍏充互鎺у埗鏄惁鍝嶅簲鐩綍璁㈤槄
-            List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform);
-            if (deviceChannelList != null) {
-                eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
+            if (channelReducesToAdd.size() > limitCount) {
+                for (int i = 0; i < channelReducesToAdd.size(); i += limitCount) {
+                    int toIndex = i + limitCount;
+                    if (i + limitCount > channelReducesToAdd.size()) {
+                        toIndex = channelReducesToAdd.size();
+                    }
+                    int count = platformChannelMapper.addChannels(platformId, channelReducesToAdd.subList(i, toIndex));
+                    result = result || count < 0;
+                    allCount += count;
+                    logger.info("[鍏宠仈閫氶亾]鍥芥爣閫氶亾 骞冲彴锛歿}, 鍏遍渶鍏宠仈閫氶亾鏁�:{}, 宸插叧鑱旓細{}", platformId, channelReducesToAdd.size(), toIndex);
+                }
+            }else {
+                allCount = platformChannelMapper.addChannels(platformId, channelReducesToAdd);
+                result = result || allCount < 0;
+                logger.info("[鍏宠仈閫氶亾]鍥芥爣閫氶亾 骞冲彴锛歿}, 鍏宠仈閫氶亾鏁�:{}", platformId, channelReducesToAdd.size());
             }
-        }
 
-        return result;
+            if (result) {
+                //浜嬪姟鍥炴粴
+                dataSourceTransactionManager.rollback(transactionStatus);
+                allCount = 0;
+            }else {
+                logger.info("[鍏宠仈閫氶亾]鍥芥爣閫氶亾 骞冲彴锛歿}, 姝e湪瀛樺叆鏁版嵁搴�", platformId);
+                dataSourceTransactionManager.commit(transactionStatus);
+
+            }
+            SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platformId);
+            if (catalogSubscribe != null) {
+                List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform);
+                if (deviceChannelList != null) {
+                    eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
+                }
+            }
+            logger.info("[鍏宠仈閫氶亾]鍥芥爣閫氶亾 骞冲彴锛歿}, 瀛樺叆鏁版嵁搴撴垚鍔�", platformId);
+        }
+        return allCount;
     }
 
     private List<DeviceChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId, ParentPlatform platform) {
diff --git a/web_src/src/components/dialog/chooseChannel.vue b/web_src/src/components/dialog/chooseChannel.vue
index e0e79c3..be7e969 100644
--- a/web_src/src/components/dialog/chooseChannel.vue
+++ b/web_src/src/components/dialog/chooseChannel.vue
@@ -1,7 +1,7 @@
 <template>
-<div id="chooseChannel" v-loading="isLoging">
+<div id="chooseChannel" >
 
-    <el-dialog title="閫夋嫨閫氶亾" v-if="showDialog" top="2rem" width="90%" :close-on-click-modal="false" :visible.sync="showDialog" :destroy-on-close="true" @close="close()">
+    <el-dialog title="閫夋嫨閫氶亾" v-loading="loading" v-if="showDialog" top="2rem" width="90%" :close-on-click-modal="false" :visible.sync="showDialog" :destroy-on-close="true" @close="close()">
       <el-row>
         <el-col :span="10">
           <el-tabs v-model="catalogTabActiveName" >
@@ -56,7 +56,7 @@
     },
     data() {
         return {
-            isLoging: false,
+            loading: false,
             tabActiveName: "gbChannel",
             catalogTabActiveName: "catalog",
             platformId: "",
@@ -94,18 +94,17 @@
 
         },
         save: function() {
-            var that = this;
 
             this.$axios({
                 method:"post",
                 url:"/api/platform/update_channel_for_gb",
                 data:{
-                    platformId:  that.platformId,
-                    channelReduces:  that.chooseData
+                    platformId:  this.platformId,
+                    channelReduces:  this.chooseData
                 }
             }).then((res)=>{
               if (res.data.code === 0) {
-                    that.$message({
+                this.$message({
                         showClose: true,
                         message: '淇濆瓨鎴愬姛,',
                         type: 'success'
@@ -114,6 +113,7 @@
             }).catch(function (error) {
                 console.log(error);
             });
+
         },
         catalogIdChange: function (id, name) {
             this.catalogId = id;
diff --git a/web_src/src/components/dialog/chooseChannelForGb.vue b/web_src/src/components/dialog/chooseChannelForGb.vue
index fc97b4c..bc71577 100644
--- a/web_src/src/components/dialog/chooseChannelForGb.vue
+++ b/web_src/src/components/dialog/chooseChannelForGb.vue
@@ -1,5 +1,5 @@
 <template>
-<div id="chooseChannelForGb" >
+<div id="chooseChannelForGb" v-loading="loading">
   <div style="font-size: 17px; color: #606060; white-space: nowrap; line-height: 30px; font-family: monospace;">
     <span v-if="catalogId == null">{{catalogName}}鐨勫浗鏍囬�氶亾</span>
     <span v-if="catalogId != null">{{catalogName}}({{catalogId}})鐨勫浗鏍囬�氶亾</span>
@@ -79,6 +79,7 @@
     },
     data() {
         return {
+            loading: false,
             gbChannels: [],
             gbChoosechannel:{},
             searchSrt: "",
@@ -118,7 +119,9 @@
         },
         add: function (row) {
           let all = typeof(row) === "undefined"
+
           this.getCatalogFromUser((catalogId)=> {
+            let task = null;
             this.$axios({
               method:"post",
               url:"/api/platform/update_channel_for_gb",
@@ -130,12 +133,20 @@
               }
             }).then((res)=>{
               console.log("淇濆瓨鎴愬姛")
+              window.clearTimeout(task);
+              this.loading = false;
               this.getChannelList();
-            }).catch(function (error) {
+            }).catch((error)=> {
+              window.clearTimeout(task);
+              this.loading = false;
               console.log(error);
             });
+            task= setTimeout(()=>{
+              this.loading = true;
+            }, 200)
           })
 
+
         },
         remove: function (row) {
           let all = typeof(row) === "undefined"
diff --git a/web_src/src/components/dialog/chooseChannelForStream.vue b/web_src/src/components/dialog/chooseChannelForStream.vue
index 6c4653b..b522a63 100644
--- a/web_src/src/components/dialog/chooseChannelForStream.vue
+++ b/web_src/src/components/dialog/chooseChannelForStream.vue
@@ -1,5 +1,5 @@
 <template>
-<div id="chooseChannelFoStream" >
+<div id="chooseChannelFoStream" v-loading="loading">
     <div style="font-size: 17px; color: #606060; white-space: nowrap; line-height: 30px; font-family: monospace;">
       <span v-if="catalogId == null">{{catalogName}}鐨勭洿鎾�氶亾</span>
       <span v-if="catalogId != null">{{catalogName}}({{catalogId}})鐨勭洿鎾�氶亾</span>
@@ -85,6 +85,7 @@
     },
     data() {
         return {
+            loading: false,
             gbStreams: [],
             gbChoosechannel:{},
             channelType: "",
@@ -132,6 +133,7 @@
         add: function (row, scope) {
           let all = typeof(row) === "undefined"
           this.getCatalogFromUser((catalogId)=>{
+            let task = null;
             this.$axios({
               method:"post",
               url:"/api/gbStream/add",
@@ -143,11 +145,18 @@
               }
             }).then((res)=>{
               console.log("淇濆瓨鎴愬姛")
+              window.clearTimeout(task);
+              this.loading = false;
               // this.gbStreams.splice(scope.$index,1)
               this.getChannelList();
             }).catch(function (error) {
+              window.clearTimeout(task);
+              this.loading = false;
               console.log(error);
             });
+            task= setTimeout(()=>{
+              this.loading = true;
+            }, 200)
           })
 
 

--
Gitblit v1.8.0