Merge remote-tracking branch 'origin/main'

main
陈伟 2025-11-29 10:52:02 +08:00
commit 6337953876
8 changed files with 331 additions and 20 deletions

View File

@ -1,22 +1,23 @@
using OpenAuth.App.BaseApp.Base;
using OpenAuth.Repository.Domain;
using DocumentFormat.OpenXml.EMMA;
using DocumentFormat.OpenXml.Math;
using Infrastructure;
using Infrastructure.CloudSdk.minio;
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using NPOI.SS.Formula.Functions;
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 OpenAuth.App.Interface;
using SqlSugar;
using Infrastructure;
using OpenAuth.App.ServiceApp.Response;
using DocumentFormat.OpenXml.EMMA;
using NPOI.SS.Formula.Functions;
using Infrastructure.Extensions;
using DocumentFormat.OpenXml.Math;
using Microsoft.Extensions.Configuration;
using Infrastructure.CloudSdk.minio;
using Microsoft.AspNetCore.Http;
namespace OpenAuth.App.ServiceApp
{
@ -405,10 +406,47 @@ namespace OpenAuth.App.ServiceApp
};
}
}
/// <summary>
/// 添加无人机操作日志
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public async Task<bool> AddOperationLog(LasaControlOperation info)
{
using (var db = UnitWork.CreateContext())
{
var flag = await db.LasaControlOperation.InsertAsync(info);
if (db.Commit())
return true;
else
return false;
}
}
/// <summary>
/// 获取无人机操作日志
/// </summary>
/// <param name="sn"></param>
/// <param name="page"></param>
/// <param name="limit"></param>
/// <returns></returns>
public async Task<Response<PageInfo<List<LasaControlOperation>>>> GetOperationLogList(string taskid, int page, int limit)
{
RefAsync<int> totalCount = 0;
using (var db = UnitWork.CreateContext())
{
var list = await db.LasaControlOperation.AsQueryable()
.Where(x => x.TaskId == taskid)
.OrderBy(x => x.CreateTime, OrderByType.Asc)
.ToPageListAsync(page, limit, totalCount);
return new Response<PageInfo<List<LasaControlOperation>>>
{
Result = new PageInfo<List<LasaControlOperation>> { Items = list, Total = totalCount }
};
}
}
#endregion
public async Task<Response<PageInfo<List<LasaMediaFile>>>> GetMediaFile(string flightId,string taskId, string airId, string device,
public async Task<Response<PageInfo<List<LasaMediaFile>>>> GetMediaFile(string flightId, string taskId, string airId, string device,
int? type, string picname, DateTime? startTime, DateTime? endTime, int page, int limit, string parentKey, int? objectKeyExist)
{
RefAsync<int> totalCount = 0;
@ -511,5 +549,47 @@ namespace OpenAuth.App.ServiceApp
await _client.Ado.ExecuteCommandAsync(sql);
return new Response<string> { Result = "修改成功!" };
}
#region 天气阻飞
//天气预报和是否有人在操作
//public async Task<Response<bool>> IsCanFly(string sn, string dock, string address = "兰山")
//{
// var rainThreshforecast = 3; // 天气预报雨量
// var windSpeedThresh = 12;// 机场设定雨量
// double weatherWindSpeedforecast = 0; // 天气预报风速
// double weatherWindSpeedThre = 12;// 机场设定风速
// switch (dock)
// {
// case "Dock":
// weatherWindSpeedThre = 12;
// break;
// case "Dock 2":
// weatherWindSpeedThre = 8;
// break;
// case "Dock 3":
// weatherWindSpeedThre = 8;
// break;
// }
// using (var httpClient = new HttpClient())
// {
// var response = await httpClient.GetAsync(
// $"http://v1.yiketianqi.com/api?unescape=1&version=v61&appid=84261622&appsecret=k0WPY4Cx&city={address}");
// if (response.IsSuccessStatusCode)
// {
// var content = await response.Content.ReadAsStringAsync();
// var weather = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(content);
// var winMeterStr =
// weather.GetValue("win_meter")?.Value<string>(); //风速
// if (!string.IsNullOrEmpty(winMeterStr))
// {
// weatherWindSpeedforecast = int.Parse(winMeterStr.Replace("km/h", "")) / 3.6;
// }
// }
// }
//}
#endregion
}
}

