102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[ApiVersion("1.0")]
|
|
[Route("api/[controller]/v{version:apiVersion}")]
|
|
[ApiController]
|
|
public class HomeController : ControllerBase
|
|
{
|
|
private readonly ILogger<HomeController> _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;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="logger"></param>
|
|
/// <param name="deviceSerive"></param>
|
|
/// <param name="alertService"></param>
|
|
/// <param name="videoService"></param>
|
|
/// <param name="hj212Service"></param>
|
|
/// <param name="radarService"></param>
|
|
/// <param name="memoryCache"></param>
|
|
public HomeController(ILogger<HomeController> 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;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("view")]
|
|
public async Task<IActionResult> 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);
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class columnView
|
|
{
|
|
public string hour { get; set; }
|
|
/// <summary>
|
|
/// a34004=PM2.5浓度,a34002=PM10,a34001=tsp浓度
|
|
/// </summary>
|
|
public string type { get; set; }
|
|
public double value { get; set; }
|
|
}
|
|
}
|
|
}
|