dev_lx #35

Merged
LiuXin merged 3 commits from dev_lx into main 3 weeks ago
  1. 2
      WeiCloud.Fusion/Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj
  2. 33
      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>
<PackageId>Common.Shared.Application</PackageId>
<Version>3.6.0</Version>
<Version>3.8.0</Version>
<Authors>zrh-lx</Authors>
<Company>zrh-lx</Company> <!-- 可选 -->
<Description>包含所有公共使用的 DTO、契约、接口模型等,供微服务之间共享使用</Description>

@ -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<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)

@ -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
{
@ -186,7 +178,7 @@ namespace Video.API.Controllers.DaHua
/// <param name="id"></param>
/// <param name="channelId">视频id</param>
/// <returns></returns>
[HttpGet]
[HttpGet("dh/snapshot")]
public async Task<DaHApiResult<SnapshotResDto>> InvokeSnapshot(string deviceCode, long id, int channelId)
{
return await _dahGeneralCtlService.InvokeSnapshot(deviceCode, id, channelId);
@ -197,7 +189,7 @@ namespace Video.API.Controllers.DaHua
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost]
[HttpPost("dh/camera")]
public async Task<DaHApiResult<CameraControlResDto>> OperateCamera(CameraControlReqDto dto)
{
return await _dahGeneralCtlService.OperateCameraAsync(dto);
@ -208,7 +200,7 @@ namespace Video.API.Controllers.DaHua
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost]
[HttpPost("dh/direction")]
public async Task<DaHApiResult<CameraControlResDto>> OperateDirect(CameraDirectionControlReqDto dto)
{
return await _dahGeneralCtlService.OperateDirectAsync(dto);

@ -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 放进请求体
@ -635,19 +639,19 @@ namespace Video.DomainService
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)
{
_logger.LogWarning("控制云台镜头请求业务失败: {Body}", body);
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);
return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "控制云台镜头反序列化失败" };
}
apiResult.Data = outer.Data;
return apiResult;
}
catch (Exception ex)
@ -695,19 +699,19 @@ namespace Video.DomainService
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)
{
_logger.LogWarning("云台方向控制请求业务失败: {Body}", body);
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);
return new DaHApiResult<CameraControlResDto> { Success = false, Code = "1013", Msg = "云台方向控制反序列化失败" };
}
apiResult.Data = outer.Data;
return apiResult;
}
catch (Exception ex)

Loading…
Cancel
Save