2024-05-20 14:56:49 +00:00
|
|
|
|
using langguanApi.Common.Redis;
|
|
|
|
|
|
using langguanApi.Common;
|
|
|
|
|
|
using langguanApi.Extensions.AutoDI;
|
|
|
|
|
|
using langguanApi.Model;
|
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace langguanApi.Service
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// HomeService
|
|
|
|
|
|
/// </summary>
|
2024-05-20 15:10:31 +00:00
|
|
|
|
[ServiceInjection(InjectionType.Singleton)]
|
2024-05-20 14:56:49 +00:00
|
|
|
|
public class HomeService
|
|
|
|
|
|
{
|
|
|
|
|
|
private DeviceService _deviceService;
|
|
|
|
|
|
private Hj212Service _hj212Service;
|
|
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
|
private CacheManager _cacheManager;
|
|
|
|
|
|
private readonly WeatherService _weatherService;
|
2024-05-21 15:53:40 +00:00
|
|
|
|
private readonly AlertService _alertService;
|
2024-05-20 14:56:49 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// HomeService
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="device"></param>
|
|
|
|
|
|
/// <param name="hj212Service"></param>
|
|
|
|
|
|
public HomeService(DeviceService device, Hj212Service hj212Service,
|
2024-05-21 15:53:40 +00:00
|
|
|
|
IConfiguration configuration, CacheManager cacheManager,
|
|
|
|
|
|
WeatherService weatherService, AlertService alertService)
|
2024-05-20 14:56:49 +00:00
|
|
|
|
{
|
|
|
|
|
|
_deviceService = device;
|
|
|
|
|
|
_hj212Service = hj212Service;
|
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
|
_cacheManager = cacheManager;
|
|
|
|
|
|
_weatherService = weatherService;
|
2024-05-21 15:53:40 +00:00
|
|
|
|
_alertService = alertService;
|
2024-05-20 14:56:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// view
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<ApiResult> View()
|
|
|
|
|
|
{
|
|
|
|
|
|
var devices = await _deviceService.GetAsync();
|
|
|
|
|
|
var ariQuality = "";
|
|
|
|
|
|
Expression<Func<Model.HJ212, bool>> filter = exp => true;
|
|
|
|
|
|
var Realtime = await _hj212Service.Realtime();
|
2024-05-21 15:53:40 +00:00
|
|
|
|
var getViewTop = await _hj212Service.GetViewTop();
|
|
|
|
|
|
var alerts = await _alertService.IndexData();
|
2024-05-20 14:56:49 +00:00
|
|
|
|
// 获取天气信息,缓存1小时,如果不存在,则调用WeatherService获取
|
|
|
|
|
|
Func<Task<object>> getWeatherFunc = async () => await _weatherService.GetWeather();
|
|
|
|
|
|
var weather = await _cacheManager.GetConvertVale(RedisKeylist.Weather, getWeatherFunc, 60 * 60);
|
|
|
|
|
|
return new ApiResult
|
|
|
|
|
|
{
|
|
|
|
|
|
code = 0,
|
|
|
|
|
|
data = new
|
|
|
|
|
|
{
|
|
|
|
|
|
home = new
|
|
|
|
|
|
{
|
|
|
|
|
|
center = new
|
|
|
|
|
|
{
|
|
|
|
|
|
lon = _configuration.GetValue<double>("Home:Center:Lon"),
|
|
|
|
|
|
lat = _configuration.GetValue<double>("Home:Center:Lat"),
|
|
|
|
|
|
},
|
|
|
|
|
|
title = _configuration.GetValue<string>("Home:Title"),
|
|
|
|
|
|
},
|
|
|
|
|
|
devices,
|
|
|
|
|
|
ariQuality,
|
|
|
|
|
|
Realtime,
|
2024-05-21 15:53:40 +00:00
|
|
|
|
getViewTop,
|
|
|
|
|
|
weather,
|
|
|
|
|
|
alerts
|
2024-05-20 14:56:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|