优化设备在线状态

This commit is contained in:
648540858
2022-05-11 18:37:24 +08:00
parent c395cf42d1
commit f6893cf95b
52 changed files with 571 additions and 802 deletions

View File

@@ -111,23 +111,6 @@ public interface IRedisCatchStorage {
*/
void clearCatchByDeviceId(String deviceId);
/**
* 获取mediaServer节点
* @param mediaServerId
* @return
*/
// MediaServerItem getMediaInfo(String mediaServerId);
/**
* 设置所有设备离线
*/
void outlineForAll();
/**
* 获取所有在线的
*/
List<String> getOnlineForAll();
/**
* 在redis添加wvp的信息
*/

View File

@@ -99,4 +99,9 @@ public interface DeviceMapper {
@Update("UPDATE device SET online=0")
int outlineForAll();
@Select("SELECT * FROM device WHERE online = 1")
List<Device> getOnlineDevices();
@Select("SELECT * FROM device WHERE ip = #{host} AND port=${port}")
Device getDeviceByHostAndPort(String host, int port);
}

View File

@@ -14,13 +14,13 @@ 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.utils.DateUtil;
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.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.*;
@SuppressWarnings("rawtypes")
@@ -38,8 +38,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Autowired
private UserSetting userSetting;
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public Long getCSEQ(String method) {
String key = VideoManagerConstants.SIP_CSEQ_PREFIX + userSetting.getServerId() + "_" + method;
@@ -469,26 +467,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
}
}
@Override
public void outlineForAll() {
List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + "*" );
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 + userSetting.getServerId() + "_" + "*" );
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, int time) {
String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetting.getServerId();
@@ -638,7 +616,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
public void addCpuInfo(double cpuInfo) {
String key = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetting.getServerId();
SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>();
systemInfoDto.setTime(format.format(System.currentTimeMillis()));
systemInfoDto.setTime(DateUtil.getNow());
systemInfoDto.setData(cpuInfo);
redis.lSet(key, systemInfoDto);
// 每秒一个最多只存30个
@@ -653,7 +631,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
public void addMemInfo(double memInfo) {
String key = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetting.getServerId();
SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>();
systemInfoDto.setTime(format.format(System.currentTimeMillis()));
systemInfoDto.setTime(DateUtil.getNow());
systemInfoDto.setData(memInfo);
redis.lSet(key, systemInfoDto);
// 每秒一个最多只存30个
@@ -668,7 +646,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
public void addNetInfo(Map<String, String> networkInterfaces) {
String key = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetting.getServerId();
SystemInfoDto<Map<String, String>> systemInfoDto = new SystemInfoDto<>();
systemInfoDto.setTime(format.format(System.currentTimeMillis()));
systemInfoDto.setTime(DateUtil.getNow());
systemInfoDto.setData(networkInterfaces);
redis.lSet(key, systemInfoDto);
// 每秒一个最多只存30个
@@ -702,7 +680,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
@Override
public boolean deviceIsOnline(String deviceId) {
String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + deviceId;
return redis.hasKey(key);
return getDevice(deviceId).getOnline() == 1;
}
}

View File

@@ -13,6 +13,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.storager.dao.*;
import com.genersoft.iot.vmp.storager.dao.dto.ChannelSourceInfo;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -26,7 +27,6 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -91,9 +91,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
@Autowired
private ParentPlatformMapper parentPlatformMapper;
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 根据设备ID判断设备是否存在
*
@@ -127,7 +124,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
*/
@Override
public synchronized boolean updateDevice(Device device) {
String now = this.format.format(System.currentTimeMillis());
String now = DateUtil.getNow();
device.setUpdateTime(now);
Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
device.setCharset(device.getCharset().toUpperCase());
@@ -140,8 +137,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return deviceMapper.update(device) > 0;
}
}
@Override
@@ -152,7 +147,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
if (streamInfo != null) {
channel.setStreamId(streamInfo.getStream());
}
String now = this.format.format(System.currentTimeMillis());
String now = DateUtil.getNow();
channel.setUpdateTime(now);
DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
if (deviceChannel == null) {
@@ -178,7 +173,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
if (streamInfo != null) {
channel.setStreamId(streamInfo.getStream());
}
String now = this.format.format(System.currentTimeMillis());
String now = DateUtil.getNow();
channel.setUpdateTime(now);
channel.setCreateTime(now);
addChannels.add(channel);
@@ -193,7 +188,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
if (streamInfo != null) {
channel.setStreamId(streamInfo.getStream());
}
String now = this.format.format(System.currentTimeMillis());
String now = DateUtil.getNow();
channel.setUpdateTime(now);
if (channelsInStore.get(channel.getChannelId()) != null) {
updateChannels.add(channel);
@@ -732,7 +727,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
boolean result = false;
streamProxyItem.setStreamType("proxy");
streamProxyItem.setStatus(true);
String now = this.format.format(System.currentTimeMillis());
String now = DateUtil.getNow();
streamProxyItem.setCreateTime(now);
streamProxyItem.setCreateStamp(System.currentTimeMillis());
try {