diff --git a/OpenAuth.Repository/Domain/LasaUav.cs b/OpenAuth.Repository/Domain/LasaUav.cs index 03a4be2..b56118c 100644 --- a/OpenAuth.Repository/Domain/LasaUav.cs +++ b/OpenAuth.Repository/Domain/LasaUav.cs @@ -29,5 +29,6 @@ namespace OpenAuth.Repository.Domain /// [SugarColumn(DefaultValue = "false")] public bool IsDelete { get; set; } + public string WorkSpaceId { get; set; } } } diff --git a/OpenAuth.WebApi/Model/mqtt/MqttHostedService.cs b/OpenAuth.WebApi/Model/mqtt/MqttHostedService.cs index 0688d3e..97e14d0 100644 --- a/OpenAuth.WebApi/Model/mqtt/MqttHostedService.cs +++ b/OpenAuth.WebApi/Model/mqtt/MqttHostedService.cs @@ -41,7 +41,8 @@ namespace OpenAuth.WebApi.Model.mqtt $"thing/product/{gateway}/osd", $"thing/product/{gateway}/events", $"thing/product/{gateway}/requests", - $"thing/product/{gateway}/services_reply" + $"thing/product/{gateway}/services_reply", + $"thing/product/{gateway}/state" }); } await _mqttCenter.ConnectAndSubscribeAsync(topics.ToArray()); diff --git a/OpenAuth.WebApi/Model/mqtt/ThingRequestHandler.cs b/OpenAuth.WebApi/Model/mqtt/ThingRequestHandler.cs index 8056764..1b2dd50 100644 --- a/OpenAuth.WebApi/Model/mqtt/ThingRequestHandler.cs +++ b/OpenAuth.WebApi/Model/mqtt/ThingRequestHandler.cs @@ -85,7 +85,7 @@ namespace OpenAuth.WebApi.Model.mqtt { device_callsign = "山东慧创", is_device_bind_organization = true, - organization_id = "379", + organization_id = "371300", organization_name = "山东慧创", sn = sn }).ToArray(); diff --git a/OpenAuth.WebApi/Model/mqtt/ThingStateHandler.cs b/OpenAuth.WebApi/Model/mqtt/ThingStateHandler.cs new file mode 100644 index 0000000..99a5ac8 --- /dev/null +++ b/OpenAuth.WebApi/Model/mqtt/ThingStateHandler.cs @@ -0,0 +1,39 @@ +using Infrastructure.CloudSdk.mqttmessagecenter; +using OpenAuth.App.ServiceApp; +using OpenAuth.Repository.Domain; +using System.Text.Json.Nodes; + +namespace OpenAuth.WebApi.Model.mqtt +{ + public class ThingStateHandler : IMqttMessageHandler + { + private readonly ILogger _logger; + AirportMaintenanceApp _app; + public ThingStateHandler(ILogger logger, AirportMaintenanceApp app) + { + _logger = logger; + _app = app; + } + + public bool CanHandle(string topic) + { + return topic.Contains("/state"); + } + + public Task HandleAsync(string topic, string payload) + { + _logger.LogError($"[Service] Topic={topic}, Payload={payload}"); + Console.WriteLine($"[Service] Topic={topic}, Payload={payload}"); + var root = JsonNode.Parse(payload)?.AsObject(); + _app.AddLog(new LasaLog + { + Id = Guid.NewGuid().ToString(), + Topic = topic, + Method = root["method"]?.ToString() ?? "", + CreateTime = DateTime.Now, + Data = root + }); + return Task.CompletedTask; + } + } +} diff --git a/OpenAuth.WebApi/Startup.cs b/OpenAuth.WebApi/Startup.cs index 14215f3..6937acb 100644 --- a/OpenAuth.WebApi/Startup.cs +++ b/OpenAuth.WebApi/Startup.cs @@ -254,16 +254,16 @@ namespace OpenAuth.WebApi StaticConfig.CustomSnowFlakeFunc = () => { return YitIdHelper.NextId(); }; var sqlSugar = new SqlSugarClient(new ConnectionConfig() + { + DbType = DbType.PostgreSQL, + ConnectionString = Configuration.GetConnectionString("OpenAuthDBContext"), + IsAutoCloseConnection = true, + MoreSettings = new ConnMoreSettings() { - DbType = DbType.PostgreSQL, - ConnectionString = Configuration.GetConnectionString("OpenAuthDBContext"), - IsAutoCloseConnection = true, - MoreSettings = new ConnMoreSettings() - { - PgSqlIsAutoToLower = false, - PgSqlIsAutoToLowerCodeFirst = false - } - }, + PgSqlIsAutoToLower = false, + PgSqlIsAutoToLowerCodeFirst = false + } + }, //var sqlSugar = new SqlSugarClient(new ConnectionConfig() //{ @@ -316,7 +316,7 @@ namespace OpenAuth.WebApi #region Quartz services.AddHostedService(); - + #endregion #region SignalR @@ -327,14 +327,13 @@ namespace OpenAuth.WebApi #region mqtt services.AddSingleton(); - //services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); - //services.AddSingleton(); - //services.AddSingleton(); - + services.AddSingleton(); + services.AddSingleton(); services.AddHostedService(); - - + + #endregion }