Commit f1fae7aac6b125957f6795f692609f2a296aee1a

Authored by panlinlin
1 parent 937e5914

增加移除离线设备的功能

src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
... ... @@ -340,7 +340,7 @@ public class ZLMHttpHookListener {
340 340 String app = json.getString("app");
341 341 String streamId = json.getString("stream");
342 342 StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
343   - if ("rtp".equals(app) && streamId.indexOf("gb_play") > -1 && streamInfo == null) {
  343 + if ("rtp".equals(app) && streamId.contains("gb_play") && streamInfo == null) {
344 344 String[] s = streamId.split("_");
345 345 if (s.length == 4) {
346 346 String deviceId = s[2];
... ...
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
... ... @@ -104,4 +104,9 @@ public interface IRedisCatchStorage {
104 104 */
105 105 boolean isChannelSendingRTP(String channelId);
106 106  
  107 + /**
  108 + * 清空某个设备的所有缓存
  109 + * @param deviceId 设备ID
  110 + */
  111 + void clearCatchByDeviceId(String deviceId);
107 112 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java
... ... @@ -38,6 +38,11 @@ public interface PlatformChannelMapper {
38 38 int delChannelForGB(String platformId, List<ChannelReduce> channelReducesToDel);
39 39  
40 40 @Delete("<script> "+
  41 + "DELETE FROM platform_gb_channel WHERE deviceId='${deviceId}' " +
  42 + "</script>")
  43 + int delChannelForDeviceId(String deviceId);
  44 +
  45 + @Delete("<script> "+
41 46 "DELETE FROM platform_gb_channel WHERE platformId='${platformId}'" +
42 47 "</script>")
43 48 int cleanChannelForGB(String platformId);
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
... ... @@ -259,4 +259,22 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
259 259 }
260 260 }
261 261  
  262 + @Override
  263 + public void clearCatchByDeviceId(String deviceId) {
  264 + List<Object> playLeys = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAYER_PREFIX,
  265 + deviceId));
  266 + if (playLeys.size() > 0) {
  267 + for (Object key : playLeys) {
  268 + redis.del(key.toString());
  269 + }
  270 + }
  271 +
  272 + List<Object> playBackers = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
  273 + deviceId));
  274 + if (playBackers.size() > 0) {
  275 + for (Object key : playBackers) {
  276 + redis.del(key.toString());
  277 + }
  278 + }
  279 + }
262 280 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
... ... @@ -195,9 +195,22 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
195 195 */
196 196 @Override
197 197 public boolean delete(String deviceId) {
198   - int result = deviceMapper.del(deviceId);
199   -
200   - return result > 0;
  198 + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
  199 + boolean result = false;
  200 + try {
  201 + if (platformChannelMapper.delChannelForDeviceId(deviceId) <0 // 删除与国标平台的关联
  202 + || deviceChannelMapper.cleanChannelsByDeviceId(deviceId) < 0 // 删除他的通道
  203 + || deviceMapper.del(deviceId) < 0 // 移除设备信息
  204 + ) {
  205 + //事务回滚
  206 + dataSourceTransactionManager.rollback(transactionStatus);
  207 + }
  208 + result = true;
  209 + dataSourceTransactionManager.commit(transactionStatus); //手动提交
  210 + }catch (Exception e) {
  211 + dataSourceTransactionManager.rollback(transactionStatus);
  212 + }
  213 + return result;
201 214 }
202 215  
203 216 /**
... ... @@ -550,4 +563,6 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
550 563 public void mediaOutline(String app, String streamId) {
551 564 gbStreamMapper.setStatus(app, streamId, false);
552 565 }
  566 +
  567 +
553 568 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
... ... @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.device;
2 2  
3 3 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
4 4 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
  5 +import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
5 6 import com.github.pagehelper.PageInfo;
6 7 import io.swagger.annotations.*;
7 8 import org.slf4j.Logger;
... ... @@ -33,6 +34,9 @@ public class DeviceQuery {
33 34  
34 35 @Autowired
35 36 private IVideoManagerStorager storager;
  37 +
  38 + @Autowired
  39 + private IRedisCatchStorage redisCatchStorage;
36 40  
37 41 @Autowired
38 42 private SIPCommander cmder;
... ... @@ -177,8 +181,10 @@ public class DeviceQuery {
177 181 if (offLineDetector.isOnline(deviceId)) {
178 182 return new ResponseEntity<String>("不允许删除在线设备!", HttpStatus.NOT_ACCEPTABLE);
179 183 }
  184 + // 清除redis记录
180 185 boolean isSuccess = storager.delete(deviceId);
181 186 if (isSuccess) {
  187 + redisCatchStorage.clearCatchByDeviceId(deviceId);
182 188 JSONObject json = new JSONObject();
183 189 json.put("deviceId", deviceId);
184 190 return new ResponseEntity<>(json.toString(),HttpStatus.OK);
... ...
web_src/src/components/DeviceList.vue
... ... @@ -51,11 +51,12 @@
51 51  
52 52 <el-table-column label="操作" width="360" align="center" fixed="right">
53 53 <template slot-scope="scope">
54   - <el-button size="mini" :ref="scope.row.deviceId + 'refbtn' " icon="el-icon-refresh" @click="refDevice(scope.row)">刷新</el-button>
  54 + <el-button size="mini" :ref="scope.row.deviceId + 'refbtn' " v-if="scope.row.online!=0" icon="el-icon-refresh" @click="refDevice(scope.row)">刷新</el-button>
55 55 <el-button-group>
56   - <el-button size="mini" icon="el-icon-video-camera-solid" v-bind:disabled="scope.row.online==0" type="primary" @click="showChannelList(scope.row)">通道</el-button>
57   - <el-button size="mini" icon="el-icon-location" v-bind:disabled="scope.row.online==0" type="primary" @click="showDevicePosition(scope.row)">定位</el-button>
58   - <el-button size="mini" icon="el-icon-s-tools" v-bind:disabled="scope.row.online==0" type="primary">控制</el-button>
  56 + <el-button size="mini" icon="el-icon-video-camera-solid" v-bind:disabled="scope.row.online==0" type="primary" @click="showChannelList(scope.row)">通道</el-button>
  57 + <el-button size="mini" icon="el-icon-location" v-bind:disabled="scope.row.online==0" type="primary" @click="showDevicePosition(scope.row)">定位</el-button>
  58 + <el-button size="mini" icon="el-icon-s-tools" v-bind:disabled="scope.row.online==0" type="primary">控制</el-button>
  59 + <el-button size="mini" icon="el-icon-delete" type="danger" v-if="scope.row.online==0" @click="deleteDevice(scope.row)">删除</el-button>
59 60 </el-button-group>
60 61 </template>
61 62 </el-table-column>
... ... @@ -155,6 +156,18 @@
155 156 });
156 157  
157 158 },
  159 + deleteDevice: function(row) {
  160 + let that = this;
  161 + this.$axios({
  162 + method: 'delete',
  163 + url:`/api/device/query/devices/${row.deviceId}/delete`
  164 + }).then((res)=>{
  165 + this.getDeviceList();
  166 + }).catch((error) =>{
  167 + console.log(error);
  168 + });
  169 +
  170 + },
158 171 showChannelList: function(row) {
159 172 console.log(JSON.stringify(row))
160 173 this.$router.push(`/channelList/${row.deviceId}/0/15/1`);
... ...