洁 任 2 months ago
commit c9d826ab50

@ -76,6 +76,7 @@ public class AlgoInstanceServiceApp : SqlSugarBaseApp<LasaAlgoInstance, SugarDbC
RefAsync<int> totalCount = 0;
var page = await Repository.AsQueryable()
.WhereIF(!string.IsNullOrEmpty(req.key), x => x.Name.Contains(req.key))
.WhereIF(!string.IsNullOrEmpty(req.algoId), x => x.AlgoIds.Contains(req.algoId))
.ToPageListAsync(req.page, req.limit, totalCount);
if (page != null && page.Count > 0)

@ -1,6 +1,7 @@
using Infrastructure;
using Infrastructure.CloudSdk.minio;
using Infrastructure.Extensions;
using Microsoft.Extensions.Logging;
using Minio;
using Newtonsoft.Json;
using OpenAuth.App.BaseApp.Base;
@ -27,10 +28,12 @@ namespace OpenAuth.App.ServiceApp.Algo
public class DaHuaAiApp : SqlSugarBaseApp<LasaAlgorithmsRepository, SugarDbContext>
{
public MinioService _minioService;
public DaHuaAiApp(ISugarUnitOfWork<SugarDbContext> unitWork, MinioService minioService,
private readonly ILogger<DaHuaAiApp> _logger;
public DaHuaAiApp(ISugarUnitOfWork<SugarDbContext> unitWork, MinioService minioService, ILogger<DaHuaAiApp> logger,
ISimpleClient<LasaAlgorithmsRepository> repository, IAuth auth) : base(unitWork, repository, auth)
{
_minioService = minioService;
_logger = logger;
}
#region 大华算法
@ -39,11 +42,18 @@ namespace OpenAuth.App.ServiceApp.Algo
{
using (var db = UnitWork.CreateContext())
{
var imageList1 = await db.LasaMediaFile.AsQueryable().Where(r => r.TaskId == firstId && r.AbsoluteAltitude != 0 && r.AbsoluteAltitude != null).OrderBy(r=>r.CreateTime).ToListAsync();
var imageList1 = await db.LasaMediaFile.AsQueryable().Where(r => r.TaskId == firstId && r.AbsoluteAltitude != 0 && r.AbsoluteAltitude != null).OrderBy(r => r.CreateTime).ToListAsync();
var imageList2 = await db.LasaMediaFile.AsQueryable().Where(r => r.TaskId == secondId && r.AbsoluteAltitude != 0 && r.AbsoluteAltitude != null).OrderBy(r => r.CreateTime).ToListAsync();
//var imageList1 = await db.LasaMediaFile.AsQueryable().Where(r => r.Id == firstId && r.AbsoluteAltitude != 0 && r.AbsoluteAltitude != null).ToListAsync();
//var imageList2 = await db.LasaMediaFile.AsQueryable().Where(r => r.Id == secondId && r.AbsoluteAltitude != 0 && r.AbsoluteAltitude != null).ToListAsync();
List<dynamic> dataList = new List<dynamic>();
if (imageList1.Count() != imageList2.Count())
{
//删除检测记录
await db.Lasa_ChangeDetection.DeleteByIdAsync(cdid);
db.Commit();
throw new Exception("任务照片数量不对应,请重新选择任务");
}
for (int i = 0; i < imageList1.Count; i++)
{
dataList.Add(new
@ -110,6 +120,7 @@ namespace OpenAuth.App.ServiceApp.Algo
public async Task<Response<bool>> AddDaHuaImg(string info)
{
Console.WriteLine(info);
_logger.LogError("耕地破坏报警数据;" + info);
using (var db = UnitWork.CreateContext())
{
var data = JsonConvert.DeserializeObject<dynamic>(info);
@ -135,7 +146,8 @@ namespace OpenAuth.App.ServiceApp.Algo
Lng = (double?)item.longitude ?? 0.0,
Lat = (double?)item.latitude ?? 0.0,
CompareIndex = index,
GroupId = compareGroupId
GroupId = compareGroupId,
CompareCount = regionArray.Length
};
// 如果是第二张图片 -> 画区域 + 上传
@ -174,7 +186,8 @@ namespace OpenAuth.App.ServiceApp.Algo
Lng = (double?)item.longitude ?? 0.0,
Lat = (double?)item.latitude ?? 0.0,
CompareIndex = index,
GroupId = compareGroupId
GroupId = compareGroupId,
CompareCount = regionArray.Length
};
// 如果是第二张图片 -> 画区域 + 上传
if (index == 1)
@ -215,7 +228,7 @@ namespace OpenAuth.App.ServiceApp.Algo
}
//public async Task<string> DrawingImgAndUpload(string url, int[][] regionArray)
public async Task<string> DrawingImgAndUpload(string url, int[][] regionArray, string cdid)
{
{
//string url = "http://123.132.248.154:6015/DroneEnforcement/2025/20250514/lQLPJyIVimQWGKnNA4PNA6Gw1D3q5gbxUvQIiumcIx4vAA_929_899.png";
// detectRegion JSON可以直接替换成你的接口返回数据
@ -307,7 +320,28 @@ namespace OpenAuth.App.ServiceApp.Algo
Console.WriteLine("已保存图片: " + savePath);
}
public async Task<Response<bool>> UpdateState(string id)
{
using (var db = UnitWork.CreateContext())
{
await db.Lasa_ChangeDetection.UpdateAsync(u => new Lasa_ChangeDetection
{
IsFinish = true
}, u => u.Id == id);
if (db.Commit())
return new Response<bool>
{
Result = true,
Message = "检测完成"
};
else
return new Response<bool>
{
Result = false,
Message = "检测完成"
};
}
}
#endregion

@ -4,4 +4,5 @@ namespace OpenAuth.App.ServiceApp.Algo.Request;
public class AlgoInstancePageRequest : PageReq
{
public string algoId { get; set; }
}

@ -1,17 +1,19 @@
using OpenAuth.App.BaseApp.Base;
using OpenAuth.Repository.Domain;
using DocumentFormat.OpenXml.EMMA;
using Infrastructure;
using Infrastructure.CloudSdk.minio;
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Http;
using OpenAuth.App.BaseApp.Base;
using OpenAuth.App.Interface;
using OpenAuth.App.ServiceApp.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Infrastructure.CloudSdk.minio;
using OpenAuth.App.Interface;
using SqlSugar;
using Infrastructure;
using Microsoft.AspNetCore.Http;
using DocumentFormat.OpenXml.EMMA;
namespace OpenAuth.App.ServiceApp
{
@ -164,13 +166,14 @@ namespace OpenAuth.App.ServiceApp
/// <param name="pageSize"></param>
/// <param name="key"></param>
/// <returns></returns>
public async Task<Response<PageInfo<List<Lasa_ChangeDetection>>>> GetChangeDetectionPageList(int page, int limit, string key)
public async Task<Response<PageInfo<List<Lasa_ChangeDetection>>>> GetChangeDetectionPageList(int page, int limit, string key, DateTime startTime, DateTime endTime)
{
RefAsync<int> totalCount = 0;
using (var db = UnitWork.CreateContext())
{
var list = await db.Lasa_ChangeDetection.AsQueryable()
.WhereIF(!string.IsNullOrEmpty(key), a => a.Title.Contains(key))
.WhereIF(!"0001/1/1 0:00:00".Equal(startTime.ToString()), a => a.CreateTime >= startTime && a.CreateTime <= endTime)
.OrderByDescending(a => a.CreateTime)
.ToPageListAsync(page, limit, totalCount);
return new Response<PageInfo<List<Lasa_ChangeDetection>>>
@ -220,6 +223,24 @@ namespace OpenAuth.App.ServiceApp
};
}
}
public async Task<Response<ChangeDetectionResp>> GetChangeDetectionById(string id)
{
using (var db = UnitWork.CreateContext())
{
ChangeDetectionResp changeDetectionResp = new ChangeDetectionResp();
var info = await db.Lasa_ChangeDetection.GetByIdAsync(id);
if (info != null)
{
changeDetectionResp = info.MapTo<ChangeDetectionResp>();
changeDetectionResp.AiAchievementDetailList = await db.LasaAiAchievementDetail.AsQueryable().Where(r => r.AiAchievementId == info.AiAchievementId).ToListAsync();
}
return new Response<ChangeDetectionResp>
{
Result = changeDetectionResp,
Message = "获取数据成功"
};
}
}
#endregion
}
}

@ -483,6 +483,7 @@ namespace OpenAuth.App.ServiceApp
task.ScheduledEndTime = x.AddMilliseconds(task.PlanExecuteDuration);
}
await db.LasaTask.UpdateAsync(task);
// 调用飞行任务
await ExecuteFlyTask(task.Id);
}
@ -2722,7 +2723,7 @@ namespace OpenAuth.App.ServiceApp
{
var taskTemp = await Repository.ChangeRepository<SugarRepositiry<LasaTask>>()
.AsQueryable()
.Where(r => r.AIInspection == "false")
.Where(r => r.AIInspection == "true")
.FirstAsync();
if (taskTemp == null)
{
@ -2763,5 +2764,27 @@ namespace OpenAuth.App.ServiceApp
Result = true
};
}
public async Task<Response<dynamic>> GetDockInfoByUavSn(string uavSn)
{
var dockInfo = await Repository.ChangeRepository<SugarRepositiry<LasaDronePort>>()
.AsQueryable().LeftJoin<LasaUav>((a, b) => a.Id == b.PId)
.Where((a, b) => b.Sn == uavSn)
.FirstAsync();
if (dockInfo != null)
{
return new Response<dynamic>
{
Result = dockInfo.Sn,
Message = "查询成功"
};
}
return new Response<dynamic>
{
Result = null,
Message = "无相关信息"
};
}
}
}

