同步代码

main
陈伟 2 months ago
parent 640c30a09a
commit e16ebc3e60

@ -158,7 +158,6 @@ public class MinioService
{
objectName = objectName.Replace($"http://{endPoint}/{_bucketName}/", "");
}
var deleteargs = new RemoveObjectArgs().WithBucket(_bucketName).WithObject(objectName);
await _minioClient.RemoveObjectAsync(deleteargs);
Console.WriteLine($"File {objectName} deleted.");

@ -57,21 +57,21 @@ public class MqttClientManager
/// <param name="password"></param>
public async Task ConnectAsync(string server, int port, string username = null, string password = null)
{
var inboundOptions = new MqttClientOptionsBuilder()
_inboundOptions = new MqttClientOptionsBuilder()
.WithClientId(Guid.NewGuid() + "_inbound")
.WithTcpServer(server, port)
.WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
.WithCredentials(username, password)
.Build();
var outboundOptions = new MqttClientOptionsBuilder()
_outboundOptions = new MqttClientOptionsBuilder()
.WithClientId(Guid.NewGuid() + "_outbound")
.WithTcpServer(server, port)
.WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
.WithCredentials(username, password)
.Build();
await _outBoundClient.ConnectAsync(inboundOptions, _cancellationTokenSource.Token);
await _inBoundClient.ConnectAsync(outboundOptions, _cancellationTokenSource.Token);
await _outBoundClient.ConnectAsync(_inboundOptions, _cancellationTokenSource.Token);
await _inBoundClient.ConnectAsync(_outboundOptions, _cancellationTokenSource.Token);
_outBoundClient.ConnectedAsync += OnConnectedAsync;
_inBoundClient.ConnectedAsync += OnConnectedAsync;
_outBoundClient.DisconnectedAsync += OnOutboundDisconnectedAsync;

@ -19,6 +19,8 @@ using OpenAuth.WebApi.CloudSdk;
using SqlSugar;
using System.Dynamic;
using System.Text;
using NPOI.HSSF.Record;
using OpenAuth.App.Request;
namespace OpenAuth.App.ServiceApp
{
@ -26,15 +28,18 @@ namespace OpenAuth.App.ServiceApp
{
private readonly MqttClientManager _mqttClientManager;
private readonly MinioService _minioService;
private readonly OpenJobApp _openJobApp;
CommonDataManager _commonDataManager;
public ManageApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<LasaDronePort> repository, IAuth auth,
MqttClientManager mqttClientManager, CommonDataManager commonDataManager, MinioService minioService)
MqttClientManager mqttClientManager, CommonDataManager commonDataManager, MinioService minioService,
OpenJobApp openJobApp)
: base(unitWork, repository, auth)
{
_mqttClientManager = mqttClientManager;
_minioService = minioService;
_commonDataManager = commonDataManager;
_openJobApp = openJobApp;
}
#region 机场管理
@ -173,6 +178,7 @@ namespace OpenAuth.App.ServiceApp
};
}
}
/// <summary>
/// 获取机场sn获取无人机列表
/// </summary>
@ -314,6 +320,29 @@ namespace OpenAuth.App.ServiceApp
task.CreateId = _auth.GetCurrentUser().User.Id;
task.CreateTime = DateTime.Now;
var flag = await db.LasaTask.InsertAsync(task);
// todo 判断任务类型添加openjob记录 (openjob 增删改)
// //{"0":"立即任务","1":"定时任务",
var type = task.TaskType;
if (type.Equals(1)) // 定时任务
{
AddOrUpdateOpenJobReq record = new AddOrUpdateOpenJobReq()
{
JobName = $"{task.Id}",
JobType = 0, // 本地任务
JobCall = "OpenAuth.App.BaseApp.Jobs.TaskJob",
JobCallParams = "{\"taskId\":\"" + task.Id + "\"}",
Cron = task.PeriodicFormula,
Status = 1, // 开启运行 todo 关于修改后关闭问题
Remark = "定时任务",
};
_openJobApp.Add(record);
}
else if (type.Equals(0))
{
// 调用飞行任务
await ExecuteFlyTask(task.Id);
}
if (db.Commit())
return new Response<bool> { Result = true, Message = "添加成功" };
else
@ -337,13 +366,43 @@ namespace OpenAuth.App.ServiceApp
//删除任务
public async Task<Response<bool>> DeleteTask(string id)
{
var task = await Repository
.ChangeRepository<SugarRepositiry<LasaTask>>()
.AsQueryable()
.Where(it => it.Id == id).SingleAsync();
if (task == null)
{
return new Response<bool> { Result = false, Message = "任务不存在" };
}
if (task.CompletedTime != null) // 定时任务
{
return new Response<bool> { Result = false, Message = "已完成任务禁止删除" };
}
using (var db = UnitWork.CreateContext())
{
var flag = await db.LasaTask.DeleteAsync(it => it.Id == id);
var taskId = task.Id;
var mediaFileList = await db.LasaMediaFile.AsQueryable()
.Where(it => it.TaskId == taskId)
.ToListAsync();
foreach (var item in mediaFileList)
{
await _minioService.DeleteFile(item.ObjectKey);
}
// 定时任务,
if (task.TaskType.Equals(1))
{
await db.SysOpenJob.AsDeleteable()
.Where(it => it.JobCallParams.Contains(taskId))
.ExecuteCommandAsync();
}
if (db.Commit())
return new Response<bool> { Result = true, Message = "删除成功" };
else
return new Response<bool> { Result = false, Message = "删除失败" };
return new Response<bool> { Result = false, Message = "删除失败" };
}
}
@ -655,6 +714,8 @@ namespace OpenAuth.App.ServiceApp
#endregion
// todo 保存任务时,执行任务
public async Task ExecuteFlyTask(string taskId)
{
// 任务信息
@ -1068,7 +1129,6 @@ namespace OpenAuth.App.ServiceApp
//修改图斑数据
var flagGeom = await db.Ado.ExecuteCommandAsync(geomSql.ToString());
});
if (transFlag.IsSuccess)
return new Response<string>
@ -1109,7 +1169,7 @@ namespace OpenAuth.App.ServiceApp
StringBuilder sql = new StringBuilder();
sql.AppendFormat($" Select * from lasa_annotation where \"WorkSpaceId\" = '{workspaceid}'");
var list = db.Db.SqlQueryable<LasaAnnotation>(sql.ToString()).ToList();
if (type!=null && list.Count > 0)
if (type != null && list.Count > 0)
{
list = list.Where(r => r.Type == type).ToList();
}
@ -1205,7 +1265,8 @@ namespace OpenAuth.App.ServiceApp
}
};
//thing/product/{gateway_sn}/services
await _mqttClientManager.PublishAsync("thing/product/8UUXN5400A079H/services", JsonConvert.SerializeObject(request));
await _mqttClientManager.PublishAsync("thing/product/8UUXN5400A079H/services",
JsonConvert.SerializeObject(request));
return new Response<bool>()
{
Result = true
@ -1225,7 +1286,8 @@ namespace OpenAuth.App.ServiceApp
video_id = "8UUXN5400A079H/165-0-7/normal-0"
}
};
await _mqttClientManager.PublishAsync("thing/product/8UUXN5400A079H/services", JsonConvert.SerializeObject(request));
await _mqttClientManager.PublishAsync("thing/product/8UUXN5400A079H/services",
JsonConvert.SerializeObject(request));
return new Response<bool>()
{
Result = true
@ -1233,12 +1295,15 @@ namespace OpenAuth.App.ServiceApp
}
#region 基本信息统计
public async Task<Response<JObject>> GetBasicInfo()
{
using (var db = UnitWork.CreateContext())
{
var dronInfo = await db.LasaDronePort.AsQueryable().Where(r => r.IsDelete == false && r.TypeId.Contains("Dock")).CountAsync();
var otherInfo = await db.LasaDronePort.AsQueryable().Where(r => r.IsDelete == false && !r.TypeId.Contains("Dock")).CountAsync();
var dronInfo = await db.LasaDronePort.AsQueryable()
.Where(r => r.IsDelete == false && r.TypeId.Contains("Dock")).CountAsync();
var otherInfo = await db.LasaDronePort.AsQueryable()
.Where(r => r.IsDelete == false && !r.TypeId.Contains("Dock")).CountAsync();
var pilotInfo = await db.SysUserRole.AsQueryable().Where(r => r.RoleId == 555252989157446).CountAsync();
var taskInfo = await db.LasaTask.AsQueryable().CountAsync();
JObject obj = new JObject
@ -1250,8 +1315,8 @@ namespace OpenAuth.App.ServiceApp
};
return new Response<JObject> { Result = obj, Message = "获取数据成功" };
}
}
#endregion
}
}

