增加报警

pull/5/head
刘鑫 3 months ago
parent 391942fdb2
commit 65513b6235
  1. 0
      WeiCloud.Fusion/AlarmService/Alarm.Application/Alarm.Application.csproj
  2. 1
      WeiCloud.Fusion/AlarmService/Alarm.Application/RequestDto/SubscribeEventReqDto.cs
  3. 0
      WeiCloud.Fusion/AlarmService/Alarm.Application/ResponeDto/EventEnvelopeDto.cs
  4. 5
      WeiCloud.Fusion/AlarmService/Alarm.DomainService/Alarm.DomainService.csproj
  5. 34
      WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs
  6. 0
      WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/IDahuaGeneralCtlService.cs
  7. 4
      WeiCloud.Fusion/AlarmService/AlarmService.API/AlarmService.API.csproj
  8. 9
      WeiCloud.Fusion/AlarmService/AlarmService.API/Program.cs
  9. 11
      WeiCloud.Fusion/AlarmService/AlarmService.API/appsettings.json
  10. 1
      WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/Common.Shared.DomainService.csproj
  11. 3
      WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/IMqttClientService.cs
  12. 15
      WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MQTTClient.cs
  13. 5
      WeiCloud.Fusion/Common.SharedService/Common.Shared.DomainService/MqttClient/MqttClientService.cs
  14. 28
      WeiCloud.Fusion/WeiCloud.Fusion.sln

@ -7,7 +7,6 @@ namespace Alarm.Application.RequestDto
[JsonPropertyName("param")] [JsonPropertyName("param")]
public required SubscribeParam Param { get; init; } public required SubscribeParam Param { get; init; }
} }
public sealed class SubscribeParam public sealed class SubscribeParam
{ {
[JsonPropertyName("monitors")] [JsonPropertyName("monitors")]

@ -13,9 +13,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Common.SharedService\Common.Shared.Application\Common.Shared.Application.csproj" />
<ProjectReference Include="..\..\Common.SharedService\Common.Shared.DomainService\Common.Shared.DomainService.csproj" />
<ProjectReference Include="..\..\WeiCloud.Core\WeiCloud.Core.csproj" />
<ProjectReference Include="..\Alarm.Application\Alarm.Application.csproj" /> <ProjectReference Include="..\Alarm.Application\Alarm.Application.csproj" />
<ProjectReference Include="..\Common.SharedService\Common.Shared.Application\Common.Shared.Application.csproj" />
<ProjectReference Include="..\WeiCloud.Core\WeiCloud.Core.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,6 +1,7 @@
using Alarm.Application.RequestDto; using Alarm.Application.RequestDto;
using Alarm.Application.ResponeDto; using Alarm.Application.ResponeDto;
using Common.Shared.Application.DaHua; using Common.Shared.Application.DaHua;
using Common.Shared.DomainService.MqttClient;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Parameters;
@ -17,12 +18,37 @@ namespace Alarm.DomainService.DahAlarm
private readonly ILogger<DahuaGeneralCtlService> _logger; private readonly ILogger<DahuaGeneralCtlService> _logger;
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly HttpClient _http; private readonly HttpClient _http;
private readonly MQTTClient _mqttClient;
private readonly IMqttClientService _mqttClientService;
private string mqttHostIp;
private int mqttHostPort;
private int mqttTimeout;
private string mqttUsername;
private string mqttPassword;
private string mqttClientId;
private string topicName;
public DahuaGeneralCtlService(ILogger<DahuaGeneralCtlService> logger, IConfiguration configuration, HttpClient http) /// <summary>
///
/// </summary>
/// <param name="logger"></param>
/// <param name="configuration"></param>
/// <param name="http"></param>
/// <param name="mQTTClient"></param>
public DahuaGeneralCtlService(ILogger<DahuaGeneralCtlService> logger, IConfiguration configuration, HttpClient http, MQTTClient mQTTClient, IMqttClientService mqttClientService)
{ {
_logger = logger; _logger = logger;
_configuration = configuration; _configuration = configuration;
_http = http; _http = http;
_mqttClient = mQTTClient;
mqttHostIp = _configuration["SubscribeMQTT:HostIP"]!;//IP地址
mqttHostPort = _configuration["SubscribeMQTT:HostPort"].ToInt();//端口号
mqttTimeout = _configuration["SubscribeMQTT:Timeout"].ToInt();//超时时间
mqttUsername = _configuration["SubscribeMQTT:UserName"]!;//用户名
mqttPassword = _configuration["SubscribeMQTT:Password"]!;//密码
mqttClientId = _configuration["SubscribeMQTT:ClientId"]!;
topicName = _configuration["SubscribeMQTT:TopicName"]!;
_mqttClientService = mqttClientService;
} }
/// <summary> /// <summary>
@ -258,6 +284,12 @@ namespace Alarm.DomainService.DahAlarm
//这是大华的残卫报警类型 //这是大华的残卫报警类型
if (dto.Info.AlarmType == 4321) if (dto.Info.AlarmType == 4321)
{ {
//拼接物联平台标准的mqtt消息格式
var payload = "[{\"taglabel\":\"" + dto.Info.DeviceCode + " + \".alart.\" + " + dto.Info.DeviceName + "\",\"value\":\"" + dto.Info.AlarmStat + "\",\"time\":\"" + DateTimeOffset.UtcNow.ToUnixTimeSeconds() + "\"}]";
await _mqttClient.EnsureConnectedAsync(mqttHostIp, mqttHostPort, mqttUsername, mqttPassword, topicName, mqttClientId);
await _mqttClientService.PublishAsync("/zrh/sun/alarm", payload);
} }
} }
} }

