From 020145b6d55761edf5812e2b132c5bacc9c23cbe Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Thu, 9 Apr 2026 20:30:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YD_YiLu/Services/Impl/DeviceSyncService.cs | 39 ++++++---------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/YD_YiLu/Services/Impl/DeviceSyncService.cs b/YD_YiLu/Services/Impl/DeviceSyncService.cs index 7a3cc1e..ad35029 100644 --- a/YD_YiLu/Services/Impl/DeviceSyncService.cs +++ b/YD_YiLu/Services/Impl/DeviceSyncService.cs @@ -334,6 +334,9 @@ namespace YD_YiLu.Api.Services.Impl .Select(x => x.SchoolCode) .FirstAsync(); + + var (start, end) = GetDateRange(dto.DateType, dto.QueryStartTime, dto.QueryEndTime); + // 4️⃣ 主查询(YL_Train + Student) var query = from t in _context.YL_Train join s in _context.Student on t.UserSerial equals s.StudentNo @@ -350,28 +353,15 @@ namespace YD_YiLu.Api.Services.Impl if (dto.OrganizeId != null && dto.OrganizeId.Count > 0 && dto.OrganizeId[0] > 0) query = query.Where(x => dto.OrganizeId.Contains(x.s.ClassId ?? 0)); - if (dto.QueryStartTime != null && dto.QueryEndTime != null) - { - var (start, end) = GetDateRange(dto.DateType, dto.QueryStartTime, dto.QueryEndTime); + if (start.HasValue) + query = query.Where(x => x.t.StartTime >= start.Value); - if (start.HasValue) - query = query.Where(x => x.t.StartTime >= start.Value); - - if (end.HasValue) - query = query.Where(x => x.t.StartTime < end.Value.AddDays(1)); - } + if (end.HasValue) + query = query.Where(x => x.t.StartTime < end.Value.AddDays(1)); // 6️⃣ 分组求总成绩并排序 var grouped = await query - .GroupBy(x => new - { - x.s.Id, - x.s.StudentName, - x.s.ClassId, - x.s.ClassName, - x.s.Sex, - x.t.CourseId, - }) + .GroupBy(x => new { x.s.Id, x.s.StudentName, x.s.ClassId, x.s.ClassName, x.s.Sex, x.t.CourseId }) .Select(g => new { Key = g.Key, @@ -380,7 +370,7 @@ namespace YD_YiLu.Api.Services.Impl .OrderByDescending(x => x.Score) .Skip((dto.Page - 1) * dto.Size) .Take(dto.Size) - .ToListAsync(); + .ToListAsync(); // ✅ 确保在此处完成 // 7️⃣ 返回结果 return grouped.Select(x => new DeviceSyncGradeOrderItemDto @@ -390,22 +380,13 @@ namespace YD_YiLu.Api.Services.Impl OrganizationId = x.Key.ClassId ?? 0, OrganizationName = x.Key.ClassName ?? "", Gender = x.Key.Sex, - Score = x.Score.ToString("0.##"), + Score = Math.Round(x.Score).ToString("0"), CourseId = x.Key.CourseId, CourseName = Util.GetEnumDescription(x.Key.CourseId) }).ToList(); } - private static DateTime? TryParseTrainTime(string tsCreateTime, string tdStartTime, string tdEndTime) - { - foreach (var s in new[] { tdEndTime, tdStartTime, tsCreateTime }) - { - if (string.IsNullOrWhiteSpace(s)) continue; - if (DateTime.TryParse(s, out var d)) return d; - } - return null; - } public async Task> LastGradeAsync(DeviceSyncLastGradeRequestDto dto) {