From 47f6edc6670166d3d660b11ae48eaa27a7e95349 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Sun, 7 Jan 2024 16:34:41 +0800 Subject: [PATCH] =?UTF-8?q?catalog=20=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skcks/docking/gb28181/common/json/JsonException.java | 2 ++ .../docking/gb28181/service/catalog/CatalogService.java | 9 +++++++++ .../docking/gb28181/service/record/RecordService.java | 5 ++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/cn/skcks/docking/gb28181/common/json/JsonException.java b/common/src/main/java/cn/skcks/docking/gb28181/common/json/JsonException.java index c9df42c..6fa16fb 100644 --- a/common/src/main/java/cn/skcks/docking/gb28181/common/json/JsonException.java +++ b/common/src/main/java/cn/skcks/docking/gb28181/common/json/JsonException.java @@ -1,5 +1,7 @@ package cn.skcks.docking.gb28181.common.json; +import lombok.Builder; + public class JsonException extends Exception{ public JsonException(String message){ super(message); diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/catalog/CatalogService.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/catalog/CatalogService.java index 0931a15..e35fd0b 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/catalog/CatalogService.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/catalog/CatalogService.java @@ -1,5 +1,7 @@ package cn.skcks.docking.gb28181.service.catalog; +import cn.skcks.docking.gb28181.common.json.JsonException; +import cn.skcks.docking.gb28181.common.json.JsonResponse; import cn.skcks.docking.gb28181.config.sip.SipConfig; import cn.skcks.docking.gb28181.constant.CmdType; import cn.skcks.docking.gb28181.core.sip.message.request.SipRequestBuilder; @@ -7,6 +9,7 @@ import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe; import cn.skcks.docking.gb28181.core.sip.message.subscribe.SipSubscribe; import cn.skcks.docking.gb28181.core.sip.service.SipService; import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDevice; +import cn.skcks.docking.gb28181.orm.mybatis.dynamic.model.DockingDeviceChannel; import cn.skcks.docking.gb28181.service.device.DeviceChannelService; import cn.skcks.docking.gb28181.service.docking.device.cache.DockingDeviceCacheService; import cn.skcks.docking.gb28181.sip.manscdp.catalog.query.CatalogQueryDTO; @@ -23,6 +26,7 @@ import javax.sip.SipProvider; import javax.sip.message.Request; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @@ -41,6 +45,11 @@ public class CatalogService { CompletableFuture> result = new CompletableFuture<>(); result.completeOnTimeout(Collections.emptyList(), 60, TimeUnit.SECONDS); DockingDevice device = deviceCacheService.getDevice(gbDeviceId); + if (device == null) { + log.info("未能找到 编码为 => {} 的设备", gbDeviceId); + result.completeExceptionally(new JsonException("未找到设备 " + gbDeviceId)); + return result; + } SipProvider provider = sipService.getProvider(device.getTransport(), device.getLocalIp()); MessageRequestBuilder requestBuilder = MessageRequestBuilder.builder() .localIp(device.getLocalIp()) diff --git a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/record/RecordService.java b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/record/RecordService.java index 8befae2..65138d1 100644 --- a/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/record/RecordService.java +++ b/gb28181-service/src/main/java/cn/skcks/docking/gb28181/service/record/RecordService.java @@ -55,17 +55,16 @@ public class RecordService { public DeferredResult>> requestRecordInfo(String deviceId, String channelId, long timeout, Date date) { log.info("查询 设备 => {} {} 的历史媒体记录, 超时时间 {} 秒", deviceId, DateUtil.formatDate(date), timeout); DeferredResult>> result = new DeferredResult<>(TimeUnit.SECONDS.toMillis(timeout)); - DockingDevice device = deviceService.getDevice(deviceId); if (device == null) { log.info("未能找到 编码为 => {} 的设备", deviceId); - result.setResult(JsonResponse.error(null, "未找到设备")); + result.setResult(JsonResponse.error("未找到设备")); return result; } Optional deviceChannel = deviceChannelService.getDeviceChannel(deviceId, channelId); if(deviceChannel.isEmpty()){ log.info("未能找到 设备编码为 => {}, 通道 => {} 的信息", deviceId, channelId); - result.setResult(JsonResponse.error(null, "未找到通道信息")); + result.setResult(JsonResponse.error("未找到通道信息")); return result; }