消息中心

feature-flyModify
zhangbin 2025-06-17 13:55:21 +08:00
commit 14db0e89d1
9 changed files with 441 additions and 126 deletions

View File

@ -0,0 +1,183 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Minio;
using Minio.DataModel;
using Minio.DataModel.Args;
using Minio.Exceptions;
namespace Infrastructure.CloudSdk.minio;
public class MinioService
{
private IMinioClient _minioClient;
public string _bucketName;
public string endPoint;
public MinioService()
{
InitializeMinIOClient();
//EnsureBucketExistsAsync(_bucketName).Wait();
}
private void InitializeMinIOClient()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"}.json",
optional: true)
.AddEnvironmentVariables();
// 构建配置
var configuration = builder.Build();
_bucketName = configuration["Minio:BucketName"];
endPoint = configuration["Minio:Endpoint"];
_minioClient = new MinioClient()
.WithEndpoint(endPoint)
.WithCredentials(configuration["Minio:AccessKey"], configuration["Minio:SecretKey"])
.Build();
}
/// <summary>
/// 创建存储桶(如果不存在)
/// </summary>
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);
}
}
/// <summary>
/// 下载文件
/// </summary>
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);
}
/// <summary>
/// 列出所有对象
/// </summary>
public async Task<IAsyncEnumerable<Item>> 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");
}
/// <summary>
/// 删除文件
/// </summary>
public async Task DeleteFile(string objectName)
{
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.");
}
catch (MinioException ex)
{
Console.WriteLine($"MinIO Exception: {ex.Message}");
}
}
public async Task<string> 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);
return "http://" + endPoint + "/" + bucketName + "/" + objectName;
}
catch (Exception ex)
{
throw new Exception($"上传文件失败: {ex.Message}");
}
}
}

View File

@ -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
/// <param name="password"></param>
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<MqttApplicationMessageReceivedEventArgs, Task> 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);
}
/// <summary>
@ -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);
}
}

View File

@ -17,6 +17,7 @@
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Minio" Version="6.0.4" />
<PackageReference Include="MQTTnet" Version="4.1.4.563" />
<PackageReference Include="NetTopologySuite" Version="2.5.0" />
<PackageReference Include="NetTopologySuite.IO.Esri.Shapefile" Version="1.0.0" />

View File

