cd
This commit is contained in:
parent
6d73f0cb52
commit
180e0fc8aa
@ -84,19 +84,18 @@ namespace YD_AllHeartRates.Api.Mqtt
|
||||
return _queue.Writer.WriteAsync(msg, stoppingToken).AsTask();
|
||||
};
|
||||
|
||||
|
||||
await foreach (var batch in ReadBatchesAsync(stoppingToken))
|
||||
{
|
||||
List<StudentDto> studentList;
|
||||
List<S_Device> devices;
|
||||
//List<S_Device> devices;
|
||||
|
||||
var studentListCacheKey = $"{AppSettings.StudentListCacheKey}_{AppSettings.SchoolCode}";
|
||||
var deviceListCacheKey = $"{AppSettings.DeviceListCacheKey}_{AppSettings.SchoolCode}";
|
||||
|
||||
studentList = _caching.Get<List<StudentDto>>(studentListCacheKey);
|
||||
devices = _caching.Get<List<S_Device>>(deviceListCacheKey);
|
||||
//devices = _caching.Get<List<S_Device>>(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<HeartRateData>();
|
||||
var jumpRopeEntities = new ConcurrentBag<JumpRopeData>();
|
||||
|
||||
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;
|
||||
|
@ -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")]
|
||||
|
@ -1 +1 @@
|
||||
22e8205ab6b5676d7d793a438db64102c980db506ddb7d0babd8c83fd38fab3a
|
||||
804f64fb7352a3fccc478d8207d7524ef14b984588a90c9a9b552c3bcbad82dd
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user