46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using Infrastructure.Cache;
|
|
using Infrastructure.CloudSdk.mqttmessagecenter;
|
|
using NPOI.SS.Formula.Functions;
|
|
using OpenAuth.App.ServiceApp;
|
|
using OpenAuth.Repository.Domain;
|
|
using System.Text.Json.Nodes;
|
|
using static Org.BouncyCastle.Math.EC.ECCurve;
|
|
|
|
namespace OpenAuth.WebApi.Model.mqtt
|
|
{
|
|
public class ThingAiTaskHandler : IMqttMessageHandler
|
|
{
|
|
LasaPlatformPushApp _app;
|
|
private readonly ICacheContext _cache;
|
|
public ThingAiTaskHandler(LasaPlatformPushApp app, ICacheContext cache)
|
|
{
|
|
_app = app;
|
|
_cache = cache;
|
|
}
|
|
public bool CanHandle(string topic)
|
|
{
|
|
return topic.Contains("ai/task");
|
|
}
|
|
public async Task HandleAsync(string topic, string payload)
|
|
{
|
|
var parts = topic.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
|
if (parts.Length == 0)
|
|
return;
|
|
var action = parts[^1];
|
|
switch (action)
|
|
{
|
|
case "tasklog":
|
|
var info = Newtonsoft.Json.JsonConvert.DeserializeObject<LasaTaskAiLog>(payload);
|
|
if (info != null)
|
|
{
|
|
await _app.AddTaskAi(info);
|
|
}
|
|
break;
|
|
case "aiachievement":
|
|
await _app.AddImgTopic(payload);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|