|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.web; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.common.PageResult; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.Device; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.vmanager.device.DeviceController; | 
|---|
|  |  |  | import com.github.pagehelper.PageInfo; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.http.HttpStatus; | 
|---|
|  |  |  | import org.springframework.http.ResponseEntity; | 
|---|
|  |  |  | import org.springframework.stereotype.Controller; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 兼容LiveGBS的API:设备信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @SuppressWarnings("unchecked") | 
|---|
|  |  |  | @CrossOrigin | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(value = "/api/v1/device") | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IVideoManagerStorager storager; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SIPCommander cmder; | 
|---|
|  |  |  | // @Autowired | 
|---|
|  |  |  | // private SIPCommander cmder; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeferredResultHolder resultHolder; | 
|---|
|  |  |  | // @Autowired | 
|---|
|  |  |  | // private DeferredResultHolder resultHolder; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceOffLineDetector offLineDetector; | 
|---|
|  |  |  | // @Autowired | 
|---|
|  |  |  | // private DeviceOffLineDetector offLineDetector; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分页获取设备列表 TODO 现在直接返回,尚未实现分页 | 
|---|
|  |  |  | 
|---|
|  |  |  | JSONObject result = new JSONObject(); | 
|---|
|  |  |  | List<Device> devices; | 
|---|
|  |  |  | if (start == null || limit ==null) { | 
|---|
|  |  |  | devices = storager.queryVideoDeviceList(null); | 
|---|
|  |  |  | devices = storager.queryVideoDeviceList(); | 
|---|
|  |  |  | result.put("DeviceCount", devices.size()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | PageResult<Device> deviceList = storager.queryVideoDeviceList(null, start, limit); | 
|---|
|  |  |  | PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit); | 
|---|
|  |  |  | result.put("DeviceCount", deviceList.getTotal()); | 
|---|
|  |  |  | devices = deviceList.getData(); | 
|---|
|  |  |  | devices = deviceList.getList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONArray deviceJSONList = new JSONArray(); | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceJsonObject.put("Online", device.getOnline() == 1); | 
|---|
|  |  |  | deviceJsonObject.put("Password", ""); | 
|---|
|  |  |  | deviceJsonObject.put("MediaTransport", device.getTransport()); | 
|---|
|  |  |  | deviceJsonObject.put("RemoteIP", device.getHost().getIp()); | 
|---|
|  |  |  | deviceJsonObject.put("RemotePort", device.getHost().getPort()); | 
|---|
|  |  |  | deviceJsonObject.put("RemoteIP", device.getIp()); | 
|---|
|  |  |  | deviceJsonObject.put("RemotePort", device.getPort()); | 
|---|
|  |  |  | deviceJsonObject.put("LastRegisterAt", ""); | 
|---|
|  |  |  | deviceJsonObject.put("LastKeepaliveAt", ""); | 
|---|
|  |  |  | deviceJsonObject.put("UpdatedAt", ""); | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceChannels = storager.queryChannelsByDeviceId(serial); | 
|---|
|  |  |  | result.put("ChannelCount", deviceChannels.size()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | PageResult<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, start, limit); | 
|---|
|  |  |  | PageInfo<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, null, null, null,start/limit, limit); | 
|---|
|  |  |  | result.put("ChannelCount", pageResult.getTotal()); | 
|---|
|  |  |  | deviceChannels = pageResult.getData(); | 
|---|
|  |  |  | deviceChannels = pageResult.getList(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONArray channleJSONList = new JSONArray(); | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceJOSNChannel.put("Name", deviceChannel.getName()); | 
|---|
|  |  |  | deviceJOSNChannel.put("Custom", false); | 
|---|
|  |  |  | deviceJOSNChannel.put("CustomName", ""); | 
|---|
|  |  |  | deviceJOSNChannel.put("SubCount", 0); // TODO ? 子节点数, SubCount > 0 表示该通道为子目录 | 
|---|
|  |  |  | deviceJOSNChannel.put("SubCount", deviceChannel.getSubCount()); // TODO ? 子节点数, SubCount > 0 表示该通道为子目录 | 
|---|
|  |  |  | deviceJOSNChannel.put("SnapURL", ""); | 
|---|
|  |  |  | deviceJOSNChannel.put("Manufacturer ", deviceChannel.getManufacture()); | 
|---|
|  |  |  | deviceJOSNChannel.put("Model", deviceChannel.getModel()); | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceJOSNChannel.put("PTZType ", deviceChannel.getPTZType()); // 云台类型, 0 - 未知, 1 - 球机, 2 - 半球, | 
|---|
|  |  |  | //   3 - 固定枪机, 4 - 遥控枪机 | 
|---|
|  |  |  | deviceJOSNChannel.put("CustomPTZType", ""); | 
|---|
|  |  |  | deviceJOSNChannel.put("StreamID", deviceChannel.getSsrc()); // StreamID 直播流ID, 有值表示正在直播 | 
|---|
|  |  |  | deviceJOSNChannel.put("StreamID", deviceChannel.getStreamId()); // StreamID 直播流ID, 有值表示正在直播 | 
|---|
|  |  |  | deviceJOSNChannel.put("NumOutputs ", -1); // 直播在线人数 | 
|---|
|  |  |  | channleJSONList.add(deviceJOSNChannel); | 
|---|
|  |  |  | } | 
|---|