ApiDeviceController.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package com.genersoft.iot.vmp.web;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.genersoft.iot.vmp.gb28181.bean.Device;
  5. import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  6. import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
  7. import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
  8. import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
  9. import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
  10. import com.github.pagehelper.PageInfo;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.util.List;
  16. /**
  17. * 兼容LiveGBS的API:设备信息
  18. */
  19. @CrossOrigin
  20. @RestController
  21. @RequestMapping(value = "/api/v1/device")
  22. public class ApiDeviceController {
  23. private final static Logger logger = LoggerFactory.getLogger(ApiDeviceController.class);
  24. @Autowired
  25. private IVideoManagerStorager storager;
  26. @Autowired
  27. private SIPCommander cmder;
  28. @Autowired
  29. private DeferredResultHolder resultHolder;
  30. @Autowired
  31. private DeviceOffLineDetector offLineDetector;
  32. /**
  33. * 分页获取设备列表 TODO 现在直接返回,尚未实现分页
  34. * @param start
  35. * @param limit
  36. * @param q
  37. * @param online
  38. * @return
  39. */
  40. @RequestMapping(value = "/list")
  41. public JSONObject list( @RequestParam(required = false)Integer start,
  42. @RequestParam(required = false)Integer limit,
  43. @RequestParam(required = false)String q,
  44. @RequestParam(required = false)Boolean online ){
  45. if (logger.isDebugEnabled()) {
  46. logger.debug("查询所有视频设备API调用");
  47. }
  48. logger.debug("查询所有视频设备API调用");
  49. JSONObject result = new JSONObject();
  50. List<Device> devices;
  51. if (start == null || limit ==null) {
  52. devices = storager.queryVideoDeviceList();
  53. result.put("DeviceCount", devices.size());
  54. }else {
  55. PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit);
  56. result.put("DeviceCount", deviceList.getTotal());
  57. devices = deviceList.getList();
  58. }
  59. JSONArray deviceJSONList = new JSONArray();
  60. for (Device device : devices) {
  61. JSONObject deviceJsonObject = new JSONObject();
  62. deviceJsonObject.put("ID", device.getDeviceId());
  63. deviceJsonObject.put("Name", device.getName());
  64. deviceJsonObject.put("Type", "GB");
  65. deviceJsonObject.put("ChannelCount", device.getChannelCount());
  66. deviceJsonObject.put("RecvStreamIP", "");
  67. deviceJsonObject.put("CatalogInterval", 3600); // 通道目录抓取周期
  68. deviceJsonObject.put("SubscribeInterval", 0); // 订阅周期(秒), 0 表示后台不周期订阅
  69. deviceJsonObject.put("Online", device.getOnline() == 1);
  70. deviceJsonObject.put("Password", "");
  71. deviceJsonObject.put("MediaTransport", device.getTransport());
  72. deviceJsonObject.put("RemoteIP", device.getIp());
  73. deviceJsonObject.put("RemotePort", device.getPort());
  74. deviceJsonObject.put("LastRegisterAt", "");
  75. deviceJsonObject.put("LastKeepaliveAt", "");
  76. deviceJsonObject.put("UpdatedAt", "");
  77. deviceJsonObject.put("CreatedAt", "");
  78. deviceJSONList.add(deviceJsonObject);
  79. }
  80. result.put("DeviceList",deviceJSONList);
  81. return result;
  82. }
  83. @RequestMapping(value = "/channellist")
  84. public JSONObject channellist( String serial,
  85. @RequestParam(required = false)String channel_type,
  86. @RequestParam(required = false)String dir_serial ,
  87. @RequestParam(required = false)Integer start,
  88. @RequestParam(required = false)Integer limit,
  89. @RequestParam(required = false)String q,
  90. @RequestParam(required = false)Boolean online ){
  91. if (logger.isDebugEnabled()) {
  92. logger.debug("查询所有视频设备API调用");
  93. }
  94. JSONObject result = new JSONObject();
  95. // 查询设备是否存在
  96. Device device = storager.queryVideoDevice(serial);
  97. if (device == null) {
  98. result.put("ChannelCount", 0);
  99. result.put("ChannelList", "[]");
  100. return result;
  101. }
  102. List<DeviceChannel> deviceChannels;
  103. if (start == null || limit ==null) {
  104. deviceChannels = storager.queryChannelsByDeviceId(serial);
  105. result.put("ChannelCount", deviceChannels.size());
  106. }else {
  107. PageInfo<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, null, null, null,start/limit, limit);
  108. result.put("ChannelCount", pageResult.getTotal());
  109. deviceChannels = pageResult.getList();
  110. }
  111. JSONArray channleJSONList = new JSONArray();
  112. for (DeviceChannel deviceChannel : deviceChannels) {
  113. JSONObject deviceJOSNChannel = new JSONObject();
  114. deviceJOSNChannel.put("ID", deviceChannel.getChannelId());
  115. deviceJOSNChannel.put("DeviceID", device.getDeviceId());
  116. deviceJOSNChannel.put("DeviceName", device.getName());
  117. deviceJOSNChannel.put("DeviceOnline", device.getOnline() == 1);
  118. deviceJOSNChannel.put("Channel", 0); // TODO 自定义序号
  119. deviceJOSNChannel.put("Name", deviceChannel.getName());
  120. deviceJOSNChannel.put("Custom", false);
  121. deviceJOSNChannel.put("CustomName", "");
  122. deviceJOSNChannel.put("SubCount", deviceChannel.getSubCount()); // TODO ? 子节点数, SubCount > 0 表示该通道为子目录
  123. deviceJOSNChannel.put("SnapURL", "");
  124. deviceJOSNChannel.put("Manufacturer ", deviceChannel.getManufacture());
  125. deviceJOSNChannel.put("Model", deviceChannel.getModel());
  126. deviceJOSNChannel.put("Owner", deviceChannel.getOwner());
  127. deviceJOSNChannel.put("CivilCode", deviceChannel.getCivilCode());
  128. deviceJOSNChannel.put("Address", deviceChannel.getAddress());
  129. deviceJOSNChannel.put("Parental", deviceChannel.getParental()); // 当为通道设备时, 是否有通道子设备, 1-有,0-没有
  130. deviceJOSNChannel.put("ParentID", deviceChannel.getParentId()); // 直接上级编号
  131. deviceJOSNChannel.put("Secrecy", deviceChannel.getSecrecy());
  132. deviceJOSNChannel.put("RegisterWay", 1); // 注册方式, 缺省为1, 允许值: 1, 2, 3
  133. // 1-IETF RFC3261,
  134. // 2-基于口令的双向认证,
  135. // 3-基于数字证书的双向认证
  136. deviceJOSNChannel.put("Status", deviceChannel.getStatus());
  137. deviceJOSNChannel.put("Longitude", deviceChannel.getLongitude());
  138. deviceJOSNChannel.put("Latitude", deviceChannel.getLatitude());
  139. deviceJOSNChannel.put("PTZType ", deviceChannel.getPTZType()); // 云台类型, 0 - 未知, 1 - 球机, 2 - 半球,
  140. // 3 - 固定枪机, 4 - 遥控枪机
  141. deviceJOSNChannel.put("CustomPTZType", "");
  142. deviceJOSNChannel.put("StreamID", deviceChannel.getStreamId()); // StreamID 直播流ID, 有值表示正在直播
  143. deviceJOSNChannel.put("NumOutputs ", -1); // 直播在线人数
  144. channleJSONList.add(deviceJOSNChannel);
  145. }
  146. result.put("ChannelList", channleJSONList);
  147. return result;
  148. }
  149. }