ApiDeviceController.java 7.6 KB

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