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 { /// /// 首页控制器 /// [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; /// /// /// /// /// /// public HomeController(DeviceService deviceService, PositionService positionService, RedisService redisService) { _deviceService = deviceService; _positionService = positionService; _redisService = redisService; } /// /// 首页 /// /// [HttpGet("view")] public async Task view() { ApiResult result = new ApiResult(); var positions = await _positionService.Index(); positions.ForEach(async p => { foreach (var item in p.Devices) { item.IsOnline = await _redisService.ExistsAsync(RedisKeyList.DeviceStatus(item.DeviceSN)); } }); result.data = new { positions }; return Ok(result); } } }