阻飞逻辑完善

main
陈伟 1 month ago
parent 913f3d40c9
commit 54d533ec75

@ -881,89 +881,92 @@ namespace OpenAuth.App.ServiceApp
.GetByIdAsync(task.WorkspaceId);
if (workspace != null)
{
// todo 关于存在多条阻飞阀值的问题 这里有可能是多个值
// todo 这里是不同机场不同值
var spaceLockFly = await Repository
.ChangeRepository<SugarRepositiry<LasaSpaceLockFly>>()
.GetSingleAsync(r => r.WorkSpaceId == task.WorkspaceId);
if (spaceLockFly != null)
if (workspace.IsCloudBlockFlight || workspace.IsWeatherBlockFlight)
{
var rainFallThreshold = int.Parse(spaceLockFly.RainFall);
var windSpeedThreshold = spaceLockFly.WindSpeed;
var weatherWindSpeedThreshold = spaceLockFly.WeatherWindSpeed;
// 云端阻飞
if (workspace.IsCloudBlockFlight)
// todo 关于存在多条阻飞阀值的问题 这里有可能是多个值
// todo 这里是不同机场不同值
var spaceLockFly = await Repository
.ChangeRepository<SugarRepositiry<LasaSpaceLockFly>>()
.GetSingleAsync(r => r.WorkSpaceId == task.WorkspaceId);
if (spaceLockFly != null)
{
// 当前时间减5秒然后取最新一条数据
// 取得机场序列号
var log = await Repository
.ChangeRepository<SugarRepositiry<LasaLog>>()
.AsQueryable()
.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))
.SingleAsync();
//不太可能为空
if (log != null)
var rainFallThreshold = int.Parse(spaceLockFly.RainFall);
var windSpeedThreshold = spaceLockFly.WindSpeed;
var weatherWindSpeedThreshold = spaceLockFly.WeatherWindSpeed;
// 云端阻飞
if (workspace.IsCloudBlockFlight)
{
var dataObject = JsonConvert.DeserializeObject<JObject>(log.Data);
var windSpeed = dataObject.GetValue("wind_speed")?.Value<float>(); // m/s
var rainfall =
dataObject.GetValue("rainfall")
?.Value<int>(); // {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"}
if (windSpeedThreshold <= windSpeed || rainFallThreshold <= rainfall)
// 当前时间减5秒然后取最新一条数据
// 取得机场序列号
var log = await Repository
.ChangeRepository<SugarRepositiry<LasaLog>>()
.AsQueryable()
.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))
.SingleAsync();
//不太可能为空
if (log != null)
{
// 不让起飞
// 更新失败原因
var failTask = new LasaTask()
var dataObject = JsonConvert.DeserializeObject<JObject>(log.Data);
var windSpeed = dataObject.GetValue("wind_speed")?.Value<float>(); // m/s
var rainfall =
dataObject.GetValue("rainfall")
?.Value<int>(); // {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"}
if (windSpeedThreshold <= windSpeed || rainFallThreshold <= rainfall)
{
Id = taskId,
Status = 2,
Reason = "当前天气条件不允许起飞"
};
await Repository
.ChangeRepository<SugarRepositiry<LasaTask>>()
.AsUpdateable(failTask)
.IgnoreNullColumns()
.ExecuteCommandAsync();
throw new Exception("当前天气条件不允许起飞");
// 不让起飞
// 更新失败原因
var failTask = new LasaTask()
{
Id = taskId,
Status = 2,
Reason = "当前天气条件不允许起飞"
};
await Repository
.ChangeRepository<SugarRepositiry<LasaTask>>()
.AsUpdateable(failTask)
.IgnoreNullColumns()
.ExecuteCommandAsync();
throw new Exception("当前天气条件不允许起飞");
}
}
// 查询所需天气数据
}
// 查询所需天气数据
}
//天气预报阻飞
if (workspace.IsWeatherBlockFlight)
{
using (var httpClient = new HttpClient())
//天气预报阻飞
if (workspace.IsWeatherBlockFlight)
{
// todo 目前地理位置是写死的兰山
var response = await httpClient.GetAsync(
"http://v1.yiketianqi.com/api?unescape=1&version=v61&appid=84261622&appsecret=k0WPY4Cx&city=兰山");
if (response.IsSuccessStatusCode)
using (var httpClient = new HttpClient())
{
var content = await response.Content.ReadAsStringAsync();
var weather = JsonConvert.DeserializeObject<JObject>(content);
var winMeterStr =
weather.GetValue("win_meter")?.Value<string>(); //风速
if (!string.IsNullOrEmpty(winMeterStr))
// todo 目前地理位置是写死的兰山
var response = await httpClient.GetAsync(
"http://v1.yiketianqi.com/api?unescape=1&version=v61&appid=84261622&appsecret=k0WPY4Cx&city=兰山");
if (response.IsSuccessStatusCode)
{
var winMeter = int.Parse(winMeterStr.Replace("km/h", "")) / 3.6;
if (weatherWindSpeedThreshold <= winMeter)
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 failTask = new LasaTask()
var winMeter = int.Parse(winMeterStr.Replace("km/h", "")) / 3.6;
if (weatherWindSpeedThreshold <= winMeter)
{
Id = taskId,
Status = 2,
Reason = "当前天气条件不允许起飞"
};
await Repository
.ChangeRepository<SugarRepositiry<LasaTask>>()
.AsUpdateable(failTask)
.IgnoreNullColumns()
.ExecuteCommandAsync();
throw new Exception("当前天气条件不允许起飞");
var failTask = new LasaTask()
{
Id = taskId,
Status = 2,
Reason = "当前天气条件不允许起飞"
};
await Repository
.ChangeRepository<SugarRepositiry<LasaTask>>()
.AsUpdateable(failTask)
.IgnoreNullColumns()
.ExecuteCommandAsync();
throw new Exception("当前天气条件不允许起飞");
}
}
}
}

Loading…
Cancel
Save