Filter approval queues by waiting time
This commit is contained in:
1 parent
634ec48f53
commit
5d2c24d702
6 files changed
+143
-58
No files matched your search
@@ -167,11 +167,15 @@ public sealed class ApprovalsController(
|
||||
int pageSize = 20,
|
||||
CancellationToken ct = default,
|
||||
bool oldestFirst = false,
|
||||
string? type = null)
|
||||
string? type = null,
|
||||
int? overdueHours = null)
|
||||
{
|
||||
if (page < 1 || pageSize is < 1 or > 100 || (long)page * pageSize > 100000)
|
||||
return ValidationProblem("page 必须大于 0,pageSize 必须在 1 到 100 之间,且分页窗口不能超过 100000 条。");
|
||||
if (overdueHours is < 1 or > 8760)
|
||||
return ValidationProblem("等待时长必须在 1 到 8760 小时之间。");
|
||||
|
||||
var cutoff = overdueHours.HasValue ? DateTime.UtcNow.AddHours(-overdueHours.Value) : (DateTime?)null;
|
||||
var take = checked(page * pageSize);
|
||||
var total = 0;
|
||||
var counts = new Dictionary<string, int>();
|
||||
@@ -193,67 +197,67 @@ public sealed class ApprovalsController(
|
||||
var substitutions = Scoped<CourseSubstitution>(x => x.Status == ApprovalStatus.Submitted && (super || x.ReviewerRoleSnapshot == null || x.ReviewerRoleSnapshot == "AnyManager" || (college && x.ReviewerRoleSnapshot == SystemRoles.CollegeAdmin) || (academic && x.ReviewerRoleSnapshot == SystemRoles.AcademicAdmin)));
|
||||
|
||||
items.AddRange(await exemptions
|
||||
.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "CourseExemption", "免修", $"{x.Student!.Name} — 《{x.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt, x.TeachingTask.Course!.College!.Name))
|
||||
.ToListAsync(ct));
|
||||
AddCount("CourseExemption", await exemptions.CountAsync(ct));
|
||||
AddCount("CourseExemption", await exemptions.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
items.AddRange(await deferred
|
||||
.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "DeferredExam", "缓考", $"{x.Student!.Name} — 《{x.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt, x.TeachingTask.Course!.College!.Name))
|
||||
.ToListAsync(ct));
|
||||
AddCount("DeferredExam", await deferred.CountAsync(ct));
|
||||
AddCount("DeferredExam", await deferred.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
var canFinalReview = scope.Current.IsInRole(SystemRoles.SuperAdmin) || scope.Current.IsInRole(SystemRoles.AcademicAdmin);
|
||||
items.AddRange(await Scoped<GradeModification>(x => x.Status == GradeModificationStatus.TeacherSubmitted || (canFinalReview && x.Status == GradeModificationStatus.CollegeApproved))
|
||||
.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "GradeModification", "成绩修改", $"{x.GradeRecord!.Student!.Name} — 《{x.GradeRecord.GradeSheet!.TeachingTask!.Course!.Name}》", $"{x.CurrentScore} → {x.RequestedScore}:{x.Reason}", x.SubmittedAt, x.GradeRecord.GradeSheet.TeachingTask.Course!.College!.Name, x.Status == GradeModificationStatus.TeacherSubmitted ? "college" : "final"))
|
||||
.ToListAsync(ct));
|
||||
AddCount("GradeModification", await Scoped<GradeModification>(x => x.Status == GradeModificationStatus.TeacherSubmitted || (canFinalReview && x.Status == GradeModificationStatus.CollegeApproved)).CountAsync(ct));
|
||||
AddCount("GradeModification", await Scoped<GradeModification>(x => x.Status == GradeModificationStatus.TeacherSubmitted || (canFinalReview && x.Status == GradeModificationStatus.CollegeApproved)).WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
items.AddRange(await substitutions
|
||||
.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "CourseSubstitution", "课程替代", $"{x.Student!.Name}:{x.SubstituteCourse!.Name} → {x.OriginalCourse!.Name}", x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name))
|
||||
.ToListAsync(ct));
|
||||
AddCount("CourseSubstitution", await substitutions.CountAsync(ct));
|
||||
AddCount("CourseSubstitution", await substitutions.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
var canCollegeReview = scope.Current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
items.AddRange(await Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved))
|
||||
.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", $"{x.Student!.Name} — {SSCLabel(x.Type)}", x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, x.State == StudentStatusChangeState.CounselorApproved ? "college" : "final"))
|
||||
.ToListAsync(ct));
|
||||
AddCount("StudentStatusChange", await Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved)).CountAsync(ct));
|
||||
AddCount("StudentStatusChange", await Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved)).WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<CourseAdjustment>(x => x.Status == CourseAdjustmentStatus.Submitted)
|
||||
.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "CourseAdjustment", CALabel(x.Type), $"《{x.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt ?? x.CreatedAt, x.TeachingTask.Course.College!.Name))
|
||||
.ToListAsync(ct));
|
||||
AddCount("CourseAdjustment", await Scoped<CourseAdjustment>(x => x.Status == CourseAdjustmentStatus.Submitted).CountAsync(ct));
|
||||
AddCount("CourseAdjustment", await Scoped<CourseAdjustment>(x => x.Status == CourseAdjustmentStatus.Submitted).WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<GradeSheet>(x => x.Status == GradeSheetStatus.Submitted)
|
||||
.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "GradeSheet", "成绩审核", $"《{x.TeachingTask!.Course!.Name}》— {x.Records.Count}人", "教师已提交成绩", x.SubmittedAt ?? x.CreatedAt, x.TeachingTask.Course.College!.Name))
|
||||
.ToListAsync(ct));
|
||||
AddCount("GradeSheet", await Scoped<GradeSheet>(x => x.Status == GradeSheetStatus.Submitted).CountAsync(ct));
|
||||
AddCount("GradeSheet", await Scoped<GradeSheet>(x => x.Status == GradeSheetStatus.Submitted).WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
|
||||
var attendance = db.AttendanceRecords.AsNoTracking().Where(x => x.AppealStatus == AttendanceAppealStatus.Pending && x.AttendanceSheet!.TeachingTask!.Status == TeachingTaskStatus.Published);
|
||||
if (!canFinalReview)
|
||||
attendance = attendance.Where(x => x.AttendanceSheet!.TeachingTask!.Teachers.Any(t => t.Teacher!.UserId == current.UserId));
|
||||
items.AddRange(await attendance
|
||||
.OrderByApprovalTime(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, oldestFirst).ThenBy(x => x.StudentId).ThenBy(x => x.AttendanceSheetId).Take(take)
|
||||
.WhereApprovalBefore(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, cutoff).OrderByApprovalTime(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, oldestFirst).ThenBy(x => x.StudentId).ThenBy(x => x.AttendanceSheetId).Take(take)
|
||||
.Select(x => new ApprovalItem(x.StudentId, "AttendanceAppeal", "考勤申诉", $"{x.Student!.Name} — 《{x.AttendanceSheet!.TeachingTask!.Course!.Name}》", x.AppealReason ?? "", x.AppealSubmittedAt ?? x.AttendanceSheet.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, null, x.AttendanceSheetId))
|
||||
.ToListAsync(ct));
|
||||
AddCount("AttendanceAppeal", await attendance.CountAsync(ct));
|
||||
AddCount("AttendanceAppeal", await attendance.WhereApprovalBefore(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, cutoff).CountAsync(ct));
|
||||
|
||||
var applications = db.TeacherCourseApplications.AsNoTracking()
|
||||
.Where(x => x.Status == TeacherCourseApplicationStatus.Pending);
|
||||
if (scope.Current.RestrictedCollegeId is { } teacherCollegeId)
|
||||
applications = applications.Where(x => x.Teacher!.CollegeId == teacherCollegeId);
|
||||
items.AddRange(await applications.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await applications.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "TeacherCourseApplication", "课程申报",
|
||||
$"{x.Teacher!.Name} — 《{x.Course!.Name}》", x.Statement ?? "",
|
||||
x.SubmittedAt, x.Teacher.College!.Name)).ToListAsync(ct));
|
||||
AddCount("TeacherCourseApplication", await applications.CountAsync(ct));
|
||||
AddCount("TeacherCourseApplication", await applications.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
// This workflow is restricted to the applicant's college even for users
|
||||
// who also hold a system-wide role.
|
||||
@@ -261,76 +265,76 @@ public sealed class ApprovalsController(
|
||||
{
|
||||
var reservations = db.ClassroomReservations.AsNoTracking().Where(x =>
|
||||
x.Status == ClassroomReservationStatus.Submitted && x.ApplicantCollegeId == collegeId);
|
||||
items.AddRange(await reservations.OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await reservations.WhereApprovalBefore(x => x.CreatedAt, cutoff).OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "ClassroomReservation", "教室借用",
|
||||
$"{x.ApplicantName} — {x.Classroom!.Name}", x.Purpose,
|
||||
x.CreatedAt, x.ApplicantCollege!.Name)).ToListAsync(ct));
|
||||
AddCount("ClassroomReservation", await reservations.CountAsync(ct));
|
||||
AddCount("ClassroomReservation", await reservations.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
|
||||
var gradeBatches = Scoped<GradeSubmissionBatch>(x => x.Status == GradeSheetStatus.Submitted);
|
||||
items.AddRange(await gradeBatches.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await gradeBatches.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "GradeSubmissionBatch", "部分成绩审核",
|
||||
$"《{x.GradeSheet!.TeachingTask!.Course!.Name}》", "部分学生成绩待审核",
|
||||
x.SubmittedAt, x.GradeSheet.TeachingTask.Course.College!.Name)).ToListAsync(ct));
|
||||
AddCount("GradeSubmissionBatch", await gradeBatches.CountAsync(ct));
|
||||
AddCount("GradeSubmissionBatch", await gradeBatches.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
var experimentGrades = Scoped<ExperimentGradeSheet>(x => x.Status == ExperimentGradeSheetStatus.Submitted && x.ExperimentProject!.TeachingTask!.Status == TeachingTaskStatus.Published);
|
||||
items.AddRange(await experimentGrades.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await experimentGrades.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "ExperimentGradeSheet", "实验成绩审核",
|
||||
x.ExperimentProject!.Name, "实验成绩待审核", x.SubmittedAt ?? x.CreatedAt,
|
||||
x.ExperimentProject.TeachingTask!.Course!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("ExperimentGradeSheet", await experimentGrades.CountAsync(ct));
|
||||
AddCount("ExperimentGradeSheet", await experimentGrades.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
|
||||
var campusApplications = Scoped<CampusRegistrationApplication>(x => x.Status == CampusRegistrationApplicationStatus.PendingReview);
|
||||
items.AddRange(await campusApplications.OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await campusApplications.WhereApprovalBefore(x => x.CreatedAt, cutoff).OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "CampusRegistration", "校园报名审核",
|
||||
$"{x.Student!.Name} — {x.Project!.Name}", x.ApplicantNote ?? "", x.CreatedAt,
|
||||
x.Project.College != null ? x.Project.College.Name : "全校")).ToListAsync(ct));
|
||||
AddCount("CampusRegistration", await campusApplications.CountAsync(ct));
|
||||
AddCount("CampusRegistration", await campusApplications.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
|
||||
{
|
||||
var canDormFinal = canFinalReview || current.IsInRole(SystemRoles.DormitoryAdmin);
|
||||
var dormApplications = Scoped<DormitoryApplication>(x => x.Status == DormitoryApplicationStatus.Submitted || (canDormFinal && x.Status == DormitoryApplicationStatus.CounselorApproved));
|
||||
items.AddRange(await dormApplications.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await dormApplications.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请",
|
||||
x.Student!.Name, x.Reason, x.SubmittedAt,
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name, x.Status == DormitoryApplicationStatus.Submitted ? "counselor" : "dormitory")).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dormApplications.CountAsync(ct));
|
||||
AddCount("DormitoryApplication", await dormApplications.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
|
||||
var declarations = Scoped<ComprehensiveAssessmentDeclaration>(x => x.Status == ComprehensiveAssessmentDeclarationStatus.CounselorApproved);
|
||||
items.AddRange(await declarations.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await declarations.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料复核",
|
||||
$"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt,
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name, "college")).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.CountAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
|
||||
var assessmentAppeals = Scoped<ComprehensiveAssessmentAppeal>(x => x.Status == ComprehensiveAssessmentAppealStatus.Submitted);
|
||||
items.AddRange(await assessmentAppeals.OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await assessmentAppeals.WhereApprovalBefore(x => x.CreatedAt, cutoff).OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentAppeal", "综合测评申诉",
|
||||
x.Student!.Name, x.Reason, x.CreatedAt,
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("AssessmentAppeal", await assessmentAppeals.CountAsync(ct));
|
||||
AddCount("AssessmentAppeal", await assessmentAppeals.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
|
||||
if (current.IsInRole(SystemRoles.Counselor))
|
||||
{
|
||||
var userId = current.UserId;
|
||||
var changes = db.StudentStatusChanges.AsNoTracking().Where(x => x.State == StudentStatusChangeState.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
items.AddRange(await changes.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await changes.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", $"{x.Student!.Name} — {SSCLabel(x.Type)}", x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor")).ToListAsync(ct));
|
||||
AddCount("StudentStatusChange", await changes.CountAsync(ct));
|
||||
AddCount("StudentStatusChange", await changes.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
var declarations = db.ComprehensiveAssessmentDeclarations.AsNoTracking().Where(x => x.Status == ComprehensiveAssessmentDeclarationStatus.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
items.AddRange(await declarations.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await declarations.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料初审", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor")).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.CountAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
if (!isManager)
|
||||
{
|
||||
var dorm = db.DormitoryApplications.AsNoTracking().Where(x => x.Status == DormitoryApplicationStatus.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
items.AddRange(await dorm.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await dorm.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor")).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dorm.CountAsync(ct));
|
||||
AddCount("DormitoryApplication", await dorm.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,9 +342,9 @@ public sealed class ApprovalsController(
|
||||
{
|
||||
var userId = current.UserId;
|
||||
var teacherAttendance = db.AttendanceRecords.AsNoTracking().Where(x => x.AppealStatus == AttendanceAppealStatus.Pending && x.AttendanceSheet!.TeachingTask!.Status == TeachingTaskStatus.Published && x.AttendanceSheet.TeachingTask.Teachers.Any(t => t.Teacher!.UserId == userId));
|
||||
items.AddRange(await teacherAttendance.OrderByApprovalTime(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, oldestFirst).ThenBy(x => x.StudentId).ThenBy(x => x.AttendanceSheetId).Take(take)
|
||||
items.AddRange(await teacherAttendance.WhereApprovalBefore(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, cutoff).OrderByApprovalTime(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, oldestFirst).ThenBy(x => x.StudentId).ThenBy(x => x.AttendanceSheetId).Take(take)
|
||||
.Select(x => new ApprovalItem(x.StudentId, "AttendanceAppeal", "考勤申诉", $"{x.Student!.Name} — 《{x.AttendanceSheet!.TeachingTask!.Course!.Name}》", x.AppealReason ?? "", x.AppealSubmittedAt ?? x.AttendanceSheet.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, null, x.AttendanceSheetId)).ToListAsync(ct));
|
||||
AddCount("AttendanceAppeal", await teacherAttendance.CountAsync(ct));
|
||||
AddCount("AttendanceAppeal", await teacherAttendance.WhereApprovalBefore(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
|
||||
if (current.IsInRole(SystemRoles.Teacher) || isManager)
|
||||
@@ -350,36 +354,36 @@ public sealed class ApprovalsController(
|
||||
gradeAppeals = gradeAppeals.Where(x => x.GradeRecord!.GradeSheet!.TeachingTask!.Teachers.Any(t => t.Teacher!.UserId == current.UserId));
|
||||
else if (current.RestrictedCollegeId is { } gradeCollegeId)
|
||||
gradeAppeals = gradeAppeals.Where(x => x.GradeRecord!.GradeSheet!.TeachingTask!.Course!.CollegeId == gradeCollegeId);
|
||||
items.AddRange(await gradeAppeals.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await gradeAppeals.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "GradeAppeal", "成绩异议", $"{x.Student!.Name} — 《{x.GradeRecord!.GradeSheet!.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt, x.GradeRecord.GradeSheet.TeachingTask.Course.College!.Name)).ToListAsync(ct));
|
||||
AddCount("GradeAppeal", await gradeAppeals.CountAsync(ct));
|
||||
AddCount("GradeAppeal", await gradeAppeals.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
|
||||
if (current.IsInRole(SystemRoles.DormitoryAdmin) && !isManager)
|
||||
{
|
||||
var dorm = Scoped<DormitoryApplication>(x => x.Status == DormitoryApplicationStatus.CounselorApproved);
|
||||
items.AddRange(await dorm.OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await dorm.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "dormitory")).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dorm.CountAsync(ct));
|
||||
AddCount("DormitoryApplication", await dorm.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
if (current.IsInRole(SystemRoles.StudentAffairsAdmin) && !isManager)
|
||||
{
|
||||
var declarations = Scoped<ComprehensiveAssessmentDeclaration>(x => x.Status == ComprehensiveAssessmentDeclarationStatus.CounselorApproved);
|
||||
items.AddRange(await declarations.OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await declarations.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt ?? x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料复核", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "college")).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.CountAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
var appeals = Scoped<ComprehensiveAssessmentAppeal>(x => x.Status == ComprehensiveAssessmentAppealStatus.Submitted);
|
||||
items.AddRange(await appeals.OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await appeals.WhereApprovalBefore(x => x.CreatedAt, cutoff).OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentAppeal", "综合测评申诉", x.Student!.Name, x.Reason, x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("AssessmentAppeal", await appeals.CountAsync(ct));
|
||||
AddCount("AssessmentAppeal", await appeals.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
|
||||
if (isManager || current.IsInRole(SystemRoles.Leader))
|
||||
{
|
||||
var plans = Scoped<TeachingImprovementPlan>(x => x.Status == ImprovementPlanStatus.Completed);
|
||||
items.AddRange(await plans.OrderByApprovalTime(x => x.UpdatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await plans.WhereApprovalBefore(x => x.UpdatedAt, cutoff).OrderByApprovalTime(x => x.UpdatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "TeachingImprovement", "教学改进复评", $"{x.Teacher.Name} — 《{x.TeachingTask.Course!.Name}》", x.ProblemSummary, x.UpdatedAt, x.TeachingTask.Course.College!.Name)).ToListAsync(ct));
|
||||
AddCount("TeachingImprovement", await plans.CountAsync(ct));
|
||||
AddCount("TeachingImprovement", await plans.WhereApprovalBefore(x => x.UpdatedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
|
||||
if (isManager || current.IsInRole(SystemRoles.Counselor))
|
||||
@@ -397,9 +401,9 @@ public sealed class ApprovalsController(
|
||||
(isAcademic && x.GraduationClearanceItem.ResponsibleRole == SystemRoles.AcademicAdmin) ||
|
||||
(isCollege && x.GraduationClearanceItem.ResponsibleRole == SystemRoles.CollegeAdmin && x.Student!.AdministrativeClass!.Major!.CollegeId == collegeId) ||
|
||||
(isCounselor && x.GraduationClearanceItem.ResponsibleRole == SystemRoles.Counselor && x.Student!.AdministrativeClass!.CounselorUserId == userId)));
|
||||
items.AddRange(await clearances.OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
items.AddRange(await clearances.WhereApprovalBefore(x => x.CreatedAt, cutoff).OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "GraduationClearance", "毕业离校办理", $"{x.Student!.Name} — {x.GraduationClearanceItem!.Name}", x.GraduationClearanceItem.ResponsibleUnit, x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("GraduationClearance", await clearances.CountAsync(ct));
|
||||
AddCount("GraduationClearance", await clearances.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
}
|
||||
|
||||
var filtered = string.IsNullOrWhiteSpace(type) ? items : items.Where(x => x.Type == type);
|
||||
@@ -1133,6 +1137,16 @@ public sealed record ApprovalProgressResponse(string Type, Guid Id, IReadOnlyLis
|
||||
|
||||
internal static class ApprovalOrderingExtensions
|
||||
{
|
||||
public static IQueryable<T> WhereApprovalBefore<T>(this IQueryable<T> source,
|
||||
System.Linq.Expressions.Expression<Func<T, DateTime>> selector, DateTime? cutoff)
|
||||
{
|
||||
if (!cutoff.HasValue) return source;
|
||||
var effectiveCutoff = cutoff.Value;
|
||||
System.Linq.Expressions.Expression<Func<DateTime>> boundary = () => effectiveCutoff;
|
||||
var body = System.Linq.Expressions.Expression.LessThanOrEqual(selector.Body, boundary.Body);
|
||||
return source.Where(System.Linq.Expressions.Expression.Lambda<Func<T, bool>>(body, selector.Parameters));
|
||||
}
|
||||
|
||||
public static IOrderedQueryable<T> OrderByApprovalTime<T>(this IQueryable<T> source,
|
||||
System.Linq.Expressions.Expression<Func<T, DateTime>> selector, bool oldestFirst) =>
|
||||
oldestFirst ? source.OrderBy(selector) : source.OrderByDescending(selector);
|
||||
|
||||
@@ -13,6 +13,39 @@ namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class ApprovalsControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public void Overdue_filter_translates_with_mysql_provider()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseMySQL("Server=localhost;Database=design;User=design;Password=unused")
|
||||
.Options;
|
||||
using var db = new AppDbContext(options);
|
||||
var sql = db.GradeSheets.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, DateTime.UtcNow).ToQueryString();
|
||||
Assert.Contains("COALESCE", sql, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("WHERE", sql, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Overdue_filter_applies_before_counts_and_pagination()
|
||||
{
|
||||
await using var fixture = await ApprovalFixture.CreateAsync();
|
||||
fixture.Db.AddRange(
|
||||
new CourseExemption { StudentId = fixture.Student.Id, TeachingTaskId = fixture.CurrentTask.Id, Reason = "已等待", SubmittedAt = DateTime.UtcNow.AddHours(-100) },
|
||||
new DeferredExam { StudentId = fixture.Student.Id, TeachingTaskId = fixture.CurrentTask.Id, Reason = "刚提交", SubmittedAt = DateTime.UtcNow.AddHours(-4) },
|
||||
new GradeSheet { TeachingTaskId = fixture.CurrentTask.Id, Status = GradeSheetStatus.Submitted, SubmittedAt = null, CreatedAt = DateTime.UtcNow.AddHours(-80) });
|
||||
await fixture.Db.SaveChangesAsync();
|
||||
var controller = new ApprovalsController(fixture.Db, new ManagerDataScope());
|
||||
var response = await controller.GetPending(1, 1, CancellationToken.None, oldestFirst: true, overdueHours: 72);
|
||||
var result = Assert.IsType<ApprovalPendingResult>(Assert.IsType<OkObjectResult>(response.Result).Value);
|
||||
Assert.Equal(2, result.Total);
|
||||
Assert.Equal("CourseExemption", Assert.Single(result.Items).Type);
|
||||
Assert.Equal(1, result.Counts["CourseExemption"]);
|
||||
Assert.Equal(1, result.Counts["GradeSheet"]);
|
||||
Assert.False(result.Counts.ContainsKey("DeferredExam"));
|
||||
var invalid = await controller.GetPending(1, 20, CancellationToken.None, overdueHours: 0);
|
||||
Assert.IsType<ObjectResult>(invalid.Result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Student_status_cancellation_is_recorded_in_progress()
|
||||
{
|
||||
|
||||
@@ -23,9 +23,14 @@ for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ?
|
||||
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
|
||||
}, user)
|
||||
let reviewed = false
|
||||
let overdueRequested = false
|
||||
await page.route(url => url.pathname.startsWith('/api/'), async route => {
|
||||
const url = new URL(route.request().url())
|
||||
if (url.pathname === '/api/approvals/pending') {
|
||||
if (url.searchParams.has('overdueHours')) {
|
||||
expect(url.searchParams.get('overdueHours')).toBe('72')
|
||||
overdueRequested = true
|
||||
}
|
||||
const items = reviewed ? [] : [{ id: 'item-1', secondaryId: scenario.secondaryId, type: scenario.type, stage: scenario.stage, label: '申请', title: '学生 — 《课程》', desc: '申请事由', time: '2026-11-01T00:00:00Z', college: '学院' }]
|
||||
return route.fulfill({ json: { items, total: items.length, page: 1, pageSize: 20, counts: reviewed ? {} : { [scenario.type]: 1 } } })
|
||||
}
|
||||
@@ -44,6 +49,11 @@ for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ?
|
||||
await page.goto('/approvals')
|
||||
const card = page.locator('.appr-card').filter({ hasText: '申请事由' })
|
||||
await expect(card).toBeVisible()
|
||||
if (scenario.type === 'AttendanceAppeal' && !scenario.reject) {
|
||||
await page.locator('.approval-overdue-filter .el-switch').click()
|
||||
await expect.poll(() => overdueRequested).toBe(true)
|
||||
await expect(page.getByText('按每条事项显示的时间计算,阈值保存在当前浏览器。')).toBeVisible()
|
||||
}
|
||||
if (scenario.progress) {
|
||||
await card.getByRole('button', { name: '办理进度' }).click()
|
||||
const dialog = page.getByRole('dialog')
|
||||
|
||||
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user