From abb60593cb77e9e9b6e67e8276fc416c2aede43f Mon Sep 17 00:00:00 2001 From: lin <18010473990@163.com> Date: 星期六, 08 一月 2022 17:35:00 +0800 Subject: [PATCH] 优化级联平台GPS订阅 --- src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 115 insertions(+), 0 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 af9a206..2dcc217 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 @@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.conf.UserSetup; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; +import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; import com.genersoft.iot.vmp.service.bean.ThirdPartyGB; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; @@ -35,6 +36,50 @@ private UserSetup userSetup; private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @Override + public Long getCSEQ(String method) { + String key = VideoManagerConstants.SIP_CSEQ_PREFIX + userSetup.getServerId() + "_" + method; + + long result = redis.incr(key, 1L); + if (result > Integer.MAX_VALUE) { + redis.set(key, 1); + result = 1; + } + return result; + } + + @Override + public Long getSN(String method) { + String key = VideoManagerConstants.SIP_SN_PREFIX + userSetup.getServerId() + "_" + method; + + long result = redis.incr(key, 1L); + if (result > Integer.MAX_VALUE) { + redis.set(key, 1); + result = 1; + } + return result; + } + + @Override + public void resetAllCSEQ() { + String scanKey = VideoManagerConstants.SIP_CSEQ_PREFIX + userSetup.getServerId() + "_*"; + List<Object> keys = redis.scan(scanKey); + for (int i = 0; i < keys.size(); i++) { + String key = (String) keys.get(i); + redis.set(key, 1); + } + } + + @Override + public void resetAllSN() { + String scanKey = VideoManagerConstants.SIP_SN_PREFIX + userSetup.getServerId() + "_*"; + List<Object> keys = redis.scan(scanKey); + for (int i = 0; i < keys.size(); i++) { + String key = (String) keys.get(i); + redis.set(key, 1); + } + } /** * 寮�濮嬫挱鏀炬椂灏嗘祦瀛樺叆redis @@ -296,6 +341,15 @@ redis.del(key.toString()); } } + + List<Object> deviceCache = redis.scan(String.format("%S%s_%s", VideoManagerConstants.DEVICE_PREFIX, + userSetup.getServerId(), + deviceId)); + if (deviceCache.size() > 0) { + for (Object key : deviceCache) { + redis.del(key.toString()); + } + } } @Override @@ -377,4 +431,65 @@ } return result; } + + @Override + public void updateDevice(Device device) { + String key = VideoManagerConstants.DEVICE_PREFIX + userSetup.getServerId() + "_" + device.getDeviceId(); + redis.set(key, device); + } + + @Override + public void removeDevice(String deviceId) { + String key = VideoManagerConstants.DEVICE_PREFIX + userSetup.getServerId() + "_" + deviceId; + redis.del(key); + } + + @Override + public Device getDevice(String deviceId) { + String key = VideoManagerConstants.DEVICE_PREFIX + userSetup.getServerId() + "_" + deviceId; + return (Device)redis.get(key); + } + + @Override + public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) { + String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetup.getServerId() + "_" + gpsMsgInfo.getId(); + redis.set(key, gpsMsgInfo, 60); // 榛樿GPS娑堟伅淇濆瓨1鍒嗛挓 + } + + @Override + public GPSMsgInfo getGpsMsgInfo(String gbId) { + String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetup.getServerId() + "_" + gbId; + return (GPSMsgInfo)redis.get(key); + } + + @Override + public void updateSubscribe(String key, SubscribeInfo subscribeInfo) { + redis.set(key, subscribeInfo, subscribeInfo.getExpires()); + } + + @Override + public SubscribeInfo getSubscribe(String key) { + return (SubscribeInfo)redis.get(key); + } + + @Override + public void delSubscribe(String key) { + redis.del(key); + } + + @Override + public List<GPSMsgInfo> getAllGpsMsgInfo() { + String scanKey = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetup.getServerId() + "_*"; + List<GPSMsgInfo> result = new ArrayList<>(); + List<Object> keys = redis.scan(scanKey); + for (int i = 0; i < keys.size(); i++) { + String key = (String) keys.get(i); + GPSMsgInfo gpsMsgInfo = (GPSMsgInfo) redis.get(key); + if (!gpsMsgInfo.isStored()) { // 鍙彇娌℃湁瀛樿繃寰� + result.add((GPSMsgInfo)redis.get(key)); + } + } + + return result; + } } -- Gitblit v1.8.0