SipDeviceRunner.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 ) {
  36. if (device.getSubscribeCycleForCatalog() > 0) {
  37. // 查询在线设备那些开启了订阅,为设备开启定时的目录订阅
  38. deviceService.addCatalogSubscribe(device);
  39. }
  40. if (device.getSubscribeCycleForMobilePosition() > 0) {
  41. deviceService.addMobilePositionSubscribe(device);
  42. }
  43. }
  44. }
  45. // 重置cseq计数
  46. redisCatchStorage.resetAllCSEQ();
  47. }
  48. }