Optimize pending approvals and fix student profile updates
This commit is contained in:
1 parent
c1822d5b91
commit
28359b4974
4 files changed
+176
-134
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq.Expressions;
|
||||
using Jiaowu.Api.Contracts;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
@@ -909,14 +910,30 @@ public sealed partial class ApprovalsController(
|
||||
if (timelinessEnabled) oldestFirst = true;
|
||||
var cutoff = overdueHours.HasValue ? DateTime.UtcNow.AddHours(-overdueHours.Value) : (DateTime?)null;
|
||||
var take = checked(page * pageSize);
|
||||
var total = 0;
|
||||
var selectedType = string.IsNullOrWhiteSpace(type) ? null : type;
|
||||
var counts = new Dictionary<string, int>();
|
||||
void AddCount(string type, int count)
|
||||
var items = new List<ApprovalItem>();
|
||||
|
||||
async Task AddPending<T>(
|
||||
string approvalType,
|
||||
IQueryable<T> source,
|
||||
Expression<Func<T, DateTime>> submittedAt,
|
||||
Expression<Func<T, Guid>> id,
|
||||
Expression<Func<T, ApprovalItem>> project,
|
||||
Expression<Func<T, Guid>>? secondaryId = null)
|
||||
{
|
||||
total += count;
|
||||
if (count > 0) counts[type] = counts.GetValueOrDefault(type) + count;
|
||||
var query = source.WhereApprovalBefore(submittedAt, cutoff);
|
||||
var count = await query.CountAsync(ct);
|
||||
if (count == 0) return;
|
||||
|
||||
counts[approvalType] = counts.GetValueOrDefault(approvalType) + count;
|
||||
if (selectedType != null && selectedType != approvalType) return;
|
||||
|
||||
var ordered = query.OrderByApprovalTime(submittedAt, oldestFirst).ThenBy(id);
|
||||
if (secondaryId != null) ordered = ordered.ThenBy(secondaryId);
|
||||
items.AddRange(await ordered.Take(take).Select(project).ToListAsync(ct));
|
||||
}
|
||||
var items = new List<ApprovalItem>(Math.Min(take * 8, 10000));
|
||||
|
||||
var current = scope.Current;
|
||||
var isManager = current.IsInRole(SystemRoles.SuperAdmin) || current.IsInRole(SystemRoles.AcademicAdmin) || current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
if (isManager)
|
||||
@@ -927,9 +944,8 @@ public sealed partial class ApprovalsController(
|
||||
var collegeId = current.RestrictedCollegeId;
|
||||
leaves = collegeId.HasValue ? leaves.Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == collegeId) : leaves.Where(x => false);
|
||||
}
|
||||
items.AddRange(await leaves.WhereApprovalBefore(x => x.CreatedAt, cutoff).OrderByApprovalTime(x => x.CreatedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentLeave", "学生请假", x.Student!.Name, x.Reason, x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("StudentLeave", await leaves.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("StudentLeave", leaves, x => x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "StudentLeave", "学生请假", x.Student!.Name, x.Reason, x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -949,9 +965,8 @@ public sealed partial class ApprovalsController(
|
||||
}
|
||||
else disciplines = disciplines.Where(x => false);
|
||||
}
|
||||
items.AddRange(await disciplines.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, "StudentDiscipline", "学生处分", x.Student!.Name, x.DisciplineType, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, x.State == StudentDisciplineState.Submitted ? "college" : "final")).ToListAsync(ct));
|
||||
AddCount("StudentDiscipline", await disciplines.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("StudentDiscipline", disciplines, x => x.SubmittedAt ?? x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "StudentDiscipline", "学生处分", x.Student!.Name, x.DisciplineType, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, x.State == StudentDisciplineState.Submitted ? "college" : "final"));
|
||||
}
|
||||
if (isManager)
|
||||
{
|
||||
@@ -962,38 +977,25 @@ public sealed partial class ApprovalsController(
|
||||
var deferred = Scoped<DeferredExam>(x => x.Status == ApprovalStatus.Submitted && (super || x.ReviewerRoleSnapshot == null || x.ReviewerRoleSnapshot == "AnyManager" || (college && x.ReviewerRoleSnapshot == SystemRoles.CollegeAdmin) || (academic && x.ReviewerRoleSnapshot == SystemRoles.AcademicAdmin)));
|
||||
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
|
||||
.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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("CourseExemption", exemptions, x => x.SubmittedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "CourseExemption", "免修", $"{x.Student!.Name} — 《{x.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt, x.TeachingTask.Course!.College!.Name));
|
||||
|
||||
items.AddRange(await deferred
|
||||
.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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("DeferredExam", deferred, x => x.SubmittedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "DeferredExam", "缓考", $"{x.Student!.Name} — 《{x.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt, x.TeachingTask.Course!.College!.Name));
|
||||
|
||||
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))
|
||||
.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)).WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("GradeModification",
|
||||
Scoped<GradeModification>(x => x.Status == GradeModificationStatus.TeacherSubmitted || (canFinalReview && x.Status == GradeModificationStatus.CollegeApproved)),
|
||||
x => x.SubmittedAt, x => x.Id,
|
||||
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"));
|
||||
|
||||
items.AddRange(await substitutions
|
||||
.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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("CourseSubstitution", substitutions, x => x.SubmittedAt, x => x.Id,
|
||||
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));
|
||||
|
||||
var canCollegeReview = scope.Current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
var statusChanges = Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved && (x.Type != StudentStatusChangeType.MajorTransfer || x.OriginalClass == null || x.TargetClass == null || x.OriginalClass.Major!.CollegeId == x.TargetClass.Major!.CollegeId || (x.ReceivingCollegeReviewedAt != null && x.ReceivingCollegeId == x.TargetClass.Major!.CollegeId))));
|
||||
items.AddRange(await statusChanges
|
||||
.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 statusChanges.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("StudentStatusChange", statusChanges, x => x.SubmittedAt, x => x.Id,
|
||||
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"));
|
||||
|
||||
if (canCollegeReview)
|
||||
{
|
||||
@@ -1003,41 +1005,33 @@ public sealed partial class ApprovalsController(
|
||||
var receivingCollegeId = current.RestrictedCollegeId;
|
||||
receiving = current.Scope == DataScope.College && receivingCollegeId.HasValue ? receiving.Where(x => x.TargetClass!.Major!.CollegeId == receivingCollegeId) : receiving.Where(x => false);
|
||||
}
|
||||
items.AddRange(await receiving.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} — 转入 {x.TargetClass!.Major!.Name} / {x.TargetClass.Name}", x.Reason, x.SubmittedAt, x.TargetClass.Major.College!.Name, "receivingCollege")).ToListAsync(ct));
|
||||
AddCount("StudentStatusChange", await receiving.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("StudentStatusChange", receiving, x => x.SubmittedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", $"{x.Student!.Name} — 转入 {x.TargetClass!.Major!.Name} / {x.TargetClass.Name}", x.Reason, x.SubmittedAt, x.TargetClass.Major.College!.Name, "receivingCollege"));
|
||||
}
|
||||
|
||||
items.AddRange(await Scoped<CourseAdjustment>(x => x.Status == CourseAdjustmentStatus.Submitted)
|
||||
.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).WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("CourseAdjustment",
|
||||
Scoped<CourseAdjustment>(x => x.Status == CourseAdjustmentStatus.Submitted),
|
||||
x => x.SubmittedAt ?? x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "CourseAdjustment", CALabel(x.Type), $"《{x.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt ?? x.CreatedAt, x.TeachingTask.Course.College!.Name));
|
||||
|
||||
items.AddRange(await Scoped<GradeSheet>(x => x.Status == GradeSheetStatus.Submitted)
|
||||
.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).WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("GradeSheet", Scoped<GradeSheet>(x => x.Status == GradeSheetStatus.Submitted), x => x.SubmittedAt ?? x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "GradeSheet", "成绩审核", $"《{x.TeachingTask!.Course!.Name}》— {x.Records.Count}人", "教师已提交成绩", x.SubmittedAt ?? x.CreatedAt, x.TeachingTask.Course.College!.Name));
|
||||
|
||||
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
|
||||
.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.WhereApprovalBefore(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("AttendanceAppeal", attendance, x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, x => x.StudentId,
|
||||
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),
|
||||
x => x.AttendanceSheetId);
|
||||
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).OrderByApprovalTime(x => x.SubmittedAt, oldestFirst).ThenBy(x => x.Id).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "TeacherCourseApplication", "课程申报",
|
||||
await AddPending("TeacherCourseApplication", applications, x => x.SubmittedAt, x => x.Id,
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
x.SubmittedAt, x.Teacher.College!.Name));
|
||||
|
||||
// This workflow is restricted to the applicant's college even for users
|
||||
// who also hold a system-wide role.
|
||||
@@ -1045,59 +1039,52 @@ public sealed partial class ApprovalsController(
|
||||
{
|
||||
var reservations = db.ClassroomReservations.AsNoTracking().Where(x =>
|
||||
x.Status == ClassroomReservationStatus.Submitted && x.ApplicantCollegeId == collegeId);
|
||||
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", "教室借用",
|
||||
await AddPending("ClassroomReservation", reservations, x => x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "ClassroomReservation", "教室借用",
|
||||
$"{x.ApplicantName} — {x.Classroom!.Name}", x.Purpose,
|
||||
x.CreatedAt, x.ApplicantCollege!.Name)).ToListAsync(ct));
|
||||
AddCount("ClassroomReservation", await reservations.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
x.CreatedAt, x.ApplicantCollege!.Name));
|
||||
}
|
||||
|
||||
var gradeBatches = Scoped<GradeSubmissionBatch>(x => x.Status == GradeSheetStatus.Submitted);
|
||||
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", "部分成绩审核",
|
||||
await AddPending("GradeSubmissionBatch", gradeBatches, x => x.SubmittedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "GradeSubmissionBatch", "部分成绩审核",
|
||||
$"《{x.GradeSheet!.TeachingTask!.Course!.Name}》", "部分学生成绩待审核",
|
||||
x.SubmittedAt, x.GradeSheet.TeachingTask.Course.College!.Name, null, x.GradeSheetId)).ToListAsync(ct));
|
||||
AddCount("GradeSubmissionBatch", await gradeBatches.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
x.SubmittedAt, x.GradeSheet.TeachingTask.Course.College!.Name, null, x.GradeSheetId));
|
||||
|
||||
var experimentGrades = Scoped<ExperimentGradeSheet>(x => x.Status == ExperimentGradeSheetStatus.Submitted && x.ExperimentProject!.TeachingTask!.Status == TeachingTaskStatus.Published);
|
||||
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", "实验成绩审核",
|
||||
await AddPending("ExperimentGradeSheet", experimentGrades, x => x.SubmittedAt ?? x.CreatedAt, x => x.Id,
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
x.ExperimentProject.TeachingTask!.Course!.College!.Name));
|
||||
|
||||
var campusApplications = Scoped<CampusRegistrationApplication>(x => x.Status == CampusRegistrationApplicationStatus.PendingReview);
|
||||
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", "校园报名审核",
|
||||
await AddPending("CampusRegistration", campusApplications, x => x.CreatedAt, x => x.Id,
|
||||
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.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
x.Project.College != null ? x.Project.College.Name : "全校"));
|
||||
|
||||
{
|
||||
var canDormFinal = canFinalReview;
|
||||
var dormApplications = Scoped<DormitoryApplication>(x => x.Status == DormitoryApplicationStatus.Submitted || (canDormFinal && x.Status == DormitoryApplicationStatus.CounselorApproved));
|
||||
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", "住宿申请",
|
||||
await AddPending("DormitoryApplication", dormApplications, x => x.SubmittedAt, x => x.Id,
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name, x.Status == DormitoryApplicationStatus.Submitted ? "counselor" : "dormitory"));
|
||||
}
|
||||
|
||||
if (!current.IsInRole(SystemRoles.StudentAffairsAdmin) || canFinalReview)
|
||||
{
|
||||
var declarations = Scoped<ComprehensiveAssessmentDeclaration>(x => x.Status == ComprehensiveAssessmentDeclarationStatus.CounselorApproved);
|
||||
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", "综合测评材料复核",
|
||||
await AddPending("AssessmentDeclaration", declarations, x => x.SubmittedAt ?? x.CreatedAt, x => x.Id,
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name, "college"));
|
||||
|
||||
var assessmentAppeals = Scoped<ComprehensiveAssessmentAppeal>(x => x.Status == ComprehensiveAssessmentAppealStatus.Submitted);
|
||||
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", "综合测评申诉",
|
||||
await AddPending("AssessmentAppeal", assessmentAppeals, x => x.CreatedAt, x => x.Id,
|
||||
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.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1105,19 +1092,16 @@ public sealed partial class ApprovalsController(
|
||||
{
|
||||
var userId = current.UserId;
|
||||
var changes = db.StudentStatusChanges.AsNoTracking().Where(x => x.State == StudentStatusChangeState.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("StudentStatusChange", changes, x => x.SubmittedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", $"{x.Student!.Name} — {SSCLabel(x.Type)}", x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor"));
|
||||
var declarations = db.ComprehensiveAssessmentDeclarations.AsNoTracking().Where(x => x.Status == ComprehensiveAssessmentDeclarationStatus.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("AssessmentDeclaration", declarations, x => x.SubmittedAt ?? x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料初审", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor"));
|
||||
if (!isManager)
|
||||
{
|
||||
var dorm = db.DormitoryApplications.AsNoTracking().Where(x => x.Status == DormitoryApplicationStatus.Submitted && x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("DormitoryApplication", dorm, x => x.SubmittedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "counselor"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1125,9 +1109,9 @@ public sealed partial 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.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.WhereApprovalBefore(x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("AttendanceAppeal", teacherAttendance, x => x.AppealSubmittedAt ?? x.AttendanceSheet!.CreatedAt, x => x.StudentId,
|
||||
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),
|
||||
x => x.AttendanceSheetId);
|
||||
}
|
||||
|
||||
if (current.IsInRole(SystemRoles.Teacher) || isManager)
|
||||
@@ -1139,38 +1123,33 @@ public sealed partial class ApprovalsController(
|
||||
gradeAppeals = gradeAppeals.Where(x => x.GradeRecord!.GradeSheet!.TeachingTask!.Course!.CollegeId == gradeCollegeId);
|
||||
else if (current.Scope != DataScope.All)
|
||||
gradeAppeals = gradeAppeals.Where(x => false);
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("GradeAppeal", gradeAppeals, x => x.SubmittedAt, x => x.Id,
|
||||
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));
|
||||
}
|
||||
|
||||
if (current.IsInRole(SystemRoles.DormitoryAdmin) &&
|
||||
!current.IsInRole(SystemRoles.SuperAdmin) && !current.IsInRole(SystemRoles.AcademicAdmin))
|
||||
{
|
||||
var dorm = db.DormitoryApplications.AsNoTracking().Where(x => x.Status == DormitoryApplicationStatus.CounselorApproved);
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("DormitoryApplication", dorm, x => x.SubmittedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "dormitory"));
|
||||
}
|
||||
if (current.IsInRole(SystemRoles.StudentAffairsAdmin) &&
|
||||
!current.IsInRole(SystemRoles.SuperAdmin) && !current.IsInRole(SystemRoles.AcademicAdmin))
|
||||
{
|
||||
var declarations = db.ComprehensiveAssessmentDeclarations.AsNoTracking().Where(x => x.Status == ComprehensiveAssessmentDeclarationStatus.CounselorApproved);
|
||||
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.WhereApprovalBefore(x => x.SubmittedAt ?? x.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("AssessmentDeclaration", declarations, x => x.SubmittedAt ?? x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料复核", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name, "college"));
|
||||
var appeals = db.ComprehensiveAssessmentAppeals.AsNoTracking().Where(x => x.Status == ComprehensiveAssessmentAppealStatus.Submitted);
|
||||
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.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("AssessmentAppeal", appeals, x => x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "AssessmentAppeal", "综合测评申诉", x.Student!.Name, x.Reason, x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name));
|
||||
}
|
||||
|
||||
if (isManager || current.IsInRole(SystemRoles.Leader))
|
||||
{
|
||||
var plans = Scoped<TeachingImprovementPlan>(x => x.Status == ImprovementPlanStatus.Completed);
|
||||
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.WhereApprovalBefore(x => x.UpdatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("TeachingImprovement", plans, x => x.UpdatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "TeachingImprovement", "教学改进复评", $"{x.Teacher.Name} — 《{x.TeachingTask.Course!.Name}》", x.ProblemSummary, x.UpdatedAt, x.TeachingTask.Course.College!.Name));
|
||||
}
|
||||
|
||||
if (isManager || current.IsInRole(SystemRoles.Counselor))
|
||||
@@ -1188,14 +1167,12 @@ public sealed partial 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.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.WhereApprovalBefore(x => x.CreatedAt, cutoff).CountAsync(ct));
|
||||
await AddPending("GraduationClearance", clearances, x => x.CreatedAt, x => x.Id,
|
||||
x => new ApprovalItem(x.Id, "GraduationClearance", "毕业离校办理", $"{x.Student!.Name} — {x.GraduationClearanceItem!.Name}", x.GraduationClearanceItem.ResponsibleUnit, x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name));
|
||||
}
|
||||
|
||||
var filtered = string.IsNullOrWhiteSpace(type) ? items : items.Where(x => x.Type == type);
|
||||
if (!string.IsNullOrWhiteSpace(type)) total = counts.GetValueOrDefault(type);
|
||||
var ordered = oldestFirst ? filtered.OrderBy(x => x.Time) : filtered.OrderByDescending(x => x.Time);
|
||||
var total = selectedType == null ? counts.Values.Sum() : counts.GetValueOrDefault(selectedType);
|
||||
var ordered = oldestFirst ? items.OrderBy(x => x.Time) : items.OrderByDescending(x => x.Time);
|
||||
var pageItems = ordered
|
||||
.ThenBy(x => x.Type)
|
||||
.ThenBy(x => x.Id)
|
||||
|
||||
@@ -10,6 +10,7 @@ using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
@@ -1864,7 +1865,8 @@ public sealed class ApprovalsControllerTests
|
||||
[Fact]
|
||||
public async Task Pending_returns_a_single_server_page_with_total()
|
||||
{
|
||||
await using var fixture = await ApprovalFixture.CreateAsync();
|
||||
var commands = new List<string>();
|
||||
await using var fixture = await ApprovalFixture.CreateAsync(commands.Add);
|
||||
fixture.Db.AddRange(
|
||||
new DeferredExam
|
||||
{
|
||||
@@ -1901,11 +1903,22 @@ public sealed class ApprovalsControllerTests
|
||||
Assert.Equal("较早提交", Assert.Single(oldestPage.Items).Desc);
|
||||
Assert.Equal(2, oldestPage.Total);
|
||||
|
||||
commands.Clear();
|
||||
var filtered = await controller.GetPending(1, 1, CancellationToken.None, type: "CourseExemption");
|
||||
var filteredPage = Assert.IsType<ApprovalPendingResult>(Assert.IsType<OkObjectResult>(filtered.Result).Value);
|
||||
Assert.Equal(1, filteredPage.Total);
|
||||
Assert.Equal("CourseExemption", Assert.Single(filteredPage.Items).Type);
|
||||
Assert.Equal(1, filteredPage.Counts["DeferredExam"]);
|
||||
var deferredQuery = Assert.Single(commands, sql => sql.Contains("FROM \"DeferredExams\""));
|
||||
Assert.Contains("SELECT COUNT(*)", deferredQuery);
|
||||
|
||||
commands.Clear();
|
||||
var empty = await controller.GetPending(1, 1, CancellationToken.None, type: "StudentLeave");
|
||||
var emptyPage = Assert.IsType<ApprovalPendingResult>(Assert.IsType<OkObjectResult>(empty.Result).Value);
|
||||
Assert.Empty(emptyPage.Items);
|
||||
Assert.Equal(0, emptyPage.Total);
|
||||
var leaveQuery = Assert.Single(commands, sql => sql.Contains("FROM \"StudentLeaves\""));
|
||||
Assert.Contains("SELECT COUNT(*)", leaveQuery);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -2094,14 +2107,14 @@ public sealed class ApprovalsControllerTests
|
||||
public TeachingTask CurrentTask { get; }
|
||||
public ApprovalsController Controller { get; }
|
||||
|
||||
public static async Task<ApprovalFixture> CreateAsync()
|
||||
public static async Task<ApprovalFixture> CreateAsync(Action<string>? recordCommand = null)
|
||||
{
|
||||
var connection = new SqliteConnection("Data Source=:memory:");
|
||||
await connection.OpenAsync();
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
var db = new AppDbContext(options);
|
||||
.UseSqlite(connection);
|
||||
if (recordCommand != null) options.LogTo(recordCommand, [RelationalEventId.CommandExecuted]);
|
||||
var db = new AppDbContext(options.Options);
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
|
||||
var college = new College { Code = "CS", Name = "计算机学院" };
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { expect, test } from '@playwright/test'
|
||||
|
||||
test.use({ serviceWorkers: 'block' })
|
||||
|
||||
test('saves contact changes with optional fields blank and preserves existing identity information', async ({ page }) => {
|
||||
const user = {
|
||||
id: 'student', userName: 'student', displayName: '测试学生', roles: ['Student'],
|
||||
permissions: [], effectiveDataScope: 'Self',
|
||||
}
|
||||
const profile = {
|
||||
studentNumber: '2026001', name: user.displayName, className: '测试班', status: 'Active',
|
||||
enrollmentYear: 2026, gender: 'Female', dateOfBirth: null, email: null, phone: null as string | null,
|
||||
nationality: '美国', ethnicity: '汉族', politicalStatus: '群众', nativePlace: '山东济南',
|
||||
}
|
||||
await page.addInitScript(savedUser => {
|
||||
localStorage.setItem('jiaowu_token', 'test-token')
|
||||
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
|
||||
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
|
||||
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
|
||||
}, user)
|
||||
await page.route(url => url.pathname.startsWith('/api/'), async route => {
|
||||
const path = new URL(route.request().url()).pathname
|
||||
if (path === '/api/auth/me') return route.fulfill({ json: user })
|
||||
if (path === '/api/plugins/runtime' || path === '/api/student-identity-changes/mine') {
|
||||
return route.fulfill({ json: [] })
|
||||
}
|
||||
if (path === '/api/student/profile') {
|
||||
if (route.request().method() === 'PUT') {
|
||||
profile.phone = route.request().postDataJSON().phone
|
||||
return route.fulfill({ json: { approvalSubmitted: false } })
|
||||
}
|
||||
return route.fulfill({ json: profile })
|
||||
}
|
||||
return route.fulfill({ json: {} })
|
||||
})
|
||||
|
||||
await page.goto('/my-profile')
|
||||
await page.getByRole('button', { name: '修改信息' }).click()
|
||||
const phone = page.getByRole('textbox', { name: '联系电话', exact: true })
|
||||
await phone.fill('13800000000')
|
||||
const saveRequest = page.waitForRequest(request =>
|
||||
new URL(request.url()).pathname === '/api/student/profile' && request.method() === 'PUT',
|
||||
)
|
||||
await page.getByRole('button', { name: '保存', exact: true }).click()
|
||||
|
||||
expect((await saveRequest).postDataJSON()).toMatchObject({
|
||||
phone: '13800000000', dateOfBirth: null, email: null,
|
||||
nationality: '美国', ethnicity: '汉族', politicalStatus: '群众', nativePlace: '山东济南',
|
||||
})
|
||||
await expect(page.getByText('个人信息已保存。')).toBeVisible()
|
||||
await expect(phone).toHaveValue('13800000000')
|
||||
})
|
||||
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