Merge pull request 'dev_lx' (#35) from dev_lx into main

Reviewed-on: #35
dev_lx^2
刘鑫 3 weeks ago
commit e4fc8cd529
  1. 2
      WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj
  2. 17
      WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/DaHua/RequestDto/OperateCameraReqDto.cs
  3. 14
      WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs
  4. 22
      WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<PackageId>Common.Shared.Application</PackageId> <PackageId>Common.Shared.Application</PackageId>
<Version>3.6.0</Version> <Version>3.8.0</Version>
<Authors>zrh-lx</Authors> <Authors>zrh-lx</Authors>
<Company>zrh-lx</Company> <!-- 可选 --> <Company>zrh-lx</Company> <!-- 可选 -->
<Description>包含所有公共使用的 DTO、契约、接口模型等,供微服务之间共享使用</Description> <Description>包含所有公共使用的 DTO、契约、接口模型等,供微服务之间共享使用</Description>

@ -99,9 +99,15 @@ namespace Common.Shared.Application.DaHua
{ {
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
string rawValue = reader.GetString(); try
{
string rawValue = reader.TokenType switch
{
JsonTokenType.String => reader.GetString(),
JsonTokenType.Number => reader.GetInt32().ToString(), // 👈 新增对数值的处理
_ => throw new JsonException($"无法解析 {typeof(T).Name}:不支持的 JSON 类型 {reader.TokenType}")
};
// 枚举值可以写成字符串数字形式(例如 "1")
foreach (T enumValue in Enum.GetValues(typeof(T))) foreach (T enumValue in Enum.GetValues(typeof(T)))
{ {
var attr = typeof(T).GetField(enumValue.ToString()) var attr = typeof(T).GetField(enumValue.ToString())
@ -114,7 +120,12 @@ namespace Common.Shared.Application.DaHua
} }
} }
throw new JsonException($"operateType 无效: {rawValue},允许值为 {string.Join(", ", Enum.GetValues(typeof(T)).Cast<T>())}"); 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) public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)

@ -1,15 +1,7 @@
using Common.Shared.Application.DaHua; using Common.Shared.Application.DaHua;
using Common.Shared.Application.DaHua.RequestDto;
using Common.Shared.Application.DaHua.ResponeDto;
using Common.Shared.DomainService; using Common.Shared.DomainService;
using Microsoft.AspNetCore.Mvc; 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;
using Video.DomainService.Dahvision;
using static QRCoder.PayloadGenerator.ShadowSocksConfig;
namespace Video.API.Controllers.DaHua namespace Video.API.Controllers.DaHua
{ {
@ -186,7 +178,7 @@ namespace Video.API.Controllers.DaHua
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="channelId">视频id</param> /// <param name="channelId">视频id</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet("dh/snapshot")]
public async Task<DaHApiResult<SnapshotResDto>> InvokeSnapshot(string deviceCode, long id, int channelId) public async Task<DaHApiResult<SnapshotResDto>> InvokeSnapshot(string deviceCode, long id, int channelId)
{ {
return await _dahGeneralCtlService.InvokeSnapshot(deviceCode, id, channelId); return await _dahGeneralCtlService.InvokeSnapshot(deviceCode, id, channelId);
@ -197,7 +189,7 @@ namespace Video.API.Controllers.DaHua
/// </summary> /// </summary>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost("dh/camera")]
public async Task<DaHApiResult<CameraControlResDto>> OperateCamera(CameraControlReqDto dto) public async Task<DaHApiResult<CameraControlResDto>> OperateCamera(CameraControlReqDto dto)
{ {
return await _dahGeneralCtlService.OperateCameraAsync(dto); return await _dahGeneralCtlService.OperateCameraAsync(dto);
@ -208,7 +200,7 @@ namespace Video.API.Controllers.DaHua
/// </summary> /// </summary>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost("dh/direction")]
public async Task<DaHApiResult<CameraControlResDto>> OperateDirect(CameraDirectionControlReqDto dto) public async Task<DaHApiResult<CameraControlResDto>> OperateDirect(CameraDirectionControlReqDto dto)
{ {
return await _dahGeneralCtlService.OperateDirectAsync(dto); return await _dahGeneralCtlService.OperateDirectAsync(dto);

@ -400,7 +400,11 @@ namespace Video.DomainService
{ {
url = $"https://{ipaddress}/evo-apigw/admin/API/SS/Playback/StartPlaybackByTime"; 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) using var req = new HttpRequestMessage(HttpMethod.Post, url)
{ {
Content = JsonContent.Create(dto) // 关键:把 dto 放进请求体 Content = JsonContent.Create(dto) // 关键:把 dto 放进请求体
@ -635,19 +639,19 @@ namespace Video.DomainService
return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1014", Msg = $"控制云台镜头错误 {(int)resp.StatusCode}" }; return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1014", Msg = $"控制云台镜头错误 {(int)resp.StatusCode}" };
} }
var outer = JsonSerializer.Deserialize<DaHApiResult<string>>(body); var outer = JsonSerializer.Deserialize<DaHApiResult<CameraControlResDto>>(body);
if (outer == null || !outer.Success || outer.Data == null) if (outer == null || !outer.Success || outer.Data == null)
{ {
_logger.LogWarning("控制云台镜头请求业务失败: {Body}", body); _logger.LogWarning("控制云台镜头请求业务失败: {Body}", body);
return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "控制云台镜头请求失败" }; return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "控制云台镜头请求失败" };
} }
var result = JsonSerializer.Deserialize<CameraControlResDto>(outer.Data);
if (result == null) if (outer.Data == null)
{ {
_logger.LogWarning("控制云台镜头请求业务反序列化失败: {Body}", body); _logger.LogWarning("控制云台镜头请求业务反序列化失败: {Body}", body);
return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "控制云台镜头反序列化失败" }; return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "控制云台镜头反序列化失败" };
} }
apiResult.Data = outer.Data;
return apiResult; return apiResult;
} }
catch (Exception ex) catch (Exception ex)
@ -695,19 +699,19 @@ namespace Video.DomainService
return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1014", Msg = $"云台方向控制错误 {(int)resp.StatusCode}" }; return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1014", Msg = $"云台方向控制错误 {(int)resp.StatusCode}" };
} }
var outer = JsonSerializer.Deserialize<DaHApiResult<string>>(body); var outer = JsonSerializer.Deserialize<DaHApiResult<CameraControlResDto>>(body);
if (outer == null || !outer.Success || outer.Data == null) if (outer == null || !outer.Success || outer.Data == null)
{ {
_logger.LogWarning("云台方向控制请求业务失败: {Body}", body); _logger.LogWarning("云台方向控制请求业务失败: {Body}", body);
return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "云台方向控制请求失败" }; return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "云台方向控制请求失败" };
} }
var result = JsonSerializer.Deserialize<CameraControlResDto>(outer.Data);
if (result == null) if (outer.Data == null)
{ {
_logger.LogWarning("云台方向控制请求业务反序列化失败: {Body}", body); _logger.LogWarning("云台方向控制请求业务反序列化失败: {Body}", body);
return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "云台方向控制反序列化失败" }; return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "云台方向控制反序列化失败" };
} }
apiResult.Data = outer.Data;
return apiResult; return apiResult;
} }
catch (Exception ex) catch (Exception ex)

Loading…
Cancel
Save