Commit 41fdb9d13f4cc8babe42be0ab79b5ffd5f5088d1
Merge branch 'wvp-28181-record' into feature/record
Showing
2 changed files
with
21 additions
and
19 deletions
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
| @@ -155,6 +155,19 @@ public class DeviceServiceImpl implements IDeviceService { | @@ -155,6 +155,19 @@ public class DeviceServiceImpl implements IDeviceService { | ||
| 155 | sync(device); | 155 | sync(device); |
| 156 | // TODO 如果设备下的通道级联到了其他平台,那么需要发送事件或者notify给上级平台 | 156 | // TODO 如果设备下的通道级联到了其他平台,那么需要发送事件或者notify给上级平台 |
| 157 | } | 157 | } |
| 158 | + // 上线添加订阅 | ||
| 159 | + if (device.getSubscribeCycleForCatalog() > 0) { | ||
| 160 | + // 查询在线设备那些开启了订阅,为设备开启定时的目录订阅 | ||
| 161 | + addCatalogSubscribe(device); | ||
| 162 | + } | ||
| 163 | + if (device.getSubscribeCycleForMobilePosition() > 0) { | ||
| 164 | + addMobilePositionSubscribe(device); | ||
| 165 | + } | ||
| 166 | + if (userSetting.getDeviceStatusNotify()) { | ||
| 167 | + // 发送redis消息 | ||
| 168 | + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, true); | ||
| 169 | + } | ||
| 170 | + | ||
| 158 | }else { | 171 | }else { |
| 159 | if (deviceChannelMapper.queryAllChannels(device.getDeviceId()).size() == 0) { | 172 | if (deviceChannelMapper.queryAllChannels(device.getDeviceId()).size() == 0) { |
| 160 | logger.info("[设备上线]: {},通道数为0,查询通道信息", device.getDeviceId()); | 173 | logger.info("[设备上线]: {},通道数为0,查询通道信息", device.getDeviceId()); |
| @@ -167,22 +180,10 @@ public class DeviceServiceImpl implements IDeviceService { | @@ -167,22 +180,10 @@ public class DeviceServiceImpl implements IDeviceService { | ||
| 167 | 180 | ||
| 168 | } | 181 | } |
| 169 | 182 | ||
| 170 | - // 上线添加订阅 | ||
| 171 | - if (device.getSubscribeCycleForCatalog() > 0) { | ||
| 172 | - // 查询在线设备那些开启了订阅,为设备开启定时的目录订阅 | ||
| 173 | - addCatalogSubscribe(device); | ||
| 174 | - } | ||
| 175 | - if (device.getSubscribeCycleForMobilePosition() > 0) { | ||
| 176 | - addMobilePositionSubscribe(device); | ||
| 177 | - } | ||
| 178 | // 刷新过期任务 | 183 | // 刷新过期任务 |
| 179 | String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId(); | 184 | String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId(); |
| 180 | // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线 | 185 | // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线 |
| 181 | dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId(), "首次注册后未能收到心跳"), device.getKeepaliveIntervalTime() * 1000 * 3); | 186 | dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId(), "首次注册后未能收到心跳"), device.getKeepaliveIntervalTime() * 1000 * 3); |
| 182 | - if (userSetting.getDeviceStatusNotify()) { | ||
| 183 | - // 发送redis消息 | ||
| 184 | - redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, true); | ||
| 185 | - } | ||
| 186 | 187 | ||
| 187 | // | 188 | // |
| 188 | // try { | 189 | // try { |
| @@ -206,6 +207,13 @@ public class DeviceServiceImpl implements IDeviceService { | @@ -206,6 +207,13 @@ public class DeviceServiceImpl implements IDeviceService { | ||
| 206 | } | 207 | } |
| 207 | String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + deviceId; | 208 | String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + deviceId; |
| 208 | dynamicTask.stop(registerExpireTaskKey); | 209 | dynamicTask.stop(registerExpireTaskKey); |
| 210 | + if (device.isOnLine()) { | ||
| 211 | + if (userSetting.getDeviceStatusNotify()) { | ||
| 212 | + // 发送redis消息 | ||
| 213 | + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, false); | ||
| 214 | + } | ||
| 215 | + } | ||
| 216 | + | ||
| 209 | device.setOnLine(false); | 217 | device.setOnLine(false); |
| 210 | redisCatchStorage.updateDevice(device); | 218 | redisCatchStorage.updateDevice(device); |
| 211 | deviceMapper.update(device); | 219 | deviceMapper.update(device); |
| @@ -223,11 +231,6 @@ public class DeviceServiceImpl implements IDeviceService { | @@ -223,11 +231,6 @@ public class DeviceServiceImpl implements IDeviceService { | ||
| 223 | // 移除订阅 | 231 | // 移除订阅 |
| 224 | removeCatalogSubscribe(device); | 232 | removeCatalogSubscribe(device); |
| 225 | removeMobilePositionSubscribe(device); | 233 | removeMobilePositionSubscribe(device); |
| 226 | - if (userSetting.getDeviceStatusNotify()) { | ||
| 227 | - // 发送redis消息 | ||
| 228 | - redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, false); | ||
| 229 | - } | ||
| 230 | - | ||
| 231 | } | 234 | } |
| 232 | 235 | ||
| 233 | @Override | 236 | @Override |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
| @@ -609,14 +609,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -609,14 +609,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 609 | @Override | 609 | @Override |
| 610 | public void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online) { | 610 | public void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online) { |
| 611 | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS; | 611 | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS; |
| 612 | - logger.info("[redis通知] 发送 推送设备/通道状态, {}/{}-{}", deviceId, channelId, online); | ||
| 613 | StringBuilder msg = new StringBuilder(); | 612 | StringBuilder msg = new StringBuilder(); |
| 614 | msg.append(deviceId); | 613 | msg.append(deviceId); |
| 615 | if (channelId != null) { | 614 | if (channelId != null) { |
| 616 | msg.append(":").append(channelId); | 615 | msg.append(":").append(channelId); |
| 617 | } | 616 | } |
| 618 | msg.append(" ").append(online? "ON":"OFF"); | 617 | msg.append(" ").append(online? "ON":"OFF"); |
| 619 | - logger.info("[redis通知] 推送状态-> {} ", msg); | 618 | + logger.info("[redis通知] 推送设备/通道状态-> {} ", msg); |
| 620 | // 使用 RedisTemplate<Object, Object> 发送字符串消息会导致发送的消息多带了双引号 | 619 | // 使用 RedisTemplate<Object, Object> 发送字符串消息会导致发送的消息多带了双引号 |
| 621 | stringRedisTemplate.convertAndSend(key, msg.toString()); | 620 | stringRedisTemplate.convertAndSend(key, msg.toString()); |
| 622 | } | 621 | } |