DeviceServiceImpl.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.genersoft.iot.vmp.service.impl;
  2. import com.genersoft.iot.vmp.conf.DynamicTask;
  3. import com.genersoft.iot.vmp.gb28181.bean.Device;
  4. import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
  5. import com.genersoft.iot.vmp.service.IDeviceService;
  6. import com.genersoft.iot.vmp.service.bean.CatalogSubscribeTask;
  7. import org.slf4j.Logger;
  8. import org.slf4j.LoggerFactory;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. /**
  12. * 设备业务(目录订阅)
  13. */
  14. @Service
  15. public class DeviceServiceImpl implements IDeviceService {
  16. private final static Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class);
  17. @Autowired
  18. private DynamicTask dynamicTask;
  19. ;
  20. @Autowired
  21. private ISIPCommander sipCommander;
  22. @Override
  23. public boolean addCatalogSubscribe(Device device) {
  24. if (device == null || device.getSubscribeCycleForCatalog() < 0) {
  25. return false;
  26. }
  27. if (dynamicTask.contains(device.getDeviceId())) {
  28. logger.info("[添加目录订阅] 设备{}的目录订阅以存在", device.getDeviceId());
  29. return false;
  30. }
  31. logger.info("[添加目录订阅] 设备{}", device.getDeviceId());
  32. // 添加目录订阅
  33. CatalogSubscribeTask catalogSubscribeTask = new CatalogSubscribeTask(device, sipCommander);
  34. catalogSubscribeTask.run();
  35. // 提前开始刷新订阅
  36. int subscribeCycleForCatalog = device.getSubscribeCycleForCatalog();
  37. // 设置最小值为30
  38. subscribeCycleForCatalog = Math.max(subscribeCycleForCatalog, 30);
  39. dynamicTask.startCron(device.getDeviceId(), catalogSubscribeTask, subscribeCycleForCatalog - 5);
  40. return true;
  41. }
  42. @Override
  43. public boolean removeCatalogSubscribe(Device device) {
  44. if (device == null || device.getSubscribeCycleForCatalog() < 0) {
  45. return false;
  46. }
  47. logger.info("移除目录订阅: {}", device.getDeviceId());
  48. dynamicTask.stopCron(device.getDeviceId());
  49. device.setSubscribeCycleForCatalog(0);
  50. sipCommander.catalogSubscribe(device, null, null);
  51. // 清空cseq计数
  52. return true;
  53. }
  54. }