using LangGuan.Command.Model;
using LangGuan.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LangGuan.Controllers
{
///
///
///
[ApiVersion("1.0")]
[Route("api/[controller]/v{version:apiVersion}")]
[ApiController]
public class HomeController : ControllerBase
{
private readonly ILogger _logger;
private DeviceSerive _deviceSerive;
private AlertService _alertSerive;
private VideoService _videoService;
private Hj212Service _hj212Service;
private RadarService _radarService;
private readonly IMemoryCache _memoryCache;
private readonly IConfiguration _iconfig;
private readonly DeviceUsedService _deviceUsedService;
///
///
///
///
///
///
///
///
///
///
public HomeController(ILogger logger, DeviceSerive deviceSerive,
AlertService alertService, VideoService videoService, Hj212Service hj212Service,
RadarService radarService, IMemoryCache memoryCache, IConfiguration configuration
, DeviceUsedService deviceUsedService)
{
_logger = logger;
_deviceSerive = deviceSerive;
_alertSerive = alertService;
_videoService = videoService;
_hj212Service = hj212Service;
_radarService = radarService;
_memoryCache = memoryCache;
_iconfig = configuration;
_deviceUsedService = deviceUsedService;
}
///
///
///
///
[HttpGet("view")]
public async Task view()
{
// await _deviceUsedService.UpdateDouble();
//设备数据
var devices = await _deviceSerive.GeAllList();
// var devices = await _memoryCache.GetOrCreate("deviceList", async entity =>
//{
// entity.AbsoluteExpirationRelativeToNow = new TimeSpan(0, 2, 0);
// return entity.Value = await _deviceSerive.GeAllList();
//});
//报警
// var alerts = await _alertSerive.GetToplist();
//视频
// var videos = await _videoService.GetAll();
var deviceUsed = await _deviceUsedService.GetList(DateTime.Now.AddDays(-7), DateTime.Now.AddDays(1));
var result = new ApiResult()
{
code = 0,
data = new
{
devices,
deviceUsed = deviceUsed,
}
};
return Ok(result);
}
///
///
///
public class columnView
{
public string hour { get; set; }
///
/// a34004=PM2.5浓度,a34002=PM10,a34001=tsp浓度
///
public string type { get; set; }
public double value { get; set; }
}
}
}