diff --git a/langguanApi.xml b/langguanApi.xml
index 25bb0c4..05606d3 100644
--- a/langguanApi.xml
+++ b/langguanApi.xml
@@ -19,6 +19,21 @@
缓存时间秒,0=int.max ,
+
+
+ http
+
+
+
+
+ 获取数据
+
+
+
+
+
+
+
sub
@@ -2009,7 +2024,7 @@
HomeService
-
+
HomeService
diff --git a/langguanApi/Common/Proxy/HttpProxy.cs b/langguanApi/Common/Proxy/HttpProxy.cs
new file mode 100644
index 0000000..a79f303
--- /dev/null
+++ b/langguanApi/Common/Proxy/HttpProxy.cs
@@ -0,0 +1,48 @@
+using Amazon.Runtime;
+using langguanApi.Extensions.AutoDI;
+
+namespace langguanApi.Common.Proxy
+{
+ ///
+ /// http
+ ///
+ [ServiceInjection(InjectionType.Singleton)]
+ public class HttpProxy
+ {
+ private readonly IHttpClientFactory _httpClientFactory;
+ public HttpProxy(IHttpClientFactory httpClientFactory)
+ {
+ _httpClientFactory = httpClientFactory;
+ }
+ ///
+ /// 获取数据
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task Get(Dictionary parameters, string requestUri)
+ {
+ //从工厂获取请求对象
+ var client = _httpClientFactory.CreateClient();
+ if (parameters != null)
+ {
+ var strParam = string.Join("&", parameters.Select(o => o.Key + "=" + o.Value));
+ requestUri = string.Concat(requestUri, '?', strParam);
+ }
+ client.BaseAddress = new Uri(requestUri);
+ var resp = await client.GetAsync(requestUri);
+ if (resp.IsSuccessStatusCode)
+ {
+ var content = await resp.Content.ReadAsStringAsync();
+ return Newtonsoft.Json.JsonConvert.DeserializeObject(content);
+ }
+ else
+ {
+ Console.WriteLine($"请求失败,状态码:{resp.StatusCode},请求地址 {requestUri}");
+ return default(T);
+ }
+ }
+ }
+}
diff --git a/langguanApi/Service/HomeService.cs b/langguanApi/Service/HomeService.cs
index 5f57bf1..0089e7b 100644
--- a/langguanApi/Service/HomeService.cs
+++ b/langguanApi/Service/HomeService.cs
@@ -3,6 +3,7 @@ using langguanApi.Common;
using langguanApi.Extensions.AutoDI;
using langguanApi.Model;
using System.Linq.Expressions;
+using langguanApi.Common.Proxy;
namespace langguanApi.Service
{
@@ -19,6 +20,7 @@ namespace langguanApi.Service
private readonly WeatherService _weatherService;
private readonly AlertService _alertService;
private readonly DetectionService _detectionService;
+ private HttpProxy _httpProxy;
///
/// HomeService
///
@@ -27,7 +29,7 @@ namespace langguanApi.Service
public HomeService(DeviceService device, Hj212Service hj212Service,
IConfiguration configuration, CacheManager cacheManager,
WeatherService weatherService, AlertService alertService,
- DetectionService detectionService)
+ DetectionService detectionService, HttpProxy httpProxy)
{
_deviceService = device;
_hj212Service = hj212Service;
@@ -36,6 +38,7 @@ namespace langguanApi.Service
_weatherService = weatherService;
_alertService = alertService;
_detectionService = detectionService;
+ _httpProxy = httpProxy;
}
///
/// view
@@ -49,7 +52,8 @@ namespace langguanApi.Service
Yesterday = 0.8,
LastWeek = 0.6,
};
- Expression> filter = exp => true;
+ // 首页热力图
+ var hotmap = new { };
// 首页设备报警数据
var alerts = await _alertService.IndexData();
// 首页设备检测数据
@@ -62,6 +66,9 @@ namespace langguanApi.Service
var ariQuality = await _cacheManager.GetConvertVale(RedisKeylist.AriQuality, getAriQualityFunc, 60 * 120);
Func> getTrendFunc = async () => await _hj212Service.GetIndexData();
var trend = await _cacheManager.GetConvertVale(RedisKeylist.Trend, getTrendFunc, 60 * new Random().Next(70));
+ // alerts += await _httpProxy.Get(null, _configuration.GetValue("Apis:AlertUrl"));
+ // alerts += await _httpProxy.Get(null, _configuration.GetValue("Apis:RateUrl"));
+
//首页清洁运输比例
var cleaData = new
{
@@ -87,6 +94,7 @@ namespace langguanApi.Service
},
devices,
+ hotmap,
weather,
ariQuality,
rate = new[] {
diff --git a/langguanApi/Service/OrganizedService.cs b/langguanApi/Service/OrganizedService.cs
index e5cadd1..7ade6d1 100644
--- a/langguanApi/Service/OrganizedService.cs
+++ b/langguanApi/Service/OrganizedService.cs
@@ -82,7 +82,7 @@ namespace langguanApi.Service
}
if (!string.IsNullOrEmpty(OrgId))
{
- deviceExp= deviceExp.And(filter => filter.OrgId == OrgId);
+ deviceExp = deviceExp.And(filter => filter.OrgId == OrgId);
}
var devices = (await _deviceService.GetListWithExp(deviceExp)).ToList();
foreach (var item in result)
@@ -106,8 +106,8 @@ namespace langguanApi.Service
public async Task List(int OrganizedType = 1)
{
List dto = new List();
- Expression> exp = filter => filter.OrganizedType == OrganizedType && filter.IsDelete == false;
-
+ Expression> exp = filter => filter.OrganizedType == OrganizedType
+ && filter.IsDelete == false;
var result = (await base.GetListWithExp(exp)).OrderByDescending(x => x.Order).ToList();
return new ApiResult() { code = 0, data = result };
}
diff --git a/langguanApi/appsettings.json b/langguanApi/appsettings.json
index 8d8d6c5..b1f015a 100644
--- a/langguanApi/appsettings.json
+++ b/langguanApi/appsettings.json
@@ -16,7 +16,14 @@
"Index": 5
},
"Weather": "https://weather.cma.cn/api/now/54511", //天气预报地址,中国气象
- "AirQuality": "https://air.cnemc.cn:18007/CityData/GetAQIDataPublishLiveInfo?cityCode=110000",//空气质量API地址
+ "AirQuality": "https://air.cnemc.cn:18007/CityData/GetAQIDataPublishLiveInfo?cityCode=110000", //空气质量API地址
+ "Apis": {
+ "RateUrl": "https://air.cnemc.cn:18007/CityData/GetAQIDataPublishLiveInfo?cityCode=110000", //首页设备在线API地址
+ "AlertUrl": "https://air.cnemc.cn:18007/CityData/GetAQIDataPublishLiveInfo?cityCode=110000", //首页设报警API地址
+ "DeviceList": "https://air.cnemc.cn:18007/CityData/GetAQIDataPublishLiveInfo?cityCode=110000", //环境治理 API地址
+ "DeviceInfo": "https://air.cnemc.cn:18007/CityData/GetAQIDataPublishLiveInfo?cityCode=110000" //设备明细 API地址
+
+ },
"Home": {
"Title": "鄂托克旗新航焦化有限公司",
"Center": {