diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 9ff3eee..c63b487 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -46,13 +46,6 @@ namespace LY.App.Controllers { 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)); - } - }); var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(), async () => await _alarmService.IndexCount(), TimeSpan.FromDays(1)); diff --git a/Service/PositionService.cs b/Service/PositionService.cs index 329ea41..fbaf309 100644 --- a/Service/PositionService.cs +++ b/Service/PositionService.cs @@ -1,4 +1,5 @@ using LY.App.Common; +using LY.App.Common.Redis; using LY.App.Extensions.DI; using LY.App.Model; using Mapster; @@ -17,9 +18,11 @@ namespace LY.App.Service public class PositionService { private readonly SqlSugarClient _db; - public PositionService(SqlSugarClient db) + private readonly RedisService _redisService; + public PositionService(SqlSugarClient db, RedisService redisService) { _db = db; + _redisService = redisService; } /// /// 添加 @@ -147,6 +150,10 @@ namespace LY.App.Service { item.SetRegionJson(); item.Devices = deviceList.Where(s => s.PositionId == item.Id).ToList()?.Adapt>() ?? new List(); + item.Devices.ForEach(async s => + { + s.IsOnline = await _redisService.ExistsAsync(RedisKeyList.DeviceStatus(s.DeviceSN)); + }); } return result; }