zhangbin 3 weeks ago
commit 1ece182c51

@ -1,3 +1,4 @@
using System.Diagnostics;
using System.Drawing;
using System.Dynamic;
using System.Net;
@ -959,22 +960,24 @@ namespace OpenAuth.App.ServiceApp
// 取得当前风速及天气
// 当前时间减5秒然后取最新一条数据
// 取得机场序列号
var topicCondition = $"thing/product/{serialNo}/osd";
var time = DateTime.Now.AddSeconds(-5);
var log = await Repository
.ChangeRepository<SugarRepositiry<LasaLog>>()
.AsQueryable()
.Where(r => r.Topic == topicCondition)
.Where(r => r.CreateTime > time)
.Where(r => SqlFunc.JsonLike(r.Data, "wind_speed"))
.OrderByDescending(r => r.CreateTime)
.Where(r => r.Data.Contains("wind_speed"))
.Where(r => r.Topic == $"thing/product/{serialNo}/osd" &&
r.CreateTime > DateTime.Now.AddSeconds(-5))
.FirstAsync();
//不太可能为空
if (log != null)
{
var dataObject = JsonConvert.DeserializeObject<JObject>(log.Data);
var windSpeed = dataObject.GetValue("wind_speed")?.Value<float>(); // m/s
var dataObject =
JsonConvert.DeserializeObject<JObject>(JsonConvert.DeserializeObject<string>(log.Data));
var windSpeed = dataObject["data"]?["wind_speed"]?.Value<float>(); // m/s
var rainfall =
dataObject.GetValue("rainfall")
?.Value<int>(); // {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"}
dataObject["data"]?["rainfall"]?.Value<int>(); // {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"}
// 如果没有天气阻飞?
if (windSpeedThreshold <= windSpeed || rainThreshold <= rainfall ||
@ -1499,19 +1502,142 @@ namespace OpenAuth.App.ServiceApp
#endregion
public async Task<string> TestExecuteFlyTask(string flightid)
public async Task<string> TestPreventFlyTask(string taskId)
{
// flighttask_prepare method
/// thing/product/{gateway_sn}/services 主题
// todo 执行下发任务
var request = new TopicServicesRequest<object>();
dynamic data = new ExpandoObject();
data.flight_id = flightid;
request.SetMethod("flighttask_execute")
.SetTid(flightid)
.SetBid(Guid.NewGuid().ToString())
.SetData(data);
return JsonConvert.SerializeObject(request);
// 任务信息
var task = await Repository.ChangeRepository<SugarRepositiry<LasaTask>>().GetByIdAsync(taskId);
var dronePort = await Repository.ChangeRepository<SugarRepositiry<LasaDronePort>>()
.GetByIdAsync(task.TaskDronePort);
if (dronePort == null)
{
throw new Exception("指定机场不存在");
}
// 取值 Dock 3
var dockTypeId = dronePort.TypeId;
var serialNo = dronePort.Sn;
if (!string.IsNullOrEmpty(task.WorkspaceId))
{
var workspace = await Repository.ChangeRepository<SugarRepositiry<LasaWorkspace>>()
.GetByIdAsync(task.WorkspaceId);
if (workspace != null)
{
// 机场天气信息 阀值(自定义和) 雨量阀值 风速阀值
// 赋值默认阀值
var rainThreshold = 3; // 大雨
var windSpeedThreshold = 12;
double weatherWindSpeed = 0; // 天气预报风速
double weatherWindSpeedThreshold = 0;
switch (dockTypeId)
{
case "Dock":
rainThreshold = 3; // 大雨
windSpeedThreshold = 12;
break;
case "Dock 2":
rainThreshold = 3; // 大雨
windSpeedThreshold = 8;
break;
case "Dock 3":
rainThreshold = 3; // 大雨
windSpeedThreshold = 8;
break;
}
// 1. 云端阻飞开启天气阻飞未开启 2. 云端阻飞未开启 3. 云端阻飞开启,天气阻飞开启
if (workspace.IsCloudBlockFlight)
{
var type = dockTypeId switch
{
"Dock" => "大疆机场",
"Dock 2" => "大疆机场2",
"Dock 3" => "大疆机场3",
_ => "大疆机场"
};
var spaceLockFly = await Repository
.ChangeRepository<SugarRepositiry<LasaSpaceLockFly>>()
.GetSingleAsync(r => r.WorkSpaceId == task.WorkspaceId && r.Name == type);
if (spaceLockFly != null)
{
rainThreshold = Convert.ToInt32(spaceLockFly.RainFall);
windSpeedThreshold = spaceLockFly.WindSpeed;
weatherWindSpeedThreshold = spaceLockFly.WeatherWindSpeed;
}
}
if (workspace.IsWeatherBlockFlight)
{
using (var httpClient = new HttpClient())
{
// todo 目前地理位置是写死的兰山
var response = await httpClient.GetAsync(
"http://v1.yiketianqi.com/api?unescape=1&version=v61&appid=84261622&appsecret=k0WPY4Cx&city=兰山");
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var weather = JsonConvert.DeserializeObject<JObject>(content);
var winMeterStr =
weather.GetValue("win_meter")?.Value<string>(); //风速
if (!string.IsNullOrEmpty(winMeterStr))
{
weatherWindSpeed = int.Parse(winMeterStr.Replace("km/h", "")) / 3.6;
}
}
}
}
Stopwatch x = new Stopwatch();
x.Start();
// 取得当前风速及天气
// 当前时间减5秒然后取最新一条数据
// 取得机场序列号
var topic = $"thing/product/{serialNo}/osd";
var time = DateTime.Now.AddSeconds(-5);
var log = await Repository
.ChangeRepository<SugarRepositiry<LasaLog>>()
.AsQueryable()
.Where(r => r.Topic == topic)
.Where(r => r.CreateTime > time)
.Where(r => SqlFunc.JsonLike(r.Data, "wind_speed"))
.OrderByDescending(r => r.CreateTime)
.FirstAsync();
x.Stop();
Console.WriteLine("耗时:" + x.ElapsedMilliseconds / 1000);
//不太可能为空
if (log != null)
{
var dataObject =
JsonConvert.DeserializeObject<JObject>(JsonConvert.DeserializeObject<string>(log.Data));
var windSpeed = dataObject["data"]?["wind_speed"]?.Value<float>(); // m/s
var rainfall =
dataObject["data"]?["rainfall"]?.Value<int>(); // {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"}
// 如果没有天气阻飞?
if (windSpeedThreshold <= windSpeed || rainThreshold <= rainfall ||
weatherWindSpeedThreshold <= weatherWindSpeed)
{
return "fail";
// 不让起飞
// 更新失败原因
var failTask = new LasaTask()
{
Id = taskId,
Status = 2,
Reason = "当前天气条件不允许起飞"
};
await Repository
.ChangeRepository<SugarRepositiry<LasaTask>>()
.AsUpdateable(failTask)
.IgnoreNullColumns()
.ExecuteCommandAsync();
throw new Exception("当前天气条件不允许起飞");
}
}
}
}
return "ok";
}
public LasaDronePort GetDroneDockBySn(string gatewaySn)

@ -96,7 +96,7 @@ public class ConfigSubscribe : IJob
var result = JsonConvert.DeserializeObject<TopicServicesRequest<dynamic>>(message);
var method = result.method;
var data = result.data;
//_logger.LogDebug($"主题:{topic}\n消息{message}");
_logger.LogInformation($"主题:{topic}\n消息{message}");
long code = 0;
switch (tempStr)
{

@ -613,11 +613,16 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
return await _app.StopDronePortLive(streamUrl);
}
/// <summary>
/// 阻飞模拟测试
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<string> TestExecuteFlyTask(string flightid)
public async Task<string> TestPreventFlyTask(string taskId)
{
return await _app.TestExecuteFlyTask(flightid);
return await _app.TestPreventFlyTask(taskId);
}
@ -844,8 +849,12 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
}
#endregion
/// <summary>
/// 媒体保存测试
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<Response<bool>> Test1111(string msg)
{
return await _app.Test1111(msg);

@ -7,7 +7,7 @@
"AllowedHosts": "*",
"DataProtection": "temp-keys/",
"ConnectionStrings": {
"OpenAuthDBContext": "PORT=5432;Database=LASAPlatform;HOST=192.168.10.163;PASSWORD=123456;USER ID=postgres;"
"OpenAuthDBContext": "PORT=5432;Database=LASAPlatformNew;HOST=192.168.10.163;PASSWORD=123456;USER ID=postgres;"
//"OpenAuthDBContext": "PORT=5432;Database=unattended1;HOST=192.168.10.115;PASSWORD=123456;USER ID=postgres;Pooling=False" //PostgreSQL
},
"AppSetting": {

@ -8,7 +8,7 @@
"DataProtection": "temp-keys/",
"ConnectionStrings": {
//"OpenAuthDBContext": "PORT=5432;Database=hopetrycore;HOST=192.168.10.124;PASSWORD=123456;USER ID=postgres;",
"OpenAuthDBContext": "PORT=5432;Database=LASAPlatform;HOST=192.168.10.163;PASSWORD=123456;USER ID=postgres;Pooling=true"
"OpenAuthDBContext": "PORT=5432;Database=LASAPlatformNew;HOST=192.168.10.163;PASSWORD=123456;USER ID=postgres;Pooling=true"
//"OpenAuthDBContext": "PORT=5432;Database=;HOST=192.168.10.131;PASSWORD=123456;USER ID=postgres;"
},
"AppSetting": {

Loading…
Cancel
Save