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