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 放进请求体