@ -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<LasaDronePort, SugarDbContext>
{
private readonly MqttClientManager _mqttClientManager;
private readonly MinioService _minioService;
public ManageApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<LasaDronePort> repository, IAuth auth,
MqttClientManager mqttClientManager)
MqttClientManager mqttClientManager, MinioService minioService)
: base(unitWork, repository, auth)
{
_mqttClientManager = mqttClientManager;
_minioService = minioService;
}
#region 机场管理
/// <summary>
/// 分页获取所有数据
/// </summary>
@ -69,6 +75,7 @@ namespace OpenAuth.App.ServiceApp
return new Response<bool> { Result = false, Message = "编辑失败" };
}
}
//删除机场信息
public async Task<Response<bool>> DeleteDronePort(string id)
{
@ -84,6 +91,7 @@ namespace OpenAuth.App.ServiceApp
return new Response<bool> { Result = false, Message = "删除失败" };
}
}
#endregion
/// <summary>
@ -107,6 +115,7 @@ namespace OpenAuth.App.ServiceApp
};
}
}
/// <summary>
/// 编辑无人机
/// </summary>
@ -126,6 +135,7 @@ namespace OpenAuth.App.ServiceApp
return new Response<bool> { Result = false, Message = "编辑失败" };
}
}
//删除无人机
public async Task<Response<bool>> DeleteUav(string id)
{
@ -249,13 +259,20 @@ namespace OpenAuth.App.ServiceApp
//编辑航线
public async Task<Response<bool>> EditAirLine(LasaAirLine lasaAirLine)
{
var oldLasaAirLine = await Repository.ChangeRepository<SugarRepositiry<LasaAirLine>>()
.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<bool> { Result = true, Message = "编辑成功" };
else
return new Response<bool> { Result = false, Message = "编辑失败" };
}
return new Response<bool> { Result = false, Message = "编辑失败" };
}
}
@ -282,13 +299,25 @@ namespace OpenAuth.App.ServiceApp
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public async Task<Response<List<dynamic>>> GetWorkspaceList(string key)
public async Task<Response<List<dynamic>>> GetWorkspaceList(int isjoin, string key, int state,
string order = "\"CreateTime\" desc")
{
RefAsync<int> totalCount = 0;
using (var db = UnitWork.CreateContext())
{
var userid = _auth.GetCurrentUser().User.Id;
List<string> ids = new List<string>();
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))
.WhereIF(state != 0, a => a.Sate == state)
.WhereIF(isjoin == 1, a => ids.Contains(a.Id))
.WhereIF(isjoin == 2, a => !ids.Contains(a.Id))
.LeftJoin<SysUser>((a, u) => a.CreateId == u.Id)
.Select<dynamic>((a, u) => new
{
@ -299,9 +328,13 @@ namespace OpenAuth.App.ServiceApp
a.CreateTime,
a.CreateId,
u.Account,
u.Name
})
u.Name,
UserNames = SqlFunc.Subqueryable<LasaSpaceUser>().Where(r => r.WorkSpaceId == a.Id)
.LeftJoin<SysUser>((r, s) => r.UserId == s.Id).SelectStringJoin((r, s) => s.Name, ",")
}).MergeTable()
.OrderBy(order)
.ToListAsync();
return new Response<List<dynamic>>
{
Result = list
@ -469,6 +502,22 @@ namespace OpenAuth.App.ServiceApp
}
}
//归档项目
public async Task<Response<bool>> 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<bool> { Result = true, Message = "归档成功" };
else
return new Response<bool> { Result = false, Message = "归档失败" };
}
}
#endregion
public async Task ExecuteFlyTask(string taskId)
@ -505,7 +554,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(),
@ -539,12 +588,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,
@ -576,7 +625,38 @@ 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<object>
{
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 Task<string> UploadFile(IFormFile xmlFile)
{
return _minioService.UploadFile(xmlFile, "");
}
}
}

View File

@ -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; }
}
}

View File

