From 9ae0691c806b6b56306c2cda5509b0a0444cec06 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 02 六月 2022 10:55:41 +0800 Subject: [PATCH] 优化快照的存储与显示 --- src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java | 59 +++++++++++++++++++++++------------------------------------ 1 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java index af3f68c..cd57666 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java @@ -21,16 +21,22 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.commons.compress.utils.IOUtils; +import org.apache.http.HttpResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; 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 javax.servlet.http.HttpServletResponse; import javax.sip.DialogState; +import java.io.*; +import java.nio.file.Files; import java.util.*; @Api(tags = "鍥芥爣璁惧鏌ヨ", value = "鍥芥爣璁惧鏌ヨ") @@ -288,7 +294,8 @@ public ResponseEntity<PageInfo> updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){ Device device = storager.queryVideoDevice(deviceId); device.setStreamMode(streamMode); - storager.updateDevice(device); +// storager.updateDevice(device); + deviceService.updateDevice(device); return new ResponseEntity<>(null,HttpStatus.OK); } @@ -305,45 +312,12 @@ public ResponseEntity<WVPResult<String>> updateDevice(Device device){ if (device != null && device.getDeviceId() != null) { - Device deviceInStore = storager.queryVideoDevice(device.getDeviceId()); - if (!StringUtils.isEmpty(device.getName())) deviceInStore.setName(device.getName()); - if (!StringUtils.isEmpty(device.getCharset())) deviceInStore.setCharset(device.getCharset()); - if (!StringUtils.isEmpty(device.getMediaServerId())) deviceInStore.setMediaServerId(device.getMediaServerId()); - // 鐩綍璁㈤槄鐩稿叧鐨勪俊鎭� - if (device.getSubscribeCycleForCatalog() > 0) { - if (deviceInStore.getSubscribeCycleForCatalog() == 0 || deviceInStore.getSubscribeCycleForCatalog() != device.getSubscribeCycleForCatalog()) { - deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog()); - // 寮�鍚闃� - deviceService.addCatalogSubscribe(deviceInStore); - } - }else if (device.getSubscribeCycleForCatalog() == 0) { - if (deviceInStore.getSubscribeCycleForCatalog() != 0) { - deviceInStore.setSubscribeCycleForCatalog(device.getSubscribeCycleForCatalog()); - // 鍙栨秷璁㈤槄 - deviceService.removeCatalogSubscribe(deviceInStore); - } - } - - // 绉诲姩浣嶇疆璁㈤槄鐩稿叧鐨勪俊鎭� - if (device.getSubscribeCycleForMobilePosition() > 0) { - if (deviceInStore.getSubscribeCycleForMobilePosition() == 0 || deviceInStore.getSubscribeCycleForMobilePosition() != device.getSubscribeCycleForMobilePosition()) { - deviceInStore.setMobilePositionSubmissionInterval(device.getMobilePositionSubmissionInterval()); - deviceInStore.setSubscribeCycleForMobilePosition(device.getSubscribeCycleForMobilePosition()); - // 寮�鍚闃� - deviceService.addMobilePositionSubscribe(deviceInStore); - } - }else if (device.getSubscribeCycleForMobilePosition() == 0) { - if (deviceInStore.getSubscribeCycleForMobilePosition() != 0) { - // 鍙栨秷璁㈤槄 - deviceService.removeMobilePositionSubscribe(deviceInStore); - } - } // TODO 鎶ヨ璁㈤槄鐩稿叧鐨勪俊鎭� - storager.updateDevice(device); - cmder.deviceInfoQuery(device); + deviceService.updateDevice(device); +// cmder.deviceInfoQuery(device); } WVPResult<String> result = new WVPResult<>(); result.setCode(0); @@ -488,4 +462,17 @@ wvpResult.setData(dialogStateMap); return wvpResult; } + + @GetMapping("/snap/{deviceId}/{channelId}") + @ApiOperation(value = "璇锋眰鎴浘", notes = "璇锋眰鎴浘") + public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId) { + + try { + final InputStream in = Files.newInputStream(new File("snap" + File.separator + deviceId + "_" + channelId + ".jpg").toPath()); + resp.setContentType(MediaType.IMAGE_PNG_VALUE); + IOUtils.copy(in, resp.getOutputStream()); + } catch (IOException e) { + resp.setStatus(HttpServletResponse.SC_NOT_FOUND); + } + } } -- Gitblit v1.8.0