From 1b7bf6e69abb7c45458eef773ce8b284cefe7ec4 Mon Sep 17 00:00:00 2001 From: LiuXin Date: Fri, 15 Aug 2025 18:11:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DahAlarm/DahuaGeneralCtlService.cs | 35 ++++++++++++++----- .../DahAlarm/IDahuaGeneralCtlService.cs | 2 +- .../Controllers/AlarmController.cs | 2 +- .../AlarmService.API/appsettings.json | 2 +- .../DaHua/VideoManageController.cs | 2 +- .../RequestDto/DahuaVideoQueryDto.cs | 20 +++++++++-- .../Dahvision/DahuaGeneralCtlService.cs | 18 +++++----- .../Dahvision/IDahuaGeneralCtlService.cs | 2 +- .../Dahvision/IRootVideoPlaybackService.cs | 2 +- .../Dahvision/RootVideoPlaybackService.cs | 2 +- 10 files changed, 61 insertions(+), 26 deletions(-) diff --git a/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs b/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs index f920b42..46f4b83 100644 --- a/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs @@ -11,6 +11,7 @@ using System; using System.Net.Http.Json; using System.Security.Cryptography; using System.Text.Json; +using System.Text.Json.Serialization; using WeiCloud.Core.BaseModels; namespace Alarm.DomainService.DahAlarm @@ -119,8 +120,8 @@ namespace Alarm.DomainService.DahAlarm Subsystem = new SubsystemConfig { SubsystemType = 0, - Name = "192.168.21.43_alarm", - Magic = "192.168.21.43" + Name = _configuration["DahuaAuth:SubsystemName"], + Magic = _configuration["DahuaAuth:SubsystemMagic"] } } }; @@ -132,8 +133,8 @@ namespace Alarm.DomainService.DahAlarm { Content = JsonContent.Create(req, options: new JsonSerializerOptions { - DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, - PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNamingPolicy = new AllLowerCaseNamingPolicy() }) }; @@ -185,14 +186,14 @@ namespace Alarm.DomainService.DahAlarm /// /// /// - public async Task> HandleAsync(EventEnvelopeDto dto) + public async Task> HandleAsync(EventEnvelopeDto dto) { - ApiResult result = new() { Code = 200, Msg = "接口调用成功", Data = true }; + DaHApiResult result = new() { Code = "200", Msg = "接口调用成功", Data = true }; try { if (dto is null) { - result.Code = 500; + result.Code = "500"; result.Msg = "请求参数不能为空"; result.Data = false; _logger.LogWarning("大华报警事件订阅回调处理失败,参数不能为空"); @@ -216,11 +217,29 @@ namespace Alarm.DomainService.DahAlarm catch (Exception ex) { _logger.LogError(ex, "大华报警事件订阅回调处理异常"); - result.Code = 500; + result.Code = "500"; result.Msg = "大华报警事件订阅回调处理异常"; result.Data = false; } return result; } + + /// + /// 取消订阅某个报警事件 + /// + /// + /// + public async Task> DeleteSubscribe(string name) + { + throw new NotImplementedException("该方法未实现"); + } + + /// + /// 转换小写 + /// + private class AllLowerCaseNamingPolicy : JsonNamingPolicy + { + public override string ConvertName(string name) => name.ToLowerInvariant(); + } } } \ No newline at end of file diff --git a/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/IDahuaGeneralCtlService.cs b/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/IDahuaGeneralCtlService.cs index f348cd3..bbd1009 100644 --- a/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/IDahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/IDahuaGeneralCtlService.cs @@ -23,6 +23,6 @@ namespace Alarm.DomainService.DahAlarm /// /// /// - Task> HandleAsync(EventEnvelopeDto env); + Task> HandleAsync(EventEnvelopeDto env); } } \ No newline at end of file diff --git a/WeiCloud.Fusion/AlarmService/AlarmService.API/Controllers/AlarmController.cs b/WeiCloud.Fusion/AlarmService/AlarmService.API/Controllers/AlarmController.cs index 25a97de..e4b842b 100644 --- a/WeiCloud.Fusion/AlarmService/AlarmService.API/Controllers/AlarmController.cs +++ b/WeiCloud.Fusion/AlarmService/AlarmService.API/Controllers/AlarmController.cs @@ -36,7 +36,7 @@ namespace AlarmService.API.Controllers /// /// [HttpPost] - public async Task> DahuaAuthCallback(EventEnvelopeDto env) + public async Task> DahuaAuthCallback(EventEnvelopeDto env) { return await _generalCtlService.HandleAsync(env); } diff --git a/WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json b/WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json index 79c0bdd..0f4b3cb 100644 --- a/WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json +++ b/WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json @@ -27,6 +27,6 @@ "Password": "Admin123", "Callback": "http://demo.weienergy.cn:5000/api/Alarm/DahuaAuthCallback", "SubsystemName": "192.168.21.43_alarm", - "SubsystemMagic": "192.168.21.43" + "SubsystemMagic": "192.168.21.43_5001" } } \ No newline at end of file diff --git a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs index 281f875..8c2b9cb 100644 --- a/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs +++ b/WeiCloud.Fusion/VideoService/Video.API/Controllers/DaHua/VideoManageController.cs @@ -49,7 +49,7 @@ namespace Video.API.Controllers.DaHua /// /// [HttpPost("rtspplayback/dh")] - public async Task> RtspPlaybackByTime(RtspPlaybackReqDto dto) + public async Task> RtspPlaybackByTime(RtspPlayBackReqDto dto) { return await _rootVideoPlaybackService.RtspPlaybackByTime(dto); } diff --git a/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs b/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs index 097cd35..be73ef0 100644 --- a/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs +++ b/WeiCloud.Fusion/VideoService/Video.Application/RequestDto/DahuaVideoQueryDto.cs @@ -8,7 +8,7 @@ namespace Video.Application /// /// hls、rtmp回放请求的数据部分 /// - public class PlaybackReqDto + public class PlaybackItem { /// /// 通道ID(格式如:1000018$1$0$0) @@ -56,7 +56,15 @@ namespace Video.Application /// /// hls、rtmp回放请求的数据部分 /// - public class RtspPlaybackReqDto + public class PlaybackReqDto + { + public PlaybackItem Data { get; set; } + } + + /// + ///rtsp回放请求的数据部分 + /// + public class RtspPlaybackItem { /// /// 通道ID(格式如:1000018$1$0$0) @@ -95,6 +103,14 @@ namespace Video.Application public string RecordSource { get; set; } } + /// + /// rtsp请求dto + /// + public class RtspPlayBackReqDto + { + public RtspPlaybackItem Data { get; set; } + } + /// /// 通道分页查询请求参数实体 /// diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs index df50009..77f936d 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs @@ -33,7 +33,7 @@ namespace Video.DomainService }); /// - /// 录像回放 + /// hls等录像回放 /// /// /// @@ -41,7 +41,7 @@ namespace Video.DomainService public async Task> RecordVideoUrl(PlaybackReqDto dto) { // 1) 参数校验 + 早退 - if (dto == null || string.IsNullOrWhiteSpace(dto.ChannelId)) + if (dto == null || string.IsNullOrWhiteSpace(dto.Data.ChannelId)) { _logger.LogWarning("录像请求失败:通道ID不能为空"); return new DaHApiResult { Success = false, Code = "1007", Msg = "通道ID不能为空" }; @@ -77,7 +77,7 @@ namespace Video.DomainService _logger.LogWarning("录像请求业务失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1008", Msg = "录像请求失败" }; } - + result.Data!.Url = result.Data.Url + "?token=" + token; return result; } catch (Exception ex) @@ -238,7 +238,7 @@ namespace Video.DomainService _logger.LogWarning("实时流请求业务失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1010", Msg = "实时流请求失败" }; } - + result.Data!.Url = result.Data.Url + "?token=" + token; return result; } catch (Exception ex) @@ -305,10 +305,10 @@ namespace Video.DomainService /// /// /// - public async Task> RtspPlaybackByTime(RtspPlaybackReqDto dto) + public async Task> RtspPlaybackByTime(RtspPlayBackReqDto dto) { // 参数校验 + 早退 - if (dto == null || string.IsNullOrWhiteSpace(dto.ChannelId)) + if (dto == null || string.IsNullOrWhiteSpace(dto.Data.ChannelId)) { _logger.LogWarning("录像请求失败:通道ID不能为空"); return new DaHApiResult { Success = false, Code = "1007", Msg = "通道ID不能为空" }; @@ -343,7 +343,7 @@ namespace Video.DomainService _logger.LogWarning("录像请求业务失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1008", Msg = "录像请求失败" }; } - + result.Data!.Url = result.Data.Url + "?token=" + token; return result; } catch (Exception ex) @@ -390,12 +390,12 @@ namespace Video.DomainService } var result = JsonSerializer.Deserialize>(body); - if (result == null || !result.Success || result.Code != "100") + if (result == null || !result.Success) { _logger.LogWarning("实时流请求业务失败: {Body}", body); return new DaHApiResult { Success = false, Code = "1010", Msg = "实时流请求失败" }; } - + result.Data!.Url = result.Data.Url + "?token=" + result.Data!.Token; return result; } catch (Exception ex) diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IDahuaGeneralCtlService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IDahuaGeneralCtlService.cs index c3a19eb..ce04c2d 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IDahuaGeneralCtlService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IDahuaGeneralCtlService.cs @@ -27,7 +27,7 @@ namespace Video.DomainService /// /// /// - Task> RtspPlaybackByTime(RtspPlaybackReqDto dto); + Task> RtspPlaybackByTime(RtspPlayBackReqDto dto); /// /// 设备通道分页查询,需要用于HlsRecordVideo diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs index 1ff573c..ff8cfaa 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/IRootVideoPlaybackService.cs @@ -32,7 +32,7 @@ namespace Video.DomainService /// /// /// - Task> RtspPlaybackByTime(RtspPlaybackReqDto dto); + Task> RtspPlaybackByTime(RtspPlayBackReqDto dto); /// /// 大华设备通道分页查询 diff --git a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs index 3138167..d453f6c 100644 --- a/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs +++ b/WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/RootVideoPlaybackService.cs @@ -140,7 +140,7 @@ namespace Video.DomainService /// /// /// - public async Task> RtspPlaybackByTime(RtspPlaybackReqDto dto) + public async Task> RtspPlaybackByTime(RtspPlayBackReqDto dto) { ApiResult result = new ApiResult() { Code = 200, Msg = "接口调用成功" };