天气阻飞修改

main
陈伟 4 weeks ago
parent 69688a9c94
commit 82e228c7cf

@ -874,6 +874,8 @@ namespace OpenAuth.App.ServiceApp
throw new Exception("指定机场不存在");
}
// 取值 Dock 3
var dockTypeId = dronePort.TypeId;
var serialNo = dronePort.Sn;
if (!string.IsNullOrEmpty(task.WorkspaceId))
{
@ -881,21 +883,72 @@ namespace OpenAuth.App.ServiceApp
.GetByIdAsync(task.WorkspaceId);
if (workspace != null)
{
if (workspace.IsCloudBlockFlight || workspace.IsWeatherBlockFlight)
// 机场天气信息 阀值(自定义和) 雨量阀值 风速阀值
// 赋值默认阀值
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
{
// todo 关于存在多条阻飞阀值的问题 这里有可能是多个值
// todo 这里是不同机场不同值
"Dock" => "大疆机场",
"Dock 2" => "大疆机场2",
"Dock 3" => "大疆机场3",
_ => "大疆机场"
};
var spaceLockFly = await Repository
.ChangeRepository<SugarRepositiry<LasaSpaceLockFly>>()
.GetSingleAsync(r => r.WorkSpaceId == task.WorkspaceId);
.GetSingleAsync(r => r.WorkSpaceId == task.WorkspaceId && r.Name == type);
if (spaceLockFly != null)
{
var rainFallThreshold = int.Parse(spaceLockFly.RainFall);
var windSpeedThreshold = spaceLockFly.WindSpeed;
var weatherWindSpeedThreshold = spaceLockFly.WeatherWindSpeed;
// 云端阻飞
if (workspace.IsCloudBlockFlight)
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;
}
}
}
}
// 取得当前风速及天气
// 当前时间减5秒然后取最新一条数据
// 取得机场序列号
var log = await Repository
@ -905,7 +958,7 @@ namespace OpenAuth.App.ServiceApp
.Where(r => r.Data.Contains("wind_speed"))
.Where(r => r.Topic == $"thing/product/{serialNo}/osd" &&
r.CreateTime > DateTime.Now.AddSeconds(-5))
.SingleAsync();
.FirstAsync();
//不太可能为空
if (log != null)
{
@ -914,7 +967,9 @@ namespace OpenAuth.App.ServiceApp
var rainfall =
dataObject.GetValue("rainfall")
?.Value<int>(); // {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"}
if (windSpeedThreshold <= windSpeed || rainFallThreshold <= rainfall)
// 如果没有天气阻飞?
if (windSpeedThreshold <= windSpeed || rainThreshold <= rainfall || weatherWindSpeedThreshold <= weatherWindSpeed)
{
// 不让起飞
// 更新失败原因
@ -932,47 +987,6 @@ namespace OpenAuth.App.ServiceApp
throw new Exception("当前天气条件不允许起飞");
}
}
// 查询所需天气数据
}
//天气预报阻飞
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))
{
var winMeter = int.Parse(winMeterStr.Replace("km/h", "")) / 3.6;
if (weatherWindSpeedThreshold <= winMeter)
{
var failTask = new LasaTask()
{
Id = taskId,
Status = 2,
Reason = "当前天气条件不允许起飞"
};
await Repository
.ChangeRepository<SugarRepositiry<LasaTask>>()
.AsUpdateable(failTask)
.IgnoreNullColumns()
.ExecuteCommandAsync();
throw new Exception("当前天气条件不允许起飞");
}
}
}
}
}
}
}
}
}

@ -275,7 +275,8 @@ public class ConfigSubscribe : IJob
string model = "";
if (objectKey.ToLower().EndsWith("jpeg"))
{
var fileUrl ="http://" + _minioService.endPoint + "/" + _minioService._bucketName + "/" + objectKey;
var fileUrl = "http://" + _minioService.endPoint + "/" + _minioService._bucketName +
"/" + objectKey;
using (var httpClient = new HttpClient())
{
suoluokey = "minipic/" + data.file.name.ToString();
@ -319,6 +320,7 @@ public class ConfigSubscribe : IJob
}
}
}
if (directory.Name.Equals("Exif SubIFD"))
{
foreach (var tag in directory.Tags)
@ -337,7 +339,8 @@ public class ConfigSubscribe : IJob
if (tag.Name.Equals("Focal Length 35"))
{
focalLength = int.Parse(tag.Description.Replace("mm", "")
focalLength = int.Parse(tag.Description
.Replace("mm", "")
.Trim());
}
}
@ -387,6 +390,11 @@ public class ConfigSubscribe : IJob
}
}
}
var createdTimeStr = (string)data.file.metadata.created_time;
var createTime = string.IsNullOrEmpty(createdTimeStr)
? DateTime.Now
: createdTimeStr.ToDateTime();
var fileUpload = new LasaMediaFile()
{
Id = Guid.NewGuid().ToString(),
@ -404,7 +412,7 @@ public class ConfigSubscribe : IJob
Name = data.file.name,
ObjectKey = data.file.object_key,
Path = data.file.path, // 目前这个好像没有值
CreateTime = ((string)data.file.metadata.created_time).ToDateTime(),
CreateTime = createTime,
WorkspaceId = executeTask.WorkspaceId,
ParentKey = folderKey[2],
Tid = result.tid,

Loading…
Cancel
Save