View File

@ -25,6 +25,10 @@ namespace OpenAuth.App.ServiceApp.Response
/// </summary>
public DateTime ConnectTime { get; set; }
/// <summary>
/// 设备sn
/// </summary>
public string DeviceSn { get; set; }
/// <summary>
/// 是否控制
/// </summary>
public bool IsLock { get; set; }

View File

@ -0,0 +1,54 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenAuth.Repository.Domain
{
[SugarTable("lasa_control_operation")]
public class LasaControlOperation
{
/// <summary>
/// Desc:标识
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public string Id { get; set; }
/// <summary>
/// Desc:专题
/// Default:
/// Nullable:False
/// </summary>
public string DeviceSn { get; set; }
/// <summary>
/// Desc:任务id
/// Default:
/// Nullable:False
/// </summary>
public string TaskId { get; set; }
/// <summary>
/// Desc:创建时间
/// Default:
/// Nullable:True
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
public long CreateId { get; set; }
/// <summary>
/// Desc:数据
/// Default:
/// Nullable:True
/// </summary>
public string Data { get; set; }
}
}

View File

@ -87,6 +87,7 @@ namespace OpenAuth.Repository
public SugarRepositiry<LasaAiAchievement> LasaAiAchievement { get; set; }
public SugarRepositiry<LasaAiAchievementDetail> LasaAiAchievementDetail { get; set; }
public SugarRepositiry<Lasa_ChangeDetection> Lasa_ChangeDetection { get; set; }
public SugarRepositiry<LasaControlOperation> LasaControlOperation { get; set; }
public SugarRepositiry<DbfineInfo> DbfineInfo { get; set; }
public SugarRepositiry<SysOpenJob> SysOpenJob { get; set; }

View File