@ -7,9 +7,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Alarm.DomainService\Alarm.DomainService.csproj" />
<ProjectReference Include="..\..\Common.SharedService\Common.Shared.Application\Common.Shared.Application.csproj" /> <ProjectReference Include="..\..\Common.SharedService\Common.Shared.Application\Common.Shared.Application.csproj" />
<ProjectReference Include="..\..\Common.SharedService\Common.Shared.DomainService\Common.Shared.DomainService.csproj" />
<ProjectReference Include="..\..\WeiCloud.Utils\WeiCloud.Utils.csproj" /> <ProjectReference Include="..\..\WeiCloud.Utils\WeiCloud.Utils.csproj" />
<ProjectReference Include="..\Alarm.Application\Alarm.Application.csproj" />
<ProjectReference Include="..\Alarm.DomainService\Alarm.DomainService.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -1,6 +1,7 @@
using AlarmService.API.Infrastructure; using AlarmService.API.Infrastructure;
using Autofac; using Autofac;
using Autofac.Extensions.DependencyInjection; using Autofac.Extensions.DependencyInjection;
using Common.Shared.DomainService.MqttClient;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using NLog; using NLog;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
@ -86,6 +87,14 @@ namespace AlarmService.API
options.Limits.MaxRequestBodySize = 200 * 1024 * 1024; // ĬÈÏ 200MB options.Limits.MaxRequestBodySize = 200 * 1024 * 1024; // ĬÈÏ 200MB
}); });
#region mqttclient
builder.Services.AddSingleton<MQTTClient>();
builder.Services.AddSingleton<IMqttClientService, MqttClientService>();
#endregion mqttclient
var app = builder.Build(); var app = builder.Build();
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())

@ -5,5 +5,16 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"SubscribeMQTT": {
"TopicName": "datasource_points_AXYJPT_v4",
"ProjectId": 530522108656160,
"HostIP": "v4.weienergy.cn",
"HostPort": 18883,
"Timeout": 5000,
"UserName": "test",
"Password": "test123",
"ClientId": "datasource_points_AXYJPT_v4",
"ApiUrl": "http://v4.weienergy.cn/datastream"
},
"AllowedHosts": "*" "AllowedHosts": "*"
} }

