Commit b444585ebe70764117fd0433183b7bcd63c430f3
1 parent
c73fe2b0
优化国标级联中的通道全部导入
Showing
7 changed files
with
100 additions
and
28 deletions
sql/2.6.6-2.6.7更新.sql
sql/2.6.7-2.6.8更新.sql deleted
100755 → 0
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
| @@ -41,6 +41,9 @@ public class GbStreamServiceImpl implements IGbStreamService { | @@ -41,6 +41,9 @@ public class GbStreamServiceImpl implements IGbStreamService { | ||
| 41 | private PlatformGbStreamMapper platformGbStreamMapper; | 41 | private PlatformGbStreamMapper platformGbStreamMapper; |
| 42 | 42 | ||
| 43 | @Autowired | 43 | @Autowired |
| 44 | + private SubscribeHolder subscribeHolder; | ||
| 45 | + | ||
| 46 | + @Autowired | ||
| 44 | private ParentPlatformMapper platformMapper; | 47 | private ParentPlatformMapper platformMapper; |
| 45 | 48 | ||
| 46 | @Autowired | 49 | @Autowired |
| @@ -73,16 +76,23 @@ public class GbStreamServiceImpl implements IGbStreamService { | @@ -73,16 +76,23 @@ public class GbStreamServiceImpl implements IGbStreamService { | ||
| 73 | } | 76 | } |
| 74 | try { | 77 | try { |
| 75 | List<DeviceChannel> deviceChannelList = new ArrayList<>(); | 78 | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| 76 | - for (GbStream gbStream : gbStreams) { | 79 | + |
| 80 | + | ||
| 81 | + for (int i = 0; i < gbStreams.size(); i++) { | ||
| 82 | + GbStream gbStream = gbStreams.get(i); | ||
| 77 | gbStream.setCatalogId(catalogId); | 83 | gbStream.setCatalogId(catalogId); |
| 78 | gbStream.setPlatformId(platformId); | 84 | gbStream.setPlatformId(platformId); |
| 79 | // TODO 修改为批量提交 | 85 | // TODO 修改为批量提交 |
| 80 | platformGbStreamMapper.add(gbStream); | 86 | platformGbStreamMapper.add(gbStream); |
| 87 | + logger.info("[关联通道]直播流通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platformId, gbStreams.size(), i + 1); | ||
| 81 | DeviceChannel deviceChannelListByStream = getDeviceChannelListByStreamWithStatus(gbStream, catalogId, parentPlatform); | 88 | DeviceChannel deviceChannelListByStream = getDeviceChannelListByStreamWithStatus(gbStream, catalogId, parentPlatform); |
| 82 | deviceChannelList.add(deviceChannelListByStream); | 89 | deviceChannelList.add(deviceChannelListByStream); |
| 83 | } | 90 | } |
| 84 | dataSourceTransactionManager.commit(transactionStatus); //手动提交 | 91 | dataSourceTransactionManager.commit(transactionStatus); //手动提交 |
| 85 | - eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); | 92 | + if (subscribeHolder.getCatalogSubscribe(platformId) != null) { |
| 93 | + eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); | ||
| 94 | + } | ||
| 95 | + | ||
| 86 | result = true; | 96 | result = true; |
| 87 | }catch (Exception e) { | 97 | }catch (Exception e) { |
| 88 | logger.error("批量保存流与平台的关系时错误", e); | 98 | logger.error("批量保存流与平台的关系时错误", e); |
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
| 1 | package com.genersoft.iot.vmp.service.impl; | 1 | package com.genersoft.iot.vmp.service.impl; |
| 2 | 2 | ||
| 3 | -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 4 | -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | ||
| 5 | -import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog; | ||
| 6 | -import com.genersoft.iot.vmp.gb28181.bean.TreeType; | 3 | +import com.genersoft.iot.vmp.gb28181.bean.*; |
| 7 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | 4 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 8 | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; | 5 | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| 9 | import com.genersoft.iot.vmp.service.IPlatformChannelService; | 6 | import com.genersoft.iot.vmp.service.IPlatformChannelService; |
| @@ -15,7 +12,10 @@ import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; | @@ -15,7 +12,10 @@ import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; | ||
| 15 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; | 13 | import org.slf4j.LoggerFactory; |
| 17 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
| 18 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 17 | +import org.springframework.transaction.TransactionDefinition; | ||
| 18 | +import org.springframework.transaction.TransactionStatus; | ||
| 19 | import org.springframework.util.ObjectUtils; | 19 | import org.springframework.util.ObjectUtils; |
| 20 | 20 | ||
| 21 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
| @@ -35,6 +35,16 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { | @@ -35,6 +35,16 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { | ||
| 35 | private PlatformChannelMapper platformChannelMapper; | 35 | private PlatformChannelMapper platformChannelMapper; |
| 36 | 36 | ||
| 37 | @Autowired | 37 | @Autowired |
| 38 | + TransactionDefinition transactionDefinition; | ||
| 39 | + | ||
| 40 | + @Autowired | ||
| 41 | + DataSourceTransactionManager dataSourceTransactionManager; | ||
| 42 | + | ||
| 43 | + @Autowired | ||
| 44 | + private SubscribeHolder subscribeHolder; | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + @Autowired | ||
| 38 | private DeviceChannelMapper deviceChannelMapper; | 48 | private DeviceChannelMapper deviceChannelMapper; |
| 39 | 49 | ||
| 40 | @Autowired | 50 | @Autowired |
| @@ -69,17 +79,47 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { | @@ -69,17 +79,47 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { | ||
| 69 | } | 79 | } |
| 70 | List<ChannelReduce> channelReducesToAdd = new ArrayList<>(deviceAndChannels.values()); | 80 | List<ChannelReduce> channelReducesToAdd = new ArrayList<>(deviceAndChannels.values()); |
| 71 | // 对剩下的数据进行存储 | 81 | // 对剩下的数据进行存储 |
| 72 | - int result = 0; | 82 | + int allCount = 0; |
| 83 | + boolean result = false; | ||
| 84 | + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); | ||
| 85 | + int limitCount = 300; | ||
| 73 | if (channelReducesToAdd.size() > 0) { | 86 | if (channelReducesToAdd.size() > 0) { |
| 74 | - result = platformChannelMapper.addChannels(platformId, channelReducesToAdd); | ||
| 75 | - // TODO 后续给平台增加控制开关以控制是否响应目录订阅 | ||
| 76 | - List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform); | ||
| 77 | - if (deviceChannelList != null) { | ||
| 78 | - eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); | 87 | + if (channelReducesToAdd.size() > limitCount) { |
| 88 | + for (int i = 0; i < channelReducesToAdd.size(); i += limitCount) { | ||
| 89 | + int toIndex = i + limitCount; | ||
| 90 | + if (i + limitCount > channelReducesToAdd.size()) { | ||
| 91 | + toIndex = channelReducesToAdd.size(); | ||
| 92 | + } | ||
| 93 | + int count = platformChannelMapper.addChannels(platformId, channelReducesToAdd.subList(i, toIndex)); | ||
| 94 | + result = result || count < 0; | ||
| 95 | + allCount += count; | ||
| 96 | + logger.info("[关联通道]国标通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platformId, channelReducesToAdd.size(), toIndex); | ||
| 97 | + } | ||
| 98 | + }else { | ||
| 99 | + allCount = platformChannelMapper.addChannels(platformId, channelReducesToAdd); | ||
| 100 | + result = result || allCount < 0; | ||
| 101 | + logger.info("[关联通道]国标通道 平台:{}, 关联通道数:{}", platformId, channelReducesToAdd.size()); | ||
| 79 | } | 102 | } |
| 80 | - } | ||
| 81 | 103 | ||
| 82 | - return result; | 104 | + if (result) { |
| 105 | + //事务回滚 | ||
| 106 | + dataSourceTransactionManager.rollback(transactionStatus); | ||
| 107 | + allCount = 0; | ||
| 108 | + }else { | ||
| 109 | + logger.info("[关联通道]国标通道 平台:{}, 正在存入数据库", platformId); | ||
| 110 | + dataSourceTransactionManager.commit(transactionStatus); | ||
| 111 | + | ||
| 112 | + } | ||
| 113 | + SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platformId); | ||
| 114 | + if (catalogSubscribe != null) { | ||
| 115 | + List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform); | ||
| 116 | + if (deviceChannelList != null) { | ||
| 117 | + eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + logger.info("[关联通道]国标通道 平台:{}, 存入数据库成功", platformId); | ||
| 121 | + } | ||
| 122 | + return allCount; | ||
| 83 | } | 123 | } |
| 84 | 124 | ||
| 85 | private List<DeviceChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId, ParentPlatform platform) { | 125 | private List<DeviceChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId, ParentPlatform platform) { |
web_src/src/components/dialog/chooseChannel.vue
| 1 | <template> | 1 | <template> |
| 2 | -<div id="chooseChannel" v-loading="isLoging"> | 2 | +<div id="chooseChannel" > |
| 3 | 3 | ||
| 4 | - <el-dialog title="选择通道" v-if="showDialog" top="2rem" width="90%" :close-on-click-modal="false" :visible.sync="showDialog" :destroy-on-close="true" @close="close()"> | 4 | + <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()"> |
| 5 | <el-row> | 5 | <el-row> |
| 6 | <el-col :span="10"> | 6 | <el-col :span="10"> |
| 7 | <el-tabs v-model="catalogTabActiveName" > | 7 | <el-tabs v-model="catalogTabActiveName" > |
| @@ -56,7 +56,7 @@ export default { | @@ -56,7 +56,7 @@ export default { | ||
| 56 | }, | 56 | }, |
| 57 | data() { | 57 | data() { |
| 58 | return { | 58 | return { |
| 59 | - isLoging: false, | 59 | + loading: false, |
| 60 | tabActiveName: "gbChannel", | 60 | tabActiveName: "gbChannel", |
| 61 | catalogTabActiveName: "catalog", | 61 | catalogTabActiveName: "catalog", |
| 62 | platformId: "", | 62 | platformId: "", |
| @@ -94,18 +94,17 @@ export default { | @@ -94,18 +94,17 @@ export default { | ||
| 94 | 94 | ||
| 95 | }, | 95 | }, |
| 96 | save: function() { | 96 | save: function() { |
| 97 | - var that = this; | ||
| 98 | 97 | ||
| 99 | this.$axios({ | 98 | this.$axios({ |
| 100 | method:"post", | 99 | method:"post", |
| 101 | url:"/api/platform/update_channel_for_gb", | 100 | url:"/api/platform/update_channel_for_gb", |
| 102 | data:{ | 101 | data:{ |
| 103 | - platformId: that.platformId, | ||
| 104 | - channelReduces: that.chooseData | 102 | + platformId: this.platformId, |
| 103 | + channelReduces: this.chooseData | ||
| 105 | } | 104 | } |
| 106 | }).then((res)=>{ | 105 | }).then((res)=>{ |
| 107 | if (res.data.code === 0) { | 106 | if (res.data.code === 0) { |
| 108 | - that.$message({ | 107 | + this.$message({ |
| 109 | showClose: true, | 108 | showClose: true, |
| 110 | message: '保存成功,', | 109 | message: '保存成功,', |
| 111 | type: 'success' | 110 | type: 'success' |
| @@ -114,6 +113,7 @@ export default { | @@ -114,6 +113,7 @@ export default { | ||
| 114 | }).catch(function (error) { | 113 | }).catch(function (error) { |
| 115 | console.log(error); | 114 | console.log(error); |
| 116 | }); | 115 | }); |
| 116 | + | ||
| 117 | }, | 117 | }, |
| 118 | catalogIdChange: function (id, name) { | 118 | catalogIdChange: function (id, name) { |
| 119 | this.catalogId = id; | 119 | this.catalogId = id; |
web_src/src/components/dialog/chooseChannelForGb.vue
| 1 | <template> | 1 | <template> |
| 2 | -<div id="chooseChannelForGb" > | 2 | +<div id="chooseChannelForGb" v-loading="loading"> |
| 3 | <div style="font-size: 17px; color: #606060; white-space: nowrap; line-height: 30px; font-family: monospace;"> | 3 | <div style="font-size: 17px; color: #606060; white-space: nowrap; line-height: 30px; font-family: monospace;"> |
| 4 | <span v-if="catalogId == null">{{catalogName}}的国标通道</span> | 4 | <span v-if="catalogId == null">{{catalogName}}的国标通道</span> |
| 5 | <span v-if="catalogId != null">{{catalogName}}({{catalogId}})的国标通道</span> | 5 | <span v-if="catalogId != null">{{catalogName}}({{catalogId}})的国标通道</span> |
| @@ -79,6 +79,7 @@ export default { | @@ -79,6 +79,7 @@ export default { | ||
| 79 | }, | 79 | }, |
| 80 | data() { | 80 | data() { |
| 81 | return { | 81 | return { |
| 82 | + loading: false, | ||
| 82 | gbChannels: [], | 83 | gbChannels: [], |
| 83 | gbChoosechannel:{}, | 84 | gbChoosechannel:{}, |
| 84 | searchSrt: "", | 85 | searchSrt: "", |
| @@ -118,7 +119,9 @@ export default { | @@ -118,7 +119,9 @@ export default { | ||
| 118 | }, | 119 | }, |
| 119 | add: function (row) { | 120 | add: function (row) { |
| 120 | let all = typeof(row) === "undefined" | 121 | let all = typeof(row) === "undefined" |
| 122 | + | ||
| 121 | this.getCatalogFromUser((catalogId)=> { | 123 | this.getCatalogFromUser((catalogId)=> { |
| 124 | + let task = null; | ||
| 122 | this.$axios({ | 125 | this.$axios({ |
| 123 | method:"post", | 126 | method:"post", |
| 124 | url:"/api/platform/update_channel_for_gb", | 127 | url:"/api/platform/update_channel_for_gb", |
| @@ -130,12 +133,20 @@ export default { | @@ -130,12 +133,20 @@ export default { | ||
| 130 | } | 133 | } |
| 131 | }).then((res)=>{ | 134 | }).then((res)=>{ |
| 132 | console.log("保存成功") | 135 | console.log("保存成功") |
| 136 | + window.clearTimeout(task); | ||
| 137 | + this.loading = false; | ||
| 133 | this.getChannelList(); | 138 | this.getChannelList(); |
| 134 | - }).catch(function (error) { | 139 | + }).catch((error)=> { |
| 140 | + window.clearTimeout(task); | ||
| 141 | + this.loading = false; | ||
| 135 | console.log(error); | 142 | console.log(error); |
| 136 | }); | 143 | }); |
| 144 | + task= setTimeout(()=>{ | ||
| 145 | + this.loading = true; | ||
| 146 | + }, 200) | ||
| 137 | }) | 147 | }) |
| 138 | 148 | ||
| 149 | + | ||
| 139 | }, | 150 | }, |
| 140 | remove: function (row) { | 151 | remove: function (row) { |
| 141 | let all = typeof(row) === "undefined" | 152 | let all = typeof(row) === "undefined" |
web_src/src/components/dialog/chooseChannelForStream.vue
| 1 | <template> | 1 | <template> |
| 2 | -<div id="chooseChannelFoStream" > | 2 | +<div id="chooseChannelFoStream" v-loading="loading"> |
| 3 | <div style="font-size: 17px; color: #606060; white-space: nowrap; line-height: 30px; font-family: monospace;"> | 3 | <div style="font-size: 17px; color: #606060; white-space: nowrap; line-height: 30px; font-family: monospace;"> |
| 4 | <span v-if="catalogId == null">{{catalogName}}的直播通道</span> | 4 | <span v-if="catalogId == null">{{catalogName}}的直播通道</span> |
| 5 | <span v-if="catalogId != null">{{catalogName}}({{catalogId}})的直播通道</span> | 5 | <span v-if="catalogId != null">{{catalogName}}({{catalogId}})的直播通道</span> |
| @@ -85,6 +85,7 @@ export default { | @@ -85,6 +85,7 @@ export default { | ||
| 85 | }, | 85 | }, |
| 86 | data() { | 86 | data() { |
| 87 | return { | 87 | return { |
| 88 | + loading: false, | ||
| 88 | gbStreams: [], | 89 | gbStreams: [], |
| 89 | gbChoosechannel:{}, | 90 | gbChoosechannel:{}, |
| 90 | channelType: "", | 91 | channelType: "", |
| @@ -132,6 +133,7 @@ export default { | @@ -132,6 +133,7 @@ export default { | ||
| 132 | add: function (row, scope) { | 133 | add: function (row, scope) { |
| 133 | let all = typeof(row) === "undefined" | 134 | let all = typeof(row) === "undefined" |
| 134 | this.getCatalogFromUser((catalogId)=>{ | 135 | this.getCatalogFromUser((catalogId)=>{ |
| 136 | + let task = null; | ||
| 135 | this.$axios({ | 137 | this.$axios({ |
| 136 | method:"post", | 138 | method:"post", |
| 137 | url:"/api/gbStream/add", | 139 | url:"/api/gbStream/add", |
| @@ -143,11 +145,18 @@ export default { | @@ -143,11 +145,18 @@ export default { | ||
| 143 | } | 145 | } |
| 144 | }).then((res)=>{ | 146 | }).then((res)=>{ |
| 145 | console.log("保存成功") | 147 | console.log("保存成功") |
| 148 | + window.clearTimeout(task); | ||
| 149 | + this.loading = false; | ||
| 146 | // this.gbStreams.splice(scope.$index,1) | 150 | // this.gbStreams.splice(scope.$index,1) |
| 147 | this.getChannelList(); | 151 | this.getChannelList(); |
| 148 | }).catch(function (error) { | 152 | }).catch(function (error) { |
| 153 | + window.clearTimeout(task); | ||
| 154 | + this.loading = false; | ||
| 149 | console.log(error); | 155 | console.log(error); |
| 150 | }); | 156 | }); |
| 157 | + task= setTimeout(()=>{ | ||
| 158 | + this.loading = true; | ||
| 159 | + }, 200) | ||
| 151 | }) | 160 | }) |
| 152 | 161 | ||
| 153 | 162 |