@ -0,0 +1,28 @@
using OpenAuth.Repository.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenAuth.App.ServiceApp.Response
{
public class ChangeDetectionResp
{
public string Id { get; set; }
public string Title { get; set; }
public string FirstId { get; set; }
public string FirstName { get; set; }
public string SecondId { get; set; }
public string SecondName { get; set; }
public DateTime? CreateTime { get; set; }
public long CreateId { get; set; }
public string AiAchievementId { get; set; }
public bool IsFinish { get; set; }
public List<LasaAiAchievementDetail> AiAchievementDetailList { get; set; }
}
}

@ -35,7 +35,7 @@ public class ConfigSubscribe : IJob
private object _dockUploadFileLocker = new();
private readonly ILogger<ConfigSubscribe> _logger;
private readonly ConcurrentDictionary<string, DateTime> _processedMessages = new();
private readonly ConcurrentDictionary<string, string> liveInfo = new();
private readonly ConcurrentDictionary<string, string> _liveInfo = new();
private readonly TimeSpan _deduplicationWindow = TimeSpan.FromMinutes(1);
public ConfigSubscribe(MqttClientManager mqttClientManager, ISqlSugarClient sqlSugarClient,
@ -83,19 +83,7 @@ public class ConfigSubscribe : IJob
private async Task HandleTopic(MqttApplicationMessageReceivedEventArgs args, string topic,
string message)
{
/*
thing/product/{device_sn}/osd properties
thing/product/{device_sn}/state properties
thing/product/{gateway_sn}/services_reply service 线
thing/product/{gateway_sn}/events
SD
thing/product/{gateway_sn}/requests
sys/product/{gateway_sn}/status 线
thing/product/{gateway_sn}/property/set_reply
thing/product/{gateway_sn}/drc/up DRC */
// 序列号提取
var sn = topic.Split("/")[2];
var tempStr = topic.Replace(sn, "*");
//Console.WriteLine($"成功调用主题 [{topic}] 的消息: {message}");
@ -106,10 +94,11 @@ public class ConfigSubscribe : IJob
//_logger.LogInformation($"主题:{topic}\n消息{message}");
long code = 0;
// rtmp://175.27.168.120:6019/live/
var rtmp = "rtmp://box.wisestcity.com:1935/live/7";
//var rtmp = "rtmp://175.27.168.120:6019/live/7";
//var rtmp = "rtmp://box.wisestcity.com:1935/live/7";
var rtmp = "rtmp://175.27.168.120:6019/live/7";
switch (tempStr)
{
// 目前主要处理了获取航线文件及临时凭证上传
case "thing/product/*/requests":
switch (method)
{
@ -149,7 +138,6 @@ public class ConfigSubscribe : IJob
}
}
};
// thing/product/{gateway_sn}/requests_reply
var tempTopic = $"thing/product/{sn}/requests_reply";
await _mqttClientManager.PublishAsync(tempTopic,
JsonConvert.SerializeObject(storageConfigRequest));
@ -205,6 +193,7 @@ public class ConfigSubscribe : IJob
}
break;
// 主要处理了文件回传及航线进度
case "thing/product/*/events":
switch (method)
{
@ -552,7 +541,7 @@ public class ConfigSubscribe : IJob
var waylineMissionState = (int)data.output.ext.wayline_mission_state;
_logger.LogDebug("航线进度未跳过处理");
code = data.result; // result
var taskAssign1 = _manageApp.GetTaskAssignByFlightId(flightId1);
// 处理航线进度 ,也有可能是失败
if (code != 0)
@ -592,7 +581,6 @@ public class ConfigSubscribe : IJob
}
else
{
// 航线成功
if (waylineMissionState.Equals(9)) // 航结结束,更新任务状态
{
@ -626,6 +614,7 @@ public class ConfigSubscribe : IJob
};
await _sqlSugarClient.Updateable(record).IgnoreNullColumns().ExecuteCommandAsync();
}
var step = (int)data.output.progress.current_step;
_logger.LogDebug($"航线进度:{waylineMissionState} {step} {message}");
if (step.Equals(25)) // todo 关于会接收到不同消息问题,如何处理
@ -639,12 +628,15 @@ public class ConfigSubscribe : IJob
_logger.LogInformation("跳过处理");
break;
}
var task = await _sqlSugarClient.Queryable<LasaTask>()
.FirstAsync(y => y.Id == taskAssign1.TaskId);
if (task != null && !string.IsNullOrEmpty(task.AIInspection) &&
task.AIInspection.Equals("true") && string.IsNullOrEmpty(task.PushUrl))
{
_logger.LogDebug("执行AI 智能巡检。。。。。");
var cameraIndex = "99-0-0";
// todo 查询获取
var uavSn = "1581F8HGX254V00A0BUY";
//var rtmp = "rtmp://box.wisestcity.com:1935/live/7";
var bid = Guid.NewGuid().ToString();
var tid = Guid.NewGuid().ToString();
@ -656,7 +648,7 @@ public class ConfigSubscribe : IJob
""data"": {{
""url_type"": 1,
""url"": ""{rtmp}"",
""video_id"": ""1581F8HGX254V00A0BUY/99-0-0/normal-0"",
""video_id"": ""{uavSn}/{cameraIndex}/normal-0"",
""video_quality"": 3
}}
}}";
@ -664,10 +656,9 @@ public class ConfigSubscribe : IJob
var topicRequest = $"thing/product/{sn}/services";
// 开启直播
await _mqttClientManager.PublishAsync(topicRequest, param);
liveInfo[$"{tid}{bid}"] = taskAssign1.TaskId;
_liveInfo[$"{tid}{bid}"] = taskAssign1.TaskId;
}
}
}
/*if (result.need_reply.Equals(1))
@ -703,9 +694,6 @@ public class ConfigSubscribe : IJob
}
break;
// 任务资源处理
// 航线进度处理
// 任务取消 thing/product/*/services_reply
case "thing/product/*/services_reply":
switch (method)
{
@ -714,13 +702,14 @@ public class ConfigSubscribe : IJob
{
break;
}
// 已验证tid bid 是相同的
// 开启直播成功调用ai model
_logger.LogDebug($"开启直播成功 {message}");
// 关于直播是否开启成功
// 取得taskid 然后从liveInfo中移除
var tempTaskId = liveInfo[$"{result.tid}{result.bid}"];
liveInfo.TryRemove($"{result.tid}{result.bid}", out _);
var tempTaskId = _liveInfo[$"{result.tid}{result.bid}"];
_liveInfo.TryRemove($"{result.tid}{result.bid}", out _);
var req = new CallAiModel { TaskId = tempTaskId, RtmpUrl = rtmp };
await _manageApp.CallAiModel(req);
break;

@ -7,16 +7,13 @@ public class LasaAiAchievementDetail
{
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public string Id { get; set; }
public string Image { get; set; }
[SugarColumn(ColumnName = "Image")] public string Image { get; set; }
[SugarColumn(ColumnName = "AiAchievementId")]
public string AiAchievementId { get; set; }
[SugarColumn(ColumnName = "Lng")]
public double Lng { get; set; }
[SugarColumn(ColumnName = "Lat")]
public double Lat { get; set; }
public string GroupId { get; set; }
public int CompareIndex { get; set; }
public int CompareIndex { get; set; }
public int CompareCount { get; set; }
}

@ -27,5 +27,6 @@ namespace OpenAuth.Repository.Domain
public DateTime? CreateTime { get; set; }
public long CreateId { get; set; }
public string AiAchievementId { get; set; }
public bool IsFinish { get; set; }
}
}

