Compare commits
2 Commits
4010272dc1
...
38b3587480
| Author | SHA1 | Date |
|---|---|---|
|
|
38b3587480 | |
|
|
bf67f21b91 |
|
|
@ -653,6 +653,7 @@ namespace OpenAuth.App.ServiceApp.Algo
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Infrastructure.CloudSdk.minio;
|
||||
using Infrastructure.Helpers;
|
||||
using Microsoft.DotNet.InternalAbstractions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using OpenAuth.App.BaseApp.Base;
|
||||
using OpenAuth.App.BasicQueryService;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.ServiceApp.Algo;
|
||||
using OpenAuth.App.ServiceApp.Algo.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.WebApi;
|
||||
|
|
@ -23,9 +27,10 @@ namespace OpenAuth.App.ServiceApp
|
|||
/// </summary>
|
||||
public class LasaPlatformPushApp : SqlSugarBaseApp<LasaPlatform, SugarDbContext>
|
||||
{
|
||||
public LasaPlatformPushApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<LasaPlatform> repository, IAuth auth): base(unitWork, repository, auth)
|
||||
private readonly ILogger<LasaPlatformPushApp> _logger;
|
||||
public LasaPlatformPushApp(ILogger<LasaPlatformPushApp> logger,ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<LasaPlatform> repository, IAuth auth): base(unitWork, repository, auth)
|
||||
{
|
||||
|
||||
_logger = logger;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取推送平台
|
||||
|
|
@ -180,5 +185,113 @@ namespace OpenAuth.App.ServiceApp
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取推送记录
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<PageInfo<List<LasaTaskAiLog>>>> GetAiLogList(int page, int limit, string key)
|
||||
{
|
||||
RefAsync<int> totalCount = 0;
|
||||
using (var db = UnitWork.CreateContext())
|
||||
{
|
||||
var list = await db.LasaTaskAiLog.AsQueryable()
|
||||
.WhereIF(!string.IsNullOrEmpty(key), (a) => a.Data.Contains(key))
|
||||
.ToPageListAsync(page, limit, totalCount);
|
||||
return new Response<PageInfo<List<LasaTaskAiLog>>>
|
||||
{
|
||||
Result = new PageInfo<List<LasaTaskAiLog>> { Items = list, Total = totalCount }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<Response<bool>> AddImgTopic(string payload)
|
||||
{
|
||||
using var db = UnitWork.CreateContext();
|
||||
|
||||
var aiinfo = JsonConvert.DeserializeObject<AiImgReq>(payload);
|
||||
if (aiinfo == null)
|
||||
{
|
||||
return new Response<bool>
|
||||
{
|
||||
Result = true,
|
||||
Message = "添加成功"
|
||||
};
|
||||
}
|
||||
|
||||
_logger.LogInformation("标签信息:{tag}", JsonConvert.SerializeObject(aiinfo.tag));
|
||||
_logger.LogInformation("aiid:{aiid}", aiinfo.aiid);
|
||||
|
||||
var config = ConfigHelper.GetConfigRoot();
|
||||
var imageBaseUrl = $"http://{config["Minio:Endpoint"]}/{config["Minio:BucketName"]}/";
|
||||
|
||||
var (lat, lng) = GetDroneLocation(aiinfo);
|
||||
|
||||
// 一次性加载模型标签
|
||||
var modelDict = (await db.LasaModelLabel.AsQueryable().Where(r => r.PId == aiinfo.aiid).ToListAsync())
|
||||
.ToDictionary(x => x.EnumValue, x => x.Name);
|
||||
|
||||
foreach (var tag in aiinfo.tag)
|
||||
{
|
||||
if (tag.confidence < 0.3)
|
||||
continue;
|
||||
|
||||
var tagKey = tag.class_id.ToString();
|
||||
var achievement = await db.LasaAiAchievement
|
||||
.GetFirstAsync(r => r.TaskId == aiinfo.taskid && r.Tag == tagKey);
|
||||
if (achievement == null)
|
||||
{
|
||||
await db.LasaAiAchievement.InsertAsync(new LasaAiAchievement
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
CreateTime = DateTime.Now,
|
||||
TaskId = aiinfo.taskid,
|
||||
AlgoId = aiinfo.aiid,
|
||||
AiModel = "yolo12x",
|
||||
Tag = tag.class_id.ToString(),
|
||||
Title = modelDict.TryGetValue(tag.class_id, out var name) ? name : string.Empty,
|
||||
ConfidenceLevel = (float)Math.Round(tag.confidence, 2) * 100,
|
||||
Cover = imageBaseUrl + aiinfo.path,
|
||||
Lat = (float)lat,
|
||||
Lng = (float)lng
|
||||
});
|
||||
}
|
||||
await db.LasaAiAchievementDetail.InsertAsync(new LasaAiAchievementDetail
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
AiAchievementId = achievement.Id,
|
||||
Image = imageBaseUrl + aiinfo.path,
|
||||
Lat = lat,
|
||||
Lng = lng
|
||||
});
|
||||
}
|
||||
|
||||
if (db.Commit())
|
||||
return new Response<bool>
|
||||
{
|
||||
Result = true,
|
||||
Message = "添加成功"
|
||||
};
|
||||
else
|
||||
return new Response<bool>
|
||||
{
|
||||
Result = false,
|
||||
Message = "添加失败"
|
||||
};
|
||||
}
|
||||
private static (double lat, double lng) GetDroneLocation(AiImgReq aiinfo)
|
||||
{
|
||||
if (aiinfo.drone_info?.data == null)
|
||||
return (0.0, 0.0);
|
||||
|
||||
return (
|
||||
aiinfo.drone_info.data.latitude ?? 0.0,
|
||||
aiinfo.drone_info.data.longitude ?? 0.0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2586,6 +2586,10 @@ namespace OpenAuth.App.ServiceApp
|
|||
.Queryable<LasaAlgoInstance>()
|
||||
.Where(x => x.Id == req.AlgoInstanceId)
|
||||
.ToListAsync();
|
||||
//获取推送平台
|
||||
var platform = await Repository
|
||||
.ChangeRepository<SugarRepositiry<LasaPlatform>>()
|
||||
.AsQueryable().Where(x => x.Id == req.AlgoInstanceId).FirstAsync();
|
||||
var tagsIds = algoInstances.Select(x => x.Tags).ToList();
|
||||
// todo 关于存在多个算法的处理 查询多个算法
|
||||
var algoIds = algoInstances.First().AlgoIds.Split(",").ToArray();
|
||||
|
|
@ -2691,7 +2695,7 @@ namespace OpenAuth.App.ServiceApp
|
|||
AiTaskId = taskId,
|
||||
TemTaskId = req.TaskId,
|
||||
State = true,
|
||||
Platform = "",
|
||||
Platform = platform == null ? "" : platform.PlatformName,
|
||||
CreateTime = DateTime.Now,
|
||||
});
|
||||
_redisCacheContext.HashSetAsync($"ai:task:{taskId}", new[]{
|
||||
|
|
|
|||
|
|
@ -105,5 +105,31 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region 算法推送记录
|
||||
/// <summary>
|
||||
/// 获取推送平台列表
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <param name="key">平台名称</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<Response<PageInfo<List<LasaTaskAiLog>>>> GetAiLogList(int page, int limit, string key)
|
||||
{
|
||||
var result = new Response<PageInfo<List<LasaTaskAiLog>>>();
|
||||
try
|
||||
{
|
||||
result = await _app.GetAiLogList(page, limit, key);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.Message;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|||
"thing/product/+/osd",
|
||||
"sys/product/+/status",
|
||||
"thing/product/+/control-operation",
|
||||
"ai/task/+/tasklog"
|
||||
"ai/task/+/tasklog",
|
||||
"ai/task/+/aiachievement"
|
||||
};
|
||||
await _mqttCenter.SubscribeAsync(topicList);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
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":
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -183,6 +183,7 @@ namespace OpenAuth.WebApi
|
|||
services.AddSingleton<IMqttMessageHandler, ThingEventHandler>();
|
||||
services.AddSingleton<IMqttMessageHandler, ThingOperationHandler>();
|
||||
services.AddSingleton<IMqttMessageHandler, ThingStatusHandler>();
|
||||
services.AddSingleton<IMqttMessageHandler, ThingAiTaskHandler>();
|
||||
services.AddHostedService<MqttHostedService>();
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue