You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
317 lines
9.1 KiB
C#
317 lines
9.1 KiB
C#
using System.Text;
|
|
using Infrastructure;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Helpers;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using OpenAuth.App.ServiceApp;
|
|
using OpenAuth.Repository.Domain;
|
|
|
|
namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
|
{
|
|
/// <summary>
|
|
/// 后台管理模块
|
|
/// </summary>
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class ManageController : ControllerBase
|
|
{
|
|
private readonly ManageApp _app;
|
|
private readonly MqttClientManager _mqttClientManager;
|
|
|
|
public ManageController(ManageApp app, MqttClientManager mqttClientManager)
|
|
{
|
|
_app = app;
|
|
_mqttClientManager = mqttClientManager;
|
|
}
|
|
|
|
#region 机场管理
|
|
|
|
/// <summary>
|
|
/// 获取机场列表
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <param name="limit"></param>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<Response<PageInfo<List<LasaDronePort>>>> GetDataList(int page, int limit, string key)
|
|
{
|
|
var result = new Response<PageInfo<List<LasaDronePort>>>();
|
|
try
|
|
{
|
|
result = await _app.GetPageList(page, limit, key);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Code = 500;
|
|
result.Message = ex.Message;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 无人机管理
|
|
|
|
/// <summary>
|
|
/// 获取无人机列表
|
|
/// </summary>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<Response<PageInfo<List<LasaUav>>>> GetUavPageList(int page, int limit, string key)
|
|
{
|
|
var result = new Response<PageInfo<List<LasaUav>>>();
|
|
try
|
|
{
|
|
result = await _app.GetUavPageList(page, limit, key);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Code = 500;
|
|
result.Message = ex.Message;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 任务管理
|
|
|
|
/// <summary>
|
|
/// 获取任务列表
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <param name="limit"></param>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<Response<PageInfo<List<LasaTask>>>> GetTaskPageList(int page, int limit, string key)
|
|
{
|
|
var result = new Response<PageInfo<List<LasaTask>>>();
|
|
try
|
|
{
|
|
result = await _app.GetTaskPageList(page, limit, key);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Code = 500;
|
|
result.Message = ex.Message;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加任务
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> AddTask(LasaTask info)
|
|
{
|
|
return await _app.AddTask(info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑任务
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> EditTask(LasaTask info)
|
|
{
|
|
return await _app.EditTask(info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除任务
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> DeleteTask(string id)
|
|
{
|
|
return await _app.DeleteTask(id);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 航线管理
|
|
|
|
/// <summary>
|
|
/// 获取航线列表
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <param name="limit"></param>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<Response<PageInfo<List<LasaAirLine>>>> GetAirLineList(int page, int limit, string key)
|
|
{
|
|
var result = new Response<PageInfo<List<LasaAirLine>>>();
|
|
try
|
|
{
|
|
result = await _app.GetAirLinePageList(page, limit, key);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Code = 500;
|
|
result.Message = ex.Message;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加航线
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> AddAirLine(LasaAirLine info)
|
|
{
|
|
return await _app.AddAirLine(info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑航线
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> EditAirLine(LasaAirLine info)
|
|
{
|
|
return await _app.EditAirLine(info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除航线
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> DeleteAirLine(string id)
|
|
{
|
|
return await _app.DeleteAirLine(id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上传航线文件
|
|
/// </summary>
|
|
/// <param name="xmlFile"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("upload")]
|
|
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 filePath = Path.Combine(uploadsFolder, "waylines.wpml");
|
|
|
|
using (var stream = new FileStream(filePath, FileMode.Create))
|
|
{
|
|
await xmlFile.CopyToAsync(stream);
|
|
}
|
|
|
|
return Ok(new { message = "上传成功", path = filePath });
|
|
}
|
|
|
|
[HttpPost("uploadwpmlfile")]
|
|
[AllowAnonymous]
|
|
public async Task<IActionResult> UploadWpmlFile(IFormFile xmlFile, string id)
|
|
{
|
|
if (xmlFile == null || xmlFile.Length == 0)
|
|
return BadRequest("文件为空");
|
|
string baseFolder = "Waylines/" + (string.IsNullOrEmpty(id) ? Guid.NewGuid().ToString() : id);
|
|
var uploadsFolder = Path.Combine(Directory.GetCurrentDirectory(), baseFolder);
|
|
if (!Directory.Exists(uploadsFolder))
|
|
Directory.CreateDirectory(uploadsFolder);
|
|
|
|
var filePath = Path.Combine(uploadsFolder, "waylines.wpml");
|
|
|
|
using (var stream = new FileStream(filePath, FileMode.Create))
|
|
{
|
|
await xmlFile.CopyToAsync(stream);
|
|
}
|
|
|
|
return Ok(new { message = "上传成功", path = filePath });
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 项目管理
|
|
|
|
/// <summary>
|
|
/// 获取项目列表
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<Response<List<LasaWorkspace>>> GetWorkspaceList(string key)
|
|
{
|
|
var result = new Response<List<LasaWorkspace>>();
|
|
try
|
|
{
|
|
result = await _app.GetWorkspaceList(key);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Code = 500;
|
|
result.Message = ex.Message;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加项目
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> AddWorkspace(LasaWorkspace info)
|
|
{
|
|
return await _app.AddWorkspace(info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑项目
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> EditWorkspace(LasaWorkspace info)
|
|
{
|
|
return await _app.EditWorkspace(info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除项目
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<Response<bool>> DeleteWorkspace(string id)
|
|
{
|
|
return await _app.DeleteWorkspace(id);
|
|
}
|
|
|
|
#endregion
|
|
|
|
// 航线任务在云端的 共享查看、下发执行、取消以及进度上报等功能。
|
|
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
public async Task Test()
|
|
{
|
|
await _mqttClientManager.SubscribeAsync("thing/product/8UUXN5400A079H/osd", async (args) =>
|
|
{
|
|
var payload = args.ApplicationMessage.Payload;
|
|
var message = Encoding.UTF8.GetString(payload);
|
|
Console.WriteLine($"收到主题 [{args.ApplicationMessage.Topic}] 的消息: {message}");
|
|
await Task.CompletedTask; // 可选:实际逻辑中可执行更多异步操作
|
|
});
|
|
}
|
|
}
|
|
} |