@ -632,6 +632,115 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return result;
}
/// <summary>
/// 添加修改mqtt客户端信息 设备为主
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> AddOrUpdateRedisDevice(MqttClientResp info)
{
var result = new Response<bool>();
try
{
var clientKey = $"client:{info.DeviceSn}";
string lockSetKey = "locked_devices";
// 查询所有锁定用户
var existingLocked = await _cache.SetMembersAsync(lockSetKey);
// 如果设备锁定,并且锁定的用户不是当前用户,则拒绝
if (existingLocked.Length > 0 && info.IsLock == true)
{
bool isCurrentUserLocked = existingLocked.Any(u => u == info.DeviceSn);
if (isCurrentUserLocked)
{
result.Code = 400;
result.Message = "已有其他用户处于锁定状态,不能添加新的锁定用户。";
result.Result = false;
return result;
}
}
// 存客户端信息
_cache.HashSetAsync(clientKey, new HashEntry[]
{
new("ClientId", info.ClientId),
new("UserId", info.UserId),
new("UserName", info.UserName),
new("ConnectTime", info.ConnectTime.ToString("O")),
new("IsLock", info.IsLock ? "true" : "false")
});
if (info.IsLock)
{
await _cache.SetAddAsync(lockSetKey, info.DeviceSn);
}
else
{
await _cache.SetRemoveAsync(lockSetKey, info.DeviceSn);
}
result.Result = true;
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.Message;
}
return result;
}
/// <summary>
/// 获取当前用户mqtt客户端信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<Response<MqttClientResp>> GetRedisDevice(string id)
{
var result = new Response<MqttClientResp>();
try
{
result.Result = ParseClient(await _cache.HashGetAllAsync($"client:{id}"));
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.Message;
}
return result;
}
/// <summary>
/// 获取所有锁定的用户客户端信息
/// </summary>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<List<MqttClientResp>> GetLockedDeviceClients()
{
var userIds = await _cache.SetMembersAsync("locked_devices");
var result = new List<MqttClientResp>();
foreach (var userId in userIds)
{
var entries = await _cache.HashGetAllAsync($"client:{userId}");
if (entries.Length > 0)
result.Add(ParseClient(entries));
}
return result;
}
//只有天气阻飞
//public async Task<Response<bool>> IsCanFly(string address,string sn,string dock)
//{
//}
#endregion
#region 获取告警信息
@ -695,19 +804,42 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return result;
}
/// <summary>
/// 根据任务获取无人机操作日志
/// </summary>
/// <param name="taskid">任务id</param>
/// <param name="page"></param>
/// <param name="limit"></param>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<Response<PageInfo<List<LasaControlOperation>>>> GetOperationLogList(string taskid, int page, int limit)
{
var result = new Response<PageInfo<List<LasaControlOperation>>>();
try
{
result = await _app.GetOperationLogList(taskid, page, limit);
}
catch (Exception ex)
{
result.Code = 500;
result.Message = ex.Message;
}
return result;
}
#endregion
[HttpGet]
public async Task<Response<PageInfo<List<LasaMediaFile>>>> GetMediaFile(string flightId,string taskId, string airId,
public async Task<Response<PageInfo<List<LasaMediaFile>>>> GetMediaFile(string flightId, string taskId, string airId,
string device, int? type, string picname, DateTime startTime, DateTime endTime, int page, int limit,
string parentKey, int? objectKeyExist)
{
var result = new Response<PageInfo<List<LasaMediaFile>>>();
try
{
result = await _app.GetMediaFile(flightId,taskId, airId, device,type, picname, startTime, endTime, page, limit,
result = await _app.GetMediaFile(flightId, taskId, airId, device, type, picname, startTime, endTime, page, limit,
parentKey, objectKeyExist);
}
catch (Exception ex)

View File

@ -81,7 +81,8 @@ namespace OpenAuth.WebApi.Model.mqtt
"thing/product/+/events",
"thing/product/+/requests",
"thing/product/+/osd",
"sys/product/+/status"
"sys/product/+/status",
"thing/product/+/control-operation"
};
await _mqttCenter.SubscribeAsync(topicList);
}

View File

@ -0,0 +1,39 @@
using Infrastructure.Cache;
using Infrastructure.CloudSdk.mqttmessagecenter;
using OpenAuth.App.ServiceApp;
using OpenAuth.Repository.Domain;
using System.Text.Json.Nodes;
namespace OpenAuth.WebApi.Model.mqtt
{
public class ThingOperationHandler : IMqttMessageHandler
{
AirportMaintenanceApp _app;
private readonly ICacheContext _cache;
public ThingOperationHandler(AirportMaintenanceApp app, ICacheContext cache)
{
_app = app;
_cache = cache;
}
public bool CanHandle(string topic)
{
return topic.Contains("/control-operation");
}
public async Task HandleAsync(string topic, string payload)
{
var root = JsonNode.Parse(payload)?.AsObject();
await _app.AddOperationLog(new LasaControlOperation
{
Id = Guid.NewGuid().ToString(),
DeviceSn = root["DeviceSn"]?.ToString() ?? "",
TaskId = root["TaskId"]?.ToString() ?? "",
CreateTime = DateTime.Now,
CreateId = long.Parse((root["CreateId"]?.ToString() ?? "0")),
Data = root["Data"]?.ToString() ?? "",
});
// 自定义处理逻辑
//return Task.CompletedTask;
}
}
}

View File

@ -181,7 +181,7 @@ namespace OpenAuth.WebApi
services.AddSingleton<IMqttMessageHandler, ThingServiceHandler>();
services.AddSingleton<IMqttMessageHandler, ThingOsdHandler>();
services.AddSingleton<IMqttMessageHandler, ThingEventHandler>();
//services.AddSingleton<IMqttMessageHandler, ThingDrcHandler>();
services.AddSingleton<IMqttMessageHandler, ThingOperationHandler>();
services.AddSingleton<IMqttMessageHandler, ThingStatusHandler>();
services.AddHostedService<MqttHostedService>();
#endregion
@ -344,7 +344,7 @@ namespace OpenAuth.WebApi
#endregion
#region Quartz
services.AddHostedService<QuartzService>();
//services.AddHostedService<QuartzService>();
#endregion