diff --git a/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs b/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs index bdf3343..5e3135a 100644 --- a/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs +++ b/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs @@ -84,19 +84,18 @@ namespace YD_AllHeartRates.Api.Mqtt return _queue.Writer.WriteAsync(msg, stoppingToken).AsTask(); }; - await foreach (var batch in ReadBatchesAsync(stoppingToken)) { List studentList; - List devices; + //List devices; var studentListCacheKey = $"{AppSettings.StudentListCacheKey}_{AppSettings.SchoolCode}"; var deviceListCacheKey = $"{AppSettings.DeviceListCacheKey}_{AppSettings.SchoolCode}"; studentList = _caching.Get>(studentListCacheKey); - devices = _caching.Get>(deviceListCacheKey); + //devices = _caching.Get>(deviceListCacheKey); - if (studentList == null || devices == null) + if (studentList == null || studentList.Count > 0) { studentList = ( from s in _smartSportsContext.Student @@ -122,19 +121,20 @@ namespace YD_AllHeartRates.Api.Mqtt ).ToList(); - devices = _smartSportsContext.Device.Where(x => x.SchoolCode == AppSettings.SchoolCode && !string.IsNullOrWhiteSpace(x.StudentNo)).ToList(); + //devices = _smartSportsContext.Device.Where(x => x.SchoolCode == AppSettings.SchoolCode && !string.IsNullOrWhiteSpace(x.StudentNo)).ToList(); _caching.AddObject(studentListCacheKey, studentList, 600); - _caching.AddObject(deviceListCacheKey, devices, 600); + //_caching.AddObject(deviceListCacheKey, devices, 600); } var heartRateEntities = new ConcurrentBag(); var jumpRopeEntities = new ConcurrentBag(); - var deviceHMap = devices.Where(x => x.DeviceType == 1).ToDictionary(x => x.Code, x => x.StudentNo); - var deviceJMap = devices.Where(x => x.DeviceType == 2).ToDictionary(x => x.Code, x => x.StudentNo); + //var deviceHMap = devices.Where(x => x.DeviceType == 1).ToDictionary(x => x.Code, x => x.StudentNo); + //var deviceJMap = devices.Where(x => x.DeviceType == 2).ToDictionary(x => x.Code, x => x.StudentNo); - var studentMap = studentList.GroupBy(x => x.StudentNo).ToDictionary(g => g.Key, g => g.First()); + var studentHMap = studentList.Where(x => x.DeviceType == 1).GroupBy(x => x.HeartRateId).ToDictionary(g => g.Key, g => g.First()); + var studentJMap = studentList.Where(x => x.DeviceType == 2).GroupBy(x => x.JumpRopeId).ToDictionary(g => g.Key, g => g.First()); Parallel.ForEach(batch, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, msg => { @@ -154,8 +154,8 @@ namespace YD_AllHeartRates.Api.Mqtt if (ble.bs_name.Contains("GTY0")) { - if (!deviceHMap.TryGetValue(ble.bs_name, out var studentNo)) continue; - if (!studentMap.TryGetValue(studentNo, out var student)) continue; + //if (!deviceHMap.TryGetValue(ble.bs_name, out var studentNo)) continue; + if (!studentHMap.TryGetValue(ble.bs_name, out var student)) continue; int cd = Array.IndexOf(data, (byte)0xCD); if (cd < 0 || data.Length < cd + 9) continue; @@ -188,8 +188,8 @@ namespace YD_AllHeartRates.Api.Mqtt else if (ble.bs_name.Contains("RS207")) { - if (!deviceJMap.TryGetValue(ble.bs_name, out var studentNo)) continue; - if (!studentMap.TryGetValue(studentNo, out var student)) continue; + //if (!deviceJMap.TryGetValue(ble.bs_name, out var studentNo)) continue; + if (!studentJMap.TryGetValue(ble.bs_name, out var student)) continue; int mfIndex = IndexOfSequence(data, new byte[] { 0xFF, 0x04, 0xFF, 0xCF }); if (mfIndex < 0 || data.Length < mfIndex + 10) continue; 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 336ae75..fced939 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+a15af967e2dd98f88c113b78a7bd304a4d3c0593")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6d73f0cb525ce75d808b306c79291c75a52c8508")] [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 47a2061..02ed41d 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 @@ -22e8205ab6b5676d7d793a438db64102c980db506ddb7d0babd8c83fd38fab3a +804f64fb7352a3fccc478d8207d7524ef14b984588a90c9a9b552c3bcbad82dd 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 f3464af..d480ef4 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 7eb93ca..67ef169 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 fb2d676..d26d9cb 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 a72f20b..1ce2f51 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 a72f20b..1ce2f51 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