From e30e28712f7ec5a3c5514484b34bdde11d0954c3 Mon Sep 17 00:00:00 2001 From: Lawrence <1934378145@qq.com> Date: 星期六, 24 十月 2020 15:26:11 +0800 Subject: [PATCH] 播放等待时间增加到30秒,避免部分设备(NVR)播放超时 --- src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java | 136 +++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 124 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java index 993ddf7..8c0ecfb 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java @@ -1,21 +1,25 @@ package com.genersoft.iot.vmp.vmanager.device; -import java.util.ArrayList; import java.util.List; +import com.genersoft.iot.vmp.common.PageResult; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; 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.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.async.DeferredResult; +import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.gb28181.bean.Device; +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; +@CrossOrigin @RestController @RequestMapping("/api") public class DeviceController { @@ -25,26 +29,134 @@ @Autowired private IVideoManagerStorager storager; + @Autowired + private SIPCommander cmder; + + @Autowired + private DeferredResultHolder resultHolder; + + @Autowired + private DeviceOffLineDetector offLineDetector; + @GetMapping("/devices/{deviceId}") - public ResponseEntity<List<Device>> devices(@PathVariable String deviceId){ + public ResponseEntity<Device> devices(@PathVariable String deviceId){ if (logger.isDebugEnabled()) { logger.debug("鏌ヨ瑙嗛璁惧API璋冪敤锛宒eviceId锛�" + deviceId); } - List<Device> deviceList = new ArrayList<>(); - deviceList.add(storager.queryVideoDevice(deviceId)); - return new ResponseEntity<>(deviceList,HttpStatus.OK); + Device device = storager.queryVideoDevice(deviceId); + return new ResponseEntity<>(device,HttpStatus.OK); } @GetMapping("/devices") - public ResponseEntity<List<Device>> devices(){ + public PageResult<Device> devices(int page, int count){ if (logger.isDebugEnabled()) { logger.debug("鏌ヨ鎵�鏈夎棰戣澶嘇PI璋冪敤"); } - List<Device> deviceList = storager.queryVideoDeviceList(null); - return new ResponseEntity<>(deviceList,HttpStatus.OK); + return storager.queryVideoDeviceList(null, page, count); + } + + /** + * 鍒嗛〉鏌ヨ閫氶亾鏁� + * @param deviceId 璁惧id + * @param page 褰撳墠椤� + * @param count 姣忛〉鏉℃暟 + * @return 閫氶亾鍒楄〃 + */ + @GetMapping("/devices/{deviceId}/channels") + public ResponseEntity<PageResult> channels(@PathVariable String deviceId, + int page, int count, + @RequestParam(required = false) String query, + @RequestParam(required = false) String online, + @RequestParam(required = false) Boolean channelType + ){ + + if (logger.isDebugEnabled()) { + logger.debug("鏌ヨ鎵�鏈夎棰戣澶嘇PI璋冪敤"); + } + PageResult pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, page, count); + return new ResponseEntity<>(pageResult,HttpStatus.OK); + } + + @PostMapping("/devices/{deviceId}/sync") + public DeferredResult<ResponseEntity<Device>> devicesSync(@PathVariable String deviceId){ + + if (logger.isDebugEnabled()) { + } + logger.debug("璁惧淇℃伅鍚屾API璋冪敤锛宒eviceId锛�" + deviceId); + + Device device = storager.queryVideoDevice(deviceId); + cmder.catalogQuery(device); + DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(); + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId, result); + return result; + } + + @PostMapping("/devices/{deviceId}/delete") + public ResponseEntity<String> delete(@PathVariable String deviceId){ + + if (logger.isDebugEnabled()) { + logger.debug("璁惧淇℃伅鍒犻櫎API璋冪敤锛宒eviceId锛�" + deviceId); + } + + if (offLineDetector.isOnline(deviceId)) { + return new ResponseEntity<String>("涓嶅厑璁稿垹闄ゅ湪绾胯澶囷紒", HttpStatus.NOT_ACCEPTABLE); + } + boolean isSuccess = storager.delete(deviceId); + if (isSuccess) { + JSONObject json = new JSONObject(); + json.put("deviceId", deviceId); + return new ResponseEntity<>(json.toString(),HttpStatus.OK); + } else { + logger.warn("璁惧棰勮API璋冪敤澶辫触锛�"); + return new ResponseEntity<String>("璁惧棰勮API璋冪敤澶辫触锛�", HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + /** + * 鍒嗛〉鏌ヨ閫氶亾鏁� + * @param channelId 閫氶亾id + * @param page 褰撳墠椤� + * @param count 姣忛〉鏉℃暟 + * @return 瀛愰�氶亾鍒楄〃 + */ + @GetMapping("/subChannels/{deviceId}/{channelId}/channels") + public ResponseEntity<PageResult> subChannels(@PathVariable String deviceId, + @PathVariable String channelId, + int page, + int count, + @RequestParam(required = false) String query, + @RequestParam(required = false) String online, + @RequestParam(required = false) Boolean channelType){ + + if (logger.isDebugEnabled()) { + logger.debug("鏌ヨ鎵�鏈夎棰戣澶嘇PI璋冪敤"); + } + DeviceChannel deviceChannel = storager.queryChannel(deviceId,channelId); + if (deviceChannel == null) { + PageResult<DeviceChannel> deviceChannelPageResult = new PageResult<>(); + new ResponseEntity<>(deviceChannelPageResult,HttpStatus.OK); + } + + PageResult 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){ + storager.updateChannel(deviceId, channel); + return new ResponseEntity<>(null,HttpStatus.OK); + } + + @GetMapping("/devices/{deviceId}/transport/{streamMode}") + @PostMapping("/devices/{deviceId}/transport/{streamMode}") + public ResponseEntity<PageResult> updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){ + Device device = storager.queryVideoDevice(deviceId); + device.setStreamMode(streamMode); + storager.updateDevice(device); + return new ResponseEntity<>(null,HttpStatus.OK); } } -- Gitblit v1.8.0