SipPlatformRunner.java 2.4 KB

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