diff --git a/OpenAuth.App/ServiceApp/AirportMaintenanceApp.cs b/OpenAuth.App/ServiceApp/AirportMaintenanceApp.cs index d29e168..8c5925e 100644 --- a/OpenAuth.App/ServiceApp/AirportMaintenanceApp.cs +++ b/OpenAuth.App/ServiceApp/AirportMaintenanceApp.cs @@ -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 { @@ -445,7 +446,7 @@ namespace OpenAuth.App.ServiceApp } #endregion - public async Task>>> GetMediaFile(string flightId,string taskId, string airId, string device, + public async Task>>> 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 totalCount = 0; @@ -548,5 +549,47 @@ namespace OpenAuth.App.ServiceApp await _client.Ado.ExecuteCommandAsync(sql); return new Response { Result = "修改成功!" }; } + + + #region 天气阻飞 + //天气预报和是否有人在操作 + //public async Task> 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(content); + // var winMeterStr = + // weather.GetValue("win_meter")?.Value(); //风速 + // if (!string.IsNullOrEmpty(winMeterStr)) + // { + // weatherWindSpeedforecast = int.Parse(winMeterStr.Replace("km/h", "")) / 3.6; + // } + // } + // } + + + //} + #endregion } } \ No newline at end of file diff --git a/OpenAuth.App/ServiceApp/Response/MqttClientResp.cs b/OpenAuth.App/ServiceApp/Response/MqttClientResp.cs index 22603af..4a45b5a 100644 --- a/OpenAuth.App/ServiceApp/Response/MqttClientResp.cs +++ b/OpenAuth.App/ServiceApp/Response/MqttClientResp.cs @@ -25,6 +25,10 @@ namespace OpenAuth.App.ServiceApp.Response /// public DateTime ConnectTime { get; set; } /// + /// 设备sn + /// + public string DeviceSn { get; set; } + /// /// 是否控制 /// public bool IsLock { get; set; } diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs index 294a5dd..ee71166 100644 --- a/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs @@ -632,6 +632,115 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers return result; } + + /// + /// 添加修改mqtt客户端信息 设备为主 + /// + /// + /// + [HttpPost] + [AllowAnonymous] + public async Task> AddOrUpdateRedisDevice(MqttClientResp info) + { + var result = new Response(); + 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; + } + /// + /// 获取当前用户mqtt客户端信息 + /// + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task> GetRedisDevice(string id) + { + var result = new Response(); + try + { + result.Result = ParseClient(await _cache.HashGetAllAsync($"client:{id}")); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.Message; + } + + return result; + } + /// + /// 获取所有锁定的用户客户端信息 + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task> GetLockedDeviceClients() + { + var userIds = await _cache.SetMembersAsync("locked_devices"); + + var result = new List(); + + 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> IsCanFly(string address,string sn,string dock) + //{ + + //} #endregion #region 获取告警信息 diff --git a/OpenAuth.WebApi/Startup.cs b/OpenAuth.WebApi/Startup.cs index aa0c4e4..bfc1577 100644 --- a/OpenAuth.WebApi/Startup.cs +++ b/OpenAuth.WebApi/Startup.cs @@ -344,7 +344,7 @@ namespace OpenAuth.WebApi #endregion #region Quartz - services.AddHostedService(); + //services.AddHostedService(); #endregion