2025-03-22 12:16:22 +00:00
|
|
|
|
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
|
|
|
|
|
|
{
|
2025-03-24 02:59:34 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 首页控制器
|
|
|
|
|
|
/// </summary>
|
2025-03-22 12:16:22 +00:00
|
|
|
|
[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;
|
2025-03-24 02:59:34 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="deviceService"></param>
|
|
|
|
|
|
/// <param name="positionService"></param>
|
|
|
|
|
|
/// <param name="redisService"></param>
|
2025-03-22 12:16:22 +00:00
|
|
|
|
public HomeController(DeviceService deviceService, PositionService positionService, RedisService redisService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_deviceService = deviceService;
|
|
|
|
|
|
_positionService = positionService;
|
|
|
|
|
|
_redisService = redisService;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 首页
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("view")]
|
|
|
|
|
|
public async Task<IActionResult> view()
|
|
|
|
|
|
{
|
|
|
|
|
|
ApiResult result = new ApiResult();
|
|
|
|
|
|
var positions = await _positionService.Index();
|
2025-03-24 02:59:34 +00:00
|
|
|
|
positions.ForEach(async p =>
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in p.Devices)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.IsOnline = await _redisService.ExistsAsync(RedisKeyList.DeviceStatus(item.DeviceSN));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-03-22 12:16:22 +00:00
|
|
|
|
result.data = new
|
|
|
|
|
|
{
|
|
|
|
|
|
positions
|
|
|
|
|
|
};
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|