From c23932eb00edfa5f734b0d17eced838c5c7577c0 Mon Sep 17 00:00:00 2001
From: 648540858 <456PANlinlin>
Date: 星期三, 17 十一月 2021 22:58:41 +0800
Subject: [PATCH] #221

---
 src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java |  222 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 179 insertions(+), 43 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
index cebb30b..e5b1269 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -1,20 +1,19 @@
 package com.genersoft.iot.vmp.storager.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
-import com.genersoft.iot.vmp.conf.MediaServerConfig;
-import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
+import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
+@SuppressWarnings("rawtypes")
 @Component
 public class RedisCatchStorageImpl implements IRedisCatchStorage {
 
@@ -24,6 +23,7 @@
     @Autowired
     private DeviceChannelMapper deviceChannelMapper;
 
+    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     /**
      * 寮�濮嬫挱鏀炬椂灏嗘祦瀛樺叆redis
@@ -32,7 +32,7 @@
      */
     @Override
     public boolean startPlay(StreamInfo stream) {
-        return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()),
+        return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
                 stream);
     }
 
@@ -44,16 +44,10 @@
     @Override
     public boolean stopPlay(StreamInfo streamInfo) {
         if (streamInfo == null) return false;
-        DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId());
-        if (deviceChannel != null) {
-            deviceChannel.setStreamId(null);
-            deviceChannel.setDeviceId(streamInfo.getDeviceID());
-            deviceChannelMapper.update(deviceChannel);
-        }
         return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
                 streamInfo.getStreamId(),
                 streamInfo.getDeviceID(),
-                streamInfo.getCahnnelId()));
+                streamInfo.getChannelId()));
     }
 
     /**
@@ -66,7 +60,7 @@
                 VideoManagerConstants.PLAYER_PREFIX,
                 streamInfo.getStreamId(),
                 streamInfo.getDeviceID(),
-                streamInfo.getCahnnelId()));
+                streamInfo.getChannelId()));
     }
     @Override
     public StreamInfo queryPlayByStreamId(String steamId) {
@@ -83,32 +77,13 @@
     }
 
     @Override
-    public StreamInfo queryPlayByDevice(String deviceId, String code) {
+    public StreamInfo queryPlayByDevice(String deviceId, String channelId) {
 //		List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
         List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
                 deviceId,
-                code));
+                channelId));
         if (playLeys == null || playLeys.size() == 0) return null;
         return (StreamInfo)redis.get(playLeys.get(0).toString());
-    }
-
-    /**
-     * 鏇存柊娴佸獟浣撲俊鎭�
-     * @param mediaServerConfig
-     * @return
-     */
-    @Override
-    public boolean updateMediaInfo(MediaServerConfig mediaServerConfig) {
-        return redis.set(VideoManagerConstants.MEDIA_SERVER_PREFIX,mediaServerConfig);
-    }
-
-    /**
-     * 鑾峰彇娴佸獟浣撲俊鎭�
-     * @return
-     */
-    @Override
-    public MediaServerConfig getMediaInfo() {
-        return (MediaServerConfig)redis.get(VideoManagerConstants.MEDIA_SERVER_PREFIX);
     }
 
     @Override
@@ -120,7 +95,7 @@
         for (int i = 0; i < players.size(); i++) {
             String key = (String) players.get(i);
             StreamInfo streamInfo = (StreamInfo)redis.get(key);
-            streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getCahnnelId(), streamInfo);
+            streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo);
         }
         return streamInfos;
     }
@@ -128,7 +103,7 @@
 
     @Override
     public boolean startPlayback(StreamInfo stream) {
-        return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()),
+        return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
                 stream);
     }
 
@@ -136,7 +111,7 @@
     @Override
     public boolean stopPlayback(StreamInfo streamInfo) {
         if (streamInfo == null) return false;
-        DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId());
+        DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getChannelId());
         if (deviceChannel != null) {
             deviceChannel.setStreamId(null);
             deviceChannel.setDeviceId(streamInfo.getDeviceID());
@@ -145,14 +120,14 @@
         return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
                 streamInfo.getStreamId(),
                 streamInfo.getDeviceID(),
-                streamInfo.getCahnnelId()));
+                streamInfo.getChannelId()));
     }
 
     @Override
     public StreamInfo queryPlaybackByDevice(String deviceId, String code) {
-        String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
-                deviceId,
-                code);
+        // String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
+        //         deviceId,
+        //         code);
         List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
                 deviceId,
                 code));
@@ -163,4 +138,165 @@
         if (playLeys == null || playLeys.size() == 0) return null;
         return (StreamInfo)redis.get(playLeys.get(0).toString());
     }
