From 75e9ca107efc5e8db620e304769001b438eddc27 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Tue, 29 Jul 2025 11:40:42 +0800 Subject: [PATCH] ff --- .../Services/Impl/LargeScreenService.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/YD_AllHeartRates.Api/Services/Impl/LargeScreenService.cs b/YD_AllHeartRates.Api/Services/Impl/LargeScreenService.cs index f0972de..1f82632 100644 --- a/YD_AllHeartRates.Api/Services/Impl/LargeScreenService.cs +++ b/YD_AllHeartRates.Api/Services/Impl/LargeScreenService.cs @@ -145,11 +145,22 @@ namespace YD_AllHeartRates.Api.Services.Impl int warmUp = 0, low = 0, medium = 0, high = 0, warning = 0; + + DateTime today = DateTime.Today; + + // 获取所有学号 + var studentNos = studentList.Select(s => s.StudentNo).ToList(); + + // 一次性获取 JumpRopeData(当天数据) + var jumpRopeDict = await _userContext.JumpRopeData + .Where(x => studentNos.Contains(x.StudentNo) && x.ScoreTime.Date == today) + .ToDictionaryAsync(x => x.StudentNo, x => x); + + foreach (var student in studentList) { var heartRateKey = $"heartRate:{student.StudentNo}"; //var jumpRopeKey = $"jumpRope:{student.StudentNo}"; - //string jumpRopeKey = $"{student.StudentNo}_{DateTime.Now:yyyyMMdd}"; var jumpRopeKey = $"jumpRope:active:{student.StudentNo}:{DateTime.Now:yyyyMMdd}"; @@ -159,10 +170,8 @@ namespace YD_AllHeartRates.Api.Services.Impl var jumpRope = _caching.Get(jumpRopeKey); - if (jumpRope == null) - { - jumpRope = await _userContext.JumpRopeData.Where(x => x.StudentNo == student.StudentNo).FirstOrDefaultAsync(); - } + if (jumpRope == null && jumpRopeDict.TryGetValue(student.StudentNo, out var jr)) + jumpRope = jr; // ❗心率缓存未命中 → 单独查数据库 //if (heartRate == null)