71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
|
|
using langguanApi.Common.Redis;
|
|||
|
|
using langguanApi.Common;
|
|||
|
|
using langguanApi.Extensions.AutoDI;
|
|||
|
|
using langguanApi.Model;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
|
|||
|
|
namespace langguanApi.Service
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// HomeService
|
|||
|
|
/// </summary>
|
|||
|
|
[ServiceInjection(InjectionType.Scoped)]
|
|||
|
|
public class HomeService
|
|||
|
|
{
|
|||
|
|
private DeviceService _deviceService;
|
|||
|
|
private Hj212Service _hj212Service;
|
|||
|
|
private readonly IConfiguration _configuration;
|
|||
|
|
private CacheManager _cacheManager;
|
|||
|
|
private readonly WeatherService _weatherService;
|
|||
|
|
/// <summary>
|
|||
|
|
/// HomeService
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="device"></param>
|
|||
|
|
/// <param name="hj212Service"></param>
|
|||
|
|
public HomeService(DeviceService device, Hj212Service hj212Service,
|
|||
|
|
IConfiguration configuration, CacheManager cacheManager, WeatherService weatherService)
|
|||
|
|
{
|
|||
|
|
_deviceService = device;
|
|||
|
|
_hj212Service = hj212Service;
|
|||
|
|
_configuration = configuration;
|
|||
|
|
_cacheManager = cacheManager;
|
|||
|
|
_weatherService = weatherService;
|
|||
|
|
}
|
|||
|
|
/// <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();
|
|||
|
|
var GetViewTop = await _hj212Service.GetViewTop();
|
|||
|
|
// 获取天气信息,缓存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,
|
|||
|
|
GetViewTop
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|