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 + { + method = "flighttask_execute", + tid = "tid", + bid = "bid", + timestamp = DateTime.Now.Ticks, + data = new + { + flight_id = "" // todo + } + }; + await _mqttClientManager.PublishAsync(flightTaskExecuteTopic, + JsonConvert.SerializeObject(flightTaskExecuteRequest)); + } + + public async Task PendingFlyTask(string taskId) + { + // todo + // todo 查看任务状态(待执行,任务执行,已暂停,已挂起) 1. 待执行,任务执行,需要先取消任务 2. 已暂停,直接挂起任务 3. 已挂起,返回 + throw new NotImplementedException(); + } + + public void UploadFile(IFormFile xmlFile) + { + // todo + _minioService.UploadFile(xmlFile, ""); } } } \ No newline at end of file diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs index 90f1597..99f10a0 100644 --- a/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs @@ -55,6 +55,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers return result; } + /// /// 编辑机场 /// @@ -64,6 +65,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers { return await _app.EditDronePort(info); } + /// /// 删除机场 /// @@ -73,6 +75,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers { return await _app.DeleteDronePort(id); } + #endregion #region 无人机管理 @@ -101,6 +104,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers return result; } + /// /// 编辑无人机 /// @@ -110,6 +114,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers { return await _app.EditUav(info); } + /// /// 删除无人机 /// @@ -119,6 +124,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers { return await _app.DeleteUav(id); } + #endregion #region 任务管理 @@ -241,23 +247,14 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers /// /// [HttpPost("upload")] + [AllowAnonymous] public async Task UploadXmlFile(IFormFile xmlFile) { if (xmlFile == null || xmlFile.Length == 0) return BadRequest("文件为空"); - var uploadsFolder = Path.Combine(Directory.GetCurrentDirectory(), "Waylines"); - if (!Directory.Exists(uploadsFolder)) - Directory.CreateDirectory(uploadsFolder); - var fileName = GenerateId.GenerateOrderNumber() + ".wpml"; - var filePath = Path.Combine(uploadsFolder, fileName); - - using (var stream = new FileStream(filePath, FileMode.Create)) - { - await xmlFile.CopyToAsync(stream); - } - - return Ok(new { message = "上传成功", path = filePath }); + _app.UploadFile(xmlFile); + return Ok(new { message = "上传成功" }); } /*/// /// 更新航线文件 @@ -300,12 +297,13 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers /// 排序 /// [HttpGet] - 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") { var result = new Response>(); try { - result = await _app.GetWorkspaceList(isjoin,key,state,order); + result = await _app.GetWorkspaceList(isjoin, key, state, order); } catch (Exception ex) { @@ -355,6 +353,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers { return await _app.CompleteWorkspace(id); } + /// /// 获取机场列表,添加项目使用 /// @@ -402,9 +401,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers #endregion // 航线任务在云端的 共享查看、下发执行、取消以及进度上报等功能。 - /// - /// 执行任务 + /// 解除挂起(执行任务) todo 需不需要加时间限制判断? /// /// [HttpPost] @@ -413,6 +411,16 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers await _app.ExecuteFlyTask(taskId); } + /// + /// 挂起任务 + /// + /// + [HttpPost] + public async Task PendingFlyTask(string taskId) + { + await _app.PendingFlyTask(taskId); + } + /// /// 测试 /// diff --git a/OpenAuth.WebApi/Startup.cs b/OpenAuth.WebApi/Startup.cs index dbbbc19..4cd6e99 100644 --- a/OpenAuth.WebApi/Startup.cs +++ b/OpenAuth.WebApi/Startup.cs @@ -4,6 +4,7 @@ using Autofac.Extensions.DependencyInjection; using ce.autofac.extension; using IdentityServer4.AccessTokenValidation; using Infrastructure; +using Infrastructure.CloudSdk.minio; using Infrastructure.Extensions.AutofacManager; using Infrastructure.Middleware; using Microsoft.AspNetCore.DataProtection; @@ -45,7 +46,9 @@ namespace OpenAuth.WebApi public void ConfigureServices(IServiceCollection services) { services.AddHttpContextAccessor(); - services.AddSingleton(provider => new MqttClientManager()); + services.AddSingleton(_ => new MqttClientManager()); + // minio client + services.AddSingleton(_ => new MinioService()); #region log4net diff --git a/OpenAuth.WebApi/appsettings.json b/OpenAuth.WebApi/appsettings.json index 733a3b4..3fb3e36 100644 --- a/OpenAuth.WebApi/appsettings.json +++ b/OpenAuth.WebApi/appsettings.json @@ -73,5 +73,12 @@ "Port": 6011, "UserName": "sdhc", "Password": "" + }, + "Minio": { + "Endpoint": "175.27.168.120:6013", + "AccessKey": "minioadmin", + "SecretKey": "minioadmin", + "BucketName": "test", + "limitspeed": 1048576 } } diff --git a/OpenAuth.WebApi/global.json b/OpenAuth.WebApi/global.json deleted file mode 100644 index 72e3f3e..0000000 --- a/OpenAuth.WebApi/global.json +++ /dev/null @@ -1,33 +0,0 @@ -//{ -// "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 3d111903885198aa20072b6bf5a3bde4c665c72f 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:39:26 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=88=AA=E7=BA=BF?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=B7=BB=E5=8A=A0=E8=B7=AF=E5=BE=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/CloudSdk/minio/MinioService.cs | 7 +++++-- OpenAuth.App/ServiceApp/ManageApp.cs | 5 ++--- .../Controllers/ServiceControllers/ManageController.cs | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Infrastructure/CloudSdk/minio/MinioService.cs b/Infrastructure/CloudSdk/minio/MinioService.cs index fe62d53..0895b7c 100644 --- a/Infrastructure/CloudSdk/minio/MinioService.cs +++ b/Infrastructure/CloudSdk/minio/MinioService.cs @@ -11,6 +11,7 @@ public class MinioService { private IMinioClient _minioClient; public string _bucketName; + public string endPoint; public MinioService() { @@ -30,8 +31,9 @@ public class MinioService // 构建配置 var configuration = builder.Build(); _bucketName = configuration["Minio:BucketName"]; + endPoint = configuration["Minio:Endpoint"]; _minioClient = new MinioClient() - .WithEndpoint(configuration["Minio:Endpoint"]) + .WithEndpoint(endPoint) .WithCredentials(configuration["Minio:AccessKey"], configuration["Minio:SecretKey"]) .Build(); } @@ -134,7 +136,7 @@ public class MinioService } } - public async void UploadFile(IFormFile file, string bucketName) + public async Task UploadFile(IFormFile file, string bucketName) { try { @@ -166,6 +168,7 @@ public class MinioService .WithContentType("application/octet-stream"); //.WithContentType(file.ContentType); await _minioClient.PutObjectAsync(putArgs); + return ""; } catch (Exception ex) { diff --git a/OpenAuth.App/ServiceApp/ManageApp.cs b/OpenAuth.App/ServiceApp/ManageApp.cs index 01e0fab..47d76c7 100644 --- a/OpenAuth.App/ServiceApp/ManageApp.cs +++ b/OpenAuth.App/ServiceApp/ManageApp.cs @@ -647,10 +647,9 @@ namespace OpenAuth.App.ServiceApp throw new NotImplementedException(); } - public void UploadFile(IFormFile xmlFile) + public Task UploadFile(IFormFile xmlFile) { - // todo - _minioService.UploadFile(xmlFile, ""); + return _minioService.UploadFile(xmlFile, ""); } } } \ No newline at end of file diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs index 99f10a0..8d61ff7 100644 --- a/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs @@ -241,6 +241,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers return await _app.DeleteAirLine(id); } + // todo 已有的文件如何处理? /// /// 上传航线文件 /// @@ -253,8 +254,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers if (xmlFile == null || xmlFile.Length == 0) return BadRequest("文件为空"); - _app.UploadFile(xmlFile); - return Ok(new { message = "上传成功" }); + var path = await _app.UploadFile(xmlFile); + return Ok(new { message = "上传成功", path }); } /*/// /// 更新航线文件 From c1d824ebf38ead3621368458bd333402219ac530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BC=9F?= <421281095@qq.com> Date: Tue, 17 Jun 2025 09:08:02 +0800 Subject: [PATCH 8/8] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E8=88=AA=E7=BA=BF?= =?UTF-8?q?=E7=BC=96=E8=BE=91=202.=20minio=E5=88=A0=E9=99=A4=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E6=96=B9=E6=B3=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/CloudSdk/minio/MinioService.cs | 11 ++++++++--- OpenAuth.App/ServiceApp/ManageApp.cs | 11 +++++++++-- .../ServiceControllers/ManageController.cs | 1 - 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Infrastructure/CloudSdk/minio/MinioService.cs b/Infrastructure/CloudSdk/minio/MinioService.cs index 0895b7c..b89021f 100644 --- a/Infrastructure/CloudSdk/minio/MinioService.cs +++ b/Infrastructure/CloudSdk/minio/MinioService.cs @@ -126,6 +126,11 @@ public class MinioService { try { + if (objectName.StartsWith("http")) + { + objectName = objectName.Replace($"http://{endPoint}/{_bucketName}/", ""); + } + var deleteargs = new RemoveObjectArgs().WithBucket(_bucketName).WithObject(objectName); await _minioClient.RemoveObjectAsync(deleteargs); Console.WriteLine($"File {objectName} deleted."); @@ -155,7 +160,7 @@ public class MinioService await _minioClient.MakeBucketAsync(mbArgs).ConfigureAwait(false); } - var objectName = $"{GenerateId.GenerateOrderNumber() }.wpml"; + var objectName = $"{GenerateId.GenerateOrderNumber()}.wpml"; // 使用内存流上传 using var stream = new MemoryStream(); await file.CopyToAsync(stream); @@ -166,9 +171,9 @@ public class MinioService .WithStreamData(stream) .WithObjectSize(stream.Length) .WithContentType("application/octet-stream"); - //.WithContentType(file.ContentType); + //.WithContentType(file.ContentType); await _minioClient.PutObjectAsync(putArgs); - return ""; + return "http://" + endPoint + "/" + bucketName + "/" + objectName; } catch (Exception ex) { diff --git a/OpenAuth.App/ServiceApp/ManageApp.cs b/OpenAuth.App/ServiceApp/ManageApp.cs index 47d76c7..4f374bc 100644 --- a/OpenAuth.App/ServiceApp/ManageApp.cs +++ b/OpenAuth.App/ServiceApp/ManageApp.cs @@ -259,13 +259,20 @@ namespace OpenAuth.App.ServiceApp //编辑航线 public async Task> EditAirLine(LasaAirLine lasaAirLine) { + var oldLasaAirLine = await Repository.ChangeRepository>() + .GetByIdAsync(lasaAirLine.Id); using (var db = UnitWork.CreateContext()) { var flag = await db.LasaAirLine.UpdateAsync(lasaAirLine); if (db.Commit()) + { + // http://175.27.168.120:6013/test/2025061617111990020017.wpml + var wmpl = oldLasaAirLine.WPML; + await _minioService.DeleteFile(wmpl); return new Response { Result = true, Message = "编辑成功" }; - else - return new Response { Result = false, Message = "编辑失败" }; + } + + return new Response { Result = false, Message = "编辑失败" }; } } diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs index 8d61ff7..384973a 100644 --- a/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/ManageController.cs @@ -253,7 +253,6 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers { if (xmlFile == null || xmlFile.Length == 0) return BadRequest("文件为空"); - var path = await _app.UploadFile(xmlFile); return Ok(new { message = "上传成功", path }); }