@ -9,7 +9,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="MQTTnet" Version="4.1.4.563" /> <PackageReference Include="MQTTnet" Version="4.1.4.563" />
<PackageReference Include="NLog" Version="6.0.3" /> <PackageReference Include="NLog" Version="6.0.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="6.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -1,5 +1,4 @@
using MQTTnet; using MQTTnet.Client;
using MQTTnet.Client;
namespace Common.Shared.DomainService.MqttClient namespace Common.Shared.DomainService.MqttClient
{ {

@ -10,12 +10,27 @@ namespace Common.Shared.DomainService.MqttClient
{ {
private readonly ILogger<MQTTClient> _logger; private readonly ILogger<MQTTClient> _logger;
internal IMqttClient mqttClient; internal IMqttClient mqttClient;
public bool IsConnected => mqttClient != null && mqttClient.IsConnected;
public MQTTClient(ILogger<MQTTClient> logger) public MQTTClient(ILogger<MQTTClient> logger)
{ {
_logger = logger; _logger = logger;
} }
/// <summary>
/// 如果未连接,则按参数调用 Init;成功后返回当前连接状态。
/// </summary>
public async Task<bool> EnsureConnectedAsync(
string serverIp, int port, string authUser, string authPwd,
string topicNameStrs = "", string clientId = "")
{
if (mqttClient == null || !mqttClient.IsConnected)
{
await Init(serverIp, port, authUser, authPwd, topicNameStrs, clientId);
}
return mqttClient != null && mqttClient.IsConnected;
}
private async Task Subscribe(string topicNameStrs) private async Task Subscribe(string topicNameStrs)
{ {
if (!string.IsNullOrWhiteSpace(topicNameStrs)) if (!string.IsNullOrWhiteSpace(topicNameStrs))

@ -1,9 +1,8 @@
using Common.Shared.DomainService.MqttClient; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
namespace WeiCloud.SafetyFirePro.Services namespace Common.Shared.DomainService.MqttClient
{ {
public class MqttClientService : IMqttClientService public class MqttClientService : IMqttClientService
{ {

@ -47,16 +47,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AlarmService", "AlarmServic
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlarmService.API", "AlarmService\AlarmService.API\AlarmService.API.csproj", "{2677EAF0-9F7F-4969-B8B1-3006F35EB93E}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlarmService.API", "AlarmService\AlarmService.API\AlarmService.API.csproj", "{2677EAF0-9F7F-4969-B8B1-3006F35EB93E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alarm.DomainService", "Alarm.DomainService\Alarm.DomainService.csproj", "{3ED553C4-3A63-4613-B979-472FDA5EA346}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common.SharedService", "Common.SharedService", "{80F3B34B-C334-44D2-A861-31FD403AD57D}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common.SharedService", "Common.SharedService", "{80F3B34B-C334-44D2-A861-31FD403AD57D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alarm.Application", "Alarm.Application\Alarm.Application.csproj", "{89367194-A636-41B9-81F0-283DCB84C296}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Shared.Application", "Common.SharedService\Common.Shared.Application\Common.Shared.Application.csproj", "{9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Shared.Application", "Common.SharedService\Common.Shared.Application\Common.Shared.Application.csproj", "{9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Shared.DomainService", "Common.SharedService\Common.Shared.DomainService\Common.Shared.DomainService.csproj", "{C2757FC0-54A9-BBD3-2E23-55F2F3912BA4}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Shared.DomainService", "Common.SharedService\Common.Shared.DomainService\Common.Shared.DomainService.csproj", "{C2757FC0-54A9-BBD3-2E23-55F2F3912BA4}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alarm.DomainService", "AlarmService\Alarm.DomainService\Alarm.DomainService.csproj", "{B6DDF83D-591E-38B6-2902-1624BE8AE9B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alarm.Application", "AlarmService\Alarm.Application\Alarm.Application.csproj", "{4B2C6EBE-E719-9F40-ADE6-C82DA632E554}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -123,14 +123,6 @@ Global
{2677EAF0-9F7F-4969-B8B1-3006F35EB93E}.Debug|Any CPU.Build.0 = Debug|Any CPU {2677EAF0-9F7F-4969-B8B1-3006F35EB93E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2677EAF0-9F7F-4969-B8B1-3006F35EB93E}.Release|Any CPU.ActiveCfg = Release|Any CPU {2677EAF0-9F7F-4969-B8B1-3006F35EB93E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2677EAF0-9F7F-4969-B8B1-3006F35EB93E}.Release|Any CPU.Build.0 = Release|Any CPU {2677EAF0-9F7F-4969-B8B1-3006F35EB93E}.Release|Any CPU.Build.0 = Release|Any CPU
{3ED553C4-3A63-4613-B979-472FDA5EA346}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3ED553C4-3A63-4613-B979-472FDA5EA346}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3ED553C4-3A63-4613-B979-472FDA5EA346}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3ED553C4-3A63-4613-B979-472FDA5EA346}.Release|Any CPU.Build.0 = Release|Any CPU
{89367194-A636-41B9-81F0-283DCB84C296}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89367194-A636-41B9-81F0-283DCB84C296}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89367194-A636-41B9-81F0-283DCB84C296}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89367194-A636-41B9-81F0-283DCB84C296}.Release|Any CPU.Build.0 = Release|Any CPU
{9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545}.Release|Any CPU.ActiveCfg = Release|Any CPU {9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -139,6 +131,14 @@ Global
{C2757FC0-54A9-BBD3-2E23-55F2F3912BA4}.Debug|Any CPU.Build.0 = Debug|Any CPU {C2757FC0-54A9-BBD3-2E23-55F2F3912BA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2757FC0-54A9-BBD3-2E23-55F2F3912BA4}.Release|Any CPU.ActiveCfg = Release|Any CPU {C2757FC0-54A9-BBD3-2E23-55F2F3912BA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2757FC0-54A9-BBD3-2E23-55F2F3912BA4}.Release|Any CPU.Build.0 = Release|Any CPU {C2757FC0-54A9-BBD3-2E23-55F2F3912BA4}.Release|Any CPU.Build.0 = Release|Any CPU
{B6DDF83D-591E-38B6-2902-1624BE8AE9B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6DDF83D-591E-38B6-2902-1624BE8AE9B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6DDF83D-591E-38B6-2902-1624BE8AE9B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6DDF83D-591E-38B6-2902-1624BE8AE9B9}.Release|Any CPU.Build.0 = Release|Any CPU
{4B2C6EBE-E719-9F40-ADE6-C82DA632E554}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B2C6EBE-E719-9F40-ADE6-C82DA632E554}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B2C6EBE-E719-9F40-ADE6-C82DA632E554}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B2C6EBE-E719-9F40-ADE6-C82DA632E554}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -159,10 +159,10 @@ Global
{40B0D902-553C-C52F-71A2-56FB176FCCBD} = {44DAA396-C724-480A-A2BC-9A33D29E8FEA} {40B0D902-553C-C52F-71A2-56FB176FCCBD} = {44DAA396-C724-480A-A2BC-9A33D29E8FEA}
{9F2BD2C5-6496-419D-B87A-4F481E963C4D} = {19A25984-FFA8-49BE-A710-6F269A406C61} {9F2BD2C5-6496-419D-B87A-4F481E963C4D} = {19A25984-FFA8-49BE-A710-6F269A406C61}
{2677EAF0-9F7F-4969-B8B1-3006F35EB93E} = {18791734-CA81-482D-964A-CA6D0F308B8E} {2677EAF0-9F7F-4969-B8B1-3006F35EB93E} = {18791734-CA81-482D-964A-CA6D0F308B8E}
{3ED553C4-3A63-4613-B979-472FDA5EA346} = {18791734-CA81-482D-964A-CA6D0F308B8E}
{89367194-A636-41B9-81F0-283DCB84C296} = {18791734-CA81-482D-964A-CA6D0F308B8E}
{9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545} = {80F3B34B-C334-44D2-A861-31FD403AD57D} {9A5FBAFF-EBE8-3156-5547-FB3ED1DEB545} = {80F3B34B-C334-44D2-A861-31FD403AD57D}
{C2757FC0-54A9-BBD3-2E23-55F2F3912BA4} = {80F3B34B-C334-44D2-A861-31FD403AD57D} {C2757FC0-54A9-BBD3-2E23-55F2F3912BA4} = {80F3B34B-C334-44D2-A861-31FD403AD57D}
{B6DDF83D-591E-38B6-2902-1624BE8AE9B9} = {18791734-CA81-482D-964A-CA6D0F308B8E}
{4B2C6EBE-E719-9F40-ADE6-C82DA632E554} = {18791734-CA81-482D-964A-CA6D0F308B8E}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {379A56DA-D3F0-4E7E-8FF7-DA8E20015BF3} SolutionGuid = {379A56DA-D3F0-4E7E-8FF7-DA8E20015BF3}

Loading…
Cancel
Save