将device信息写入redis以提高sip处理速度
This commit is contained in:
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.storager;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
@@ -169,4 +170,15 @@ public interface IRedisCatchStorage {
|
||||
ThirdPartyGB queryMemberNoGBId(String queryKey);
|
||||
|
||||
List<StreamInfo> getStreams(String mediaServerId, String pull);
|
||||
|
||||
/**
|
||||
* 将device信息写入redis
|
||||
* @param device
|
||||
*/
|
||||
void updateDevice(Device device);
|
||||
|
||||
/**
|
||||
* 获取Device
|
||||
*/
|
||||
Device getDevice(String deviceId);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.storager.dao;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -79,4 +80,17 @@ public interface GbStreamMapper {
|
||||
"</foreach>" +
|
||||
"</script>")
|
||||
void batchDel(List<StreamProxyItem> streamProxyItemList);
|
||||
|
||||
@Insert("<script> " +
|
||||
"insert into gb_stream " +
|
||||
"(app, stream, gbId, name, " +
|
||||
"longitude, latitude, streamType, mediaServerId, status)" +
|
||||
"values " +
|
||||
"<foreach collection='subList' index='index' item='item' separator=','> " +
|
||||
"('${item.app}', '${item.stream}', '${item.gbId}', '${item.name}', " +
|
||||
"'${item.longitude}', '${item.latitude}', '${item.streamType}', " +
|
||||
"'${item.mediaServerId}', ${item.status}) "+
|
||||
"</foreach> " +
|
||||
"</script>")
|
||||
void batchAdd(List<StreamPushItem> subList);
|
||||
}
|
||||
|
||||
@@ -377,4 +377,16 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDevice(Device device) {
|
||||
String key = VideoManagerConstants.DEVICE_PREFIX + userSetup.getServerId() + "_" + device.getDeviceId();
|
||||
redis.set(key, device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(String deviceId) {
|
||||
String key = VideoManagerConstants.DEVICE_PREFIX + userSetup.getServerId() + "_" + deviceId;
|
||||
return (Device)redis.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public synchronized boolean create(Device device) {
|
||||
redisCatchStorage.updateDevice(device);
|
||||
return deviceMapper.add(device) > 0;
|
||||
}
|
||||
|
||||
@@ -128,11 +129,14 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
|
||||
if (deviceByDeviceId == null) {
|
||||
device.setCreateTime(now);
|
||||
redisCatchStorage.updateDevice(device);
|
||||
return deviceMapper.add(device) > 0;
|
||||
}else {
|
||||
redisCatchStorage.updateDevice(device);
|
||||
return deviceMapper.update(device) > 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,11 +189,32 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
}
|
||||
}
|
||||
}
|
||||
int limitCount = 300;
|
||||
if (addChannels.size() > 0) {
|
||||
deviceChannelMapper.batchAdd(addChannels);
|
||||
if (addChannels.size() > limitCount) {
|
||||
for (int i = 0; i < addChannels.size(); i += limitCount) {
|
||||
int toIndex = i + limitCount;
|
||||
if (i + limitCount > addChannels.size()) {
|
||||
toIndex = addChannels.size();
|
||||
}
|
||||
deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex));
|
||||
}
|
||||
}else {
|
||||
deviceChannelMapper.batchAdd(addChannels);
|
||||
}
|
||||
}
|
||||
if (updateChannels.size() > 0) {
|
||||
deviceChannelMapper.batchUpdate(updateChannels);
|
||||
if (updateChannels.size() > limitCount) {
|
||||
for (int i = 0; i < updateChannels.size(); i += limitCount) {
|
||||
int toIndex = i + limitCount;
|
||||
if (i + limitCount > updateChannels.size()) {
|
||||
toIndex = updateChannels.size();
|
||||
}
|
||||
deviceChannelMapper.batchAdd(updateChannels.subList(i, toIndex));
|
||||
}
|
||||
}else {
|
||||
deviceChannelMapper.batchUpdate(updateChannels);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,6 +347,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
}
|
||||
device.setOnline(1);
|
||||
logger.info("更新设备在线: " + deviceId);
|
||||
redisCatchStorage.updateDevice(device);
|
||||
return deviceMapper.update(device) > 0;
|
||||
}
|
||||
|
||||
@@ -337,6 +363,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
Device device = deviceMapper.getDeviceByDeviceId(deviceId);
|
||||
if (device == null) return false;
|
||||
device.setOnline(0);
|
||||
redisCatchStorage.updateDevice(device);
|
||||
return deviceMapper.update(device) > 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user