GPSSubscribeTask.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.genersoft.iot.vmp.gb28181.task;
  2. import com.genersoft.iot.vmp.gb28181.bean.GbStream;
  3. import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
  4. import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
  5. import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
  6. import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
  7. import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  8. import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
  9. import java.text.SimpleDateFormat;
  10. import java.util.List;
  11. public class GPSSubscribeTask implements Runnable{
  12. private IRedisCatchStorage redisCatchStorage;
  13. private IVideoManagerStorager storager;
  14. private ISIPCommanderForPlatform sipCommanderForPlatform;
  15. private String platformId;
  16. private String sn;
  17. private String key;
  18. private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  19. public GPSSubscribeTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorager storager, String platformId, String sn, String key) {
  20. this.redisCatchStorage = redisCatchStorage;
  21. this.storager = storager;
  22. this.platformId = platformId;
  23. this.sn = sn;
  24. this.key = key;
  25. this.sipCommanderForPlatform = sipCommanderForPlatform;
  26. }
  27. @Override
  28. public void run() {
  29. SubscribeInfo subscribe = redisCatchStorage.getSubscribe(key);
  30. if (subscribe != null) {
  31. System.out.println("发送GPS消息");
  32. ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
  33. if (parentPlatform == null || parentPlatform.isStatus()) {
  34. // TODO 暂时只处理视频流的回复,后续增加对国标设备的支持
  35. List<GbStream> gbStreams = storager.queryGbStreamListInPlatform(platformId);
  36. if (gbStreams.size() > 0) {
  37. for (GbStream gbStream : gbStreams) {
  38. String gbId = gbStream.getGbId();
  39. GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId);
  40. if (gbStream.isStatus()) {
  41. if (gpsMsgInfo != null) {
  42. // 发送GPS消息
  43. sipCommanderForPlatform.sendMobilePosition(parentPlatform, gpsMsgInfo, subscribe);
  44. }else {
  45. // 没有在redis找到新的消息就使用数据库的消息
  46. gpsMsgInfo = new GPSMsgInfo();
  47. gpsMsgInfo.setId(gbId);
  48. gpsMsgInfo.setLat(gbStream.getLongitude());
  49. gpsMsgInfo.setLng(gbStream.getLongitude());
  50. // 发送GPS消息
  51. sipCommanderForPlatform.sendMobilePosition(parentPlatform, gpsMsgInfo, subscribe);
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }