ApiDeviceController.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package com.genersoft.iot.vmp.web.gb28181;
  2. import com.alibaba.fastjson2.JSONArray;
  3. import com.alibaba.fastjson2.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.service.IDeviceService;
  7. import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  8. import com.github.pagehelper.PageInfo;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.*;
  13. import java.util.List;
  14. /**
  15. * API兼容:设备信息
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CrossOrigin
  19. @RestController
  20. @RequestMapping(value = "/api/v1/device")
  21. public class ApiDeviceController {
  22. private final static Logger logger = LoggerFactory.getLogger(ApiDeviceController.class);
  23. @Autowired
  24. private IVideoManagerStorage storager;
  25. @Autowired
  26. private IDeviceService deviceService;
  27. // @Autowired
  28. // private SIPCommander cmder;
  29. // @Autowired
  30. // private DeferredResultHolder resultHolder;
  31. // @Autowired
  32. // private DeviceOffLineDetector offLineDetector;
  33. /**
  34. * 分页获取设备列表 现在直接返回,尚未实现分页
  35. * @param start
  36. * @param limit
  37. * @param q
  38. * @param online
  39. * @return
  40. */
  41. @RequestMapping(value = "/list")
  42. public JSONObject list( @RequestParam(required = false)Integer start,
  43. @RequestParam(required = false)Integer limit,
  44. @RequestParam(required = false)String q,
  45. @RequestParam(required = false)Boolean online ){
  46. // if (logger.isDebugEnabled()) {
  47. // logger.debug("查询所有视频设备API调用");
  48. // }
  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", device.getSubscribeCycleForCatalog()); // 订阅周期(秒), 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 code,
  86. @RequestParam(required = false)String channel_type,
  87. @RequestParam(required = false)String dir_serial ,
  88. @RequestParam(required = false)Integer start,
  89. @RequestParam(required = false)Integer limit,
  90. @RequestParam(required = false)String q,
  91. @RequestParam(required = false)Boolean online ){
  92. // if (logger.isDebugEnabled()) {
  93. // logger.debug("查询所有视频设备API调用");
  94. // }
  95. JSONObject result = new JSONObject();
  96. // 查询设备是否存在
  97. Device device = storager.queryVideoDevice(serial);
  98. if (device == null) {
  99. result.put("ChannelCount", 0);
  100. result.put("ChannelList", "[]");
  101. return result;
  102. }
  103. List<DeviceChannel> deviceChannels;
  104. List<DeviceChannel> allDeviceChannelList = storager.queryChannelsByDeviceId(serial);
  105. if (start == null || limit ==null) {
  106. deviceChannels = allDeviceChannelList;
  107. result.put("ChannelCount", deviceChannels.size());
  108. }else {
  109. deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, null,start, limit);
  110. int total = allDeviceChannelList.size();
  111. result.put("ChannelCount", total);
  112. }
  113. JSONArray channleJSONList = new JSONArray();
  114. for (DeviceChannel deviceChannel : deviceChannels) {
  115. JSONObject deviceJOSNChannel = new JSONObject();
  116. deviceJOSNChannel.put("ID", deviceChannel.getChannelId());
  117. deviceJOSNChannel.put("DeviceID", device.getDeviceId());
  118. deviceJOSNChannel.put("DeviceName", device.getName());
  119. deviceJOSNChannel.put("DeviceOnline", device.getOnline() == 1);
  120. deviceJOSNChannel.put("Channel", 0); // 自定义序号
  121. deviceJOSNChannel.put("Name", deviceChannel.getName());
  122. deviceJOSNChannel.put("Custom", false);
  123. deviceJOSNChannel.put("CustomName", "");
  124. deviceJOSNChannel.put("SubCount", deviceChannel.getSubCount()); // 子节点数, SubCount > 0 表示该通道为子目录
  125. deviceJOSNChannel.put("SnapURL", "");
  126. deviceJOSNChannel.put("Manufacturer ", deviceChannel.getManufacture());
  127. deviceJOSNChannel.put("Model", deviceChannel.getModel());
  128. deviceJOSNChannel.put("Owner", deviceChannel.getOwner());
  129. deviceJOSNChannel.put("CivilCode", deviceChannel.getCivilCode());
  130. deviceJOSNChannel.put("Address", deviceChannel.getAddress());
  131. deviceJOSNChannel.put("Parental", deviceChannel.getParental()); // 当为通道设备时, 是否有通道子设备, 1-有,0-没有
  132. deviceJOSNChannel.put("ParentID", deviceChannel.getParentId()); // 直接上级编号
  133. deviceJOSNChannel.put("Secrecy", deviceChannel.getSecrecy());
  134. deviceJOSNChannel.put("RegisterWay", 1); // 注册方式, 缺省为1, 允许值: 1, 2, 3
  135. // 1-IETF RFC3261,
  136. // 2-基于口令的双向认证,
  137. // 3-基于数字证书的双向认证
  138. deviceJOSNChannel.put("Status", deviceChannel.getStatus() == 1 ? "ON":"OFF");
  139. deviceJOSNChannel.put("Longitude", deviceChannel.getLongitude());
  140. deviceJOSNChannel.put("Latitude", deviceChannel.getLatitude());
  141. deviceJOSNChannel.put("PTZType ", deviceChannel.getPTZType()); // 云台类型, 0 - 未知, 1 - 球机, 2 - 半球,
  142. // 3 - 固定枪机, 4 - 遥控枪机
  143. deviceJOSNChannel.put("CustomPTZType", "");
  144. deviceJOSNChannel.put("StreamID", deviceChannel.getStreamId()); // StreamID 直播流ID, 有值表示正在直播
  145. deviceJOSNChannel.put("NumOutputs ", -1); // 直播在线人数
  146. channleJSONList.add(deviceJOSNChannel);
  147. }
  148. result.put("ChannelList", channleJSONList);
  149. return result;
  150. }
  151. }