From cb5afce55eec2badda5090c27564e43f201ac9af Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 12 三月 2024 23:55:00 +0800
Subject: [PATCH] 优化语音对讲定时任务的删除
---
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java | 737 ++++++++++++++++++++++++++------------------------------
1 files changed, 339 insertions(+), 398 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
old mode 100644
new mode 100755
index ecefe73..27bbdba
--- 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,30 +1,35 @@
package com.genersoft.iot.vmp.storager.impl;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.genersoft.iot.vmp.common.StreamInfo;
-import com.genersoft.iot.vmp.common.SystemInfoDto;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.genersoft.iot.vmp.common.SystemAllInfo;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.UserSetting;
-import com.genersoft.iot.vmp.gb28181.bean.*;
-import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
+import com.genersoft.iot.vmp.gb28181.bean.AlarmChannelMessage;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
+import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
-import com.genersoft.iot.vmp.media.zlm.dto.OnPublishHookParam;
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
+import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
-import com.genersoft.iot.vmp.service.bean.ThirdPartyGB;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
+import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
import com.genersoft.iot.vmp.utils.DateUtil;
+import com.genersoft.iot.vmp.utils.JsonUtil;
+import com.genersoft.iot.vmp.utils.SystemInfoUtils;
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.DependsOn;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
+import java.time.Duration;
import java.util.*;
@SuppressWarnings("rawtypes")
@@ -37,16 +42,25 @@
private DeviceChannelMapper deviceChannelMapper;
@Autowired
+ private DeviceMapper deviceMapper;
+
+ @Autowired
private UserSetting userSetting;
+
+ @Autowired
+ private RedisTemplate<Object, Object> redisTemplate;
+
+ @Autowired
+ private StringRedisTemplate stringRedisTemplate;
@Override
public Long getCSEQ() {
String key = VideoManagerConstants.SIP_CSEQ_PREFIX + userSetting.getServerId();
- long result = RedisUtil.incr(key, 1L);
- if (result > Integer.MAX_VALUE) {
- RedisUtil.set(key, 1);
- result = 1;
+ Long result = redisTemplate.opsForValue().increment(key, 1L);
+ if (result != null && result > Integer.MAX_VALUE) {
+ redisTemplate.opsForValue().set(key, 1);
+ result = 1L;
}
return result;
}
@@ -55,10 +69,10 @@
public Long getSN(String method) {
String key = VideoManagerConstants.SIP_SN_PREFIX + userSetting.getServerId() + "_" + method;
- long result = RedisUtil.incr(key, 1L);
- if (result > Integer.MAX_VALUE) {
- RedisUtil.set(key, 1);
- result = 1;
+ Long result = redisTemplate.opsForValue().increment(key, 1L);
+ if (result != null && result > Integer.MAX_VALUE) {
+ redisTemplate.opsForValue().set(key, 1);
+ result = 1L;
}
return result;
}
@@ -66,283 +80,79 @@
@Override
public void resetAllCSEQ() {
String scanKey = VideoManagerConstants.SIP_CSEQ_PREFIX + userSetting.getServerId() + "_*";
- List<Object> keys = RedisUtil.scan(scanKey);
+ List<Object> keys = RedisUtil.scan(redisTemplate, scanKey);
for (Object o : keys) {
String key = (String) o;
- RedisUtil.set(key, 1);
+ redisTemplate.opsForValue().set(key, 1);
}
}
@Override
public void resetAllSN() {
String scanKey = VideoManagerConstants.SIP_SN_PREFIX + userSetting.getServerId() + "_*";
- List<Object> keys = RedisUtil.scan(scanKey);
+ List<Object> keys = RedisUtil.scan(redisTemplate, scanKey);
for (Object o : keys) {
String key = (String) o;
- RedisUtil.set(key, 1);
- }
- }
-
- /**
- * 寮�濮嬫挱鏀炬椂灏嗘祦瀛樺叆redis
- *
- * @return
- */
- @Override
- public boolean startPlay(StreamInfo stream) {
- return RedisUtil.set(String.format("%S_%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),
- stream.getStream(), stream.getDeviceID(), stream.getChannelId()),
- stream);
- }
-
- /**
- * 鍋滄鎾斁鏃朵粠redis鍒犻櫎
- *
- * @return
- */
- @Override
- public boolean stopPlay(StreamInfo streamInfo) {
- if (streamInfo == null) {
- return false;
- }
- return RedisUtil.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
- userSetting.getServerId(),
- streamInfo.getStream(),
- streamInfo.getDeviceID(),
- streamInfo.getChannelId()));
- }
-
- /**
- * 鏌ヨ鎾斁鍒楄〃
- * @return
- */
- @Override
- public StreamInfo queryPlay(StreamInfo streamInfo) {
- return (StreamInfo)RedisUtil.get(String.format("%S_%s_%s_%s_%s",
- VideoManagerConstants.PLAYER_PREFIX,
- userSetting.getServerId(),
- streamInfo.getStream(),
- streamInfo.getDeviceID(),
- streamInfo.getChannelId()));
- }
- @Override
- public StreamInfo queryPlayByStreamId(String streamId) {
- List<Object> playLeys = RedisUtil.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId));
- if (playLeys == null || playLeys.size() == 0) {
- return null;
- }
- return (StreamInfo)RedisUtil.get(playLeys.get(0).toString());
- }
-
- @Override
- public StreamInfo queryPlayByDevice(String deviceId, String channelId) {
- List<Object> playLeys = RedisUtil.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
- userSetting.getServerId(),
- deviceId,
- channelId));
- if (playLeys == null || playLeys.size() == 0) {
- return null;
- }
- return (StreamInfo)RedisUtil.get(playLeys.get(0).toString());
- }
-
- @Override
- public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) {
- Map<String, StreamInfo> streamInfos = new HashMap<>();
-// List<Object> playLeys = RedisUtil.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId));
- List<Object> players = RedisUtil.scan(String.format("%S_%s_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId));
- if (players.size() == 0) {
- return streamInfos;
- }
- for (Object player : players) {
- String key = (String) player;
- StreamInfo streamInfo = (StreamInfo) RedisUtil.get(key);
- streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo);
- }
- return streamInfos;
- }
-
-
- @Override
- public boolean startPlayback(StreamInfo stream, String callId) {
- return RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
- userSetting.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream);
- }
-
- @Override
- public boolean startDownload(StreamInfo stream, String callId) {
- boolean result;
- if (stream.getProgress() == 1) {
- result = RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
- userSetting.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream);
- }else {
- result = RedisUtil.set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
- userSetting.getServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream, 60*60);
- }
- return result;
- }
- @Override
- public boolean stopDownload(String deviceId, String channelId, String stream, String callId) {
- DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
- if (deviceChannel != null) {
- deviceChannel.setStreamId(null);
- deviceChannel.setDeviceId(deviceId);
- deviceChannelMapper.update(deviceChannel);
- }
- if (deviceId == null) {
- deviceId = "*";
- }
- if (channelId == null) {
- channelId = "*";
- }
- if (stream == null) {
- stream = "*";
- }
- if (callId == null) {
- callId = "*";
- }
- String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
- userSetting.getServerId(),
- deviceId,
- channelId,
- stream,
- callId
- );
- List<Object> scan = RedisUtil.scan(key);
- if (scan.size() > 0) {
- for (Object keyObj : scan) {
- RedisUtil.del((String) keyObj);
- }
- }
- return true;
- }
-
- @Override
- public boolean stopPlayback(String deviceId, String channelId, String stream, String callId) {
- DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
- if (deviceChannel != null) {
- deviceChannel.setStreamId(null);
- deviceChannel.setDeviceId(deviceId);
- deviceChannelMapper.update(deviceChannel);
- }
- if (deviceId == null) {
- deviceId = "*";
- }
- if (channelId == null) {
- channelId = "*";
- }
- if (stream == null) {
- stream = "*";
- }
- if (callId == null) {
- callId = "*";
- }
- String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
- userSetting.getServerId(),
- deviceId,
- channelId,
- stream,
- callId
- );
- List<Object> scan = RedisUtil.scan(key);
- if (scan.size() > 0) {
- for (Object keyObj : scan) {
- RedisUtil.del((String) keyObj);
- }
- }
- return true;
- }
-
- @Override
- public StreamInfo queryPlayback(String deviceId, String channelId, String stream, String callId) {
- if (stream == null && callId == null) {
- return null;
- }
- if (deviceId == null) {
- deviceId = "*";
- }
- if (channelId == null) {
- channelId = "*";
- }
- if (stream == null) {
- stream = "*";
- }
- if (callId == null) {
- callId = "*";
- }
- String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
- userSetting.getServerId(),
- deviceId,
- channelId,
- stream,
- callId
- );
- List<Object> streamInfoScan = RedisUtil.scan(key);
- if (streamInfoScan.size() > 0) {
- return (StreamInfo) RedisUtil.get((String) streamInfoScan.get(0));
- }else {
- return null;
+ redisTemplate.opsForValue().set(key, 1);
}
}
@Override
public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) {
String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetting.getServerId() + "_" + parentPlatformCatch.getId();
- RedisUtil.set(key, parentPlatformCatch);
+ redisTemplate.opsForValue().set(key, parentPlatformCatch);
}
@Override
public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) {
- return (ParentPlatformCatch)RedisUtil.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetting.getServerId() + "_" + platformGbId);
+ return (ParentPlatformCatch)redisTemplate.opsForValue().get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetting.getServerId() + "_" + platformGbId);
}
@Override
public void delPlatformCatchInfo(String platformGbId) {
- RedisUtil.del(VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetting.getServerId() + "_" + platformGbId);
+ redisTemplate.delete(VideoManagerConstants.PLATFORM_CATCH_PREFIX + userSetting.getServerId() + "_" + platformGbId);
}
@Override
public void delPlatformKeepalive(String platformGbId) {
- RedisUtil.del(VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetting.getServerId() + "_" + platformGbId);
+ redisTemplate.delete(VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetting.getServerId() + "_" + platformGbId);
}
@Override
public void delPlatformRegister(String platformGbId) {
- RedisUtil.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetting.getServerId() + "_" + platformGbId);
+ redisTemplate.delete(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetting.getServerId() + "_" + platformGbId);
}
@Override
public void updatePlatformRegisterInfo(String callId, PlatformRegisterInfo platformRegisterInfo) {
String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId;
- RedisUtil.set(key, platformRegisterInfo, 30);
+ Duration duration = Duration.ofSeconds(30L);
+ redisTemplate.opsForValue().set(key, platformRegisterInfo, duration);
}
@Override
public PlatformRegisterInfo queryPlatformRegisterInfo(String callId) {
- return (PlatformRegisterInfo)RedisUtil.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId);
+ return (PlatformRegisterInfo)redisTemplate.opsForValue().get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId);
}
@Override
public void delPlatformRegisterInfo(String callId) {
- RedisUtil.del(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId);
- }
-
- @Override
- public void cleanPlatformRegisterInfos() {
- List regInfos = RedisUtil.scan(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + "*");
- for (Object key : regInfos) {
- RedisUtil.del(key.toString());
- }
+ redisTemplate.delete(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId);
}
@Override
public void updateSendRTPSever(SendRtpItem sendRtpItem) {
- String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_"
- + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId() + "_"
- + sendRtpItem.getStreamId() + "_" + sendRtpItem.getCallId();
- RedisUtil.set(key, sendRtpItem);
+
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX +
+ userSetting.getServerId() + "_"
+ + sendRtpItem.getMediaServerId() + "_"
+ + sendRtpItem.getPlatformId() + "_"
+ + sendRtpItem.getChannelId() + "_"
+ + sendRtpItem.getStream() + "_"
+ + sendRtpItem.getCallId();
+ redisTemplate.opsForValue().set(key, sendRtpItem);
}
@Override
@@ -359,11 +169,15 @@
if (callId == null) {
callId = "*";
}
- String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
- + "_" + channelId + "_" + streamId + "_" + callId;
- List<Object> scan = RedisUtil.scan(key);
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ + userSetting.getServerId() + "_*_"
+ + platformGbId + "_"
+ + channelId + "_"
+ + streamId + "_"
+ + callId;
+ List<Object> scan = RedisUtil.scan(redisTemplate, key);
if (scan.size() > 0) {
- return (SendRtpItem)RedisUtil.get((String)scan.get(0));
+ return (SendRtpItem)redisTemplate.opsForValue().get(scan.get(0));
}else {
return null;
}
@@ -377,12 +191,38 @@
String platformGbId = "*";
String callId = "*";
String streamId = "*";
- String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
- + "_" + channelId + "_" + streamId + "_" + callId;
- List<Object> scan = RedisUtil.scan(key);
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ + userSetting.getServerId() + "_*_"
+ + platformGbId + "_"
+ + channelId + "_"
+ + streamId + "_"
+ + callId;
+ List<Object> scan = RedisUtil.scan(redisTemplate, key);
List<SendRtpItem> result = new ArrayList<>();
for (Object o : scan) {
- result.add((SendRtpItem) RedisUtil.get((String) o));
+ result.add((SendRtpItem) redisTemplate.opsForValue().get(o));
+ }
+ return result;
+ }
+
+ @Override
+ public List<SendRtpItem> querySendRTPServerByStream(String stream) {
+ if (stream == null) {
+ return null;
+ }
+ String platformGbId = "*";
+ String callId = "*";
+ String channelId = "*";
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ + userSetting.getServerId() + "_*_"
+ + platformGbId + "_"
+ + channelId + "_"
+ + stream + "_"
+ + callId;
+ List<Object> scan = RedisUtil.scan(redisTemplate, key);
+ List<SendRtpItem> result = new ArrayList<>();
+ for (Object o : scan) {
+ result.add((SendRtpItem) redisTemplate.opsForValue().get(o));
}
return result;
}
@@ -392,13 +232,15 @@
if (platformGbId == null) {
platformGbId = "*";
}
- String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId + "_*" + "_*" + "_*";
- List<Object> queryResult = RedisUtil.scan(key);
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ + userSetting.getServerId() + "_*_"
+ + platformGbId + "_*" + "_*" + "_*";
+ List<Object> queryResult = RedisUtil.scan(redisTemplate, key);
List<SendRtpItem> result= new ArrayList<>();
for (Object o : queryResult) {
String keyItem = (String) o;
- result.add((SendRtpItem) RedisUtil.get(keyItem));
+ result.add((SendRtpItem) redisTemplate.opsForValue().get(keyItem));
}
return result;
@@ -406,8 +248,6 @@
/**
* 鍒犻櫎RTP鎺ㄩ�佷俊鎭紦瀛�
- * @param platformGbId
- * @param channelId
*/
@Override
public void deleteSendRTPServer(String platformGbId, String channelId, String callId, String streamId) {
@@ -417,149 +257,95 @@
if (callId == null) {
callId = "*";
}
- String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
- + "_" + channelId + "_" + streamId + "_" + callId;
- List<Object> scan = RedisUtil.scan(key);
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ + userSetting.getServerId() + "_*_"
+ + platformGbId + "_"
+ + channelId + "_"
+ + streamId + "_"
+ + callId;
+ List<Object> scan = RedisUtil.scan(redisTemplate, key);
if (scan.size() > 0) {
for (Object keyStr : scan) {
- RedisUtil.del((String)keyStr);
+ redisTemplate.delete(keyStr);
}
}
}
+ @Override
+ public List<SendRtpItem> queryAllSendRTPServer() {
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ + userSetting.getServerId() + "_*";
+ List<Object> queryResult = RedisUtil.scan(redisTemplate, key);
+ List<SendRtpItem> result= new ArrayList<>();
+ for (Object o : queryResult) {
+ String keyItem = (String) o;
+ result.add((SendRtpItem) redisTemplate.opsForValue().get(keyItem));
+ }
+
+ return result;
+ }
/**
* 鏌ヨ鏌愪釜閫氶亾鏄惁瀛樺湪涓婄骇鐐规挱锛圧TP鎺ㄩ�侊級
- * @param channelId
*/
@Override
public boolean isChannelSendingRTP(String channelId) {
- String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + "*_" + channelId + "*_" + "*_";
- List<Object> RtpStreams = RedisUtil.scan(key);
- if (RtpStreams.size() > 0) {
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public void clearCatchByDeviceId(String deviceId) {
- List<Object> playLeys = RedisUtil.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX,
- userSetting.getServerId(),
- deviceId));
- if (playLeys.size() > 0) {
- for (Object key : playLeys) {
- RedisUtil.del(key.toString());
- }
- }
-
- List<Object> playBackers = RedisUtil.scan(String.format("%S_%s_%s_*_*_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
- userSetting.getServerId(),
- deviceId));
- if (playBackers.size() > 0) {
- for (Object key : playBackers) {
- RedisUtil.del(key.toString());
- }
- }
-
- List<Object> deviceCache = RedisUtil.scan(String.format("%S%s_%s", VideoManagerConstants.DEVICE_PREFIX,
- userSetting.getServerId(),
- deviceId));
- if (deviceCache.size() > 0) {
- for (Object key : deviceCache) {
- RedisUtil.del(key.toString());
- }
- }
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ + userSetting.getServerId() + "_*_*_"
+ + channelId + "*_" + "*_";
+ List<Object> RtpStreams = RedisUtil.scan(redisTemplate, key);
+ return RtpStreams.size() > 0;
}
@Override
public void updateWVPInfo(JSONObject jsonObject, int time) {
String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetting.getServerId();
- RedisUtil.set(key, jsonObject, time);
+ Duration duration = Duration.ofSeconds(time);
+ redisTemplate.opsForValue().set(key, jsonObject, duration);
}
@Override
public void sendStreamChangeMsg(String type, JSONObject jsonObject) {
String key = VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + type;
- logger.info("[redis 娴佸彉鍖栦簨浠禲 {}: {}", key, jsonObject.toString());
- RedisUtil.convertAndSend(key, jsonObject);
+ logger.info("[redis 娴佸彉鍖栦簨浠禲 鍙戦�� {}: {}", key, jsonObject.toString());
+ redisTemplate.convertAndSend(key, jsonObject);
}
@Override
- public void addStream(MediaServerItem mediaServerItem, String type, String app, String streamId, MediaItem mediaItem) {
+ public void addStream(MediaServerItem mediaServerItem, String type, String app, String streamId, OnStreamChangedHookParam onStreamChangedHookParam) {
// 鏌ユ壘鏄惁浣跨敤浜哻allID
StreamAuthorityInfo streamAuthorityInfo = getStreamAuthorityInfo(app, streamId);
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerItem.getId();
if (streamAuthorityInfo != null) {
- mediaItem.setCallId(streamAuthorityInfo.getCallId());
+ onStreamChangedHookParam.setCallId(streamAuthorityInfo.getCallId());
}
- RedisUtil.set(key, mediaItem);
+ redisTemplate.opsForValue().set(key, onStreamChangedHookParam);
}
@Override
public void removeStream(String mediaServerId, String type, String app, String streamId) {
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerId;
- RedisUtil.del(key);
- }
-
- @Override
- public StreamInfo queryDownload(String deviceId, String channelId, String stream, String callId) {
- if (stream == null && callId == null) {
- return null;
- }
- if (deviceId == null) {
- deviceId = "*";
- }
- if (channelId == null) {
- channelId = "*";
- }
- if (stream == null) {
- stream = "*";
- }
- if (callId == null) {
- callId = "*";
- }
- String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
- userSetting.getServerId(),
- deviceId,
- channelId,
- stream,
- callId
- );
- List<Object> streamInfoScan = RedisUtil.scan(key);
- if (streamInfoScan.size() > 0) {
- return (StreamInfo) RedisUtil.get((String) streamInfoScan.get(0));
- }else {
- return null;
- }
- }
-
- @Override
- public ThirdPartyGB queryMemberNoGBId(String queryKey) {
- String key = VideoManagerConstants.WVP_STREAM_GB_ID_PREFIX + queryKey;
- JSONObject jsonObject = (JSONObject)RedisUtil.get(key);
- return JSONObject.toJavaObject(jsonObject, ThirdPartyGB.class);
+ redisTemplate.delete(key);
}
@Override
public void removeStream(String mediaServerId, String type) {
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_*_*_" + mediaServerId;
- List<Object> streams = RedisUtil.scan(key);
+ List<Object> streams = RedisUtil.scan(redisTemplate, key);
for (Object stream : streams) {
- RedisUtil.del((String) stream);
+ redisTemplate.delete(stream);
}
}
@Override
- public List<MediaItem> getStreams(String mediaServerId, String type) {
- List<MediaItem> result = new ArrayList<>();
+ public List<OnStreamChangedHookParam> getStreams(String mediaServerId, String type) {
+ List<OnStreamChangedHookParam> result = new ArrayList<>();
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_*_*_" + mediaServerId;
- List<Object> streams = RedisUtil.scan(key);
+ List<Object> streams = RedisUtil.scan(redisTemplate, key);
for (Object stream : streams) {
- MediaItem mediaItem = (MediaItem)RedisUtil.get((String) stream);
- result.add(mediaItem);
+ OnStreamChangedHookParam onStreamChangedHookParam = (OnStreamChangedHookParam)redisTemplate.opsForValue().get(stream);
+ result.add(onStreamChangedHookParam);
}
return result;
}
@@ -567,43 +353,78 @@
@Override
public void updateDevice(Device device) {
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + device.getDeviceId();
- RedisUtil.set(key, device);
+ redisTemplate.opsForValue().set(key, device);
}
@Override
public void removeDevice(String deviceId) {
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId;
- RedisUtil.del(key);
+ redisTemplate.delete(key);
+ }
+
+ @Override
+ public void removeAllDevice() {
+ String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*";
+ List<Object> keys = RedisUtil.scan(redisTemplate, scanKey);
+ for (Object key : keys) {
+ redisTemplate.delete(key);
+ }
+ }
+
+ @Override
+ public List<Device> getAllDevices() {
+ String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*";
+ List<Device> result = new ArrayList<>();
+ List<Object> keys = RedisUtil.scan(redisTemplate, scanKey);
+ for (Object o : keys) {
+ String key = (String) o;
+ Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class);
+ if (Objects.nonNull(device)) {
+ // 鍙彇娌℃湁瀛樿繃寰�
+ result.add(JsonUtil.redisJsonToObject(redisTemplate, key, Device.class));
+ }
+ }
+
+ return result;
}
@Override
public Device getDevice(String deviceId) {
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId;
- return (Device)RedisUtil.get(key);
+ Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class);
+ if (device == null){
+ device = deviceMapper.getDeviceByDeviceId(deviceId);
+ if (device != null) {
+ updateDevice(device);
+ }
+ }
+ return device;
}
@Override
public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) {
String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gpsMsgInfo.getId();
- RedisUtil.set(key, gpsMsgInfo, 60); // 榛樿GPS娑堟伅淇濆瓨1鍒嗛挓
+ Duration duration = Duration.ofSeconds(60L);
+ redisTemplate.opsForValue().set(key, gpsMsgInfo, duration);
+ // 榛樿GPS娑堟伅淇濆瓨1鍒嗛挓
}
@Override
public GPSMsgInfo getGpsMsgInfo(String gbId) {
String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gbId;
- return (GPSMsgInfo)RedisUtil.get(key);
+ return JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class);
}
@Override
public List<GPSMsgInfo> getAllGpsMsgInfo() {
String scanKey = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_*";
List<GPSMsgInfo> result = new ArrayList<>();
- List<Object> keys = RedisUtil.scan(scanKey);
+ List<Object> keys = RedisUtil.scan(redisTemplate, scanKey);
for (Object o : keys) {
String key = (String) o;
- GPSMsgInfo gpsMsgInfo = (GPSMsgInfo) RedisUtil.get(key);
- if (!gpsMsgInfo.isStored()) { // 鍙彇娌℃湁瀛樿繃寰�
- result.add((GPSMsgInfo) RedisUtil.get(key));
+ GPSMsgInfo gpsMsgInfo = JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class);
+ if (Objects.nonNull(gpsMsgInfo) && !gpsMsgInfo.isStored()) { // 鍙彇娌℃湁瀛樿繃寰�
+ result.add(JsonUtil.redisJsonToObject(redisTemplate, key, GPSMsgInfo.class));
}
}
@@ -613,32 +434,44 @@
@Override
public void updateStreamAuthorityInfo(String app, String stream, StreamAuthorityInfo streamAuthorityInfo) {
String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream;
- RedisUtil.set(key, streamAuthorityInfo);
+ redisTemplate.opsForValue().set(key, streamAuthorityInfo);
}
@Override
public void removeStreamAuthorityInfo(String app, String stream) {
String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
- RedisUtil.del(key);
+ redisTemplate.delete(key);
}
@Override
public StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream) {
String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
- return (StreamAuthorityInfo) RedisUtil.get(key);
+ return JsonUtil.redisJsonToObject(redisTemplate, key, StreamAuthorityInfo.class);
+ }
+
+ @Override
+ public List<StreamAuthorityInfo> getAllStreamAuthorityInfo() {
+ String scanKey = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_*_*" ;
+ List<StreamAuthorityInfo> result = new ArrayList<>();
+ List<Object> keys = RedisUtil.scan(redisTemplate, scanKey);
+ for (Object o : keys) {
+ String key = (String) o;
+ result.add(JsonUtil.redisJsonToObject(redisTemplate, key, StreamAuthorityInfo.class));
+ }
+ return result;
}
@Override
- public MediaItem getStreamInfo(String app, String streamId, String mediaServerId) {
+ public OnStreamChangedHookParam getStreamInfo(String app, String streamId, String mediaServerId) {
String scanKey = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_*_" + app + "_" + streamId + "_" + mediaServerId;
- MediaItem result = null;
- List<Object> keys = RedisUtil.scan(scanKey);
+ OnStreamChangedHookParam result = null;
+ List<Object> keys = RedisUtil.scan(redisTemplate, scanKey);
if (keys.size() > 0) {
String key = (String) keys.get(0);
- result = (MediaItem)RedisUtil.get(key);
+ result = JsonUtil.redisJsonToObject(redisTemplate, key, OnStreamChangedHookParam.class);
}
return result;
@@ -647,14 +480,15 @@
@Override
public void addCpuInfo(double cpuInfo) {
String key = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetting.getServerId();
- SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>();
- systemInfoDto.setTime(DateUtil.getNow());
- systemInfoDto.setData(cpuInfo);
- RedisUtil.lSet(key, systemInfoDto);
+ Map<String, String> infoMap = new HashMap<>();
+ infoMap.put("time", DateUtil.getNow());
+ infoMap.put("data", String.valueOf(cpuInfo));
+ redisTemplate.opsForList().rightPush(key, infoMap);
// 姣忕涓�涓紝鏈�澶氬彧瀛�30涓�
- if (RedisUtil.lGetListSize(key) > 30) {
- for (int i = 0; i < RedisUtil.lGetListSize(key) - 30; i++) {
- RedisUtil.lLeftPop(key);
+ Long size = redisTemplate.opsForList().size(key);
+ if (size != null && size >= 30) {
+ for (int i = 0; i < size - 30; i++) {
+ redisTemplate.opsForList().leftPop(key);
}
}
}
@@ -662,66 +496,173 @@
@Override
public void addMemInfo(double memInfo) {
String key = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetting.getServerId();
- SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>();
- systemInfoDto.setTime(DateUtil.getNow());
- systemInfoDto.setData(memInfo);
- RedisUtil.lSet(key, systemInfoDto);
+ Map<String, String> infoMap = new HashMap<>();
+ infoMap.put("time", DateUtil.getNow());
+ infoMap.put("data", String.valueOf(memInfo));
+ redisTemplate.opsForList().rightPush(key, infoMap);
// 姣忕涓�涓紝鏈�澶氬彧瀛�30涓�
- if (RedisUtil.lGetListSize(key) > 30) {
- for (int i = 0; i < RedisUtil.lGetListSize(key) - 30; i++) {
- RedisUtil.lLeftPop(key);
+ Long size = redisTemplate.opsForList().size(key);
+ if (size != null && size >= 30) {
+ for (int i = 0; i < size - 30; i++) {
+ redisTemplate.opsForList().leftPop(key);
}
}
}
@Override
- public void addNetInfo(Map<String, String> networkInterfaces) {
+ public void addNetInfo(Map<String, Double> networkInterfaces) {
String key = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetting.getServerId();
- SystemInfoDto<Map<String, String>> systemInfoDto = new SystemInfoDto<>();
- systemInfoDto.setTime(DateUtil.getNow());
- systemInfoDto.setData(networkInterfaces);
- RedisUtil.lSet(key, systemInfoDto);
+ Map<String, Object> infoMap = new HashMap<>();
+ infoMap.put("time", DateUtil.getNow());
+ for (String netKey : networkInterfaces.keySet()) {
+ infoMap.put(netKey, networkInterfaces.get(netKey));
+ }
+ redisTemplate.opsForList().rightPush(key, infoMap);
// 姣忕涓�涓紝鏈�澶氬彧瀛�30涓�
- if (RedisUtil.lGetListSize(key) > 30) {
- for (int i = 0; i < RedisUtil.lGetListSize(key) - 30; i++) {
- RedisUtil.lLeftPop(key);
+ Long size = redisTemplate.opsForList().size(key);
+ if (size != null && size >= 30) {
+ for (int i = 0; i < size - 30; i++) {
+ redisTemplate.opsForList().leftPop(key);
}
}
+ }
+
+ @Override
+ public void addDiskInfo(List<Map<String, Object>> diskInfo) {
+
+ String key = VideoManagerConstants.SYSTEM_INFO_DISK_PREFIX + userSetting.getServerId();
+ redisTemplate.opsForValue().set(key, diskInfo);
+ }
+
+ @Override
+ public SystemAllInfo getSystemInfo() {
+ String cpuKey = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetting.getServerId();
+ String memKey = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetting.getServerId();
+ String netKey = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetting.getServerId();
+ String diskKey = VideoManagerConstants.SYSTEM_INFO_DISK_PREFIX + userSetting.getServerId();
+ SystemAllInfo systemAllInfo = new SystemAllInfo();
+ systemAllInfo.setCpu(redisTemplate.opsForList().range(cpuKey, 0, -1));
+ systemAllInfo.setMem(redisTemplate.opsForList().range(memKey, 0, -1));
+ systemAllInfo.setNet(redisTemplate.opsForList().range(netKey, 0, -1));
+
+ systemAllInfo.setDisk(redisTemplate.opsForValue().get(diskKey));
+ systemAllInfo.setNetTotal(SystemInfoUtils.getNetworkTotal());
+ return systemAllInfo;
}
@Override
public void sendMobilePositionMsg(JSONObject jsonObject) {
String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_MOBILE_POSITION;
- logger.info("[redis鍙戦�侀�氱煡]绉诲姩浣嶇疆 {}: {}", key, jsonObject.toString());
- RedisUtil.convertAndSend(key, jsonObject);
+ logger.info("[redis鍙戦�侀�氱煡] 鍙戦�� 绉诲姩浣嶇疆 {}: {}", key, jsonObject.toString());
+ redisTemplate.convertAndSend(key, jsonObject);
}
@Override
public void sendStreamPushRequestedMsg(MessageForPushChannel msg) {
String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_REQUESTED;
- logger.info("[redis鍙戦�侀�氱煡]鎺ㄦ祦琚姹� {}: {}/{}", key, msg.getApp(), msg.getStream());
- RedisUtil.convertAndSend(key, (JSONObject)JSON.toJSON(msg));
+ logger.info("[redis鍙戦�侀�氱煡] 鍙戦�� 鎺ㄦ祦琚姹� {}: {}/{}", key, msg.getApp(), msg.getStream());
+ redisTemplate.convertAndSend(key, JSON.toJSON(msg));
}
@Override
public void sendAlarmMsg(AlarmChannelMessage msg) {
+ // 姝ゆ秷鎭敤浜庡鎺ョ涓夋柟鏈嶅姟涓嬬骇鏉ョ殑娑堟伅鍐呭
String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM;
- logger.info("[redis鍙戦�侀�氱煡] 鎶ヨ{}: {}", key, JSON.toJSON(msg));
- RedisUtil.convertAndSend(key, (JSONObject)JSON.toJSON(msg));
+ logger.info("[redis鍙戦�侀�氱煡] 鍙戦�� 鎶ヨ{}: {}", key, JSON.toJSON(msg));
+ redisTemplate.convertAndSend(key, JSON.toJSON(msg));
}
@Override
public boolean deviceIsOnline(String deviceId) {
- return getDevice(deviceId).getOnline() == 1;
+ return getDevice(deviceId).isOnLine();
}
@Override
public void sendStreamPushRequestedMsgForStatus() {
String key = VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED;
- logger.info("[redis閫氱煡]鑾峰彇鎵�鏈夋帹娴佽澶囩殑鐘舵��");
+ logger.info("[redis閫氱煡] 鍙戦�� 鑾峰彇鎵�鏈夋帹娴佽澶囩殑鐘舵��");
JSONObject jsonObject = new JSONObject();
jsonObject.put(key, key);
- RedisUtil.convertAndSend(key, jsonObject);
+ redisTemplate.convertAndSend(key, jsonObject);
+ }
+
+ @Override
+ public int getPushStreamCount(String id) {
+ String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_PUSH_*_*_" + id;
+ return RedisUtil.scan(redisTemplate, key).size();
+ }
+
+ @Override
+ public int getProxyStreamCount(String id) {
+ String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_PULL_*_*_" + id;
+ return RedisUtil.scan(redisTemplate, key).size();
+ }
+
+ @Override
+ public int getGbSendCount(String id) {
+ String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX
+ + userSetting.getServerId() + "_*_" + id + "_*";
+ return RedisUtil.scan(redisTemplate, key).size();
+ }
+
+ @Override
+ public void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online) {
+ String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS;
+ StringBuilder msg = new StringBuilder();
+ msg.append(deviceId);
+ if (channelId != null) {
+ msg.append(":").append(channelId);
+ }
+ msg.append(" ").append(online? "ON":"OFF");
+ logger.info("[redis閫氱煡] 鎺ㄩ�佽澶�/閫氶亾鐘舵��-> {} ", msg);
+ // 浣跨敤 RedisTemplate<Object, Object> 鍙戦�佸瓧绗︿覆娑堟伅浼氬鑷村彂閫佺殑娑堟伅澶氬甫浜嗗弻寮曞彿
+ stringRedisTemplate.convertAndSend(key, msg.toString());
+ }
+
+ @Override
+ public void sendChannelAddOrDelete(String deviceId, String channelId, boolean add) {
+ String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS;
+
+
+ StringBuilder msg = new StringBuilder();
+ msg.append(deviceId);
+ if (channelId != null) {
+ msg.append(":").append(channelId);
+ }
+ msg.append(" ").append(add? "ADD":"DELETE");
+ logger.info("[redis閫氱煡] 鎺ㄩ�侀�氶亾-> {}", msg);
+ // 浣跨敤 RedisTemplate<Object, Object> 鍙戦�佸瓧绗︿覆娑堟伅浼氬鑷村彂閫佺殑娑堟伅澶氬甫浜嗗弻寮曞彿
+ stringRedisTemplate.convertAndSend(key, msg.toString());
+ }
+
+ @Override
+ public void sendPlatformStartPlayMsg(MessageForPushChannel msg) {
+ String key = VideoManagerConstants.VM_MSG_STREAM_START_PLAY_NOTIFY;
+ logger.info("[redis鍙戦�侀�氱煡] 鍙戦�� 鎺ㄦ祦琚笂绾у钩鍙拌鐪� {}: {}/{}->{}", key, msg.getApp(), msg.getStream(), msg.getPlatFormId());
+ redisTemplate.convertAndSend(key, JSON.toJSON(msg));
+ }
+
+ @Override
+ public void sendPlatformStopPlayMsg(MessageForPushChannel msg) {
+ String key = VideoManagerConstants.VM_MSG_STREAM_STOP_PLAY_NOTIFY;
+ logger.info("[redis鍙戦�侀�氱煡] 鍙戦�� 涓婄骇骞冲彴鍋滄瑙傜湅 {}: {}/{}->{}", key, msg.getApp(), msg.getStream(), msg.getPlatFormId());
+ redisTemplate.convertAndSend(key, JSON.toJSON(msg));
+ }
+
+ @Override
+ public void addPushListItem(String app, String stream, OnStreamChangedHookParam param) {
+ String key = VideoManagerConstants.PUSH_STREAM_LIST + app + "_" + stream;
+ redisTemplate.opsForValue().set(key, param);
+ }
+
+ @Override
+ public void removePushListItem(String app, String stream, String mediaServerId) {
+ String key = VideoManagerConstants.PUSH_STREAM_LIST + app + "_" + stream;
+ OnStreamChangedHookParam param = (OnStreamChangedHookParam)redisTemplate.opsForValue().get(key);
+ if (param != null && param.getMediaServerId().equalsIgnoreCase(mediaServerId)) {
+ redisTemplate.delete(key);
+ }
+
}
}
--
Gitblit v1.8.0