From 45532b78e82c844ebb2eee0c3fb735c48c27245b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BC=9F?= <421281095@qq.com> Date: Wed, 17 Dec 2025 10:59:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=97=E6=B3=95=E8=B0=83=E7=94=A8=E6=94=B9?= =?UTF-8?q?=E5=8A=A8=E9=87=8D=E6=96=B0=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenAuth.App/ServiceApp/ManageApp.cs | 109 +++++++++++++++++---------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/OpenAuth.App/ServiceApp/ManageApp.cs b/OpenAuth.App/ServiceApp/ManageApp.cs index 88bb5eb..78f9a99 100644 --- a/OpenAuth.App/ServiceApp/ManageApp.cs +++ b/OpenAuth.App/ServiceApp/ManageApp.cs @@ -2586,14 +2586,51 @@ namespace OpenAuth.App.ServiceApp .Where(x => x.Id == req.AlgoInstanceId) .ToListAsync(); var tagsIds = algoInstances.Select(x => x.Tags).ToList(); - // todo 关于存在多个算法的处理 + // todo 关于存在多个算法的处理 查询多个算法 var algoIds = algoInstances.First().AlgoIds.Split(",").ToArray(); - var algo = await db + var algos = await db .Queryable() - .Where(x => x.Id == algoIds[0]) - .FirstAsync(); - dynamic json = new - ExpandoObject(); + .Where(x => algoIds.Contains(x.Id)).ToListAsync(); + //创建多模型数据结构 + var models = new List(); + foreach (var algo in algos) + { + // 当前算法对应的 tag + var algoInstance = algoInstances.First(a => a.AlgoIds.Contains(algo.Id)); + + var tagIds = algoInstance.Tags.Split(",", StringSplitOptions.RemoveEmptyEntries); + + var labels = await db.Queryable() + .Where(l => tagIds.Contains(l.Id) && l.PId == algo.Id) + .ToListAsync(); + + Dictionary tags = new Dictionary(); + + foreach (var label in labels) + { + tags[label.EnumValue.ToString()] = new ModelTag + { + name = label.Name, + reliability = label.Reliability, + select = true, + color = label.Color + }; + } + + var model = new ModelConfig + { + path = algo.Path, + encryption_key = algo.SecretKey, + tags = tags, + conf_thres = algo.ConfThres, + imgsz = algo.Imgsz, + device = "cuda:0", + line_width = 2, + enabled = algo.Enable + }; + + models.Add(model); + } var x = SnowFlakeSingle.instance; //var pushUrl = $"rtmp://box.wisestcity.com:1935/live/{x.NextId()}"; var config = ConfigHelper.GetConfigRoot(); @@ -2616,17 +2653,14 @@ namespace OpenAuth.App.ServiceApp { pushUrl += req.UavSn + 1; } - - json.rtmp_url = req.RtmpUrl; // 无人机直播流 - json.push_url = pushUrl; // 识别结果推流 - json.imgsz = 640; - json.frame_skip = 1; - json.model_name = algo.Path; - //json.model_name = "yolo12x.pt"; - json.taskname = task.TaskName; - json.taskid = req.TaskId; - // 算法id - json.AlgoId = algo.Id; + var reqBody = new StartDetectionResp + { + rtmp_url = req.RtmpUrl, + push_url = pushUrl, + taskname = task.TaskName, + taskid = req.TaskId, + models = models + }; var taskRecord = new LasaTask() { Id = req.TaskId, @@ -2634,35 +2668,28 @@ namespace OpenAuth.App.ServiceApp PushUrl = pushUrl, AIInspection = "true", }; - var tagIdArray = new List(); - foreach (var tagId in tagsIds) - { - tagIdArray.AddRange(tagId.Split(",").ToList()); - } - await db.Updateable(taskRecord).IgnoreNullColumns().ExecuteCommandAsync(); - var tag = await db - .Queryable() - .Where(l => tagIdArray.Contains(l.Id)) - .ToArrayAsync(); - IDictionary jsonTag = new Dictionary(); - foreach (var lasaModelLabel in tag) - { - var model = new - { - name = lasaModelLabel.Name, - reliability = lasaModelLabel.Reliability - }; - jsonTag[lasaModelLabel.EnumValue.ToString()] = model; - } - json.tag = jsonTag; - _logger.LogDebug($"发送的json:{JsonConvert.SerializeObject(json)}"); - var content = new StringContent(JsonConvert.SerializeObject(json), Encoding.UTF8, "application/json"); + _logger.LogDebug($"发送的json:{JsonConvert.SerializeObject(reqBody)}"); + var content = new StringContent(JsonConvert.SerializeObject(reqBody), Encoding.UTF8, "application/json"); var url = config["AIModelApi:Url"]; using var httpClient = new HttpClient(); - var response = await httpClient.PostAsync($"{url}/start_detection", content); + var response = await httpClient.PostAsync($"{url}/api/tasks/creat", content); //var response = await httpClient.PostAsync("http://192.168.10.131:9025/start_detection", content); + if (response.IsSuccessStatusCode)//低一哦成功记录当前任务数据 + { + var responseStr = await response.Content.ReadAsStringAsync(); + var root = JsonNode.Parse(responseStr)?.AsObject(); + var taskId = root?["data"]?["task_id"]?.ToString(); + if (!string.IsNullOrEmpty(taskId)) + { + _redisCacheContext.HashSetAsync($"ai:task:{taskId}", new[]{ + new HashEntry("TaskId", taskId), + new HashEntry("Status", "running"), + new HashEntry("CreateTime", DateTime.Now.ToString("O")) + }); + } + } _logger.LogDebug($"成功调用{response.IsSuccessStatusCode}"); db.Ado.CommitTran(); }