| | |
| | | package com.genersoft.iot.vmp.vmanager.device; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.genersoft.iot.vmp.common.PageResult; |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| | | 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.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.context.request.async.DeferredResult; |
| | | |
| | |
| | | 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 javax.sip.message.Response; |
| | | |
| | | @CrossOrigin |
| | | @RestController |
| | |
| | | } |
| | | |
| | | @GetMapping("/devices") |
| | | public PageResult<Device> devices(int page, int count){ |
| | | public PageInfo<Device> devices(int page, int count){ |
| | | |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("查询所有视频设备API调用"); |
| | | } |
| | | |
| | | return storager.queryVideoDeviceList(null, page, count); |
| | | return storager.queryVideoDeviceList(page, count); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询通道数 |
| | | * |
| | | * @param deviceId 设备id |
| | | * @param page 当前页 |
| | | * @param count 每页条数 |
| | | * @param query 查询内容 |
| | | * @param online 是否在线 在线 true / 离线 false |
| | | * @param channelType 设备 false/子目录 true |
| | | * @return 通道列表 |
| | | */ |
| | | @GetMapping("devices/{deviceId}/channels") |
| | | public ResponseEntity<PageResult> channels(@PathVariable String deviceId, |
| | | @GetMapping("/devices/{deviceId}/channels") |
| | | public ResponseEntity<PageInfo> channels(@PathVariable String deviceId, |
| | | int page, int count, |
| | | @RequestParam(required = false) String query, |
| | | @RequestParam(required = false) String online, |
| | | @RequestParam(required = false) Boolean online, |
| | | @RequestParam(required = false) Boolean channelType |
| | | ){ |
| | | |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("查询所有视频设备API调用"); |
| | | } |
| | | PageResult pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, page, count); |
| | | if (StringUtils.isEmpty(query)) { |
| | | query = null; |
| | | } |
| | | |
| | | PageInfo pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, page, count); |
| | | return new ResponseEntity<>(pageResult,HttpStatus.OK); |
| | | } |
| | | |
| | |
| | | |
| | | if (logger.isDebugEnabled()) { |
| | | } |
| | | logger.debug("设备信息同步API调用,deviceId:" + deviceId); |
| | | logger.debug("设备通道信息同步API调用,deviceId:" + deviceId); |
| | | |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | cmder.catalogQuery(device); |
| | | DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(); |
| | | cmder.catalogQuery(device, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId); |
| | | msg.setData(String.format("同步通道失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(2*1000L); |
| | | result.onTimeout(()->{ |
| | | logger.warn(String.format("设备通道信息同步超时")); |
| | | // 释放rtpserver |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId); |
| | | msg.setData("Timeout"); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId, result); |
| | | return result; |
| | | } |
| | |
| | | * @param count 每页条数 |
| | | * @return 子通道列表 |
| | | */ |
| | | @GetMapping("subChannels/{deviceId}/{channelId}/channels") |
| | | public ResponseEntity<PageResult> subChannels(@PathVariable String deviceId, |
| | | @GetMapping("/subChannels/{deviceId}/{channelId}/channels") |
| | | public ResponseEntity<PageInfo> subChannels(@PathVariable String deviceId, |
| | | @PathVariable String channelId, |
| | | int page, |
| | | int count, |
| | |
| | | } |
| | | DeviceChannel deviceChannel = storager.queryChannel(deviceId,channelId); |
| | | if (deviceChannel == null) { |
| | | PageResult<DeviceChannel> deviceChannelPageResult = new PageResult<>(); |
| | | new ResponseEntity<>(deviceChannelPageResult,HttpStatus.OK); |
| | | PageInfo<DeviceChannel> deviceChannelPageResult = new PageInfo<>(); |
| | | return new ResponseEntity<>(deviceChannelPageResult,HttpStatus.OK); |
| | | } |
| | | |
| | | PageResult pageResult = storager.querySubChannels(deviceId, channelId, query, channelType, online, page, count); |
| | | PageInfo pageResult = storager.querySubChannels(deviceId, channelId, query, channelType, online, page, count); |
| | | return new ResponseEntity<>(pageResult,HttpStatus.OK); |
| | | } |
| | | |
| | | @PostMapping("channel/update/{deviceId}") |
| | | public ResponseEntity<PageResult> updateChannel(@PathVariable String deviceId,DeviceChannel channel){ |
| | | @PostMapping("/channel/update/{deviceId}") |
| | | public ResponseEntity<PageInfo> updateChannel(@PathVariable String deviceId,DeviceChannel channel){ |
| | | storager.updateChannel(deviceId, channel); |
| | | return new ResponseEntity<>(null,HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping("/devices/{deviceId}/transport/{streamMode}") |
| | | @PostMapping("/devices/{deviceId}/transport/{streamMode}") |
| | | public ResponseEntity<PageInfo> updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){ |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | device.setStreamMode(streamMode); |
| | | storager.updateDevice(device); |
| | | return new ResponseEntity<>(null,HttpStatus.OK); |
| | | } |
| | | } |