1. minio 上传文件后缀保持

2. 任务下发记录表添加字段
3. 任务下发修改
4. 全局订阅添加订阅
main
陈伟 3 months ago
parent 27cfc84e43
commit 69a4457a27

@ -184,7 +184,8 @@ public class MinioService
await _minioClient.MakeBucketAsync(mbArgs).ConfigureAwait(false);
}
var objectName = $"{GenerateId.GenerateOrderNumber()}.kmz";
var suffix = Path.GetExtension(file.FileName);
var objectName = $"{GenerateId.GenerateOrderNumber()}{suffix}";
// 使用内存流上传
using var stream = new MemoryStream();
await file.CopyToAsync(stream);

@ -34,6 +34,10 @@ public class ConfigSubscribe : IJob
.SubscribeAsync($"thing/product/{gatewaySn}/services_reply",
async (args) => await HandleTopic(gatewaySn, args.ApplicationMessage.Topic,
Encoding.UTF8.GetString(args.ApplicationMessage.Payload)));
await mqttClientManager
.SubscribeAsync($"thing/product/{gatewaySn}/events",
async (args) => await HandleTopic(gatewaySn, args.ApplicationMessage.Topic,
Encoding.UTF8.GetString(args.ApplicationMessage.Payload)));
}
public async Task Execute(IJobExecutionContext context)
@ -69,15 +73,98 @@ public class ConfigSubscribe : IJob
sys/product/{gateway_sn}/status 线
thing/product/{gateway_sn}/property/set_reply
thing/product/{gateway_sn}/drc/up DRC */
// thing/product/8UUXN5400A079H/requests
if (topic.Equals("thing/product/8UUXN5400A079H/requests"))
{
Console.WriteLine("收到的资源请求-未处理字符串");
}
var tempStr = topic.Replace(sn, "*");
if (tempStr.Equals("thing/product/*/requests"))
{
Console.WriteLine("收到的资源请求");
}
//Console.WriteLine($"成功调用主题 [{topic}] 的消息: {message}");
// 主题方法
var result = JsonConvert.DeserializeObject<TopicServicesRequest<dynamic>>(message);
var method = result.method;
var data = result.data;
long code = data.result;
var hasProperty = false;
foreach (var property in data.GetType().GetProperties())
{
if (property.Name != "result") continue;
hasProperty = true;
break;
}
long code = 0;
if (hasProperty)
{
code = data.result;
}
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)
{
case "flighttask_resource_get":
Console.WriteLine($"获取资源请求:{JsonConvert.SerializeObject(data)}");
var flightId = data.flight_id;
LasaTaskAssign taskAssign =
manageApp.GetTaskAssignByBidAndTidAndFlightId(result.bid, result.tid, flightId);
var flightTaskResourceGetTopic = $"thing/product/{sn}/requests_reply";
dynamic outData = new ExpandoObject();
var outRequest = new TopicServicesRequest<object>()
{
method = "flighttask_resource_get",
tid = result.tid,
bid = result.bid,
timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
data = outData
};
outData.result = 0;
outData.output = new
{
file = new
{
fingerprint = taskAssign.Md5,
url = taskAssign.Wpml
}
};
await mqttClientManager.PublishAsync(flightTaskResourceGetTopic,
JsonConvert.SerializeObject(outRequest));
break;
default:
Console.WriteLine($"未知请求:{message}");
break;
}
break;
// thing/product/8UUXN5400A079H/events
// {"bid":"0ebc789e-7f06-4830-a58a-8c4753cd493c",
// "data":{"output":{"ext":{"current_waypoint_index":0,
// "flight_id":"d6c00cc5-ec59-4bab-8508-fcb259f00a60",
// "media_count":0,"track_id":"","wayline_id":65535,"wayline_mission_state":2},
// "progress":{"current_step":36,"percent":15},"status":"failed"},"result":314013},
// "method":"flighttask_progress","need_reply":1,"tid":"84b048f7-43db-41c5-86c5-8938dc446ea4","timestamp":1750411329943,"gateway":"8UUXN5400A079H"}
case "thing/product/*/events":
if (method.Equals("flighttask_progress"))
{
// todo 处理航线进度 ,也有可能是失败
if (code != 0)
{
Console.WriteLine($"航线进度错误信息:{ErrorMap[code]}");
}
}
break;
// todo
// 任务资源处理
// 航线进度处理
@ -87,7 +174,7 @@ public class ConfigSubscribe : IJob
{
case "flighttask_prepare": // 下发任务响应
// 报错处理
Console.WriteLine("处理prepare消息");
var taskAssign = manageApp.GetTaskAssignByBidAndTid(result.bid, result.tid);
if (code == 0)
{
@ -95,11 +182,12 @@ public class ConfigSubscribe : IJob
var flightId = taskAssign.FlightId;
var request = new TopicServicesRequest<object>();
dynamic data1 = new ExpandoObject();
data.flight_id = flightId;
data1.flight_id = flightId;
request.SetMethod("flighttask_execute")
.SetTid(Guid.NewGuid().ToString())
.SetBid(Guid.NewGuid().ToString())
.SetData(data);
.SetTimestamp(DateTimeOffset.Now.ToUnixTimeMilliseconds())
.SetData(data1);
// 任务执行
await mqttClientManager.PublishAsync($"thing/product/{sn}/services",
JsonConvert.SerializeObject(request));
@ -127,7 +215,7 @@ public class ConfigSubscribe : IJob
}
else
{
Console.WriteLine($"任务成功");
Console.WriteLine($"flighttask_execute 任务成功");
}
break;

@ -576,7 +576,7 @@ namespace OpenAuth.App.ServiceApp
method = "flighttask_prepare",
tid = Guid.NewGuid().ToString(),
bid = Guid.NewGuid().ToString(),
timestamp = DateTime.Now.Ticks,
timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds()
};
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
@ -592,7 +592,10 @@ namespace OpenAuth.App.ServiceApp
//var serverIp = configuration["MQTT:Server"];
dynamic data = new ExpandoObject();
data.flight_id = Guid.NewGuid().ToString();
data.execute_time = DateTime.Now.Ticks + 5000;
data.execute_time = DateTimeOffset.Now.ToUnixTimeMilliseconds();
//{"0":"立即任务","1":"定时任务","2":"条件任务"}
// 立即任务和定时任务均由execute_time指定执行时间条件任务支持ready_conditions字段指定任务就绪条件设备可在指定时间段内满足就绪条件后即可执行立即任务媒体上传优先级最高定时任务和条件任务媒体上传优先级相同
// 若task_type任务类型指定为“立即执行”时设备端限制了30s的时间误差若设备收到指令的时间与execute_time相差超过30s将报错且该任务无法正常执行。
data.task_type = task.TaskType;
var md5 = await _minioService.GetMetaObject(wpml, "");
data.file = new
@ -665,9 +668,9 @@ namespace OpenAuth.App.ServiceApp
// todo 获取指定值 计算 还是
battery_capacity = 77, // 设备电量百分比,范围 0-100
// todo 设定时间
begin_time = DateTime.Now.Ticks + 50000, // 任务开始执行时间必须大于该值
begin_time = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 50000, // 任务开始执行时间必须大于该值
// todo 设定结束时间
end_time = DateTime.Now.Ticks + 100000, // 任务结束时间必须
end_time = DateTimeOffset.Now.ToUnixTimeMilliseconds() + 100000, // 任务结束时间必须
};
}
@ -684,9 +687,11 @@ namespace OpenAuth.App.ServiceApp
Status = 1,
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
TaskId = taskId
TaskId = taskId,
Md5 = md5,
Wpml = wpml
};
Repository.ChangeRepository<SugarRepositiry<LasaTaskAssign>>().Insert(taskAssign);
await Repository.ChangeRepository<SugarRepositiry<LasaTaskAssign>>().InsertAsync(taskAssign);
// 任务下发
await _mqttClientManager.PublishAsync(topic, JsonConvert.SerializeObject(request));
return JsonConvert.SerializeObject(request);
@ -899,5 +904,12 @@ namespace OpenAuth.App.ServiceApp
.ChangeRepository<SugarRepositiry<LasaTaskAssign>>()
.GetSingle(r => r.Bid == bid && r.Tid == tid);
}
public LasaTaskAssign GetTaskAssignByBidAndTidAndFlightId(string bid, string tid, string flightId)
{
return Repository
.ChangeRepository<SugarRepositiry<LasaTaskAssign>>()
.GetSingle(r => r.Bid == bid && r.Tid == tid && r.FlightId == flightId);
}
}
}

@ -17,4 +17,6 @@ public class LasaTaskAssign
public DateTime? UpdateTime { get; set; }
public string Reason { get; set; }
public string TaskId { get; set; }
public string Md5 { get; set; }
public string Wpml { get; set; }
}
Loading…
Cancel
Save