66 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
using LY.App.Common;
 | 
						|
using LY.App.Common.Redis;
 | 
						|
using LY.App.Device;
 | 
						|
using LY.App.Model;
 | 
						|
using LY.App.Service;
 | 
						|
using Microsoft.AspNetCore.Http;
 | 
						|
using Microsoft.AspNetCore.Mvc;
 | 
						|
 | 
						|
namespace LY.App.Controllers
 | 
						|
{
 | 
						|
    /// <summary>
 | 
						|
    /// 首页控制器
 | 
						|
    /// </summary>
 | 
						|
    [Route("api/[controller]")]
 | 
						|
    [ApiController]
 | 
						|
    public class HomeController : ControllerBase
 | 
						|
    {
 | 
						|
        private readonly DeviceService _deviceService;
 | 
						|
        private readonly DeviceManager deviceManager = DeviceManager.Instance;
 | 
						|
        private readonly PositionService _positionService;
 | 
						|
        private readonly RedisService _redisService;
 | 
						|
        private readonly AlarmService _alarmService;
 | 
						|
        private readonly WeatherService _weatherService;
 | 
						|
        /// <summary>
 | 
						|
        ///     
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="deviceService"></param>
 | 
						|
        /// <param name="positionService"></param>
 | 
						|
        /// <param name="redisService"></param>
 | 
						|
        /// <param name="alarmService"></param>
 | 
						|
        /// <param name="weatherService"></param>
 | 
						|
        public HomeController(DeviceService deviceService, PositionService positionService,
 | 
						|
            RedisService redisService, AlarmService alarmService, WeatherService weatherService)
 | 
						|
        {
 | 
						|
            _deviceService = deviceService;
 | 
						|
            _positionService = positionService;
 | 
						|
            _redisService = redisService;
 | 
						|
            _alarmService = alarmService;
 | 
						|
            _weatherService = weatherService;
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 首页
 | 
						|
        /// </summary>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpGet("index")]
 | 
						|
        public async Task<IActionResult> view()
 | 
						|
        {
 | 
						|
            ApiResult result = new ApiResult();
 | 
						|
            var positions = await _positionService.Index();
 | 
						|
            var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(),
 | 
						|
                   async () => await _alarmService.IndexCount(),
 | 
						|
                   TimeSpan.FromSeconds(DateTimeHelper.GetRemainSeconds()));
 | 
						|
            var weather = await _redisService.GetOrSetAsync(RedisKeyList.Index_Weather,
 | 
						|
                   async () => await _weatherService.GetWeather(),
 | 
						|
                   TimeSpan.FromHours(3));
 | 
						|
            result.data = new
 | 
						|
            {
 | 
						|
                positions,
 | 
						|
                alarmCount,
 | 
						|
                weather
 | 
						|
            };
 | 
						|
            return Ok(result);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |