分组
This commit is contained in:
parent
86ee1ef4bd
commit
a425fcc1a4
@ -309,10 +309,10 @@ namespace YD_XinWei.Api.Services.Impl
|
||||
.ToListAsync();
|
||||
|
||||
// 2. 内存分组取每个学生最新一条
|
||||
var realTimeResults = sourceData
|
||||
.GroupBy(x => x.StudentNo) // 按学生分组
|
||||
.Select(g => g.MaxBy(x => x.ScoreTime)) // 每组取最新一条
|
||||
.Where(x => x != null) // 避免空值
|
||||
var latestPerStudent = sourceData.OrderBy(x => x.ScoreTime).ToList();
|
||||
|
||||
// 3. 映射到 DTO
|
||||
var realTimeResults = latestPerStudent
|
||||
.Select(x => new ItemRealTimeResultDto
|
||||
{
|
||||
StudentNo = x.StudentNo,
|
||||
@ -320,9 +320,7 @@ namespace YD_XinWei.Api.Services.Impl
|
||||
Photo = studentPhotoDict.TryGetValue(x.StudentNo, out var photo) ? photo : string.Empty,
|
||||
GradeAndClassName = $"{x.GradeName}-{x.ClassName}",
|
||||
CategoryValue = x.CategoryValue,
|
||||
Value = x.CategoryValue == 1
|
||||
? $"{x.Height}cm/{x.Weight}kg"
|
||||
: $"{x.Value}{((SportsTestItemType)x.CategoryValue).GetUnit()}",
|
||||
Value = x.CategoryValue == 1 ? $"{x.Height}cm/{x.Weight}kg" : $"{x.Value}{((SportsTestItemType)x.CategoryValue).GetUnit()}",
|
||||
Score = x.Score,
|
||||
Rank = string.IsNullOrEmpty(x.Rank) ? "不及格" : x.Rank,
|
||||
ScoreTime = x.ScoreTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user