648540858
2023-02-14 bdc0f83e29281bb46c5fe7a6eb6562f7f0e616af
启动时清理无效的设备缓存数据,避免设备无法注册
6个文件已修改
59 ■■■■■ 已修改文件
src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/service/IDeviceService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java
@@ -69,6 +69,26 @@
        // 重置cseq计数
        redisCatchStorage.resetAllCSEQ();
        // 清理redis
        // 清理数据库不存在但是redis中存在的数据
        List<Device> devicesInDb = deviceService.getAll();
        if (devicesInDb.size() == 0) {
            redisCatchStorage.removeAllDevice();
        }else {
            List<Device> devicesInRedis = redisCatchStorage.getAllDevices();
            if (devicesInRedis.size() > 0) {
                Map<String, Device> deviceMapInDb = new HashMap<>();
                devicesInDb.parallelStream().forEach(device -> {
                    deviceMapInDb.put(device.getDeviceId(), device);
                });
                devicesInRedis.parallelStream().forEach(device -> {
                    if (deviceMapInDb.get(device.getDeviceId()) == null) {
                        redisCatchStorage.removeDevice(device.getDeviceId());
                    }
                });
            }
        }
        // 查找国标推流
        List<SendRtpItem> sendRtpItems = redisCatchStorage.queryAllSendRTPServer();
        if (sendRtpItems.size() > 0) {
src/main/java/com/genersoft/iot/vmp/service/IDeviceService.java
@@ -163,4 +163,8 @@
     */
    ResourceBaceInfo getOverview();
    /**
     * 获取所有设备
     */
    List<Device> getAll();
}
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -631,4 +631,9 @@
    public ResourceBaceInfo getOverview() {
        return deviceMapper.getOverview();
    }
    @Override
    public List<Device> getAll() {
        return deviceMapper.getAll();
    }
}
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -258,4 +258,7 @@
    List<SendRtpItem> queryAllSendRTPServer();
    List<Device> getAllDevices();
    void removeAllDevice();
}
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
@@ -280,4 +280,6 @@
    @Select("select count(1) as total, sum(online) as online from device")
    ResourceBaceInfo getOverview();
    @Select("select * from device")
    List<Device> getAll();
}
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -665,6 +665,31 @@
    }
    @Override
    public void removeAllDevice() {
        String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*";
        List<Object> keys = RedisUtil.scan(scanKey);
        for (Object key : keys) {
            RedisUtil.del((String) key);
        }
    }
    @Override
    public List<Device> getAllDevices() {
        String scanKey = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_*";
        List<Device> result = new ArrayList<>();
        List<Object> keys = RedisUtil.scan(scanKey);
        for (Object o : keys) {
            String key = (String) o;
            Device device = JsonUtil.redisJsonToObject(key, Device.class);
            if (Objects.nonNull(device)) { // 只取没有存过得
                result.add(JsonUtil.redisJsonToObject(key, Device.class));
            }
        }
        return result;
    }
    @Override
    public Device getDevice(String deviceId) {
        String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId;
        return JsonUtil.redisJsonToObject(key, Device.class);