SipPlatformRunner.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.genersoft.iot.vmp.conf;
  2. import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
  3. import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
  4. import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
  5. import com.genersoft.iot.vmp.service.IPlatformService;
  6. import com.genersoft.iot.vmp.service.impl.PlatformServiceImpl;
  7. import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  8. import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.boot.CommandLineRunner;
  13. import org.springframework.core.annotation.Order;
  14. import org.springframework.stereotype.Component;
  15. import java.util.List;
  16. /**
  17. * 系统启动时控制上级平台重新注册
  18. * @author lin
  19. */
  20. @Component
  21. @Order(value=13)
  22. public class SipPlatformRunner implements CommandLineRunner {
  23. @Autowired
  24. private IVideoManagerStorage storager;
  25. @Autowired
  26. private IRedisCatchStorage redisCatchStorage;
  27. @Autowired
  28. private IPlatformService platformService;
  29. @Autowired
  30. private ISIPCommanderForPlatform sipCommanderForPlatform;
  31. private final static Logger logger = LoggerFactory.getLogger(PlatformServiceImpl.class);
  32. @Override
  33. public void run(String... args) throws Exception {
  34. // 获取所有启用的平台
  35. List<ParentPlatform> parentPlatforms = storager.queryEnableParentPlatformList(true);
  36. for (ParentPlatform parentPlatform : parentPlatforms) {
  37. ParentPlatformCatch parentPlatformCatchOld = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
  38. // 更新缓存
  39. ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch();
  40. parentPlatformCatch.setParentPlatform(parentPlatform);
  41. parentPlatformCatch.setId(parentPlatform.getServerGBId());
  42. redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
  43. if (parentPlatformCatchOld != null) {
  44. // 取消订阅
  45. try {
  46. sipCommanderForPlatform.unregister(parentPlatform, parentPlatformCatchOld.getSipTransactionInfo(), null, (eventResult)->{
  47. platformService.login(parentPlatform);
  48. });
  49. } catch (Exception e) {
  50. logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage());
  51. platformService.offline(parentPlatform, true);
  52. continue;
  53. }
  54. }
  55. // 设置所有平台离线
  56. platformService.offline(parentPlatform, false);
  57. }
  58. }
  59. }