From 00fdc6281c7cd20409b6b28bcbcad9ebb11b5432 Mon Sep 17 00:00:00 2001
From: Lawrence <1934378145@qq.com>
Date: 星期一, 26 十月 2020 16:51:31 +0800
Subject: [PATCH] 添加新功能说明
---
src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java | 65 ++++++++++++++++++++++----------
1 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java
index 91b60a1..10f3815 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java
@@ -66,7 +66,6 @@
if (deviceMap.get(device.getDeviceId()) == null) {
deviceMap.put(device.getDeviceId(), new HashMap<String, HashSet<String>>());
}
-// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + device.getDeviceId() + "_" + "*");
// 鏇存柊device涓殑閫氶亾鏁伴噺
device.setChannelCount(deviceMap.get(device.getDeviceId()).size());
// 瀛樺偍device
@@ -90,10 +89,9 @@
// 瀛樺偍閫氶亾
redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId +
"_" + channel.getChannelId() +
- ":" + channel.getName() +
"_" + (channel.getStatus() == 1 ? "on":"off") +
"_" + (channelMap.get(channelId).size() > 0)+
- "_" + channel.getParentId(),
+ "_" + (StringUtils.isEmpty(channel.getParentId())?null:channel.getParentId()),
channel);
// 鏇存柊device涓殑閫氶亾鏁伴噺
Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId);
@@ -113,7 +111,13 @@
DeviceChannel deviceChannel = queryChannel(deviceId, parentId);
if (deviceChannel != null) {
deviceChannel.setSubCount(channelMap.get(parentId).size());
- redis.set(VideoManagerConstants.CACHEKEY_PREFIX+deviceId + "_" + deviceChannel.getChannelId(),
+// redis.set(VideoManagerConstants.CACHEKEY_PREFIX+deviceId + "_" + deviceChannel.getChannelId(),
+// deviceChannel);
+ redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId +
+ "_" + deviceChannel.getChannelId() +
+ "_" + (deviceChannel.getStatus() == 1 ? "on":"off") +
+ "_" + (channelMap.get(deviceChannel.getChannelId()).size() > 0)+
+ "_" + (StringUtils.isEmpty(deviceChannel.getParentId())?null:deviceChannel.getParentId()),
deviceChannel);
}
@@ -149,7 +153,15 @@
"_" + queryOnline + // 鎼滅储鏄惁鍦ㄧ嚎
"_" + queryHasSubChannel + // 鎼滅储鏄惁鍚湁瀛愯妭鐐�
"_" + "*";
- List<Object> deviceChannelList = redis.keys(queryStr);
+// List<Object> deviceChannelList = redis.keys(queryStr);
+ List<Object> deviceChannelList = redis.scan(queryStr);
+ //瀵规煡璇㈢粨鏋滄帓搴忥紝閬垮厤鍑虹幇閫氶亾鎺掑垪椤哄簭涔卞簭鐨勬儏鍐�
+ Collections.sort(deviceChannelList,new Comparator<Object>(){
+ @Override
+ public int compare(Object o1, Object o2) {
+ return o1.toString().compareToIgnoreCase(o2.toString());
+ }
+ });
pageResult.setPage(page);
pageResult.setCount(count);
pageResult.setTotal(deviceChannelList.size());
@@ -173,10 +185,12 @@
@Override
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) {
List<DeviceChannel> result = new ArrayList<>();
- List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
+// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
+ List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
+
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
for (int i = 0; i < deviceChannelList.size(); i++) {
- result.add((DeviceChannel)redis.get((String)deviceChannelList.get(i)));
+ result.add((DeviceChannel)redis.get((String) deviceChannelList.get(i)));
}
}
return result;
@@ -197,7 +211,8 @@
"_" + queryHasSubChannel + // 鎼滅储鏄惁鍚湁瀛愯妭鐐�
"_" + parentChannelId;
- List<Object> deviceChannelList = redis.keys(queryStr);
+// List<Object> deviceChannelList = redis.keys(queryStr);
+ List<Object> deviceChannelList = redis.scan(queryStr);
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
for (int i = 0; i < deviceChannelList.size(); i++) {
@@ -223,7 +238,8 @@
public List<DeviceChannel> querySubChannels(String deviceId, String parentChannelId) {
List<DeviceChannel> allDeviceChannels = new ArrayList<>();
- List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
+// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
+ List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
for (int i = 0; i < deviceChannelList.size(); i++) {
@@ -240,7 +256,8 @@
@Override
public DeviceChannel queryChannel(String deviceId, String channelId) {
DeviceChannel deviceChannel = null;
- List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId +
+// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId +
+ List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId +
"_" + channelId + "*");
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(0));
@@ -264,7 +281,8 @@
if (deviceIds == null || deviceIds.length == 0) {
- List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*");
+// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*");
+ List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*");
pageResult.setTotal(deviceIdList.size());
int maxCount = (page + 1)* count;
for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) {
@@ -290,7 +308,8 @@
List<Device> devices = new ArrayList<>();
if (deviceIds == null || deviceIds.length == 0) {
- List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*");
+// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*");
+ List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*");
for (int i = 0; i < deviceIdList.size(); i++) {
devices.add((Device)redis.get((String)deviceIdList.get(i)));
}
@@ -385,14 +404,16 @@
}
@Override
public StreamInfo queryPlayBySSRC(String ssrc) {
- List<Object> playLeys = redis.keys(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, ssrc));
+// List<Object> playLeys = redis.keys(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, ssrc));
+ List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, ssrc));
if (playLeys == null || playLeys.size() == 0) return null;
return (StreamInfo)redis.get(playLeys.get(0).toString());
}
@Override
public StreamInfo queryPlayByDevice(String deviceId, String code) {
- List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
+// 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));
if (playLeys == null || playLeys.size() == 0) return null;
@@ -427,19 +448,21 @@
for (Device device : devices) {
// 鏇存柊璁惧涓嬬殑閫氶亾
HashMap<String, HashSet<String>> channelMap = new HashMap<String, HashSet<String>>();
- List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX +
+// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX +
+ List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX +
device.getDeviceId() + "_" + "*");
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
for (int i = 0; i < deviceChannelList.size(); i++) {
String key = (String)deviceChannelList.get(i);
String[] s = key.split("_");
- String channelId = s[3].split(":")[0];
+ String channelId = s[3];
HashSet<String> subChannel = channelMap.get(channelId);
if (subChannel == null) {
subChannel = new HashSet<>();
}
- if (!"null".equals(s[6])) {
- subChannel.add(s[6]);
+ System.out.println(key);
+ if (s.length == 6 && !"null".equals(s[5])) {
+ subChannel.add(s[5]);
}
channelMap.put(channelId, subChannel);
}
@@ -451,7 +474,8 @@
@Override
public void cleanChannelsForDevice(String deviceId) {
List<DeviceChannel> result = new ArrayList<>();
- List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
+// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
+ List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
for (int i = 0; i < deviceChannelList.size(); i++) {
redis.del((String)deviceChannelList.get(i));
@@ -462,7 +486,8 @@
@Override
public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) {
Map<String, StreamInfo> streamInfos = new HashMap<>();
- List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId));
+// List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId));
+ List<Object> playLeys = redis.scan(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId));
if (playLeys.size() == 0) return streamInfos;
for (int i = 0; i < playLeys.size(); i++) {
String key = (String) playLeys.get(i);
--
Gitblit v1.8.0