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 | 41 | private PlatformGbStreamMapper platformGbStreamMapper; |
| 42 | 42 | |
| 43 | 43 | @Autowired |
| 44 | + private SubscribeHolder subscribeHolder; | |
| 45 | + | |
| 46 | + @Autowired | |
| 44 | 47 | private ParentPlatformMapper platformMapper; |
| 45 | 48 | |
| 46 | 49 | @Autowired |
| ... | ... | @@ -73,16 +76,23 @@ public class GbStreamServiceImpl implements IGbStreamService { |
| 73 | 76 | } |
| 74 | 77 | try { |
| 75 | 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 | 83 | gbStream.setCatalogId(catalogId); |
| 78 | 84 | gbStream.setPlatformId(platformId); |
| 79 | 85 | // TODO 修改为批量提交 |
| 80 | 86 | platformGbStreamMapper.add(gbStream); |
| 87 | + logger.info("[关联通道]直播流通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platformId, gbStreams.size(), i + 1); | |
| 81 | 88 | DeviceChannel deviceChannelListByStream = getDeviceChannelListByStreamWithStatus(gbStream, catalogId, parentPlatform); |
| 82 | 89 | deviceChannelList.add(deviceChannelListByStream); |
| 83 | 90 | } |
| 84 | 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 | 96 | result = true; |
| 87 | 97 | }catch (Exception e) { |
| 88 | 98 | logger.error("批量保存流与平台的关系时错误", e); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
| 1 | 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 | 4 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 8 | 5 | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| 9 | 6 | import com.genersoft.iot.vmp.service.IPlatformChannelService; |
| ... | ... | @@ -15,7 +12,10 @@ import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; |
| 15 | 12 | import org.slf4j.Logger; |
| 16 | 13 | import org.slf4j.LoggerFactory; |
| 17 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; | |
| 18 | 16 | import org.springframework.stereotype.Service; |
| 17 | +import org.springframework.transaction.TransactionDefinition; | |
| 18 | +import org.springframework.transaction.TransactionStatus; | |
| 19 | 19 | import org.springframework.util.ObjectUtils; |
| 20 | 20 | |
| 21 | 21 | import java.util.ArrayList; |
| ... | ... | @@ -35,6 +35,16 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { |
| 35 | 35 | private PlatformChannelMapper platformChannelMapper; |
| 36 | 36 | |
| 37 | 37 | @Autowired |
| 38 | + TransactionDefinition transactionDefinition; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + DataSourceTransactionManager dataSourceTransactionManager; | |
| 42 | + | |
| 43 | + @Autowired | |
| 44 | + private SubscribeHolder subscribeHolder; | |
| 45 | + | |
| 46 | + | |
| 47 | + @Autowired | |
| 38 | 48 | private DeviceChannelMapper deviceChannelMapper; |
| 39 | 49 | |
| 40 | 50 | @Autowired |
| ... | ... | @@ -69,17 +79,47 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { |
| 69 | 79 | } |
| 70 | 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 | 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 | 125 | private List<DeviceChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId, ParentPlatform platform) { | ... | ... |
web_src/src/components/dialog/chooseChannel.vue
| 1 | 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 | 5 | <el-row> |
| 6 | 6 | <el-col :span="10"> |
| 7 | 7 | <el-tabs v-model="catalogTabActiveName" > |
| ... | ... | @@ -56,7 +56,7 @@ export default { |
| 56 | 56 | }, |
| 57 | 57 | data() { |
| 58 | 58 | return { |
| 59 | - isLoging: false, | |
| 59 | + loading: false, | |
| 60 | 60 | tabActiveName: "gbChannel", |
| 61 | 61 | catalogTabActiveName: "catalog", |
| 62 | 62 | platformId: "", |
| ... | ... | @@ -94,18 +94,17 @@ export default { |
| 94 | 94 | |
| 95 | 95 | }, |
| 96 | 96 | save: function() { |
| 97 | - var that = this; | |
| 98 | 97 | |
| 99 | 98 | this.$axios({ |
| 100 | 99 | method:"post", |
| 101 | 100 | url:"/api/platform/update_channel_for_gb", |
| 102 | 101 | data:{ |
| 103 | - platformId: that.platformId, | |
| 104 | - channelReduces: that.chooseData | |
| 102 | + platformId: this.platformId, | |
| 103 | + channelReduces: this.chooseData | |
| 105 | 104 | } |
| 106 | 105 | }).then((res)=>{ |
| 107 | 106 | if (res.data.code === 0) { |
| 108 | - that.$message({ | |
| 107 | + this.$message({ | |
| 109 | 108 | showClose: true, |
| 110 | 109 | message: '保存成功,', |
| 111 | 110 | type: 'success' |
| ... | ... | @@ -114,6 +113,7 @@ export default { |
| 114 | 113 | }).catch(function (error) { |
| 115 | 114 | console.log(error); |
| 116 | 115 | }); |
| 116 | + | |
| 117 | 117 | }, |
| 118 | 118 | catalogIdChange: function (id, name) { |
| 119 | 119 | this.catalogId = id; | ... | ... |
web_src/src/components/dialog/chooseChannelForGb.vue
| 1 | 1 | <template> |
| 2 | -<div id="chooseChannelForGb" > | |
| 2 | +<div id="chooseChannelForGb" v-loading="loading"> | |
| 3 | 3 | <div style="font-size: 17px; color: #606060; white-space: nowrap; line-height: 30px; font-family: monospace;"> |
| 4 | 4 | <span v-if="catalogId == null">{{catalogName}}的国标通道</span> |
| 5 | 5 | <span v-if="catalogId != null">{{catalogName}}({{catalogId}})的国标通道</span> |
| ... | ... | @@ -79,6 +79,7 @@ export default { |
| 79 | 79 | }, |
| 80 | 80 | data() { |
| 81 | 81 | return { |
| 82 | + loading: false, | |
| 82 | 83 | gbChannels: [], |
| 83 | 84 | gbChoosechannel:{}, |
| 84 | 85 | searchSrt: "", |
| ... | ... | @@ -118,7 +119,9 @@ export default { |
| 118 | 119 | }, |
| 119 | 120 | add: function (row) { |
| 120 | 121 | let all = typeof(row) === "undefined" |
| 122 | + | |
| 121 | 123 | this.getCatalogFromUser((catalogId)=> { |
| 124 | + let task = null; | |
| 122 | 125 | this.$axios({ |
| 123 | 126 | method:"post", |
| 124 | 127 | url:"/api/platform/update_channel_for_gb", |
| ... | ... | @@ -130,12 +133,20 @@ export default { |
| 130 | 133 | } |
| 131 | 134 | }).then((res)=>{ |
| 132 | 135 | console.log("保存成功") |
| 136 | + window.clearTimeout(task); | |
| 137 | + this.loading = false; | |
| 133 | 138 | this.getChannelList(); |
| 134 | - }).catch(function (error) { | |
| 139 | + }).catch((error)=> { | |
| 140 | + window.clearTimeout(task); | |
| 141 | + this.loading = false; | |
| 135 | 142 | console.log(error); |
| 136 | 143 | }); |
| 144 | + task= setTimeout(()=>{ | |
| 145 | + this.loading = true; | |
| 146 | + }, 200) | |
| 137 | 147 | }) |
| 138 | 148 | |
| 149 | + | |
| 139 | 150 | }, |
| 140 | 151 | remove: function (row) { |
| 141 | 152 | let all = typeof(row) === "undefined" | ... | ... |
web_src/src/components/dialog/chooseChannelForStream.vue
| 1 | 1 | <template> |
| 2 | -<div id="chooseChannelFoStream" > | |
| 2 | +<div id="chooseChannelFoStream" v-loading="loading"> | |
| 3 | 3 | <div style="font-size: 17px; color: #606060; white-space: nowrap; line-height: 30px; font-family: monospace;"> |
| 4 | 4 | <span v-if="catalogId == null">{{catalogName}}的直播通道</span> |
| 5 | 5 | <span v-if="catalogId != null">{{catalogName}}({{catalogId}})的直播通道</span> |
| ... | ... | @@ -85,6 +85,7 @@ export default { |
| 85 | 85 | }, |
| 86 | 86 | data() { |
| 87 | 87 | return { |
| 88 | + loading: false, | |
| 88 | 89 | gbStreams: [], |
| 89 | 90 | gbChoosechannel:{}, |
| 90 | 91 | channelType: "", |
| ... | ... | @@ -132,6 +133,7 @@ export default { |
| 132 | 133 | add: function (row, scope) { |
| 133 | 134 | let all = typeof(row) === "undefined" |
| 134 | 135 | this.getCatalogFromUser((catalogId)=>{ |
| 136 | + let task = null; | |
| 135 | 137 | this.$axios({ |
| 136 | 138 | method:"post", |
| 137 | 139 | url:"/api/gbStream/add", |
| ... | ... | @@ -143,11 +145,18 @@ export default { |
| 143 | 145 | } |
| 144 | 146 | }).then((res)=>{ |
| 145 | 147 | console.log("保存成功") |
| 148 | + window.clearTimeout(task); | |
| 149 | + this.loading = false; | |
| 146 | 150 | // this.gbStreams.splice(scope.$index,1) |
| 147 | 151 | this.getChannelList(); |
| 148 | 152 | }).catch(function (error) { |
| 153 | + window.clearTimeout(task); | |
| 154 | + this.loading = false; | |
| 149 | 155 | console.log(error); |
| 150 | 156 | }); |
| 157 | + task= setTimeout(()=>{ | |
| 158 | + this.loading = true; | |
| 159 | + }, 200) | |
| 151 | 160 | }) |
| 152 | 161 | |
| 153 | 162 | ... | ... |