@ -98,13 +98,6 @@ public class ConfigSubscribe : IJob
switch (tempStr)
{
case "thing/product/*/requests":
//{"bid":"f936a236-030c-4358-bee9-b5075e1e2ddf",
//"data":{"flight_id":"e5ce8433-c264-4357-84d9-b701faf90d9e"},
//"method":"flighttask_resource_get",
//"tid":"61b6389a-7b72-49ae-bb46-0729e85c95d2",
//"timestamp":1750554644321,
//"gateway":"8UUXN5400A079H"}
// todo 处理资源获取请求
switch (method)
{
// 临时凭证上传
@ -130,14 +123,14 @@ public class ConfigSubscribe : IJob
{
bucket = "test",
endpoint = "http://175.27.168.120:6013",
object_key_prefix = $"{Guid.NewGuid().ToString()}", // todo 是否设计任务id
object_key_prefix = Guid.NewGuid().ToString(), // todo 是否设计任务id
provider = "minio",
region = "linyi",
credentials = new
{
access_key_id = "minioadmin",
access_key_secret = "minioadmin",
expire = 480,
expire = 3600,
security_token = ""
}
}
@ -151,6 +144,12 @@ public class ConfigSubscribe : IJob
case "flight_areas_get":
//Console.WriteLine("跳过自定义飞行区文件获取");
break;
//{"bid":"f936a236-030c-4358-bee9-b5075e1e2ddf",
//"data":{"flight_id":"e5ce8433-c264-4357-84d9-b701faf90d9e"},
//"method":"flighttask_resource_get",
//"tid":"61b6389a-7b72-49ae-bb46-0729e85c95d2",
//"timestamp":1750554644321,
//"gateway":"8UUXN5400A079H"}
// 获取航线
case "flighttask_resource_get":
string flightId = data.flight_id + "";
@ -211,69 +210,65 @@ public class ConfigSubscribe : IJob
{
break;
}
lock (_dockUploadFileLocker)
string flightId = data.file.ext.flight_id;
string taskId = _manageApp.GetTaskAssignByFlightId(flightId).TaskId;
var fileUpload = new LasaMediaFile()
{
string flightId = data.file.ext.flight_id;
string taskId = _manageApp.GetTaskAssignByFlightId(flightId).TaskId;
var fileUpload = new LasaMediaFile()
{
Id = Guid.NewGuid().ToString(),
FlightId = flightId, // 计划id
TaskId = taskId, // 任务id
DroneModelKey = data.file.ext.drone_model_key, // 无人机型号
IsOriginal = data.file.ext.is_original,
MediaIndex = data.file.ext.media_index,
PayloadModelKey = data.file.ext.payload_model_key, //这应该可以标明是什么设置
AbsoluteAltitude = data.file.metadata.absolute_altitude, // 拍摄绝对高度
GimbalYawDegree = data.file.metadata.gimbal_yaw_degree, //云台偏航角度
RelativeAltitude = data.file.metadata.relative_altitude, // 拍摄相对高度
Lat = data.file.metadata.shoot_position.lat,
Lng = data.file.metadata.shoot_position.lng,
Name = data.file.name,
ObjectKey = data.file.object_key,
Path = data.file.path, // 目前这个好像没有值
CreateTime = ((string)data.file.metadata.created_time).ToDateTime(),
};
// todo 添加事务
_sqlSugarClient.Insertable(fileUpload).ExecuteCommand();
if (result.need_reply.Equals(1))
Id = Guid.NewGuid().ToString(),
FlightId = flightId, // 计划id
TaskId = taskId, // 任务id
DroneModelKey = data.file.ext.drone_model_key, // 无人机型号
IsOriginal = data.file.ext.is_original,
MediaIndex = data.file.ext.media_index,
PayloadModelKey = data.file.ext.payload_model_key, //这应该可以标明是什么设置
AbsoluteAltitude = data.file.metadata.absolute_altitude, // 拍摄绝对高度
GimbalYawDegree = data.file.metadata.gimbal_yaw_degree, //云台偏航角度
RelativeAltitude = data.file.metadata.relative_altitude, // 拍摄相对高度
Lat = data.file.metadata.shoot_position.lat,
Lng = data.file.metadata.shoot_position.lng,
Name = data.file.name,
ObjectKey = data.file.object_key,
Path = data.file.path, // 目前这个好像没有值
CreateTime = ((string)data.file.metadata.created_time).ToDateTime(),
};
// todo 添加事务
await _sqlSugarClient.Insertable(fileUpload).ExecuteCommandAsync();
if (result.need_reply.Equals(1))
{
var fileUploadCallbackEventReply = new FileUploadCallbackEventReply<object>()
{
var fileUploadCallbackEventReply = new FileUploadCallbackEventReply<object>()
bid = result.bid,
tid = result.tid,
method = "file_upload_callback",
gateway = sn,
data = new
{
bid = result.bid,
tid = result.tid,
method = "file_upload_callback",
gateway = sn,
data = new
{
result = 0
},
timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
};
_ = _mqttClientManager.PublishAsync($"thing/product/{sn}/events_reply",
JsonConvert.SerializeObject(fileUploadCallbackEventReply));
}
var expectFileCount = data.flight_task.expected_file_count;
var uploadedFileCount = data.flight_task.uploaded_file_count;
var taskRecord = new LasaTask()
{
Id = taskId,
ExpectedFileCount = expectFileCount, // 期望文件数量
UploadedFileCount = uploadedFileCount // 已上传文件数量
result = 0
},
timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
};
// 当expectFileCount 等于uploadedFileCount时则表示航线执行完成
if (uploadedFileCount.Equals(expectFileCount))
{
taskRecord.Status = 5; // 成功状态
}
_ = _mqttClientManager.PublishAsync($"thing/product/{sn}/events_reply",
JsonConvert.SerializeObject(fileUploadCallbackEventReply));
}
_sqlSugarClient.Updateable(taskRecord)
.IgnoreNullColumns().ExecuteCommand();
var expectFileCount = data.flight_task.expected_file_count;
var uploadedFileCount = data.flight_task.uploaded_file_count;
var taskRecord = new LasaTask()
{
Id = taskId,
ExpectedFileCount = expectFileCount, // 期望文件数量
UploadedFileCount = uploadedFileCount // 已上传文件数量
};
// 当expectFileCount 等于uploadedFileCount时则表示航线执行完成
if (uploadedFileCount.Equals(expectFileCount))
{
taskRecord.Status = 5; // 成功状态
}
await _sqlSugarClient.Updateable(taskRecord)
.IgnoreNullColumns().ExecuteCommandAsync();
break;
case "release_terminal_control_area":
//暂不处理

@ -25,7 +25,7 @@ namespace OpenAuth.Repository.Domain
public string TaskName { get; set; }
/// <summary>
/// 任务类型
/// 任务类型 "0":"立即任务","1":"定时任务"
/// </summary>
public int TaskType { get; set; }

@ -81,6 +81,8 @@ namespace OpenAuth.Repository
public SugarRepositiry<DroneDocktask> DroneDocktask { get; set; }
public SugarRepositiry<LasaMediaFile> LasaMediaFile { get; set; }
public SugarRepositiry<SysOpenJob> SysOpenJob { get; set; }
#endregion
}
}

@ -220,7 +220,7 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
}
/// <summary>
/// 删除任务
/// 删除任务 只要未完成的都可删除吗?
/// </summary>
/// <returns></returns>
[HttpPost]

Loading…
Cancel
Save