diff --git a/Infrastructure/Cache/RedisCacheContext.cs b/Infrastructure/Cache/RedisCacheContext.cs
index ceedd6d..ab88fd4 100644
--- a/Infrastructure/Cache/RedisCacheContext.cs
+++ b/Infrastructure/Cache/RedisCacheContext.cs
@@ -54,10 +54,41 @@ namespace Infrastructure.Cache
{
return iDatabase.KeyDelete(key);
}
-
+ ///
+ /// HSET - 异步设置哈希表中的多个字段。
+ ///
+ ///
+ ///
+ ///
+ public void HashSetAsync(RedisKey key, HashEntry[] hashFields, CommandFlags flags = CommandFlags.None)
+ {
+ iDatabase.HashSetAsync(key, hashFields, CommandFlags.None);
+ }
+ ///
+ /// HGETALL - 异步获取哈希表中的所有字段和值。
+ ///
+ ///
+ ///
+ ///
+ public Task HashGetAllAsync(RedisKey key, CommandFlags flags = CommandFlags.None)
+ {
+ return iDatabase.HashGetAllAsync(key, CommandFlags.None);
+ }
public override Task Lock(string id, Func> func, string key = "hc")
{
return func(id);
}
+ public Task SetMembersAsync(RedisKey key, CommandFlags flags = CommandFlags.None)
+ {
+ return iDatabase.SetMembersAsync(key, CommandFlags.None);
+ }
+ public Task SetAddAsync(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None)
+ {
+ return iDatabase.SetAddAsync(key, value, CommandFlags.None);
+ }
+ public Task SetRemoveAsync(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None)
+ {
+ return iDatabase.SetRemoveAsync(key, value, CommandFlags.None);
+ }
}
}
\ No newline at end of file
diff --git a/OpenAuth.App/ServiceApp/DroneDockManage/AirportMaintenanceApp.cs b/OpenAuth.App/ServiceApp/DroneDockManage/AirportMaintenanceApp.cs
new file mode 100644
index 0000000..b0eedb1
--- /dev/null
+++ b/OpenAuth.App/ServiceApp/DroneDockManage/AirportMaintenanceApp.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenAuth.App.ServiceApp.DroneDockManage
+{
+ public class AirportMaintenanceApp
+ {
+ }
+}
diff --git a/OpenAuth.App/ServiceApp/DroneDockManage/Response/MqttClientResp.cs b/OpenAuth.App/ServiceApp/DroneDockManage/Response/MqttClientResp.cs
new file mode 100644
index 0000000..bd41f07
--- /dev/null
+++ b/OpenAuth.App/ServiceApp/DroneDockManage/Response/MqttClientResp.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenAuth.App.ServiceApp.DroneDockManage.Response
+{
+ public class MqttClientResp
+ {
+ ///
+ /// 客户端ID
+ ///
+ public string ClientId { get; set; }
+ ///
+ /// 用户id
+ ///
+ public string UserId { get; set; }
+ ///
+ /// 用户名
+ ///
+ public string UserName { get; set; }
+ ///
+ /// 连接时间
+ ///
+ public DateTime ConnectTime { get; set; }
+ ///
+ /// 是否控制
+ ///
+ public bool IsLock { get; set; }
+
+ }
+}
diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/DroneDockManage/AirportMaintenanceController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/DroneDockManage/AirportMaintenanceController.cs
new file mode 100644
index 0000000..04ee357
--- /dev/null
+++ b/OpenAuth.WebApi/Controllers/ServiceControllers/DroneDockManage/AirportMaintenanceController.cs
@@ -0,0 +1,150 @@
+using Infrastructure;
+using Infrastructure.Cache;
+using Microsoft.AspNetCore.Mvc;
+using OpenAuth.App.ServiceApp.DroneDockManage;
+using OpenAuth.App.ServiceApp.DroneDockManage.Response;
+using StackExchange.Redis;
+
+namespace OpenAuth.WebApi.Controllers.ServiceControllers.DroneDockManage
+{
+ ///
+ /// 机场运维
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class AirportMaintenanceController : ControllerBase
+ {
+ private readonly AirportMaintenanceApp _app;
+ private readonly RedisCacheContext _cache;
+ private readonly HttpClient _httpClient;
+
+ public AirportMaintenanceController(AirportMaintenanceApp app,
+ RedisCacheContext cache, HttpClient httpClient)
+ {
+ _app = app;
+ _cache = cache;
+ _httpClient = httpClient;
+ }
+ #region redis 多用户控制
+
+ ///
+ /// 添加修改mqtt客户端信息
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task> AddOrUpdateRedisUser(MqttClientResp info)
+ {
+ var result = new Response();
+ try
+ {
+ var clientKey = $"client:{info.UserId}";
+ string lockSetKey = "locked_users";
+
+ // 查询所有锁定用户
+ var existingLocked = await _cache.SetMembersAsync(lockSetKey);
+
+ // 如果有锁定用户,并且锁定的用户不是当前用户,则拒绝
+ if (existingLocked.Length > 0 && info.IsLock == true)
+ {
+ bool isCurrentUserLocked = existingLocked.Any(u => u == info.UserId);
+ 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.UserId);
+ }
+ else
+ {
+ await _cache.SetRemoveAsync(lockSetKey, info.UserId);
+ }
+
+ result.Result = true;
+ }
+ catch (Exception ex)
+ {
+ result.Code = 500;
+ result.Message = ex.Message;
+ }
+
+ return result;
+ }
+
+ ///
+ /// 获取当前用户mqtt客户端信息
+ ///
+ ///
+ ///
+ [HttpGet]
+ public async Task> GetRedisUser(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;
+ }
+
+ private MqttClientResp ParseClient(HashEntry[] entries)
+ {
+ if (entries == null || entries.Length == 0)
+ return null;
+ var dict = entries.ToDictionary(e => e.Name.ToString(), e => e.Value.ToString());
+ return new MqttClientResp
+ {
+ ClientId = dict["ClientId"],
+ UserId = dict["UserId"],
+ UserName = dict["UserName"],
+ ConnectTime = DateTime.Parse(dict["ConnectTime"]),
+ IsLock = bool.Parse(dict["IsLock"])
+ };
+ }
+
+ ///
+ /// 获取所有锁定的用户客户端信息
+ ///
+ ///
+ [HttpGet]
+ public async Task> GetLockedClients()
+ {
+ var userIds = await _cache.SetMembersAsync("locked_users");
+
+ 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;
+ }
+
+ #endregion
+ }
+}
diff --git a/OpenAuth.WebApi/appsettings.Production.json b/OpenAuth.WebApi/appsettings.Production.json
index 0f7038d..e46a1c0 100644
--- a/OpenAuth.WebApi/appsettings.Production.json
+++ b/OpenAuth.WebApi/appsettings.Production.json
@@ -18,10 +18,9 @@
},
"UploadPath": "", //附件上传的路径,如果为空则保存在站点根目录
"RedisConf": {
- "Conn": "175.27.168.120:6050,password=HopetryRedis1406",
- //"Conn": "127.0.0.1:6379,password=123456",
- "Database": 5
- },
+ "Conn": "123.132.248.154:9253,password=HopetryRedis1406",
+ "Database": 1
+ }, //redis配置
"HttpHost": "http://*:10010 ", //启动绑定地址及端口
"SYSTEM_USERPWD": "123456"
},
diff --git a/OpenAuth.WebApi/appsettings.json b/OpenAuth.WebApi/appsettings.json
index c9485ca..6463cc5 100644
--- a/OpenAuth.WebApi/appsettings.json
+++ b/OpenAuth.WebApi/appsettings.json
@@ -22,15 +22,15 @@
"UploadPath": "",
//附件上传的路径,如果为空则保存在站点根目录
"RedisConf": {
- "Conn": "175.27.168.120:6050,password=HopetryRedis1406",
+ "Conn": "192.168.10.163:6379,password=123456",
//"Conn": "127.0.0.1:6379,password=123456",
- "Database": 5
+ "Database": 7
},
//redis配置
"HttpHost": "http://*:10070 ",
//启动绑定地址及端口
"SYSTEM_USERPWD": "123456",
- "ASECode": "hc",
+ "ASECode": "hc",
"TopAreaCode": "371300",
//大屏最高行政区划编码
"SchemeCode": "0000001",
@@ -67,6 +67,12 @@
"TiffStoreNamePrefix": "tiff_store",
"TiffDir": "E:/tiff"
},
+ "MQTT": {
+ "Server": "175.27.168.120",
+ "Port": 6011,
+ "UserName": "sdhc",
+ "Password": ""
+ },
"FlyImageDir": "e:/fly",
"WebSocket": "ws://192.168.10.106:5698/ws"
}