+
+    @Override
+    public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) {
+        String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX + parentPlatformCatch.getId();
+        redis.set(key, parentPlatformCatch);
+    }
+
+    @Override
+    public void updatePlatformKeepalive(ParentPlatform parentPlatform) {
+        String key = VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + parentPlatform.getServerGBId();
+        redis.set(key, "", Integer.parseInt(parentPlatform.getKeepTimeout()));
+    }
+
+    @Override
+    public void updatePlatformRegister(ParentPlatform parentPlatform) {
+        String key = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + parentPlatform.getServerGBId();
+        redis.set(key, "", Integer.parseInt(parentPlatform.getExpires()));
+    }
+
+    @Override
+    public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) {
+        return (ParentPlatformCatch)redis.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId);
+    }
+
+    @Override
+    public void delPlatformCatchInfo(String platformGbId) {
+        redis.del(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId);
+    }
+
+    @Override
+    public void delPlatformKeepalive(String platformGbId) {
+        redis.del(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + platformGbId);
+    }
+
+    @Override
+    public void delPlatformRegister(String platformGbId) {
+        redis.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + platformGbId);
+    }
+
+
+    @Override
+    public void updatePlatformRegisterInfo(String callId, String platformGbId) {
+        String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId;
+        redis.set(key, platformGbId);
+    }
+
+
+    @Override
+    public String queryPlatformRegisterInfo(String callId) {
+        return (String)redis.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId);
+    }
+
+    @Override
+    public void delPlatformRegisterInfo(String callId) {
+        redis.del(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId);
+    }
+
+    @Override
+    public void cleanPlatformRegisterInfos() {
+        List regInfos = redis.scan(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + "*");
+        for (Object key : regInfos) {
+            redis.del(key.toString());
+        }
+    }
+
+    @Override
+    public void updateSendRTPSever(SendRtpItem sendRtpItem) {
+        String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId();
+        redis.set(key, sendRtpItem);
+    }
+
+    @Override
+    public SendRtpItem querySendRTPServer(String platformGbId, String channelId) {
+        String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_" + channelId;
+        return (SendRtpItem)redis.get(key);
+    }
+
+    @Override
+    public List<SendRtpItem> querySendRTPServer(String platformGbId) {
+        String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_*";
+        List<Object> queryResult = redis.scan(key);
+        List<SendRtpItem> result= new ArrayList<>();
+
+        for (int i = 0; i < queryResult.size(); i++) {
+            String keyItem = (String) queryResult.get(i);
+            result.add((SendRtpItem)redis.get(keyItem));
+        }
+
+        return result;
+    }
+
+    /**
+     * 鍒犻櫎RTP鎺ㄩ�佷俊鎭紦瀛�
+     * @param platformGbId
+     * @param channelId
+     */
+    @Override
+    public void deleteSendRTPServer(String platformGbId, String channelId) {
+        String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + platformGbId + "_" + channelId;
+        redis.del(key);
+    }
+
+    /**
+     * 鏌ヨ鏌愪釜閫氶亾鏄惁瀛樺湪涓婄骇鐐规挱锛圧TP鎺ㄩ�侊級
+     * @param channelId
+     */
+    @Override
+    public boolean isChannelSendingRTP(String channelId) {
+        String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + "*_" + channelId;
+        List<Object> RtpStreams = redis.scan(key);
+        if (RtpStreams.size() > 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public void clearCatchByDeviceId(String deviceId) {
+        List<Object> playLeys = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAYER_PREFIX,
+                deviceId));
+        if (playLeys.size() > 0) {
+            for (Object key : playLeys) {
+                redis.del(key.toString());
+            }
+        }
+
+        List<Object> playBackers = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
+                deviceId));
+        if (playBackers.size() > 0) {
+            for (Object key : playBackers) {
+                redis.del(key.toString());
+            }
+        }
+    }
+
+    @Override
+    public void outlineForAll() {
+        List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + "*" );
+        for (int i = 0; i < onlineDevices.size(); i++) {
+            String key = (String) onlineDevices.get(i);
+            redis.del(key);
+        }
+    }
+
+    @Override
+    public List<String> getOnlineForAll() {
+        List<String> result = new ArrayList<>();
+        List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + "*" );
+        for (int i = 0; i < onlineDevices.size(); i++) {
+            String key = (String) onlineDevices.get(i);
+            result.add((String) redis.get(key));
+        }
+        return result;
+    }
+
+    @Override
+    public void updateWVPInfo(JSONObject jsonObject) {
+
+    }
+
 }

--
Gitblit v1.8.0