@ -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
@ -77,13 +78,13 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<Response<int>> ExchangeCamera(string camera,int position,string videoId)
public async Task<Response<int>> ExchangeCamera(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
var topicRequest = $"thing/product/8UUXN5400A079H/services";
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] +"/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
@ -92,29 +93,23 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
camera_position = position,
video_id = "8UUXN5400A079H/165-0-7/normal-0"
camera_position = zhiboReq.position,
video_id = zhiboReq.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)
@ -133,13 +128,14 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<Response<int>> SetCamera(string cameraType, string videoId)
public async Task<Response<int>> SetCamera(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
var topicRequest = $"thing/product/8UUXN5400A079H/services";
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
@ -148,29 +144,24 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
video_type = cameraType,
video_id = "8UUXN5400A079H/165-0-7/normal-0"
video_type = zhiboReq.cameraType,
video_id = zhiboReq.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)
@ -188,13 +179,13 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<Response<int>> SetCameraVideo(int videoQuality, string videoId)
public async Task<Response<int>> SetCameraVideo(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
var topicRequest = $"thing/product/8UUXN5400A079H/services";
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
@ -203,29 +194,24 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
video_quality = videoQuality,
video_id = "8UUXN5400A079H/165-0-7/normal-0"
video_quality = zhiboReq.videoQuality,
video_id = zhiboReq.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)
@ -243,14 +229,14 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<Response<int>> EndLive( string videoId)
public async Task<Response<int>> EndLive( Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
var topicRequest = $"thing/product/8UUXN5400A079H/services";
var requestData = new
var videoids = zhiboReq.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 = zhiboReq.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;
@ -301,13 +282,13 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<Response<int>> StartLive(string videoId,int urlType,string url,int quality)
public async Task<Response<int>> StartLive(Zhibo zhiboReq)
{
Response<int> response = new Response<int>();
try
{
var topicRequest = $"thing/product/8UUXN5400A079H/services";
var videoids = zhiboReq.videoId.Split("/");
var topicRequest = $"thing/product/" + videoids[0] + "/services";
var requestData = new
{
bid = Guid.NewGuid().ToString(),
@ -316,18 +297,25 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
data = new
{
url_type = urlType,
url = url,
video_quality = quality,
video_id = "8UUXN5400A079H/165-0-7/normal-0"
url_type = zhiboReq.urlType,
url = zhiboReq.url,
video_quality = zhiboReq.videoQuality,
video_id = zhiboReq.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;

View File

@ -55,6 +55,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return result;
}
/// <summary>
/// 编辑机场
/// </summary>
@ -64,6 +65,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
return await _app.EditDronePort(info);
}
/// <summary>
/// 删除机场
/// </summary>
@ -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;
}
/// <summary>
/// 编辑无人机
/// </summary>
@ -110,6 +114,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
return await _app.EditUav(info);
}
/// <summary>
/// 删除无人机
/// </summary>
@ -119,6 +124,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
return await _app.DeleteUav(id);
}
#endregion
#region 任务管理
@ -235,29 +241,20 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return await _app.DeleteAirLine(id);
}
// todo 已有的文件如何处理?
/// <summary>
/// 上传航线文件
/// </summary>
/// <param name="xmlFile"></param>
/// <returns></returns>
[HttpPost("upload")]
[AllowAnonymous]
public async Task<IActionResult> 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 });
var path = await _app.UploadFile(xmlFile);
return Ok(new { message = "上传成功", path });
}
/*/// <summary>
/// 更新航线文件
@ -294,15 +291,19 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
/// <summary>
/// 获取项目列表
/// </summary>
/// <param name="key"></param>
/// <param name="isjoin">是否是已加入的项目0全部1加入2未加入</param>
/// <param name="key">项目名称筛选</param>
/// <param name="state">状态0全部1进行中2已归档</param>
/// <param name="order">排序</param>
/// <returns></returns>
[HttpGet]
public async Task<Response<List<dynamic>>> GetWorkspaceList(string key)
public async Task<Response<List<dynamic>>> GetWorkspaceList(int isjoin, string key, int state,
string order = "\"CreateTime\" desc")
{
var result = new Response<List<dynamic>>();
try
{
result = await _app.GetWorkspaceList(key);
result = await _app.GetWorkspaceList(isjoin, key, state, order);
}
catch (Exception ex)
{
@ -343,6 +344,16 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return await _app.DeleteWorkspace(id);
}
/// <summary>
/// 归档项目
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<Response<bool>> CompleteWorkspace(string id)
{
return await _app.CompleteWorkspace(id);
}
/// <summary>
/// 获取机场列表,添加项目使用
/// </summary>
@ -390,9 +401,8 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
#endregion
// 航线任务在云端的 共享查看、下发执行、取消以及进度上报等功能。
/// <summary>
/// 执行任务
/// 解除挂起(执行任务 todo 需不需要加时间限制判断?
/// </summary>
/// <param name="taskId"></param>
[HttpPost]
@ -401,6 +411,16 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
await _app.ExecuteFlyTask(taskId);
}
/// <summary>
/// 挂起任务
/// </summary>
/// <param name="taskId"></param>
[HttpPost]
public async Task PendingFlyTask(string taskId)
{
await _app.PendingFlyTask(taskId);
}
/// <summary>
/// 测试
/// </summary>

View File

@ -5,7 +5,6 @@ using ce.autofac.extension;
using DocumentFormat.OpenXml.Validation;
using IdentityServer4.AccessTokenValidation;
using Infrastructure;
using Infrastructure.CloudSdk.mqttmessagecenter;
using Infrastructure.Extensions.AutofacManager;
using Infrastructure.Middleware;
using Microsoft.AspNetCore.DataProtection;
@ -48,7 +47,9 @@ namespace OpenAuth.WebApi
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpContextAccessor();
services.AddSingleton<MqttClientManager>(provider => new MqttClientManager());
services.AddSingleton(_ => new MqttClientManager());
// minio client
services.AddSingleton(_ => new MinioService());
#region log4net

View File

@ -73,5 +73,12 @@
"Port": 6011,
"UserName": "sdhc",
"Password": ""
},
"Minio": {
"Endpoint": "175.27.168.120:6013",
"AccessKey": "minioadmin",
"SecretKey": "minioadmin",
"BucketName": "test",
"limitspeed": 1048576
}
}