|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
using Infrastructure.CloudSdk.mqttmessagecenter;
|
|
|
|
|
using OpenAuth.App.ServiceApp;
|
|
|
|
|
using OpenAuth.Repository.Domain;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
|
|
|
|
@ -10,20 +11,22 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
private readonly ILogger<ThingRequestHandler> _logger;
|
|
|
|
|
private readonly MqttClientManager _mqttClientManager;
|
|
|
|
|
AirportMaintenanceApp _app;
|
|
|
|
|
ManageApp _manageApp;
|
|
|
|
|
|
|
|
|
|
public ThingRequestHandler(ILogger<ThingRequestHandler> logger, MqttClientManager mqttClientManager, AirportMaintenanceApp app)
|
|
|
|
|
public ThingRequestHandler(ILogger<ThingRequestHandler> logger, MqttClientManager mqttClientManager, AirportMaintenanceApp app, ManageApp manageApp)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_mqttClientManager = mqttClientManager;
|
|
|
|
|
_app = app;
|
|
|
|
|
_manageApp = manageApp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanHandle(string topic)
|
|
|
|
|
{
|
|
|
|
|
return topic.Contains("/requests");
|
|
|
|
|
return topic.Contains("/requests1");
|
|
|
|
|
}
|
|
|
|
|
string bid, tid, previousgateway;
|
|
|
|
|
int timestamp;
|
|
|
|
|
long timestamp;
|
|
|
|
|
public async Task HandleAsync(string topic, string payload)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"[Request] Topic={topic}, Payload={payload}");
|
|
|
|
@ -41,13 +44,13 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
}
|
|
|
|
|
bid = root["bid"]?.ToString() ?? "";
|
|
|
|
|
tid = root["tid"]?.ToString() ?? "";
|
|
|
|
|
timestamp = int.Parse(root["timestamp"]?.ToString() ?? "0");
|
|
|
|
|
timestamp = long.Parse(root["timestamp"]?.ToString() ?? "0");
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = bid,
|
|
|
|
|
method = "config",
|
|
|
|
|
tid = tid,
|
|
|
|
|
timestamp = timestamp,
|
|
|
|
|
timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
|
gateway = gateway,
|
|
|
|
|
data = new
|
|
|
|
|
{
|
|
|
|
@ -60,12 +63,34 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
string payloadreq = JsonSerializer.Serialize(requestData);
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{gateway}/requests_reply", payloadreq);
|
|
|
|
|
await _app.UpdateCodeStatus(gateway);
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{gateway}/requests1_reply", payloadreq);
|
|
|
|
|
await _app.UpdateGateway(gateway, tid);
|
|
|
|
|
}
|
|
|
|
|
if (payload.Contains("airport_bind_status"))
|
|
|
|
|
{
|
|
|
|
|
//解析返回的设备sn 先不解析,先测试绑定
|
|
|
|
|
var root = JsonNode.Parse(payload)?.AsObject();
|
|
|
|
|
if (root == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 从 data.devices 中提取 sn 列表
|
|
|
|
|
var snList = root?["data"]?["devices"]?.AsArray()
|
|
|
|
|
.Select(d => d?["sn"]?.ToString())
|
|
|
|
|
.Where(sn => !string.IsNullOrEmpty(sn))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
// 生成 bind_status 对象列表
|
|
|
|
|
var bindStatusList = snList?.Select(sn => new
|
|
|
|
|
{
|
|
|
|
|
device_callsign = "山东慧创",
|
|
|
|
|
is_device_bind_organization = true,
|
|
|
|
|
organization_id = "379",
|
|
|
|
|
organization_name = "山东慧创",
|
|
|
|
|
sn = sn
|
|
|
|
|
}).ToArray();
|
|
|
|
|
|
|
|
|
|
// 构造最终请求对象
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = Guid.NewGuid().ToString(),
|
|
|
|
@ -73,25 +98,7 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
{
|
|
|
|
|
output = new
|
|
|
|
|
{
|
|
|
|
|
bind_status = new[]
|
|
|
|
|
{
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
device_callsign = "山东慧创",
|
|
|
|
|
is_device_bind_organization = true,
|
|
|
|
|
organization_id = "379",
|
|
|
|
|
organization_name = "山东慧创",
|
|
|
|
|
sn = "8UUXN5400A079H"
|
|
|
|
|
},
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
device_callsign = "山东慧创",
|
|
|
|
|
is_device_bind_organization = true,
|
|
|
|
|
organization_id = "379",
|
|
|
|
|
organization_name = "山东慧创",
|
|
|
|
|
sn = "1581F8HGX254V00A0BUY"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bind_status = bindStatusList
|
|
|
|
|
},
|
|
|
|
|
result = 0
|
|
|
|
|
},
|
|
|
|
@ -101,11 +108,13 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
};
|
|
|
|
|
string payloadreq = JsonSerializer.Serialize(requestData);
|
|
|
|
|
string getway = topic.Split('/')[2];
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests_reply", payloadreq);
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests1_reply", payloadreq);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (payload.Contains("airport_organization_get"))
|
|
|
|
|
{
|
|
|
|
|
if (payload.Contains("airport_organization_get"))//
|
|
|
|
|
{
|
|
|
|
|
var root = JsonNode.Parse(payload)?.AsObject();
|
|
|
|
|
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = Guid.NewGuid().ToString(),
|
|
|
|
@ -123,11 +132,51 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
};
|
|
|
|
|
string payloadreq = JsonSerializer.Serialize(requestData);
|
|
|
|
|
string getway = topic.Split('/')[2];
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests_reply", payloadreq);
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests1_reply", payloadreq);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (payload.Contains("airport_organization_bind"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// 解析 JSON
|
|
|
|
|
var root = JsonNode.Parse(payload)?.AsObject();
|
|
|
|
|
// 获取 bind_devices 数组
|
|
|
|
|
var bindDevices = root?["data"]?["bind_devices"]?.AsArray();
|
|
|
|
|
string dronesn = "", uavsn = "";
|
|
|
|
|
LasaDronePort lasaDronePort = new LasaDronePort();
|
|
|
|
|
LasaUav lasaUav = new LasaUav();
|
|
|
|
|
if (bindDevices != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var device in bindDevices)
|
|
|
|
|
{
|
|
|
|
|
var obj = device?.AsObject();
|
|
|
|
|
if (obj["device_model_key"].ToString().Contains("3-"))
|
|
|
|
|
{
|
|
|
|
|
lasaDronePort.Id = Guid.NewGuid().ToString();
|
|
|
|
|
lasaDronePort.OrgId = obj["organization_id"]?.ToString();
|
|
|
|
|
lasaDronePort.CreateTime = DateTime.Now;
|
|
|
|
|
lasaDronePort.IsDelete = false;
|
|
|
|
|
lasaDronePort.TypeId = "Dock 3";
|
|
|
|
|
lasaDronePort.Sn = obj["sn"].ToString();
|
|
|
|
|
lasaDronePort.BindStatus = 1;
|
|
|
|
|
lasaDronePort.Name = "机场";
|
|
|
|
|
dronesn = obj["sn"].ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lasaUav.Id = Guid.NewGuid().ToString();
|
|
|
|
|
lasaUav.IsDelete = false;
|
|
|
|
|
//lasaUav.TypeId = obj["device_model_key"].ToString();
|
|
|
|
|
lasaUav.TypeId = "M4TD";
|
|
|
|
|
lasaUav.Sn = obj["sn"].ToString();
|
|
|
|
|
lasaUav.PId = lasaDronePort.Id;
|
|
|
|
|
lasaUav.Name = "飞行器";
|
|
|
|
|
uavsn = obj["sn"].ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_manageApp.AddDronePort(lasaDronePort);
|
|
|
|
|
_manageApp.AddLasaUav(lasaUav);
|
|
|
|
|
var requestData = new
|
|
|
|
|
{
|
|
|
|
|
bid = Guid.NewGuid().ToString(),
|
|
|
|
@ -140,12 +189,12 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
err_code = 210231,
|
|
|
|
|
sn = "8UUXN5400A079H"
|
|
|
|
|
sn = dronesn
|
|
|
|
|
},
|
|
|
|
|
new
|
|
|
|
|
{
|
|
|
|
|
err_code = 210231,
|
|
|
|
|
sn = "1581F8HGX254V00A0BUY"
|
|
|
|
|
sn = uavsn
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -157,7 +206,7 @@ namespace OpenAuth.WebApi.Model.mqtt
|
|
|
|
|
};
|
|
|
|
|
string payloadreq = JsonSerializer.Serialize(requestData);
|
|
|
|
|
string getway = topic.Split('/')[2];
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests_reply", payloadreq);
|
|
|
|
|
await _mqttClientManager.PublishAsync($"thing/product/{getway}/requests1_reply", payloadreq);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|