diff --git a/OpenAuth.App/ServiceApp/ManageApp.cs b/OpenAuth.App/ServiceApp/ManageApp.cs index 8c81e63..c603e15 100644 --- a/OpenAuth.App/ServiceApp/ManageApp.cs +++ b/OpenAuth.App/ServiceApp/ManageApp.cs @@ -2533,153 +2533,6 @@ namespace OpenAuth.App.ServiceApp }; } - public async Task> CallAiModelOld(CallAiModel req) - { - _logger.LogDebug("成功调用CallAIModel"); - var task = await Repository - .ChangeRepository>() - .GetByIdAsync(req.TaskId); - using var db = Repository.AsSugarClient(); - try - { - db.Ado.BeginTran(); - if (task.FlightTaskType.Equals(1)) // 手飞任务 - { - var aiInspection = new LasaAiInspection - { - Id = Guid.NewGuid().ToString(), - TaskId = req.TaskId, - AlgoInstanceId = req.AlgoInstanceId, - }; - if (!string.IsNullOrEmpty(req.WarningContent)) - { - aiInspection.WarningTitle = req.WarningTitle; - } - - if (!string.IsNullOrEmpty(req.WarningContent)) - { - aiInspection.WarningContent = req.WarningContent; - } - - // 关于多次调用问题 - var count = await db.Queryable().Where(x => x.TaskId == req.TaskId).CountAsync(); - if (count == 0) - { - // 设置任务智能巡检标识 - task.AIInspection = "true"; - task.Status = 3; // 表示智能巡检中 - await db.Updateable(task).ExecuteCommandAsync(); - await db.Insertable(aiInspection).ExecuteCommandAsync(); - } - } - else - { - // 计划任务 - var aiInspection = await Repository - .ChangeRepository>() - .AsQueryable().Where(x => x.TaskId == req.TaskId).FirstAsync(); - req.AlgoInstanceId = aiInspection.AlgoInstanceId; - } - - var algoInstances = await db - .Queryable() - .Where(x => x.Id == req.AlgoInstanceId) - .ToListAsync(); - var tagsIds = algoInstances.Select(x => x.Tags).ToList(); - // todo 关于存在多个算法的处理 - var algoIds = algoInstances.First().AlgoIds.Split(",").ToArray(); - var algo = await db - .Queryable() - .Where(x => x.Id == algoIds[0]) - .FirstAsync(); - dynamic json = new - ExpandoObject(); - var x = SnowFlakeSingle.instance; - //var pushUrl = $"rtmp://box.wisestcity.com:1935/live/{x.NextId()}"; - var config = ConfigHelper.GetConfigRoot(); - var pushUrl = config["AIModelApi:PushUrl"]; - // 取得无人机sn + 1 - if (string.IsNullOrEmpty(req.UavSn)) - { - var lasaDronePort = await Repository.AsSugarClient().Queryable() - .LeftJoin((a, b) => a.Id == b.PId) - .Where((a, b) => a.Id == task.TaskDronePort).Select( - (a, b) => new - { - UavSn = b.Sn, - b.TypeId - } - ).FirstAsync(); - pushUrl += lasaDronePort.UavSn + "1"; - } - else - { - 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 taskRecord = new LasaTask() - { - Id = req.TaskId, - Status = 6, // 智能巡检状态 - 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"); - var url = config["AIModelApi:Url"]; - using var httpClient = new HttpClient(); - var response = await httpClient.PostAsync($"{url}/start_detection", content); - //var response = await httpClient.PostAsync("http://192.168.10.131:9025/start_detection", content); - _logger.LogDebug($"成功调用{response.IsSuccessStatusCode}"); - db.Ado.CommitTran(); - } - catch (Exception ex) - { - db.Ado.RollbackTran(); - throw ex; - //throw new Exception("调用智能巡检失败"); - } - - return new Response() - { - Result = true - }; - } - - public async Task> CallAiModel(CallAiModel req) { _logger.LogDebug("成功调用CallAIModel"); @@ -2853,6 +2706,8 @@ namespace OpenAuth.App.ServiceApp }; } + + public async Task> EndHandFlyTask(string taskid) { var savedTask = await Repository.ChangeRepository>().AsQueryable()