|
|
|
@ -2,6 +2,8 @@
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Infrastructure.Cache;
|
|
|
|
|
using Infrastructure.CloudSdk.wayline;
|
|
|
|
|
using MQTTnet;
|
|
|
|
|
using MQTTnet.Client;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using OpenAuth.App.ServiceApp;
|
|
|
|
|
using OpenAuth.Repository.Domain;
|
|
|
|
@ -13,34 +15,41 @@ namespace OpenAuth.App.BaseApp.Subscribe;
|
|
|
|
|
|
|
|
|
|
public class ConfigSubscribe : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly MqttClientManager mqttClientManager;
|
|
|
|
|
private readonly ISqlSugarClient sqlSugarClient;
|
|
|
|
|
private readonly RedisCacheContext redisCacheContext;
|
|
|
|
|
private readonly ManageApp manageApp;
|
|
|
|
|
private object locker = new();
|
|
|
|
|
private readonly MqttClientManager _mqttClientManager;
|
|
|
|
|
private readonly ISqlSugarClient _sqlSugarClient;
|
|
|
|
|
private readonly RedisCacheContext _redisCacheContext;
|
|
|
|
|
private readonly ManageApp _manageApp;
|
|
|
|
|
private object _locker = new();
|
|
|
|
|
|
|
|
|
|
public ConfigSubscribe(MqttClientManager mqttClientManager, ISqlSugarClient sqlSugarClient,
|
|
|
|
|
ICacheContext redisCacheContext, ManageApp manageApp)
|
|
|
|
|
{
|
|
|
|
|
this.mqttClientManager = mqttClientManager;
|
|
|
|
|
this.sqlSugarClient = sqlSugarClient;
|
|
|
|
|
this.redisCacheContext = redisCacheContext as RedisCacheContext;
|
|
|
|
|
this.manageApp = manageApp;
|
|
|
|
|
_mqttClientManager = mqttClientManager;
|
|
|
|
|
_sqlSugarClient = sqlSugarClient;
|
|
|
|
|
_redisCacheContext = redisCacheContext as RedisCacheContext;
|
|
|
|
|
_manageApp = manageApp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task Subscribe()
|
|
|
|
|
{
|
|
|
|
|
string gatewaySn = "8UUXN5400A079H";
|
|
|
|
|
// 或者 thing/product/#
|
|
|
|
|
// sys/product/#
|
|
|
|
|
string[] topicList =
|
|
|
|
|
{
|
|
|
|
|
$"thing/product/{gatewaySn}/services_reply",
|
|
|
|
|
$"thing/product/{gatewaySn}/events",
|
|
|
|
|
$"thing/product/{gatewaySn}/requests"
|
|
|
|
|
"thing/product/+/services_reply",
|
|
|
|
|
"thing/product/+/events",
|
|
|
|
|
"thing/product/+/requests"
|
|
|
|
|
};
|
|
|
|
|
await mqttClientManager
|
|
|
|
|
|
|
|
|
|
await _mqttClientManager
|
|
|
|
|
.SubscribeAsync(topicList,
|
|
|
|
|
async (args) => await HandleTopic(gatewaySn, args.ApplicationMessage.Topic,
|
|
|
|
|
Encoding.UTF8.GetString(args.ApplicationMessage.Payload)));
|
|
|
|
|
async (args) =>
|
|
|
|
|
{
|
|
|
|
|
args.IsHandled = false; // todo 待实验确定
|
|
|
|
|
args.AutoAcknowledge = true; // todo 待实验确定
|
|
|
|
|
await HandleTopic(args, args.ApplicationMessage.Topic,
|
|
|
|
|
Encoding.UTF8.GetString(args.ApplicationMessage.Payload));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
|
|
@ -48,21 +57,10 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
await Subscribe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo 暂时不使用
|
|
|
|
|
public static readonly string[] TopicList =
|
|
|
|
|
{
|
|
|
|
|
"thing/product/*/osd",
|
|
|
|
|
"thing/product/*/state",
|
|
|
|
|
"thing/product/*/services_reply",
|
|
|
|
|
"thing/product/*/events",
|
|
|
|
|
"thing/product/*/requests",
|
|
|
|
|
"sys/product/*/status",
|
|
|
|
|
"thing/product/*/property/set_reply",
|
|
|
|
|
"thing/product/*/drc/up"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task HandleTopic(string sn, string topic, string message)
|
|
|
|
|
private async Task HandleTopic(MqttApplicationMessageReceivedEventArgs args, string topic,
|
|
|
|
|
string message)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
thing/product/{device_sn}/osd 设备端定频向云平台推送的设备属性(properties),
|
|
|
|
@ -76,8 +74,8 @@ 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sn = topic.Split("/")[2];
|
|
|
|
|
var tempStr = topic.Replace(sn, "*");
|
|
|
|
|
//Console.WriteLine($"成功调用主题 [{topic}] 的消息: {message}");
|
|
|
|
|
// 主题方法
|
|
|
|
@ -135,7 +133,7 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
};
|
|
|
|
|
// thing/product/{gateway_sn}/requests_reply
|
|
|
|
|
var tempTopic = $"thing/product/{sn}/requests_reply";
|
|
|
|
|
await mqttClientManager.PublishAsync(tempTopic,
|
|
|
|
|
await _mqttClientManager.PublishAsync(tempTopic,
|
|
|
|
|
JsonConvert.SerializeObject(storageConfigRequest));
|
|
|
|
|
break;
|
|
|
|
|
case "flight_areas_get":
|
|
|
|
@ -146,7 +144,7 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
Console.WriteLine("进入资源获取处理");
|
|
|
|
|
string flightId = data.flight_id + "";
|
|
|
|
|
Console.WriteLine($"任务ID:{flightId}");
|
|
|
|
|
if (sqlSugarClient != null)
|
|
|
|
|
if (_sqlSugarClient != null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("manageApp 注入没有问题");
|
|
|
|
|
}
|
|
|
|
@ -155,7 +153,7 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
// http://175.27.168.120:6013/test/2025062209390863860047.kmz
|
|
|
|
|
// md5 585c833012ddb794eaac1050ef71aa31
|
|
|
|
|
// todo 这一小段运行异常
|
|
|
|
|
var taskAssign = await sqlSugarClient
|
|
|
|
|
var taskAssign = await _sqlSugarClient
|
|
|
|
|
.Queryable<LasaTaskAssign>()
|
|
|
|
|
.Where(x => x.FlightId == flightId)
|
|
|
|
|
.SingleAsync();
|
|
|
|
@ -170,8 +168,7 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
file = new
|
|
|
|
|
{
|
|
|
|
|
fingerprint = taskAssign.Md5,
|
|
|
|
|
url = "http://175.27.168.120:6013/test/2025062415430484240112.kmz"
|
|
|
|
|
// url = "http://175.27.168.120:6013/test/2025062209390863860047.kmz"
|
|
|
|
|
url = taskAssign.Wpml
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var outRequest = new TopicServicesRequest<object>()
|
|
|
|
@ -185,7 +182,7 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(
|
|
|
|
|
$"topic: {flightTaskResourceGetTopic} 发送资源获取处理结果:{JsonConvert.SerializeObject(outRequest)}");
|
|
|
|
|
await mqttClientManager.PublishAsync(flightTaskResourceGetTopic,
|
|
|
|
|
await _mqttClientManager.PublishAsync(flightTaskResourceGetTopic,
|
|
|
|
|
JsonConvert.SerializeObject(outRequest));
|
|
|
|
|
break;
|
|
|
|
|
case "config":
|
|
|
|
@ -196,22 +193,15 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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"))
|
|
|
|
|
{
|
|
|
|
|
code = data.result;
|
|
|
|
|
// todo 处理航线进度 ,也有可能是失败
|
|
|
|
|
// 处理航线进度 ,也有可能是失败
|
|
|
|
|
if (code != 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"航线进度错误信息:{ErrorMap[code]} {message}");
|
|
|
|
|
// todo 取消任务
|
|
|
|
|
// 取消任务
|
|
|
|
|
var cancelTaskTopic = $"thing/product/{sn}/services";
|
|
|
|
|
var cancelTaskRequest = new TopicServicesRequest<object>()
|
|
|
|
|
{
|
|
|
|
@ -224,13 +214,13 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
flight_ids = new[] { data.output.ext.flight_id }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
await mqttClientManager.PublishAsync(cancelTaskTopic,
|
|
|
|
|
await _mqttClientManager.PublishAsync(cancelTaskTopic,
|
|
|
|
|
JsonConvert.SerializeObject(cancelTaskRequest));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!method.Equals("hms"))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"未知事件events:{message}");
|
|
|
|
|
Console.WriteLine($"未处理事件events:{message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
@ -248,7 +238,7 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
// 报错处理
|
|
|
|
|
Console.WriteLine("进入prepare订阅消息");
|
|
|
|
|
code = data.result;
|
|
|
|
|
var taskAssign = manageApp.GetTaskAssignByBidAndTid(result.bid, result.tid);
|
|
|
|
|
var taskAssign = _manageApp.GetTaskAssignByBidAndTid(result.bid, result.tid);
|
|
|
|
|
Console.WriteLine($"prepare 任务信息:{JsonConvert.SerializeObject(taskAssign)}");
|
|
|
|
|
if (code == 0)
|
|
|
|
|
{
|
|
|
|
@ -269,14 +259,14 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
.SetTimestamp(DateTimeOffset.Now.ToUnixTimeMilliseconds())
|
|
|
|
|
.SetData(data1);
|
|
|
|
|
// 任务执行
|
|
|
|
|
_ = mqttClientManager.PublishAsync($"thing/product/{sn}/services",
|
|
|
|
|
_ = _mqttClientManager.PublishAsync($"thing/product/{sn}/services",
|
|
|
|
|
JsonConvert.SerializeObject(request));
|
|
|
|
|
var taskAssignRecord = new LasaTaskAssign()
|
|
|
|
|
{
|
|
|
|
|
Id = taskAssign.Id,
|
|
|
|
|
Status = 1
|
|
|
|
|
};
|
|
|
|
|
sqlSugarClient.Updateable(taskAssignRecord).IgnoreNullColumns()
|
|
|
|
|
_sqlSugarClient.Updateable(taskAssignRecord).IgnoreNullColumns()
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
// todo 锁定这个机场 ,不再执行其它任务
|
|
|
|
|
}
|
|
|
|
@ -290,7 +280,7 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
Reason = errorMsg,
|
|
|
|
|
Status = 2
|
|
|
|
|
};
|
|
|
|
|
sqlSugarClient.Updateable(taskAssignRecord).IgnoreNullColumns().ExecuteCommand();
|
|
|
|
|
_sqlSugarClient.Updateable(taskAssignRecord).IgnoreNullColumns().ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|