From d0e1ca014836a3d38cdd6fc3755039934471b2b8 Mon Sep 17 00:00:00 2001 From: LiuXin Date: Thu, 16 Oct 2025 16:10:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=91=E5=8F=B0?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DaHua/VideoManageController.cs | 8 -------- .../Dahvision/DahuaGeneralCtlService.cs | 16 ++++++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs index 62a28a2..9747e41 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs +++ b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs @@ -1,15 +1,7 @@ using Common.Shared.Application.DaHua; -using Common.Shared.Application.DaHua.RequestDto; -using Common.Shared.Application.DaHua.ResponeDto; using Common.Shared.DomainService; using Microsoft.AspNetCore.Mvc; -using Microsoft.OpenApi.Models; -using Org.BouncyCastle.Ocsp; -using System.Text; -using System.Text.Json; using Video.DomainService; -using Video.DomainService.Dahvision; -using static QRCoder.PayloadGenerator.ShadowSocksConfig; namespace Video.API.Controllers.DaHua { diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs index f1dbf79..16db05e 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs @@ -635,19 +635,19 @@ namespace Video.DomainService return new DaHApiResult { Success = false, Code = "1014", Msg = $"控制云台镜头错误 {(int)resp.StatusCode}" }; } - var outer = JsonSerializer.Deserialize>(body); + var outer = JsonSerializer.Deserialize>(body); if (outer == null || !outer.Success || outer.Data == null) { _logger.LogWarning("控制云台镜头请求业务失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1013", Msg = "控制云台镜头请求失败" }; } - var result = JsonSerializer.Deserialize(outer.Data); - if (result == null) + + if (outer.Data == null) { _logger.LogWarning("控制云台镜头请求业务反序列化失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1013", Msg = "控制云台镜头反序列化失败" }; } - + apiResult.Data = outer.Data; return apiResult; } catch (Exception ex) @@ -695,19 +695,19 @@ namespace Video.DomainService return new DaHApiResult { Success = false, Code = "1014", Msg = $"云台方向控制错误 {(int)resp.StatusCode}" }; } - var outer = JsonSerializer.Deserialize>(body); + var outer = JsonSerializer.Deserialize>(body); if (outer == null || !outer.Success || outer.Data == null) { _logger.LogWarning("云台方向控制请求业务失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1013", Msg = "云台方向控制请求失败" }; } - var result = JsonSerializer.Deserialize(outer.Data); - if (result == null) + + if (outer.Data == null) { _logger.LogWarning("云台方向控制请求业务反序列化失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1013", Msg = "云台方向控制反序列化失败" }; } - + apiResult.Data = outer.Data; return apiResult; } catch (Exception ex) -- 2.36.2 From f21a4d6dfdb4cb9ce33cf53549b0ba04835da336 Mon Sep 17 00:00:00 2001 From: LiuXin Date: Mon, 20 Oct 2025 16:43:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common.Shared.Application.csproj | 2 +- .../DaHua/RequestDto/OperateCameraReqDto.cs | 33 ++++++++++++------- .../DaHua/VideoManageController.cs | 6 ++-- .../Dahvision/DahuaGeneralCtlService.cs | 6 +++- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj index 01ef372..00daa01 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj @@ -7,7 +7,7 @@ Common.Shared.Application - 3.6.0 + 3.8.0 zrh-lx zrh-lx 包含所有公共使用的 DTO、契约、接口模型等,供微服务之间共享使用 diff --git a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/RequestDto/OperateCameraReqDto.cs b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/RequestDto/OperateCameraReqDto.cs index 36fe09d..a783c31 100644 --- a/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/RequestDto/OperateCameraReqDto.cs +++ b/WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/RequestDto/OperateCameraReqDto.cs @@ -99,22 +99,33 @@ namespace Common.Shared.Application.DaHua { public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - string rawValue = reader.GetString(); - - // 枚举值可以写成字符串数字形式(例如 "1") - foreach (T enumValue in Enum.GetValues(typeof(T))) + try { - var attr = typeof(T).GetField(enumValue.ToString()) - ?.GetCustomAttributes(typeof(EnumValueAttribute), false) - ?.FirstOrDefault() as EnumValueAttribute; + string rawValue = reader.TokenType switch + { + JsonTokenType.String => reader.GetString(), + JsonTokenType.Number => reader.GetInt32().ToString(), // 👈 新增对数值的处理 + _ => throw new JsonException($"无法解析 {typeof(T).Name}:不支持的 JSON 类型 {reader.TokenType}") + }; - if (attr?.Value == rawValue) + foreach (T enumValue in Enum.GetValues(typeof(T))) { - return enumValue; + var attr = typeof(T).GetField(enumValue.ToString()) + ?.GetCustomAttributes(typeof(EnumValueAttribute), false) + ?.FirstOrDefault() as EnumValueAttribute; + + if (attr?.Value == rawValue) + { + return enumValue; + } } - } - throw new JsonException($"operateType 无效: {rawValue},允许值为 {string.Join(", ", Enum.GetValues(typeof(T)).Cast())}"); + throw new JsonException($"无效的枚举值: {rawValue}"); + } + catch (Exception ex) + { + throw new JsonException($"反序列化 {typeof(T).Name} 失败: {ex.Message}", ex); + } } public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) diff --git a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs index 9747e41..0633816 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs +++ b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs @@ -178,7 +178,7 @@ namespace Video.API.Controllers.DaHua /// /// 视频id /// - [HttpGet] + [HttpGet("dh/snapshot")] public async Task> InvokeSnapshot(string deviceCode, long id, int channelId) { return await _dahGeneralCtlService.InvokeSnapshot(deviceCode, id, channelId); @@ -189,7 +189,7 @@ namespace Video.API.Controllers.DaHua /// /// /// - [HttpPost] + [HttpPost("dh/camera")] public async Task> OperateCamera(CameraControlReqDto dto) { return await _dahGeneralCtlService.OperateCameraAsync(dto); @@ -200,7 +200,7 @@ namespace Video.API.Controllers.DaHua /// /// /// - [HttpPost] + [HttpPost("dh/direction")] public async Task> OperateDirect(CameraDirectionControlReqDto dto) { return await _dahGeneralCtlService.OperateDirectAsync(dto); diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs index 16db05e..2f6f6a9 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs @@ -400,7 +400,11 @@ namespace Video.DomainService { url = $"https://{ipaddress}/evo-apigw/admin/API/SS/Playback/StartPlaybackByTime"; } - dto.Data.RecordType = resultRecord.Data!.Records[0].RecordType; + var recordType = resultRecord.Data?.Records?.FirstOrDefault()?.RecordType; + if (recordType != null) + { + dto.Data.RecordType = recordType; + } using var req = new HttpRequestMessage(HttpMethod.Post, url) { Content = JsonContent.Create(dto) // 关键:把 dto 放进请求体 -- 2.36.2