32 lines
977 B
C#
32 lines
977 B
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 ThingOnboardCaseHandler : IMqttMessageHandler
|
|
{
|
|
private readonly ICacheContext _cache;
|
|
public ThingOnboardCaseHandler(AirportMaintenanceApp app, ICacheContext cache)
|
|
{
|
|
_cache = cache;
|
|
}
|
|
public bool CanHandle(string topic)
|
|
{
|
|
return topic.Contains("/onboardcase");
|
|
}
|
|
public async Task HandleAsync(string topic, string payload)
|
|
{
|
|
var root = JsonNode.Parse(payload)?.AsObject();
|
|
if (root != null && root["type"]?.ToString() == "status_update")
|
|
{
|
|
var onboardcase = _cache.Set(root["device_id"]?.ToString(), payload, DateTime.Now.AddSeconds(20));
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|