huancun
This commit is contained in:
parent
a15af967e2
commit
02b030afc2
@ -84,56 +84,58 @@ namespace YD_AllHeartRates.Api.Mqtt
|
|||||||
return _queue.Writer.WriteAsync(msg, stoppingToken).AsTask();
|
return _queue.Writer.WriteAsync(msg, stoppingToken).AsTask();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
List<StudentDto> studentList;
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (studentList == null || devices == null)
|
||||||
|
{
|
||||||
|
studentList = (
|
||||||
|
from s in _smartSportsContext.Student
|
||||||
|
join c in _smartSportsContext.Class on s.ClassId equals c.Id
|
||||||
|
join d in _smartSportsContext.Device on s.StudentNo equals d.StudentNo into sd
|
||||||
|
from d in sd.DefaultIfEmpty()
|
||||||
|
where s.SchoolCode == AppSettings.SchoolCode && s.StudentStatus == 1
|
||||||
|
select new StudentDto
|
||||||
|
{
|
||||||
|
SchoolCode = s.SchoolCode,
|
||||||
|
StudentNo = s.StudentNo,
|
||||||
|
StudentName = s.StudentName,
|
||||||
|
Sex = s.Sex,
|
||||||
|
Age = s.Age,
|
||||||
|
HeartRateId = d != null ? d.Code : "",
|
||||||
|
JumpRopeId = d != null ? d.Code : "",
|
||||||
|
ClassId = s.ClassId,
|
||||||
|
ClassName = s.ClassName,
|
||||||
|
GradeId = c.GradeId,
|
||||||
|
GradeName = c.GradeName ?? "",
|
||||||
|
DeviceType = d != null ? d.DeviceType : 0
|
||||||
|
}
|
||||||
|
).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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 studentMap = studentList.GroupBy(x => x.StudentNo).ToDictionary(g => g.Key, g => g.First());
|
||||||
|
|
||||||
|
|
||||||
await foreach (var batch in ReadBatchesAsync(stoppingToken))
|
await foreach (var batch in ReadBatchesAsync(stoppingToken))
|
||||||
{
|
{
|
||||||
List<StudentDto> studentList;
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (studentList == null || devices == null)
|
|
||||||
{
|
|
||||||
studentList = (
|
|
||||||
from s in _smartSportsContext.Student
|
|
||||||
join c in _smartSportsContext.Class on s.ClassId equals c.Id
|
|
||||||
join d in _smartSportsContext.Device on s.StudentNo equals d.StudentNo into sd
|
|
||||||
from d in sd.DefaultIfEmpty()
|
|
||||||
where s.SchoolCode == AppSettings.SchoolCode && s.StudentStatus == 1
|
|
||||||
select new StudentDto
|
|
||||||
{
|
|
||||||
SchoolCode = s.SchoolCode,
|
|
||||||
StudentNo = s.StudentNo,
|
|
||||||
StudentName = s.StudentName,
|
|
||||||
Sex = s.Sex,
|
|
||||||
Age = s.Age,
|
|
||||||
HeartRateId = d != null ? d.Code : "",
|
|
||||||
JumpRopeId = d != null ? d.Code : "",
|
|
||||||
ClassId = s.ClassId,
|
|
||||||
ClassName = s.ClassName,
|
|
||||||
GradeId = c.GradeId,
|
|
||||||
GradeName = c.GradeName ?? "",
|
|
||||||
DeviceType = d != null ? d.DeviceType : 0
|
|
||||||
}
|
|
||||||
).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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 studentMap = studentList.GroupBy(x => x.StudentNo).ToDictionary(g => g.Key, g => g.First());
|
|
||||||
|
|
||||||
Parallel.ForEach(batch, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, msg =>
|
Parallel.ForEach(batch, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, msg =>
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Api")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Api")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4af2ed6c7dde8915d38199959dc15eb0626ad29e")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a15af967e2dd98f88c113b78a7bd304a4d3c0593")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Api")]
|
[assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Api")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Api")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Api")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
@ -1 +1 @@
|
|||||||
beaa3e786d777e801e865749bc1ed887c9c8bed6062702fc86efc5e999ecbaef
|
22e8205ab6b5676d7d793a438db64102c980db506ddb7d0babd8c83fd38fab3a
|
||||||
|
@ -1 +1 @@
|
|||||||
5f7fb39ffdbe64b582eda15bdc00418a6579ad165c38355ff639a59366e2f9f7
|
9b82f68e122f7768a48d83e21fcb65980b61db40f12686a3b3daf32153b4fa35
|
||||||
|
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