SipDeviceRunner.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.genersoft.iot.vmp.conf.runner;
  2. import com.genersoft.iot.vmp.conf.UserSetting;
  3. import com.genersoft.iot.vmp.gb28181.bean.Device;
  4. import com.genersoft.iot.vmp.service.IDeviceService;
  5. import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  6. import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.boot.CommandLineRunner;
  9. import org.springframework.core.annotation.Order;
  10. import org.springframework.stereotype.Component;
  11. import java.util.List;
  12. /**
  13. * 系统启动时控制设备离线
  14. */
  15. @Component
  16. @Order(value=4)
  17. public class SipDeviceRunner implements CommandLineRunner {
  18. @Autowired
  19. private IVideoManagerStorage storager;
  20. @Autowired
  21. private IRedisCatchStorage redisCatchStorage;
  22. @Autowired
  23. private UserSetting userSetting;
  24. @Autowired
  25. private IDeviceService deviceService;
  26. @Override
  27. public void run(String... args) throws Exception {
  28. // 读取redis没有心跳信息的则设置为离线,等收到下次心跳设置为在线
  29. // 设置所有设备离线
  30. storager.outlineForAll();
  31. List<String> onlineForAll = redisCatchStorage.getOnlineForAll();
  32. for (String deviceId : onlineForAll) {
  33. storager.online(deviceId);
  34. Device device = redisCatchStorage.getDevice(deviceId);
  35. if (device != null && device.getSubscribeCycleForCatalog() > 0) {
  36. // 查询在线设备那些开启了订阅,为设备开启定时的目录订阅
  37. deviceService.addCatalogSubscribe(device);
  38. deviceService.addMobilePositionSubscribe(device);
  39. }
  40. }
  41. // 重置cseq计数
  42. redisCatchStorage.resetAllCSEQ();
  43. }
  44. }