@ -4,6 +4,7 @@ using Infrastructure.CloudSdk.minio;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.ServiceApp;
using OpenAuth.App.ServiceApp.Response;
using OpenAuth.Repository.Domain;
using System.Net.Http;
@ -27,7 +28,6 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> AddAlgorithmsRepository(LasaAlgorithmsRepository info)
{
var result = new Response<bool>();
@ -48,7 +48,6 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> UpdateAlgorithmsRepository(LasaAlgorithmsRepository info)
{
var result = new Response<bool>();
@ -69,7 +68,6 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> DeleteAlgorithmsRepository(string id)
{
var result = new Response<bool>();
@ -91,7 +89,6 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// <param name="limit"></param>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<Response<PageInfo<List<LasaAlgorithmsRepository>>>> GetAlgorithmsRepositoryList(int page, int limit, string key)
{
var result = new Response<PageInfo<List<LasaAlgorithmsRepository>>>();
@ -116,13 +113,12 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// <param name="key"></param>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<Response<PageInfo<List<Lasa_ChangeDetection>>>> GetChangeDetectionPageList(int page, int limit, string key)
public async Task<Response<PageInfo<List<Lasa_ChangeDetection>>>> GetChangeDetectionPageList(int page, int limit, string key, DateTime startTime, DateTime endTime)
{
var result = new Response<PageInfo<List<Lasa_ChangeDetection>>>();
try
{
result = await _app.GetChangeDetectionPageList(page, limit, key);
result = await _app.GetChangeDetectionPageList(page, limit, key, startTime, endTime);
}
catch (Exception ex)
{
@ -137,7 +133,6 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<string>> AddChangeDetection(Lasa_ChangeDetection info)
{
var result = new Response<string>();
@ -158,7 +153,6 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> DeleteChangeDetection(string id)
{
var result = new Response<bool>();
@ -173,6 +167,26 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
}
return result;
}
/// <summary>
/// 检测详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public async Task<Response<ChangeDetectionResp>> GetChangeDetectionById(string id)
{
var result = new Response<ChangeDetectionResp>();
try
{
result = await _app.GetChangeDetectionById(id);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.Message;
}
return result;
}
#endregion
}
}

@ -223,8 +223,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// </summary>
/// <param name="firstId"></param>
/// <param name="secondId"></param>
/// <param name="cdId"></param>
[HttpPost]
[AllowAnonymous]
public async Task<Response<string>> BehaviorAlarm(string firstId, string secondId, string cdId)
{
var mq = await RabbitMqSender.CreateAsync("123.132.248.154", 9103, "DHCloudg1", "Cloud0#4fCraQrm");
@ -233,6 +233,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
await mq.SendAsync("event.capturePic.1.sdhc04", JsonConvert.SerializeObject(data));
}
await _app.UpdateState(cdId);
return new Response<string>()
{
Code = 200,

@ -925,5 +925,16 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
return await _app.GetLastHandFlyTask();
}
/// <summary>
/// 获取无人机 dock 信息
/// </summary>
/// <param name="uavSn"></param>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<Response<dynamic>> GetDockInfoByUavSn(string uavSn)
{
return await _app.GetDockInfoByUavSn(uavSn);
}
}
}

@ -1,16 +1,18 @@
using OpenAuth.App.ServiceApp.DroneDocking;
using Autofac;
using OpenAuth.App.ServiceApp.DroneDocking;
namespace OpenAuth.WebApi.SystemTask;
public class DelayedExecutionService : BackgroundService
{
private readonly ILogger<DelayedExecutionService> _logger;
private readonly DroneDockApp _droneDockApp;
private readonly ILifetimeScope _lifetimeScope;
public DelayedExecutionService(ILogger<DelayedExecutionService> logger, DroneDockApp droneDockApp)
public DelayedExecutionService(ILogger<DelayedExecutionService> logger, ILifetimeScope lifetimeScope)
{
_logger = logger;
_droneDockApp = droneDockApp;
//_droneDockApp = droneDockApp;
_lifetimeScope = lifetimeScope;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@ -41,7 +43,22 @@ public class DelayedExecutionService : BackgroundService
private async Task PerformDelayedTask()
{
await _droneDockApp.ReportDroneStatus();
await using (var scope = _lifetimeScope.BeginLifetimeScope())
{
// 2. 从子作用域中解析 AppService 实例InstancePerLifetimeScope 服务)
var appService = scope.Resolve<DroneDockApp>();
try
{
// 3. 调用 app 服务类的方法
await appService.ReportDroneStatus();
_logger.LogInformation("ReportDroneStatus 方法执行成功");
}
catch (Exception ex)
{
_logger.LogError(ex, "ReportDroneStatus 方法执行失败");
}
} // 4. 子作用域释放AppService 及内部资源(如数据库连接)自动释放
await Task.CompletedTask;
}
}
Loading…
Cancel
Save