Commit 41fdb9d13f4cc8babe42be0ab79b5ffd5f5088d1

Authored by 648540858
2 parents c0b79878 a380246e

Merge branch 'wvp-28181-record' into feature/record

src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
... ... @@ -155,6 +155,19 @@ public class DeviceServiceImpl implements IDeviceService {
155 155 sync(device);
156 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 171 }else {
159 172 if (deviceChannelMapper.queryAllChannels(device.getDeviceId()).size() == 0) {
160 173 logger.info("[设备上线]: {},通道数为0,查询通道信息", device.getDeviceId());
... ... @@ -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 184 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
180 185 // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线
181 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 189 // try {
... ... @@ -206,6 +207,13 @@ public class DeviceServiceImpl implements IDeviceService {
206 207 }
207 208 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + deviceId;
208 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 217 device.setOnLine(false);
210 218 redisCatchStorage.updateDevice(device);
211 219 deviceMapper.update(device);
... ... @@ -223,11 +231,6 @@ public class DeviceServiceImpl implements IDeviceService {
223 231 // 移除订阅
224 232 removeCatalogSubscribe(device);
225 233 removeMobilePositionSubscribe(device);
226   - if (userSetting.getDeviceStatusNotify()) {
227   - // 发送redis消息
228   - redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, false);
229   - }
230   -
231 234 }
232 235  
233 236 @Override
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
... ... @@ -609,14 +609,13 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
609 609 @Override
610 610 public void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online) {
611 611 String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS;
612   - logger.info("[redis通知] 发送 推送设备/通道状态, {}/{}-{}", deviceId, channelId, online);
613 612 StringBuilder msg = new StringBuilder();
614 613 msg.append(deviceId);
615 614 if (channelId != null) {
616 615 msg.append(":").append(channelId);
617 616 }
618 617 msg.append(" ").append(online? "ON":"OFF");
619   - logger.info("[redis通知] 推送状态-> {} ", msg);
  618 + logger.info("[redis通知] 推送设备/通道状态-> {} ", msg);
620 619 // 使用 RedisTemplate<Object, Object> 发送字符串消息会导致发送的消息多带了双引号
621 620 stringRedisTemplate.convertAndSend(key, msg.toString());
622 621 }
... ...