From dc1065a603b88d0e658de294a247a54829261fcf Mon Sep 17 00:00:00 2001 From: yanghongwei Date: Tue, 22 Apr 2025 21:06:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/HomeController.cs | 7 ------- Service/PositionService.cs | 9 ++++++++- 2 files changed, 8 insertions(+), 8 deletions(-) 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; }