From f79fd58e3470548cbd099782c0a59ae8e701fc65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E4=BC=9F?= <421281095@qq.com>
Date: Fri, 13 Jun 2025 10:11:42 +0800
Subject: [PATCH 1/8] =?UTF-8?q?mqtt=E4=BC=98=E5=8C=96=EF=BC=9A=E5=AE=9E?=
=?UTF-8?q?=E7=8E=B0=E5=87=BA=E7=AB=99=E5=85=A5=E7=AB=99=EF=BC=8C=E4=BD=BF?=
=?UTF-8?q?=E7=94=A8=E4=B8=8D=E5=90=8Cmqtt=E5=AE=9E=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../CloudSdk/mqtt/MqttClientManager.cs | 28 +++++++++++++------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/Infrastructure/CloudSdk/mqtt/MqttClientManager.cs b/Infrastructure/CloudSdk/mqtt/MqttClientManager.cs
index 9617040..f6cffb9 100644
--- a/Infrastructure/CloudSdk/mqtt/MqttClientManager.cs
+++ b/Infrastructure/CloudSdk/mqtt/MqttClientManager.cs
@@ -7,12 +7,15 @@ namespace OpenAuth.WebApi;
public class MqttClientManager
{
- private IMqttClient _mqttClient;
+ private IMqttClient _outBoundClient;
+ private IMqttClient _inBoundClient;
+
public MqttClientManager()
{
var mqttFactory = new MqttFactory();
- _mqttClient = mqttFactory.CreateMqttClient();
+ _outBoundClient = mqttFactory.CreateMqttClient();
+ _inBoundClient = mqttFactory.CreateMqttClient();
// 创建配置构建器
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
@@ -40,25 +43,31 @@ public class MqttClientManager
///
public async Task ConnectAsync(string server, int port, string username = null, string password = null)
{
- var mqttClientOptions = new MqttClientOptionsBuilder()
- .WithClientId("client001")
+ var inboundOptions = new MqttClientOptionsBuilder()
+ .WithClientId(Guid.NewGuid() + "_inbound")
+ .WithTcpServer(server, port)
+ .WithCredentials(username, password)
+ .Build();
+ var outboundOptions = new MqttClientOptionsBuilder()
+ .WithClientId(Guid.NewGuid() + "_outbound")
.WithTcpServer(server, port)
.WithCredentials(username, password)
.Build();
- await _mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
+ await _outBoundClient.ConnectAsync(inboundOptions, CancellationToken.None);
+ await _inBoundClient.ConnectAsync(outboundOptions, CancellationToken.None);
}
public async Task SubscribeAsync(string topic,
Func handler)
{
- await _mqttClient.SubscribeAsync(topic, MqttQualityOfServiceLevel.AtLeastOnce, CancellationToken.None);
- _mqttClient.ApplicationMessageReceivedAsync += handler;
+ await _inBoundClient.SubscribeAsync(topic, MqttQualityOfServiceLevel.AtLeastOnce, CancellationToken.None);
+ _inBoundClient.ApplicationMessageReceivedAsync += handler;
}
public async Task UnsubscribeAsync(string topic)
{
- await _mqttClient.UnsubscribeAsync(topic, CancellationToken.None);
+ await _inBoundClient.UnsubscribeAsync(topic, CancellationToken.None);
}
///
@@ -72,8 +81,9 @@ public class MqttClientManager
var mqttMsg = new MqttApplicationMessageBuilder()
.WithTopic(topic)
.WithPayload(message)
+ // 级别 0 1 2
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce)
.Build();
- await _mqttClient.PublishAsync(mqttMsg, CancellationToken.None);
+ await _outBoundClient.PublishAsync(mqttMsg, CancellationToken.None);
}
}
\ No newline at end of file
From a957034cfa8a848efd8544d28aab8657badd585d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B4=81=20=E4=BB=BB?=
Date: Fri, 13 Jun 2025 11:39:52 +0800
Subject: [PATCH 2/8] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8?=
=?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=BD=92=E6=A1=A3?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
OpenAuth.App/ServiceApp/ManageApp.cs | 36 ++++++++++++++++---
.../ServiceControllers/ManageController.cs | 18 ++++++++--
2 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/OpenAuth.App/ServiceApp/ManageApp.cs b/OpenAuth.App/ServiceApp/ManageApp.cs
index 72b514a..4a4c66d 100644
--- a/OpenAuth.App/ServiceApp/ManageApp.cs
+++ b/OpenAuth.App/ServiceApp/ManageApp.cs
@@ -192,14 +192,23 @@ namespace OpenAuth.App.ServiceApp
///
///
///
- public async Task>> GetWorkspaceList(string key)
+ public async Task>> GetWorkspaceList(int isjoin,string key,int state,string order= "\"CreateTime\" desc")
{
RefAsync totalCount = 0;
using (var db = UnitWork.CreateContext())
{
+ var userid = _auth.GetCurrentUser().User.Id;
+ List ids=new List();
+ if (isjoin == 1)
+ {
+ ids=db.LasaSpaceUser.AsQueryable().Where(r=>r.UserId== userid)?.Select(r => r.WorkSpaceId).ToList();
+ }
var list = await db.LasaWorkspace.AsQueryable()
.WhereIF(!string.IsNullOrEmpty(key), a => a.WorkspaceName.Contains(key))
- .LeftJoin((a,u)=>a.CreateId==u.Id)
+ .WhereIF(state != 0, a => a.Sate == state)
+ .WhereIF(isjoin == 1, a => ids.Contains(a.Id))
+ .WhereIF(isjoin == 2, a => !ids.Contains(a.Id))
+ .LeftJoin((a, u) => a.CreateId == u.Id)
.Select((a, u) => new
{
a.Id,
@@ -209,9 +218,12 @@ namespace OpenAuth.App.ServiceApp
a.CreateTime,
a.CreateId,
u.Account,
- u.Name
- })
+ u.Name,
+ UserNames = SqlFunc.Subqueryable().Where(r => r.WorkSpaceId == a.Id).LeftJoin((r, s) => r.UserId == s.Id).SelectStringJoin((r, s) => s.Name, ",")
+ }).MergeTable()
+ .OrderBy(order)
.ToListAsync();
+
return new Response>
{
Result = list
@@ -374,6 +386,22 @@ namespace OpenAuth.App.ServiceApp
return new Response { Result = false, Message = "删除失败" };
}
}
+
+ //归档项目
+ public async Task> CompleteWorkspace(string id)
+ {
+ using (var db = UnitWork.CreateContext())
+ {
+ await db.LasaWorkspace.UpdateAsync(u => new LasaWorkspace
+ {
+ Sate = 2
+ }, u => u.Id == id);
+ if (db.Commit())
+ return new Response { Result = true, Message = "归档成功" };
+ else
+ return new Response { Result = false, Message = "归档失败" };
+ }
+ }
#endregion
public async Task ExecuteFlyTask(string taskId)
diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs
index de2c14f..5b97d6d 100644
--- a/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs
+++ b/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs
@@ -258,15 +258,18 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
/// 获取项目列表
///
- ///
+ /// 是否是已加入的项目(0全部,1加入,2未加入)
+ /// 项目名称筛选
+ /// 状态(0全部,1进行中,2已归档)
+ /// 排序
///
[HttpGet]
- public async Task>> GetWorkspaceList(string key)
+ public async Task>> GetWorkspaceList(int isjoin, string key, int state, string order = "\"CreateTime\" desc")
{
var result = new Response>();
try
{
- result = await _app.GetWorkspaceList(key);
+ result = await _app.GetWorkspaceList(isjoin,key,state,order);
}
catch (Exception ex)
{
@@ -307,6 +310,15 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return await _app.DeleteWorkspace(id);
}
+ ///
+ /// 归档项目
+ ///
+ ///
+ [HttpPost]
+ public async Task> CompleteWorkspace(string id)
+ {
+ return await _app.CompleteWorkspace(id);
+ }
///
/// 获取机场列表,添加项目使用
///
From d52b4aa45c8421595731a55ed2c059cb9d574dc0 Mon Sep 17 00:00:00 2001
From: lgd
Date: Fri, 13 Jun 2025 15:09:37 +0800
Subject: [PATCH 3/8] =?UTF-8?q?minio=E6=96=B9=E6=B3=95=E9=9B=86=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Infrastructure/CloudSdk/minio/MinioService.cs | 131 ++++++++++++++++++
Infrastructure/Infrastructure.csproj | 1 +
OpenAuth.WebApi/global.json | 33 +++++
3 files changed, 165 insertions(+)
create mode 100644 Infrastructure/CloudSdk/minio/MinioService.cs
create mode 100644 OpenAuth.WebApi/global.json
diff --git a/Infrastructure/CloudSdk/minio/MinioService.cs b/Infrastructure/CloudSdk/minio/MinioService.cs
new file mode 100644
index 0000000..d1e32ea
--- /dev/null
+++ b/Infrastructure/CloudSdk/minio/MinioService.cs
@@ -0,0 +1,131 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading.Tasks;
+using Minio.Exceptions;
+using Minio;
+using Microsoft.Extensions.Configuration;
+using Minio.DataModel.Args;
+using Minio.DataModel;
+
+namespace Infrastructure.CloudSdk.minio;
+public class MinioService
+{
+ private IMinioClient _minioClient;
+ public readonly string _bucketName = null;
+ public MinioService()
+ {
+ InitializeMinIOClient();
+ EnsureBucketExistsAsync(_bucketName).Wait();
+ }
+ private void InitializeMinIOClient()
+ {
+ var builder = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("global.json", optional: false, reloadOnChange: true);
+ // 构建配置
+ var config = builder.Build();
+
+ _minioClient = new MinioClient()
+ .WithEndpoint(config["Minio:Endpoint"])
+ .WithCredentials(config["Minio:AccessKey"], config["Minio:SecretKey"])
+ .Build();
+ }
+ ///
+ /// 创建存储桶(如果不存在)
+ ///
+ public async Task CreateBucketIfNotExists(string _bucketName)
+ {
+ var existsArgs = new BucketExistsArgs().WithBucket(_bucketName);
+ bool found = await _minioClient.BucketExistsAsync(existsArgs);
+ if (!found)
+ {
+
+ var makeArgs = new MakeBucketArgs().WithBucket(_bucketName);
+ await _minioClient.MakeBucketAsync(makeArgs);
+ Console.WriteLine($"Bucket {_bucketName} created.");
+ }
+ }
+ public async Task EnsureBucketExistsAsync(string bucketName)
+ {
+ var existsArgs = new BucketExistsArgs().WithBucket(bucketName);
+ var x = await _minioClient.BucketExistsAsync(existsArgs);
+ Console.WriteLine($" {bucketName} exist status: " + x);
+ // 如果存储桶不存在,则创建存储桶
+ if (!x)
+ {
+ var makeArgs = new MakeBucketArgs().WithBucket(bucketName);
+ await _minioClient.MakeBucketAsync(makeArgs);
+ }
+ }
+
+
+ ///
+ /// 下载文件
+ ///
+ public async Task DownLoadObject(string bucketName, string objectKey, string localDir, string objectETag,
+ CancellationToken token = default)
+ {
+ var index = objectKey.LastIndexOf("/", StringComparison.Ordinal);
+ if (index > 0)
+ {
+ var dir = Path.Combine(localDir, objectKey.Substring(0, index));
+ if (!Directory.Exists(dir))
+ {
+ Directory.CreateDirectory(dir);
+ }
+ }
+
+ var localPath = Path.Combine(localDir, objectKey.Replace('/', Path.DirectorySeparatorChar));
+ var getArgs = new GetObjectArgs()
+ .WithBucket(string.IsNullOrEmpty(bucketName) ? _bucketName : bucketName)
+ .WithObject(objectKey)
+ .WithFile(localPath);
+ var stat = await _minioClient.GetObjectAsync(getArgs, token);
+
+ }
+
+ ///
+ /// 列出所有对象
+ ///
+ public async Task> ListAllObject(string bucketName, string prefix, bool recursive,
+ CancellationToken token = default)
+ {
+ // Just list of objects
+ // Check whether 'mybucket' exists or not.
+ if (string.IsNullOrEmpty(bucketName))
+ {
+ bucketName = _bucketName;
+ }
+
+ var existsArgs = new BucketExistsArgs().WithBucket(bucketName);
+ var found = await _minioClient.BucketExistsAsync(existsArgs, token);
+ if (found)
+ {
+ var args = new ListObjectsArgs()
+ .WithBucket(bucketName)
+ .WithPrefix(prefix)
+ .WithRecursive(recursive);
+ return _minioClient.ListObjectsEnumAsync(args, token);
+ }
+
+ Console.WriteLine("mybucket does not exist");
+ throw new Exception("bucket not found");
+ }
+ ///
+ /// 删除文件
+ ///
+ public async Task DeleteFile(string objectName)
+ {
+ try
+ {
+ var deleteargs = new RemoveObjectArgs().WithBucket(_bucketName).WithObject(objectName);
+ await _minioClient.RemoveObjectAsync(deleteargs);
+ Console.WriteLine($"File {objectName} deleted.");
+ }
+ catch (MinioException ex)
+ {
+ Console.WriteLine($"MinIO Exception: {ex.Message}");
+ }
+ }
+}
diff --git a/Infrastructure/Infrastructure.csproj b/Infrastructure/Infrastructure.csproj
index 07ab002..8468633 100644
--- a/Infrastructure/Infrastructure.csproj
+++ b/Infrastructure/Infrastructure.csproj
@@ -17,6 +17,7 @@
+
diff --git a/OpenAuth.WebApi/global.json b/OpenAuth.WebApi/global.json
new file mode 100644
index 0000000..72e3f3e
--- /dev/null
+++ b/OpenAuth.WebApi/global.json
@@ -0,0 +1,33 @@
+//{
+// "Minio": {
+// "Endpoint": "192.168.20.239:9000",
+// "AccessKey": "cqlatqb0dgqdBRar7KVF",
+// "SecretKey": "FUFzd5VeoBeWhrpql6MBON5tQxNzcIgaK7vkvofX",
+// "BucketName": "drone"
+// }
+//}
+{
+ "Minio": {
+ "Endpoint": "192.168.10.163:9016",
+ "AccessKey": "I2c35jD6ayApaneyQZyC",
+ "SecretKey": "XHlrNeCHK0xf8y2Fo0K5OKyDeaI2ItfEsFbzQPFk",
+ "BucketName": "demo",
+ "limitspeed": 1048576
+ }
+//{
+// "Minio": {
+// "Endpoint": "192.168.20.239:9106",
+// "AccessKey": "minioadmin",
+// "SecretKey": "hopetry@minio",
+// "BucketName": "dev",
+// "limitspeed": 1048576
+// }
+ //"Minio": {
+ // "Endpoint": "nas.continue.fun:10044",
+ // "AccessKey": "xilonp6jAjBIf0DTaLfY",
+ // "SecretKey": "DgJF1eUTy61V3s26ofzfpRKUsnr9YVAF5kkwYXZ3",
+ // "BucketName": "mdimage",
+ // "limitspeed": 1048576
+ //}
+
+}
From 02d1bf1e84016cd2310efb990e475d7c7d33574c Mon Sep 17 00:00:00 2001
From: lgd
Date: Mon, 16 Jun 2025 15:12:06 +0800
Subject: [PATCH 4/8] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E6=8E=A5=E5=8F=A3?=
=?UTF-8?q?=E6=9B=B4=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AirportMaintenanceController.cs | 142 ++++++++----------
1 file changed, 65 insertions(+), 77 deletions(-)
diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs
index 58005e0..1228306 100644
--- a/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs
+++ b/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using MQTTnet;
using OpenAuth.App.ServiceApp;
using OpenAuth.Repository.Domain;
+using System.Text;
using System.Text.Json;
namespace OpenAuth.WebApi.Controllers.ServiceControllers
@@ -82,8 +83,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
Response response = new Response();
try
{
-
- var topicRequest = $"thing/product/8UUXN5400A079H/services";
+ var videoids = videoId.Split("/");
+ var topicRequest = $"thing/product/" + videoids[0] +"/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
@@ -93,28 +94,22 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
data = new
{
camera_position = position,
- video_id = "8UUXN5400A079H/165-0-7/normal-0"
+ video_id = videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
- var topicRequest1 = $"thing/product/8UUXN5400A079H/services_reply";
- var requestData1 = new
- {
- bid = Guid.NewGuid().ToString(),
- method = "live_camera_change",
- tid = Guid.NewGuid().ToString(),
- timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- data = new
- {
- result = 0
- }
- };
- string payload1 = JsonSerializer.Serialize(requestData1);
- await _mqttClientManager.PublishAsync(topicRequest1, payload1);
+ var topicRequest1 = $"thing/product/" + videoids[0] +"/services_reply";
- response.Result = 1;
+ await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
+ {
+ var payload = args.ApplicationMessage.Payload;
+ var message = Encoding.UTF8.GetString(payload);
+ Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
+ await Task.CompletedTask;
+ });
+ response.Result = 0;
}
catch (Exception ex)
@@ -139,7 +134,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
try
{
- var topicRequest = $"thing/product/8UUXN5400A079H/services";
+ var videoids = videoId.Split("/");
+ var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
@@ -149,28 +145,23 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
data = new
{
video_type = cameraType,
- video_id = "8UUXN5400A079H/165-0-7/normal-0"
+ video_id = videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
- var topicRequest1 = $"thing/product/8UUXN5400A079H/services_reply";
- var requestData1 = new
- {
- bid = Guid.NewGuid().ToString(),
- method = "live_lens_change",
- tid = Guid.NewGuid().ToString(),
- timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- data = new
- {
- result = 0
- }
- };
- string payload1 = JsonSerializer.Serialize(requestData1);
- await _mqttClientManager.PublishAsync(topicRequest1, payload1);
+ var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
- response.Result = 1;
+ await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
+ {
+ var payload = args.ApplicationMessage.Payload;
+ var message = Encoding.UTF8.GetString(payload);
+ Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
+ await Task.CompletedTask;
+ });
+
+ response.Result = 0;
}
catch (Exception ex)
@@ -193,8 +184,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
Response response = new Response();
try
{
-
- var topicRequest = $"thing/product/8UUXN5400A079H/services";
+ var videoids = videoId.Split("/");
+ var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
@@ -204,28 +195,23 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
data = new
{
video_quality = videoQuality,
- video_id = "8UUXN5400A079H/165-0-7/normal-0"
+ video_id = videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
- var topicRequest1 = $"thing/product/8UUXN5400A079H/services_reply";
- var requestData1 = new
- {
- bid = Guid.NewGuid().ToString(),
- method = "live_set_quality",
- tid = Guid.NewGuid().ToString(),
- timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- data = new
- {
- result = 0
- }
- };
- string payload1 = JsonSerializer.Serialize(requestData1);
- await _mqttClientManager.PublishAsync(topicRequest1, payload1);
+ var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
- response.Result = 1;
+ await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
+ {
+ var payload = args.ApplicationMessage.Payload;
+ var message = Encoding.UTF8.GetString(payload);
+ Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
+ await Task.CompletedTask;
+ });
+
+ response.Result = 0;
}
catch (Exception ex)
@@ -248,9 +234,9 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
Response response = new Response();
try
{
-
- var topicRequest = $"thing/product/8UUXN5400A079H/services";
- var requestData = new
+ var videoids = videoId.Split("/");
+ var topicRequest = $"thing/product/" + videoids[0] + "/services";
+ var requestData = new
{
bid = Guid.NewGuid().ToString(),
method = "live_stop_push",
@@ -259,28 +245,23 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
data = new
{
- video_id = "8UUXN5400A079H/165-0-7/normal-0"
+ video_id = videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
- var topicRequest1 = $"thing/product/8UUXN5400A079H/services_reply";
- var requestData1 = new
- {
- bid = Guid.NewGuid().ToString(),
- method = "live_start_push",
- tid = Guid.NewGuid().ToString(),
- timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- data = new
- {
- result = 0
- }
- };
- string payload1 = JsonSerializer.Serialize(requestData1);
- await _mqttClientManager.PublishAsync(topicRequest1, payload1);
+ var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
- response.Result = 1;
+ await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
+ {
+ var payload = args.ApplicationMessage.Payload;
+ var message = Encoding.UTF8.GetString(payload);
+ Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
+ await Task.CompletedTask;
+ });
+
+ response.Result = 0;
@@ -306,8 +287,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
Response response = new Response();
try
{
-
- var topicRequest = $"thing/product/8UUXN5400A079H/services";
+ var videoids = videoId.Split("/");
+ var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
@@ -319,15 +300,22 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
url_type = urlType,
url = url,
video_quality = quality,
- video_id = "8UUXN5400A079H/165-0-7/normal-0"
+ video_id = videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
await _mqttClientManager.PublishAsync(topicRequest, payload);
+ var topicRequest1 = $"thing/product/" + videoids[0] + "/services_reply";
+ await _mqttClientManager.SubscribeAsync(topicRequest1, async (args) =>
+ {
+ var payload1 = args.ApplicationMessage.Payload;
+ var message = Encoding.UTF8.GetString(payload1);
+ Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
+ await Task.CompletedTask;
+ });
-
- response.Result = 1;
+ response.Result = 0;
From 2cad2606cd7cefeee4d7791f158039afc5ce4a71 Mon Sep 17 00:00:00 2001
From: lgd
Date: Mon, 16 Jun 2025 15:52:11 +0800
Subject: [PATCH 5/8] =?UTF-8?q?=E5=85=A5=E5=8F=82=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
OpenAuth.Repository/Domain/Zhibo.cs | 25 +++++++++++
.../AirportMaintenanceController.cs | 42 +++++++++----------
2 files changed, 46 insertions(+), 21 deletions(-)
create mode 100644 OpenAuth.Repository/Domain/Zhibo.cs
diff --git a/OpenAuth.Repository/Domain/Zhibo.cs b/OpenAuth.Repository/Domain/Zhibo.cs
new file mode 100644
index 0000000..7974319
--- /dev/null
+++ b/OpenAuth.Repository/Domain/Zhibo.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenAuth.Repository.Domain
+{
+ public class Zhibo
+ {
+ public Zhibo() { }
+
+ public string videoId { get; set; }
+
+ public int position { get; set; }
+
+ public string cameraType { get; set; }
+
+ public int videoQuality { get; set; }
+
+ public int urlType { get; set; }
+
+ public string url { get; set; }
+ }
+}
diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs
index 1228306..2400980 100644
--- a/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs
+++ b/OpenAuth.WebApi/Controllers/ServiceControllers/AirportMaintenanceController.cs
@@ -78,12 +78,12 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
///
[HttpPost]
- public async Task> ExchangeCamera(string camera,int position,string videoId)
+ public async Task> ExchangeCamera(Zhibo zhiboReq)
{
Response response = new Response();
try
{
- var videoids = videoId.Split("/");
+ var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] +"/services";
var requestData = new
{
@@ -93,8 +93,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
- camera_position = position,
- video_id = videoId
+ camera_position = zhiboReq.position,
+ video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
@@ -128,13 +128,13 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
///
[HttpPost]
- public async Task> SetCamera(string cameraType, string videoId)
+ public async Task> SetCamera(Zhibo zhiboReq)
{
Response response = new Response();
try
{
- var videoids = videoId.Split("/");
+ var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
@@ -144,8 +144,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
- video_type = cameraType,
- video_id = videoId
+ video_type = zhiboReq.cameraType,
+ video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
@@ -179,12 +179,12 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
///
[HttpPost]
- public async Task> SetCameraVideo(int videoQuality, string videoId)
+ public async Task> SetCameraVideo(Zhibo zhiboReq)
{
Response response = new Response();
try
{
- var videoids = videoId.Split("/");
+ var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
@@ -194,8 +194,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
- video_quality = videoQuality,
- video_id = videoId
+ video_quality = zhiboReq.videoQuality,
+ video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
@@ -229,12 +229,12 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
///
[HttpPost]
- public async Task> EndLive( string videoId)
+ public async Task> EndLive( Zhibo zhiboReq)
{
Response response = new Response();
try
{
- var videoids = videoId.Split("/");
+ var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
@@ -245,7 +245,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
data = new
{
- video_id = videoId
+ video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
@@ -282,12 +282,12 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
///
[HttpPost]
- public async Task> StartLive(string videoId,int urlType,string url,int quality)
+ public async Task> StartLive(Zhibo zhiboReq)
{
Response response = new Response();
try
{
- var videoids = videoId.Split("/");
+ var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
@@ -297,10 +297,10 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
- url_type = urlType,
- url = url,
- video_quality = quality,
- video_id = videoId
+ url_type = zhiboReq.urlType,
+ url = zhiboReq.url,
+ video_quality = zhiboReq.videoQuality,
+ video_id = zhiboReq.videoId
}
};
string payload = JsonSerializer.Serialize(requestData);
From 1d609239af4b1c42284b49d0d3334fbb6f3e4b95 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E4=BC=9F?= <421281095@qq.com>
Date: Mon, 16 Jun 2025 16:15:02 +0800
Subject: [PATCH 6/8] =?UTF-8?q?1.=20MinioService.cs=20=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E4=BE=9D=E8=B5=96=E6=B3=A8=E5=85=A5=202.=20=E8=88=AA=E7=BA=BF?=
=?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BF=AE=E6=94=B9=203.=20MinioService.cs=20?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8A=E4=BC=A0=E6=96=B9=E6=B3=95=204.=20M?=
=?UTF-8?q?inioService=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E9=87=8D?=
=?UTF-8?q?=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Infrastructure/CloudSdk/minio/MinioService.cs | 88 ++++++++++++++-----
OpenAuth.App/ServiceApp/ManageApp.cs | 63 +++++++++++--
.../ServiceControllers/ManageController.cs | 40 +++++----
OpenAuth.WebApi/Startup.cs | 5 +-
OpenAuth.WebApi/appsettings.json | 7 ++
OpenAuth.WebApi/global.json | 33 -------
6 files changed, 156 insertions(+), 80 deletions(-)
delete mode 100644 OpenAuth.WebApi/global.json
diff --git a/Infrastructure/CloudSdk/minio/MinioService.cs b/Infrastructure/CloudSdk/minio/MinioService.cs
index d1e32ea..fe62d53 100644
--- a/Infrastructure/CloudSdk/minio/MinioService.cs
+++ b/Infrastructure/CloudSdk/minio/MinioService.cs
@@ -1,36 +1,41 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Threading.Tasks;
-using Minio.Exceptions;
-using Minio;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
-using Minio.DataModel.Args;
+using Minio;
using Minio.DataModel;
+using Minio.DataModel.Args;
+using Minio.Exceptions;
namespace Infrastructure.CloudSdk.minio;
+
public class MinioService
{
- private IMinioClient _minioClient;
- public readonly string _bucketName = null;
+ private IMinioClient _minioClient;
+ public string _bucketName;
+
public MinioService()
{
InitializeMinIOClient();
- EnsureBucketExistsAsync(_bucketName).Wait();
+ //EnsureBucketExistsAsync(_bucketName).Wait();
}
+
private void InitializeMinIOClient()
{
var builder = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddJsonFile("global.json", optional: false, reloadOnChange: true);
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
+ .AddJsonFile(
+ $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"}.json",
+ optional: true)
+ .AddEnvironmentVariables();
// 构建配置
- var config = builder.Build();
-
+ var configuration = builder.Build();
+ _bucketName = configuration["Minio:BucketName"];
_minioClient = new MinioClient()
- .WithEndpoint(config["Minio:Endpoint"])
- .WithCredentials(config["Minio:AccessKey"], config["Minio:SecretKey"])
+ .WithEndpoint(configuration["Minio:Endpoint"])
+ .WithCredentials(configuration["Minio:AccessKey"], configuration["Minio:SecretKey"])
.Build();
}
+
///
/// 创建存储桶(如果不存在)
///
@@ -40,12 +45,12 @@ public class MinioService
bool found = await _minioClient.BucketExistsAsync(existsArgs);
if (!found)
{
-
var makeArgs = new MakeBucketArgs().WithBucket(_bucketName);
await _minioClient.MakeBucketAsync(makeArgs);
Console.WriteLine($"Bucket {_bucketName} created.");
}
}
+
public async Task EnsureBucketExistsAsync(string bucketName)
{
var existsArgs = new BucketExistsArgs().WithBucket(bucketName);
@@ -58,13 +63,13 @@ public class MinioService
await _minioClient.MakeBucketAsync(makeArgs);
}
}
-
+
///
/// 下载文件
///
public async Task DownLoadObject(string bucketName, string objectKey, string localDir, string objectETag,
- CancellationToken token = default)
+ CancellationToken token = default)
{
var index = objectKey.LastIndexOf("/", StringComparison.Ordinal);
if (index > 0)
@@ -82,14 +87,13 @@ public class MinioService
.WithObject(objectKey)
.WithFile(localPath);
var stat = await _minioClient.GetObjectAsync(getArgs, token);
-
}
///
/// 列出所有对象
///
public async Task> ListAllObject(string bucketName, string prefix, bool recursive,
- CancellationToken token = default)
+ CancellationToken token = default)
{
// Just list of objects
// Check whether 'mybucket' exists or not.
@@ -112,6 +116,7 @@ public class MinioService
Console.WriteLine("mybucket does not exist");
throw new Exception("bucket not found");
}
+
///
/// 删除文件
///
@@ -128,4 +133,43 @@ public class MinioService
Console.WriteLine($"MinIO Exception: {ex.Message}");
}
}
-}
+
+ public async void UploadFile(IFormFile file, string bucketName)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(bucketName))
+ {
+ bucketName = _bucketName;
+ }
+
+ //判断桶是否存在
+ var beArgs = new BucketExistsArgs().WithBucket(bucketName);
+ bool found = await _minioClient.BucketExistsAsync(beArgs).ConfigureAwait(false);
+ if (!found)
+ {
+ var mbArgs = new MakeBucketArgs()
+ .WithBucket(bucketName);
+ await _minioClient.MakeBucketAsync(mbArgs).ConfigureAwait(false);
+ }
+
+ var objectName = $"{GenerateId.GenerateOrderNumber() }.wpml";
+ // 使用内存流上传
+ using var stream = new MemoryStream();
+ await file.CopyToAsync(stream);
+ stream.Position = 0;
+ var putArgs = new PutObjectArgs()
+ .WithBucket(bucketName)
+ .WithObject(objectName)
+ .WithStreamData(stream)
+ .WithObjectSize(stream.Length)
+ .WithContentType("application/octet-stream");
+ //.WithContentType(file.ContentType);
+ await _minioClient.PutObjectAsync(putArgs);
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"上传文件失败: {ex.Message}");
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenAuth.App/ServiceApp/ManageApp.cs b/OpenAuth.App/ServiceApp/ManageApp.cs
index acb2901..01e0fab 100644
--- a/OpenAuth.App/ServiceApp/ManageApp.cs
+++ b/OpenAuth.App/ServiceApp/ManageApp.cs
@@ -1,6 +1,8 @@
using DocumentFormat.OpenXml.Wordprocessing;
using Infrastructure;
+using Infrastructure.CloudSdk.minio;
using Infrastructure.CloudSdk.wayline;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using OpenAuth.App.BaseApp.Base;
@@ -18,14 +20,18 @@ namespace OpenAuth.App.ServiceApp
public class ManageApp : SqlSugarBaseApp
{
private readonly MqttClientManager _mqttClientManager;
+ private readonly MinioService _minioService;
public ManageApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth,
- MqttClientManager mqttClientManager)
+ MqttClientManager mqttClientManager, MinioService minioService)
: base(unitWork, repository, auth)
{
_mqttClientManager = mqttClientManager;
+ _minioService = minioService;
}
+
#region 机场管理
+
///
/// 分页获取所有数据
///
@@ -69,6 +75,7 @@ namespace OpenAuth.App.ServiceApp
return new Response { Result = false, Message = "编辑失败" };
}
}
+
//删除机场信息
public async Task> DeleteDronePort(string id)
{
@@ -84,6 +91,7 @@ namespace OpenAuth.App.ServiceApp
return new Response { Result = false, Message = "删除失败" };
}
}
+
#endregion
///
@@ -107,6 +115,7 @@ namespace OpenAuth.App.ServiceApp
};
}
}
+
///
/// 编辑无人机
///
@@ -126,6 +135,7 @@ namespace OpenAuth.App.ServiceApp
return new Response { Result = false, Message = "编辑失败" };
}
}
+
//删除无人机
public async Task> DeleteUav(string id)
{
@@ -282,17 +292,20 @@ namespace OpenAuth.App.ServiceApp
///
///
///
- public async Task>> GetWorkspaceList(int isjoin,string key,int state,string order= "\"CreateTime\" desc")
+ public async Task>> GetWorkspaceList(int isjoin, string key, int state,
+ string order = "\"CreateTime\" desc")
{
RefAsync totalCount = 0;
using (var db = UnitWork.CreateContext())
{
var userid = _auth.GetCurrentUser().User.Id;
- List ids=new List();
+ List ids = new List();
if (isjoin == 1)
{
- ids=db.LasaSpaceUser.AsQueryable().Where(r=>r.UserId== userid)?.Select(r => r.WorkSpaceId).ToList();
+ ids = db.LasaSpaceUser.AsQueryable().Where(r => r.UserId == userid)?.Select(r => r.WorkSpaceId)
+ .ToList();
}
+
var list = await db.LasaWorkspace.AsQueryable()
.WhereIF(!string.IsNullOrEmpty(key), a => a.WorkspaceName.Contains(key))
.WhereIF(state != 0, a => a.Sate == state)
@@ -309,7 +322,8 @@ namespace OpenAuth.App.ServiceApp
a.CreateId,
u.Account,
u.Name,
- UserNames = SqlFunc.Subqueryable().Where(r => r.WorkSpaceId == a.Id).LeftJoin((r, s) => r.UserId == s.Id).SelectStringJoin((r, s) => s.Name, ",")
+ UserNames = SqlFunc.Subqueryable().Where(r => r.WorkSpaceId == a.Id)
+ .LeftJoin((r, s) => r.UserId == s.Id).SelectStringJoin((r, s) => s.Name, ",")
}).MergeTable()
.OrderBy(order)
.ToListAsync();
@@ -496,6 +510,7 @@ namespace OpenAuth.App.ServiceApp
return new Response { Result = false, Message = "归档失败" };
}
}
+
#endregion
public async Task ExecuteFlyTask(string taskId)
@@ -532,7 +547,7 @@ namespace OpenAuth.App.ServiceApp
var configuration = builder.Build();
var wpmlDir = configuration["WpmlDir"];
// 读取连接字符串
- var serverIp = configuration["MQTT:Server"];
+ //var serverIp = configuration["MQTT:Server"];
var data = new
{
flight_id = Guid.NewGuid().ToString(),
@@ -566,12 +581,12 @@ namespace OpenAuth.App.ServiceApp
break_point = new
{
index = 1, // 断点序号
- state = 1 ,// “0":"在航段上","1":"在航点上
+ state = 1, // “0":"在航段上","1":"在航点上
progress = 1.0, // {"max":"1.0","min":"0"}
wayline_id = "" // 航线id
},
// 返航高度 {"max":1500,"min":20,"step":"","unit_name":"米 / m"}
- rth_altitude = 150, // todo 取自任务
+ rth_altitude = 150, // todo 取自任务
// 返航高度模式 {"0":"智能高度","1":"设定高度"}
// 智能返航模式下,飞行器将自动规划最佳返航高度。大疆机场当前不支持设置返航高度模式,只能选择'设定高度'模式。当环境,光线不满足视觉系统要求时(譬如傍晚阳光直射、夜间弱光无光),飞行器将使用您设定的返航高度进行直线返航
rth_mode = 1,
@@ -603,7 +618,39 @@ namespace OpenAuth.App.ServiceApp
flight_safety_advance_check = 0
};
request.SetData(data);
+ // 任务下发
await _mqttClientManager.PublishAsync(topic, JsonConvert.SerializeObject(request));
+ // todo 是否查询就绪任务 执行任务
+ await _mqttClientManager.PublishAsync(topic, JsonConvert.SerializeObject(request));
+ //thing/product/{gateway_sn}/services
+ var flightTaskExecuteTopic = string.Format(GatewayManager.FlightTaskPrepare, serialNo);
+ // todo
+ var flightTaskExecuteRequest = new TopicServicesRequest