ApiDeviceController.java 8.3 KB

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