diff --git a/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs b/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs index c4d345a..eeef06d 100644 --- a/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs +++ b/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs @@ -172,12 +172,12 @@ namespace YD_AllHeartRates.Api.Mqtt if (string.IsNullOrWhiteSpace(ble.RawData)) continue; var student = _studentList.FirstOrDefault(x => x.JumpRopeId == ble.BleName); - if (student?.GradeId == 0 || student?.ClassId == 0) continue; + if (student == null || student.GradeId == 0 || student.ClassId == 0) continue; var data = ParseHexData(ble.RawData); if (data == null) continue; - int mfIndex = IndexOfSequence(data, new byte[] { 0xFF, 0x04, 0xFF, 0xCF }); + int mfIndex = Array.IndexOf(data, new byte[] { 0xFF, 0x04, 0xFF, 0xCF }); if (mfIndex < 0 || data.Length < mfIndex + 10) continue; int jumpCount = data[mfIndex + 5] + (data[mfIndex + 6] << 8); @@ -297,27 +297,5 @@ namespace YD_AllHeartRates.Api.Mqtt } if (buffer.Count > 0) yield return buffer; } - public static int IndexOfSequence(byte[] buffer, byte[] pattern) - { - if (pattern.Length == 0 || buffer.Length < pattern.Length) - return -1; - - for (int i = 0; i <= buffer.Length - pattern.Length; i++) - { - bool matched = true; - for (int j = 0; j < pattern.Length; j++) - { - if (buffer[i + j] != pattern[j]) - { - matched = false; - break; - } - } - if (matched) - return i; - } - return -1; - } - } } diff --git a/YD_AllHeartRates.Api/Services/Impl/LargeScreenService.cs b/YD_AllHeartRates.Api/Services/Impl/LargeScreenService.cs index 00b485e..c4225b1 100644 --- a/YD_AllHeartRates.Api/Services/Impl/LargeScreenService.cs +++ b/YD_AllHeartRates.Api/Services/Impl/LargeScreenService.cs @@ -1,6 +1,7 @@  using AutoMapper; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; using System.Drawing; using System.Reflection.PortableExecutable; @@ -24,6 +25,7 @@ namespace YD_AllHeartRates.Api.Services.Impl private readonly LoginContext _loginContext; private string schoolCode; private readonly ICaching _caching; + private readonly Dictionary _jumpDailyMap = new(); /// /// 构造 @@ -147,11 +149,17 @@ namespace YD_AllHeartRates.Api.Services.Impl foreach (var student in studentList) { var heartRateKey = $"heartRate:{student.StudentNo}"; - var jumpRopeKey = $"jumpRope:{student.StudentNo}"; + //var jumpRopeKey = $"jumpRope:{student.StudentNo}"; + + string jumpRopeKey = $"{student.StudentNo}_{DateTime.Now:yyyyMMdd}"; // 先从缓存拿 var heartRate = _caching.Get(heartRateKey); - var jumpRope = _caching.Get(jumpRopeKey); + + //var jumpRope = _caching.Get(jumpRopeKey); + + _jumpDailyMap.TryGetValue(jumpRopeKey, out var jumpRope); + // ❗心率缓存未命中 → 单独查数据库 //if (heartRate == null) @@ -173,8 +181,8 @@ namespace YD_AllHeartRates.Api.Services.Impl // .OrderByDescending(x => x.ScoreTime) // .FirstOrDefaultAsync(); - // //if (jumpRope != null) - // // _caching.AddObject(jumpRopeKey, jumpRope, 60); + // if (jumpRope != null) + // _caching.AddObject(jumpRopeKey, jumpRope, 60); //} // 心率强度判断 diff --git a/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.AssemblyInfo.cs b/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.AssemblyInfo.cs index b7e203b..65cab11 100644 --- a/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.AssemblyInfo.cs +++ b/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Api")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e813d22174a36ed6a56d32c6680c8cbe3560475c")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3c399871d7a4fff8b5d368263e3942991a974fdd")] [assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Api")] [assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Api")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.AssemblyInfoInputs.cache b/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.AssemblyInfoInputs.cache index f1520f6..4aecdd9 100644 --- a/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.AssemblyInfoInputs.cache +++ b/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.AssemblyInfoInputs.cache @@ -1 +1 @@ -297fd43299ec4dd1d6e6586c0f993bcc28ee868403ee350c618e71c5827769a6 +937ead42c43efa52de467b7e6b0b10b17938c2bb3b9c6b465840319e0efb56a9 diff --git a/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.dll b/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.dll index f2917b9..cf0b253 100644 Binary files a/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.dll and b/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.dll differ diff --git a/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.pdb b/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.pdb index bb39e89..37dfbee 100644 Binary files a/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.pdb and b/YD_AllHeartRates.Api/obj/Debug/net6.0/YD_AllHeartRates.Api.pdb differ diff --git a/YD_AllHeartRates.Api/obj/Debug/net6.0/apphost.exe b/YD_AllHeartRates.Api/obj/Debug/net6.0/apphost.exe index ae1434e..9101a1c 100644 Binary files a/YD_AllHeartRates.Api/obj/Debug/net6.0/apphost.exe and b/YD_AllHeartRates.Api/obj/Debug/net6.0/apphost.exe differ diff --git a/YD_AllHeartRates.Api/obj/Debug/net6.0/ref/YD_AllHeartRates.Api.dll b/YD_AllHeartRates.Api/obj/Debug/net6.0/ref/YD_AllHeartRates.Api.dll index a8d2fa8..396ffe1 100644 Binary files a/YD_AllHeartRates.Api/obj/Debug/net6.0/ref/YD_AllHeartRates.Api.dll and b/YD_AllHeartRates.Api/obj/Debug/net6.0/ref/YD_AllHeartRates.Api.dll differ diff --git a/YD_AllHeartRates.Api/obj/Debug/net6.0/refint/YD_AllHeartRates.Api.dll b/YD_AllHeartRates.Api/obj/Debug/net6.0/refint/YD_AllHeartRates.Api.dll index a8d2fa8..396ffe1 100644 Binary files a/YD_AllHeartRates.Api/obj/Debug/net6.0/refint/YD_AllHeartRates.Api.dll and b/YD_AllHeartRates.Api/obj/Debug/net6.0/refint/YD_AllHeartRates.Api.dll differ