修复问题

pull/35/head
刘鑫 3 weeks ago
parent 5d651015c5
commit f21a4d6dfd
  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. 6
      WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs
  4. 6
      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)

@ -178,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);
@ -189,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);
@ -200,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 放进请求体

Loading…
Cancel
Save