空气质量
This commit is contained in:
parent
649c2be62d
commit
f71dac2ac2
|
|
@ -29,6 +29,11 @@
|
||||||
缓存天气信息
|
缓存天气信息
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="F:langguanApi.Common.Redis.RedisKeylist.AriQuality">
|
||||||
|
<summary>
|
||||||
|
缓存ARI数据
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="F:langguanApi.Common.Redis.RedisKeylist.CleanData">
|
<member name="F:langguanApi.Common.Redis.RedisKeylist.CleanData">
|
||||||
<summary>
|
<summary>
|
||||||
缓存清洁数据
|
缓存清洁数据
|
||||||
|
|
@ -2228,6 +2233,67 @@
|
||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:langguanApi.Service.WeatherService.GetAirQuality">
|
||||||
|
<summary>
|
||||||
|
爬空气质量数据
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.Quality.key">
|
||||||
|
<summary>
|
||||||
|
空气质量key
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.Quality.val">
|
||||||
|
<summary>
|
||||||
|
空气质量指数数值
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.Quality.level">
|
||||||
|
<summary>
|
||||||
|
空气质量指数级别
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.Quality.standard">
|
||||||
|
<summary>
|
||||||
|
空气质量指数标准
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="T:langguanApi.Service.WeatherService.AirQuality">
|
||||||
|
<summary>
|
||||||
|
空气质量数据
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.AirQuality.CO">
|
||||||
|
<summary>
|
||||||
|
一氧化碳
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.AirQuality.NO2">
|
||||||
|
<summary>
|
||||||
|
二氧化氮
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.AirQuality.O3">
|
||||||
|
<summary>
|
||||||
|
臭氧
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.AirQuality.PM10">
|
||||||
|
<summary>
|
||||||
|
PM10
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.AirQuality.PM2_5">
|
||||||
|
<summary>
|
||||||
|
PM25
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:langguanApi.Service.WeatherService.AirQuality.SO2">
|
||||||
|
<summary>
|
||||||
|
二氧化硫
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:langguanApi.Service.WeatherService.Location.id">
|
<member name="P:langguanApi.Service.WeatherService.Location.id">
|
||||||
<summary>
|
<summary>
|
||||||
54511
|
54511
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Weather = "weather";
|
public static string Weather = "weather";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 缓存ARI数据
|
||||||
|
/// </summary>
|
||||||
|
public static string AriQuality = "arqulaty";
|
||||||
|
/// <summary>
|
||||||
/// 缓存清洁数据
|
/// 缓存清洁数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string CleanData = "cleandata";
|
public static string CleanData = "cleandata";
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace langguanApi.Service
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hours"></param>
|
/// <param name="hours"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<Model.HJ212>> GetViewTop(int hours = -10)
|
public async Task<List<Model.HJ212>> GetViewTop(int hours = -5)
|
||||||
{
|
{
|
||||||
var date = DateTime.Now.AddHours(-8).AddHours(hours);
|
var date = DateTime.Now.AddHours(-8).AddHours(hours);
|
||||||
Expression<Func<Model.HJ212, bool>> exp = filter => filter.CreateDateTime >= date;
|
Expression<Func<Model.HJ212, bool>> exp = filter => filter.CreateDateTime >= date;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ namespace langguanApi.Service
|
||||||
public async Task<ApiResult> View()
|
public async Task<ApiResult> View()
|
||||||
{
|
{
|
||||||
var devices = await _deviceService.GetAsync();
|
var devices = await _deviceService.GetAsync();
|
||||||
var ariQuality = "";
|
|
||||||
var cleanData = new
|
var cleanData = new
|
||||||
{
|
{
|
||||||
Yesterday = 0.8,
|
Yesterday = 0.8,
|
||||||
|
|
@ -55,6 +54,8 @@ namespace langguanApi.Service
|
||||||
// 获取天气信息,缓存1小时,如果不存在,则调用WeatherService获取
|
// 获取天气信息,缓存1小时,如果不存在,则调用WeatherService获取
|
||||||
Func<Task<object>> getWeatherFunc = async () => await _weatherService.GetWeather();
|
Func<Task<object>> getWeatherFunc = async () => await _weatherService.GetWeather();
|
||||||
var weather = await _cacheManager.GetConvertVale(RedisKeylist.Weather, getWeatherFunc, 60 * 60);
|
var weather = await _cacheManager.GetConvertVale(RedisKeylist.Weather, getWeatherFunc, 60 * 60);
|
||||||
|
Func<Task<object>> getAriQualityFunc= async () => await _weatherService.GetAirQuality();
|
||||||
|
var ariQuality = await _cacheManager.GetConvertVale(RedisKeylist.AriQuality, getAriQualityFunc, 60 * 120);
|
||||||
return new ApiResult
|
return new ApiResult
|
||||||
{
|
{
|
||||||
code = 0,
|
code = 0,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
using langguanApi.Extensions.AutoDI;
|
using langguanApi.Extensions.AutoDI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using NPOI.SS.Formula.Functions;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace langguanApi.Service
|
namespace langguanApi.Service
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +16,7 @@ namespace langguanApi.Service
|
||||||
{
|
{
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_logger=logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 爬气象局的天气数据%
|
/// 爬气象局的天气数据%
|
||||||
|
|
@ -50,6 +52,203 @@ namespace langguanApi.Service
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 爬空气质量数据
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<object> GetAirQuality()
|
||||||
|
{
|
||||||
|
var client = _httpClientFactory.CreateClient();
|
||||||
|
var resp = await client.GetAsync(_configuration.GetSection("AirQuality").Value);
|
||||||
|
if (resp.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var data = await resp.Content.ReadAsStringAsync();
|
||||||
|
var air = JsonConvert.DeserializeObject<AirQuality>(data);
|
||||||
|
return Convert2QualityList(air);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
private List<Quality> Convert2QualityList(AirQuality airQuality)
|
||||||
|
{
|
||||||
|
Type modelType = typeof(AirQuality);
|
||||||
|
List<Quality> qualityList = new List<Quality>();
|
||||||
|
PropertyInfo[] PropertyList = modelType.GetProperties();
|
||||||
|
foreach (PropertyInfo item in PropertyList)
|
||||||
|
{
|
||||||
|
Quality quality = new Quality();
|
||||||
|
object value = item.GetValue(airQuality, null);
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
var tuple = GetStandard(item.Name, value.ToString());
|
||||||
|
quality.key = tuple.Item1;
|
||||||
|
quality.val = value.ToString();
|
||||||
|
quality.standard = tuple.Item2;
|
||||||
|
quality.level = tuple.Item3;
|
||||||
|
qualityList.Add(quality);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return qualityList;
|
||||||
|
}
|
||||||
|
private Tuple<string, string, string> GetStandard(string key, string value)
|
||||||
|
{
|
||||||
|
string standard = "";
|
||||||
|
string keyword = "";
|
||||||
|
string level = "";
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case "CO":
|
||||||
|
keyword = "一氧化碳";
|
||||||
|
standard = "0.5μg/m3";
|
||||||
|
if (double.Parse(value) >= 0.5)
|
||||||
|
{
|
||||||
|
level = "优";
|
||||||
|
}
|
||||||
|
else if (double.Parse(value) >= 0.3)
|
||||||
|
{
|
||||||
|
level = "持平";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
level = "差";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "NO2":
|
||||||
|
keyword = "二氧化氮";
|
||||||
|
standard = "50μg/m3";
|
||||||
|
if (double.Parse(value) >= 50)
|
||||||
|
{
|
||||||
|
level = "优";
|
||||||
|
}
|
||||||
|
else if (double.Parse(value) >= 150)
|
||||||
|
{
|
||||||
|
level = "轻度污染";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
level = "中度污染";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "O3":
|
||||||
|
keyword = "臭氧";
|
||||||
|
standard = "100μg/m3";
|
||||||
|
if (double.Parse(value) >= 100)
|
||||||
|
{
|
||||||
|
level = "优";
|
||||||
|
}
|
||||||
|
else if (double.Parse(value) >= 50)
|
||||||
|
{
|
||||||
|
level = "持平";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
level = "差";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "PM10":
|
||||||
|
keyword = "PM10";
|
||||||
|
standard = "50ug/m3";
|
||||||
|
if (double.Parse(value) >= 50)
|
||||||
|
{
|
||||||
|
level = "优";
|
||||||
|
}
|
||||||
|
else if (double.Parse(value) >= 150)
|
||||||
|
{
|
||||||
|
level = "中";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
level = "差";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "PM2_5":
|
||||||
|
|
||||||
|
keyword = "PM2.5";
|
||||||
|
standard = "25ug/m3";
|
||||||
|
if (double.Parse(value) >= 25)
|
||||||
|
{
|
||||||
|
level = "优";
|
||||||
|
}
|
||||||
|
else if (double.Parse(value) >= 100)
|
||||||
|
{
|
||||||
|
level = "中";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
level = "差";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "SO2":
|
||||||
|
|
||||||
|
keyword = "二氧化硫";
|
||||||
|
standard = "15μg/m3";
|
||||||
|
if (double.Parse(value) >= 15)
|
||||||
|
{
|
||||||
|
level = "优";
|
||||||
|
}
|
||||||
|
else if (double.Parse(value) >= 35)
|
||||||
|
{
|
||||||
|
level = "中";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
level = "差";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return new Tuple<string, string, string>(keyword, standard, level);
|
||||||
|
}
|
||||||
|
public class Quality
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 空气质量key
|
||||||
|
/// </summary>
|
||||||
|
public string key { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 空气质量指数数值
|
||||||
|
/// </summary>
|
||||||
|
public string val { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 空气质量指数级别
|
||||||
|
/// </summary>
|
||||||
|
public string level { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 空气质量指数标准
|
||||||
|
/// </summary>
|
||||||
|
public string standard { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 空气质量数据
|
||||||
|
/// </summary>
|
||||||
|
public class AirQuality
|
||||||
|
{
|
||||||
|
// public string Area { get; set; }
|
||||||
|
// public int CityCode { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 一氧化碳
|
||||||
|
/// </summary>
|
||||||
|
public string CO { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 二氧化氮
|
||||||
|
/// </summary>
|
||||||
|
public string NO2 { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 臭氧
|
||||||
|
/// </summary>
|
||||||
|
public string O3 { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PM10
|
||||||
|
/// </summary>
|
||||||
|
public string PM10 { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// PM25
|
||||||
|
/// </summary>
|
||||||
|
public string PM2_5 { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 二氧化硫
|
||||||
|
/// </summary>
|
||||||
|
public string SO2 { get; set; }
|
||||||
|
}
|
||||||
public class Location
|
public class Location
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"Index": 5
|
"Index": 5
|
||||||
},
|
},
|
||||||
"Weather": "https://weather.cma.cn/api/now/54511", //天气预报地址,中国气象
|
"Weather": "https://weather.cma.cn/api/now/54511", //天气预报地址,中国气象
|
||||||
|
"AirQuality": "https://air.cnemc.cn:18007/CityData/GetAQIDataPublishLiveInfo?cityCode=110000",//空气质量API地址
|
||||||
"Home": {
|
"Home": {
|
||||||
"Title": "鄂托克旗新航焦化有限公司",
|
"Title": "鄂托克旗新航焦化有限公司",
|
||||||
"Center": {
|
"Center": {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue