Fix approved exam exceptions in grade and exam lists
This commit is contained in:
1 parent
1a4cb2799a
commit
3500aedcaa
4 files changed
+62
-8
No files matched your search
@@ -999,9 +999,11 @@ public sealed class ExamsController(
|
||||
|
||||
var hasAssignedSeats = await db.ExamSeats.AnyAsync(x => x.ExamSessionId == id, cancellationToken);
|
||||
var blockedStudents = TeachingTaskRosterQuery.BlockedStudentIdsForTask(db, session.TeachingTaskId);
|
||||
var excludedStudents = db.CourseExemptions.Where(x => x.TeachingTaskId == session.TeachingTaskId && x.Status == ApprovalStatus.Approved).Select(x => x.StudentId)
|
||||
.Union(db.DeferredExams.Where(x => x.TeachingTaskId == session.TeachingTaskId && x.Status == ApprovalStatus.Approved).Select(x => x.StudentId));
|
||||
var assignedStudents = await db.ExamSeats.AsNoTracking()
|
||||
.Where(x => x.ExamSessionId == id)
|
||||
.Where(x => !blockedStudents.Contains(x.StudentId))
|
||||
.Where(x => !blockedStudents.Contains(x.StudentId) && !excludedStudents.Contains(x.StudentId))
|
||||
.OrderBy(x => x.ExamRoom!.Classroom!.Building!.Name)
|
||||
.ThenBy(x => x.ExamRoom!.Classroom!.Name)
|
||||
.ThenBy(x => x.SeatNumber)
|
||||
@@ -1049,6 +1051,7 @@ public sealed class ExamsController(
|
||||
db,
|
||||
[session.TeachingTaskId],
|
||||
cancellationToken);
|
||||
var excludedIds = (await excludedStudents.ToListAsync(cancellationToken)).ToHashSet();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
@@ -1065,7 +1068,7 @@ public sealed class ExamsController(
|
||||
student.Name,
|
||||
student.ClassName,
|
||||
SeatNumber = (index + 1).ToString("D3")
|
||||
})
|
||||
}).Where(student => !excludedIds.Contains(student.StudentId))
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1144,6 +1147,8 @@ public sealed class ExamsController(
|
||||
.ToDictionaryAsync(session => session.Id, session => session.TeachingTaskId, cancellationToken);
|
||||
var blockedSeats = await TeachingTaskRosterQuery.LoadBlockedPairsAsync(db,
|
||||
taskBySession.Values, rooms.SelectMany(room => room.Seats).Select(seat => seat.StudentId), cancellationToken);
|
||||
var approvalExclusions = await ExamApprovalExclusions.LoadAsync(db,
|
||||
taskBySession.Values.Concat(legacySessions.Select(x => x.TeachingTaskId)), cancellationToken);
|
||||
var sheets = rooms.Select(room => new ExamSignInSessionData(
|
||||
room.Id,
|
||||
room.ExamDate,
|
||||
@@ -1165,7 +1170,7 @@ public sealed class ExamsController(
|
||||
.ToList(),
|
||||
room.Seats
|
||||
.Where(seat => taskBySession.TryGetValue(seat.ExamSessionId, out var taskId) &&
|
||||
!blockedSeats.Contains((taskId, seat.StudentId)))
|
||||
!blockedSeats.Contains((taskId, seat.StudentId)) && !approvalExclusions.Contains((taskId, seat.StudentId)))
|
||||
.OrderBy(seat => seat.SeatNumber)
|
||||
.Select(seat => new ExamSignInStudentData(
|
||||
seat.StudentId,
|
||||
@@ -1191,7 +1196,7 @@ public sealed class ExamsController(
|
||||
student.StudentNumber,
|
||||
student.Name,
|
||||
student.ClassName,
|
||||
index + 1))
|
||||
index + 1)).Where(student => !approvalExclusions.Contains((session.TeachingTaskId, student.StudentId)))
|
||||
.ToList())))
|
||||
.ToList();
|
||||
var data = new ExamSignInWorkbookData(
|
||||
@@ -1323,11 +1328,13 @@ public sealed class ExamsController(
|
||||
return ConflictProblem("当前账号未关联学生档案。");
|
||||
|
||||
var blockedTaskIds = TeachingTaskRosterQuery.BlockedTaskIdsForStudent(db, studentId.Value);
|
||||
var excludedTaskIds = ExamApprovalExclusions.TaskIdsForStudent(db, studentId.Value);
|
||||
var assignedSchedule = await db.ExamSeats.AsNoTracking()
|
||||
.Where(x =>
|
||||
x.StudentId == studentId.Value &&
|
||||
x.ExamRoom!.ExamPlan!.Status == ExamPlanStatus.Published &&
|
||||
!blockedTaskIds.Contains(x.ExamSession!.TeachingTaskId))
|
||||
!blockedTaskIds.Contains(x.ExamSession!.TeachingTaskId) &&
|
||||
!excludedTaskIds.Contains(x.ExamSession.TeachingTaskId))
|
||||
.Select(x => new
|
||||
{
|
||||
x.ExamSessionId,
|
||||
@@ -1354,7 +1361,7 @@ public sealed class ExamsController(
|
||||
var legacySchedule = await db.ExamSessions.AsNoTracking()
|
||||
.Where(x => x.ExamPlan!.Status == ExamPlanStatus.Published &&
|
||||
!x.RoomLinks.Any() &&
|
||||
rosterTaskIds.Contains(x.TeachingTaskId))
|
||||
rosterTaskIds.Contains(x.TeachingTaskId) && !excludedTaskIds.Contains(x.TeachingTaskId))
|
||||
.OrderBy(x => x.ExamDate).ThenBy(x => x.StartPeriod)
|
||||
.Select(x => new
|
||||
{
|
||||
|
||||
@@ -229,6 +229,22 @@ public sealed class GradesController(
|
||||
if (studentIds.Count == 0)
|
||||
return ConflictProblem("教学班当前没有有效学生,无法建立成绩单。");
|
||||
|
||||
// Applications can be approved before the grade sheet exists. Apply the
|
||||
// most recent approval when the student's initial record is created.
|
||||
var exemptions = await db.CourseExemptions.AsNoTracking()
|
||||
.Where(x => x.TeachingTaskId == task.Id && x.Status == ApprovalStatus.Approved)
|
||||
.Select(x => new { x.StudentId, x.ReviewedAt })
|
||||
.ToListAsync(cancellationToken);
|
||||
var deferred = await db.DeferredExams.AsNoTracking()
|
||||
.Where(x => x.TeachingTaskId == task.Id && x.Status == ApprovalStatus.Approved)
|
||||
.Select(x => new { x.StudentId, x.ReviewedAt })
|
||||
.ToListAsync(cancellationToken);
|
||||
var approvedStatuses = exemptions
|
||||
.Select(x => (x.StudentId, x.ReviewedAt, Status: GradeExamStatus.Exempt))
|
||||
.Concat(deferred.Select(x => (x.StudentId, x.ReviewedAt, Status: GradeExamStatus.Deferred)))
|
||||
.GroupBy(x => x.StudentId)
|
||||
.ToDictionary(x => x.Key, x => x.OrderByDescending(a => a.ReviewedAt).First().Status);
|
||||
|
||||
var sheet = new GradeSheet
|
||||
{
|
||||
TeachingTaskId = task.Id,
|
||||
@@ -239,6 +255,7 @@ public sealed class GradesController(
|
||||
Records = studentIds.Select(studentId => new GradeRecord
|
||||
{
|
||||
StudentId = studentId,
|
||||
ExamStatus = approvedStatuses.GetValueOrDefault(studentId, GradeExamStatus.Normal),
|
||||
ItemScores = items.Select(item => new GradeItemScore
|
||||
{
|
||||
GradeItemId = item.Id
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Exams;
|
||||
|
||||
public static class ExamApprovalExclusions
|
||||
{
|
||||
public static IQueryable<Guid> TaskIdsForStudent(AppDbContext db, Guid studentId) =>
|
||||
db.CourseExemptions.Where(x => x.StudentId == studentId && x.Status == ApprovalStatus.Approved)
|
||||
.Select(x => x.TeachingTaskId)
|
||||
.Union(db.DeferredExams.Where(x => x.StudentId == studentId && x.Status == ApprovalStatus.Approved)
|
||||
.Select(x => x.TeachingTaskId));
|
||||
|
||||
public static async Task<HashSet<(Guid TeachingTaskId, Guid StudentId)>> LoadAsync(
|
||||
AppDbContext db, IEnumerable<Guid> taskIds, CancellationToken token)
|
||||
{
|
||||
var ids = taskIds.Distinct().ToArray();
|
||||
if (ids.Length == 0) return [];
|
||||
var exemptions = await db.CourseExemptions.AsNoTracking().WhereIn(ids, x => x.TeachingTaskId)
|
||||
.Where(x => x.Status == ApprovalStatus.Approved)
|
||||
.Select(x => new { x.TeachingTaskId, x.StudentId }).ToListAsync(token);
|
||||
var deferred = await db.DeferredExams.AsNoTracking().WhereIn(ids, x => x.TeachingTaskId)
|
||||
.Where(x => x.Status == ApprovalStatus.Approved)
|
||||
.Select(x => new { x.TeachingTaskId, x.StudentId }).ToListAsync(token);
|
||||
return exemptions.Concat(deferred).Select(x => (x.TeachingTaskId, x.StudentId)).ToHashSet();
|
||||
}
|
||||
}
|
||||
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user