43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using Infrastructure.Cache;
|
|
using Infrastructure.CloudSdk.mqttmessagecenter;
|
|
using OpenAuth.App.ServiceApp;
|
|
using OpenAuth.Repository.Domain;
|
|
using System.Text.Json.Nodes;
|
|
|
|
namespace OpenAuth.WebApi.Model.mqtt
|
|
{
|
|
public class ThingOperationHandler : IMqttMessageHandler
|
|
{
|
|
AirportMaintenanceApp _app;
|
|
private readonly ICacheContext _cache;
|
|
public ThingOperationHandler(AirportMaintenanceApp app, ICacheContext cache)
|
|
{
|
|
_app = app;
|
|
_cache = cache;
|
|
}
|
|
public bool CanHandle(string topic)
|
|
{
|
|
return topic.Contains("/control-operation");
|
|
}
|
|
public async Task HandleAsync(string topic, string payload)
|
|
{
|
|
var root = JsonNode.Parse(payload)?.AsObject();
|
|
await _app.AddOperationLog(new LasaControlOperation
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
DeviceSn = root["DeviceSn"]?.ToString() ?? "",
|
|
TaskId = root["TaskId"]?.ToString() ?? "",
|
|
CreateTime = DateTime.Now,
|
|
CreateId = long.Parse((root["CreateId"]?.ToString() ?? "0")),
|
|
Data = root["Data"]?.ToJsonString() ?? ""
|
|
});
|
|
//var info = Newtonsoft.Json.JsonConvert.DeserializeObject<LasaControlOperation>(payload);
|
|
//info.Id = Guid.NewGuid().ToString();
|
|
//info.CreateTime = DateTime.Now;
|
|
//await _app.AddOperationLog(info);
|
|
// 自定义处理逻辑
|
|
//return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|