Expand approval center and configure reviewer routing
This commit is contained in:
1 parent
cc1b60450f
commit
2d1a43fd39
14 files changed
+12632
-78
No files matched your search
@@ -23,77 +23,288 @@ public sealed class ApprovalsController(
|
||||
private const string Managers = SystemRoles.SuperAdmin + "," + SystemRoles.AcademicAdmin + "," + SystemRoles.CollegeAdmin;
|
||||
private const string Teachers = Managers + "," + SystemRoles.Teacher;
|
||||
private const string Students = Managers + "," + SystemRoles.Student;
|
||||
private static readonly string[] ConfigurableTypes = ["CourseExemption", "DeferredExam", "CourseSubstitution"];
|
||||
|
||||
[HttpGet("workflow-settings")]
|
||||
[Authorize(Roles = SystemRoles.SuperAdmin)]
|
||||
public async Task<ActionResult> GetWorkflowSettings(CancellationToken ct)
|
||||
{
|
||||
var settings = await db.ApprovalRouteSettings.AsNoTracking().ToListAsync(ct);
|
||||
return Ok(ConfigurableTypes.Select(type => new
|
||||
{
|
||||
Type = type,
|
||||
ReviewerRole = settings.FirstOrDefault(x => x.Type == type)?.ReviewerRole ?? "AnyManager"
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpPut("workflow-settings/{type}")]
|
||||
[Authorize(Roles = SystemRoles.SuperAdmin)]
|
||||
public async Task<ActionResult> UpdateWorkflowSetting(string type, ApprovalRouteSettingRequest request, CancellationToken ct)
|
||||
{
|
||||
if (!ConfigurableTypes.Contains(type) || request.ReviewerRole is not ("AnyManager" or SystemRoles.CollegeAdmin or SystemRoles.AcademicAdmin))
|
||||
return ValidationProblem("审批类型或审核角色无效。");
|
||||
var setting = await db.ApprovalRouteSettings.FirstOrDefaultAsync(x => x.Type == type, ct);
|
||||
if (setting is null)
|
||||
{
|
||||
setting = new ApprovalRouteSetting { Type = type, ReviewerRole = request.ReviewerRole };
|
||||
db.ApprovalRouteSettings.Add(setting);
|
||||
}
|
||||
else setting.ReviewerRole = request.ReviewerRole;
|
||||
await db.SaveChangesAsync(ct);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// ═══════════════ Aggregated pending ═══════════════
|
||||
[HttpGet("pending")]
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult<PagedResult<ApprovalItem>>> GetPending(
|
||||
[Authorize(Roles = Managers + "," + SystemRoles.Teacher + "," + SystemRoles.Counselor + "," + SystemRoles.DormitoryAdmin + "," + SystemRoles.StudentAffairsAdmin + "," + SystemRoles.Leader)]
|
||||
public async Task<ActionResult<ApprovalPendingResult>> GetPending(
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
CancellationToken ct = default)
|
||||
CancellationToken ct = default,
|
||||
bool oldestFirst = false)
|
||||
{
|
||||
if (page < 1 || pageSize is < 1 or > 100)
|
||||
return ValidationProblem("page 必须大于 0,pageSize 必须在 1 到 100 之间。");
|
||||
if (page < 1 || pageSize is < 1 or > 100 || (long)page * pageSize > 100000)
|
||||
return ValidationProblem("page 必须大于 0,pageSize 必须在 1 到 100 之间,且分页窗口不能超过 100000 条。");
|
||||
|
||||
var take = checked(page * pageSize);
|
||||
var total = 0;
|
||||
var items = new List<ApprovalItem>(take * 8);
|
||||
var counts = new Dictionary<string, int>();
|
||||
void AddCount(string type, int count)
|
||||
{
|
||||
total += count;
|
||||
if (count > 0) counts[type] = counts.GetValueOrDefault(type) + count;
|
||||
}
|
||||
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)
|
||||
{
|
||||
var super = current.IsInRole(SystemRoles.SuperAdmin);
|
||||
var college = current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
var academic = current.IsInRole(SystemRoles.AcademicAdmin);
|
||||
var exemptions = Scoped<CourseExemption>(x => x.Status == ApprovalStatus.Submitted && (super || x.ReviewerRoleSnapshot == null || x.ReviewerRoleSnapshot == "AnyManager" || (college && x.ReviewerRoleSnapshot == SystemRoles.CollegeAdmin) || (academic && x.ReviewerRoleSnapshot == SystemRoles.AcademicAdmin)));
|
||||
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 Scoped<CourseExemption>(x => x.Status == ApprovalStatus.Submitted)
|
||||
.OrderByDescending(x => x.SubmittedAt).Take(take)
|
||||
items.AddRange(await exemptions
|
||||
.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));
|
||||
total += await Scoped<CourseExemption>(x => x.Status == ApprovalStatus.Submitted).CountAsync(ct);
|
||||
AddCount("CourseExemption", await exemptions.CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<DeferredExam>(x => x.Status == ApprovalStatus.Submitted)
|
||||
.OrderByDescending(x => x.SubmittedAt).Take(take)
|
||||
items.AddRange(await deferred
|
||||
.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));
|
||||
total += await Scoped<DeferredExam>(x => x.Status == ApprovalStatus.Submitted).CountAsync(ct);
|
||||
AddCount("DeferredExam", await deferred.CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<GradeModification>(x => x.Status == GradeModificationStatus.TeacherSubmitted || x.Status == GradeModificationStatus.CollegeApproved)
|
||||
.OrderByDescending(x => x.SubmittedAt).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))
|
||||
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)
|
||||
.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));
|
||||
total += await Scoped<GradeModification>(x => x.Status == GradeModificationStatus.TeacherSubmitted || x.Status == GradeModificationStatus.CollegeApproved).CountAsync(ct);
|
||||
AddCount("GradeModification", await Scoped<GradeModification>(x => x.Status == GradeModificationStatus.TeacherSubmitted || (canFinalReview && x.Status == GradeModificationStatus.CollegeApproved)).CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<CourseSubstitution>(x => x.Status == ApprovalStatus.Submitted)
|
||||
.OrderByDescending(x => x.SubmittedAt).Take(take)
|
||||
items.AddRange(await substitutions
|
||||
.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));
|
||||
total += await Scoped<CourseSubstitution>(x => x.Status == ApprovalStatus.Submitted).CountAsync(ct);
|
||||
AddCount("CourseSubstitution", await substitutions.CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<StudentStatusChange>(x => x.State != StudentStatusChangeState.Approved && x.State != StudentStatusChangeState.Rejected && x.State != StudentStatusChangeState.Cancelled)
|
||||
.OrderByDescending(x => x.SubmittedAt).Take(take)
|
||||
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)
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", $"{x.Student!.Name} — {SSCLabel(x.Type)}", x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name))
|
||||
.ToListAsync(ct));
|
||||
total += await Scoped<StudentStatusChange>(x => x.State != StudentStatusChangeState.Approved && x.State != StudentStatusChangeState.Rejected && x.State != StudentStatusChangeState.Cancelled).CountAsync(ct);
|
||||
AddCount("StudentStatusChange", await Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved)).CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<CourseAdjustment>(x => x.Status == CourseAdjustmentStatus.Submitted)
|
||||
.OrderByDescending(x => x.SubmittedAt).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "CourseAdjustment", CALabel(x.Type), $"《{x.TeachingTask!.Course!.Name}》", x.Reason, x.SubmittedAt!.Value, x.TeachingTask.Course.College!.Name))
|
||||
.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));
|
||||
total += await Scoped<CourseAdjustment>(x => x.Status == CourseAdjustmentStatus.Submitted).CountAsync(ct);
|
||||
AddCount("CourseAdjustment", await Scoped<CourseAdjustment>(x => x.Status == CourseAdjustmentStatus.Submitted).CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<GradeSheet>(x => x.Status == GradeSheetStatus.Submitted)
|
||||
.OrderByDescending(x => x.SubmittedAt).Take(take)
|
||||
.Select(x => new ApprovalItem(x.Id, "GradeSheet", "成绩审核", $"《{x.TeachingTask!.Course!.Name}》— {x.Records.Count}人", "教师已提交成绩", x.SubmittedAt!.Value, x.TeachingTask.Course.College!.Name))
|
||||
.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));
|
||||
total += await Scoped<GradeSheet>(x => x.Status == GradeSheetStatus.Submitted).CountAsync(ct);
|
||||
AddCount("GradeSheet", await Scoped<GradeSheet>(x => x.Status == GradeSheetStatus.Submitted).CountAsync(ct));
|
||||
|
||||
items.AddRange(await Scoped<AttendanceRecord>(x => x.AppealStatus == AttendanceAppealStatus.Pending)
|
||||
.OrderByDescending(x => x.AppealSubmittedAt).Take(take)
|
||||
.Select(x => new ApprovalItem(x.StudentId, "AttendanceAppeal", "考勤申诉", $"{x.Student!.Name} — 《{x.AttendanceSheet!.TeachingTask!.Course!.Name}》", x.AppealReason ?? "", x.AppealSubmittedAt!.Value, x.Student.AdministrativeClass!.Major!.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
|
||||
.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));
|
||||
total += await Scoped<AttendanceRecord>(x => x.AppealStatus == AttendanceAppealStatus.Pending).CountAsync(ct);
|
||||
AddCount("AttendanceAppeal", await attendance.CountAsync(ct));
|
||||
|
||||
var pageItems = items
|
||||
.OrderByDescending(x => x.Time)
|
||||
.ThenByDescending(x => x.Id)
|
||||
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)
|
||||
.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));
|
||||
|
||||
// This workflow is restricted to the applicant's college even for users
|
||||
// who also hold a system-wide role.
|
||||
if (scope.Current.IsInRole(SystemRoles.CollegeAdmin) && scope.Current.CollegeId is { } collegeId)
|
||||
{
|
||||
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)
|
||||
.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));
|
||||
}
|
||||
|
||||
var gradeBatches = Scoped<GradeSubmissionBatch>(x => x.Status == GradeSheetStatus.Submitted);
|
||||
items.AddRange(await gradeBatches.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));
|
||||
|
||||
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)
|
||||
.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));
|
||||
|
||||
var campusApplications = Scoped<CampusRegistrationApplication>(x => x.Status == CampusRegistrationApplicationStatus.PendingReview);
|
||||
items.AddRange(await campusApplications.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));
|
||||
|
||||
{
|
||||
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)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请",
|
||||
x.Student!.Name, x.Reason, x.SubmittedAt,
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dormApplications.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)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料复核",
|
||||
$"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt,
|
||||
x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.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)
|
||||
.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));
|
||||
}
|
||||
|
||||
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)
|
||||
.Select(x => new ApprovalItem(x.Id, "StudentStatusChange", "学籍异动", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("StudentStatusChange", await changes.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)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料初审", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.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)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dorm.CountAsync(ct));
|
||||
}
|
||||
}
|
||||
|
||||
if ((current.IsInRole(SystemRoles.Teacher) || current.IsInRole(SystemRoles.Counselor)) && !isManager)
|
||||
{
|
||||
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)
|
||||
.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));
|
||||
}
|
||||
|
||||
if (current.IsInRole(SystemRoles.Teacher) || isManager)
|
||||
{
|
||||
var gradeAppeals = db.GradeAppeals.AsNoTracking().Where(x => x.Status == GradeAppealStatus.Submitted && x.GradeRecord!.GradeSheet!.TeachingTask!.Status != TeachingTaskStatus.Closed);
|
||||
if (!isManager)
|
||||
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)
|
||||
.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));
|
||||
}
|
||||
|
||||
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)
|
||||
.Select(x => new ApprovalItem(x.Id, "DormitoryApplication", "住宿申请", x.Student!.Name, x.Reason, x.SubmittedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("DormitoryApplication", await dorm.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)
|
||||
.Select(x => new ApprovalItem(x.Id, "AssessmentDeclaration", "综合测评材料复核", $"{x.Student!.Name} — {x.Title}", x.Category, x.SubmittedAt ?? x.CreatedAt, x.Student.AdministrativeClass!.Major!.College!.Name)).ToListAsync(ct));
|
||||
AddCount("AssessmentDeclaration", await declarations.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)
|
||||
.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));
|
||||
}
|
||||
|
||||
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)
|
||||
.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));
|
||||
}
|
||||
|
||||
if (isManager || current.IsInRole(SystemRoles.Counselor))
|
||||
{
|
||||
var isSuper = current.IsInRole(SystemRoles.SuperAdmin);
|
||||
var isAcademic = current.IsInRole(SystemRoles.AcademicAdmin);
|
||||
var isCollege = current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
var isCounselor = current.IsInRole(SystemRoles.Counselor);
|
||||
var collegeId = current.CollegeId;
|
||||
var userId = current.UserId;
|
||||
var clearances = db.GraduationClearanceRecords.AsNoTracking().Where(x =>
|
||||
x.Status == GraduationClearanceRecordStatus.Pending &&
|
||||
x.GraduationClearanceItem!.GraduationClearanceBatch!.Status == GraduationClearanceBatchStatus.Open &&
|
||||
(isSuper ||
|
||||
(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)
|
||||
.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));
|
||||
}
|
||||
|
||||
var ordered = oldestFirst ? items.OrderBy(x => x.Time) : items.OrderByDescending(x => x.Time);
|
||||
var pageItems = ordered
|
||||
.ThenBy(x => x.Type)
|
||||
.ThenBy(x => x.Id)
|
||||
.ThenBy(x => x.SecondaryId)
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToArray();
|
||||
return Ok(new PagedResult<ApprovalItem>(pageItems, total, page, pageSize));
|
||||
return Ok(new ApprovalPendingResult(pageItems, total, page, pageSize, counts));
|
||||
}
|
||||
|
||||
[HttpGet("pending/{type}/{id:guid}")]
|
||||
@@ -103,33 +314,38 @@ public sealed class ApprovalsController(
|
||||
Guid id,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var canFinalReview = scope.Current.IsInRole(SystemRoles.SuperAdmin) || scope.Current.IsInRole(SystemRoles.AcademicAdmin);
|
||||
var super = scope.Current.IsInRole(SystemRoles.SuperAdmin);
|
||||
var college = scope.Current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
var academic = scope.Current.IsInRole(SystemRoles.AcademicAdmin);
|
||||
ApprovalItem? item = type switch
|
||||
{
|
||||
"CourseExemption" => await Scoped<CourseExemption>(x =>
|
||||
x.Id == id && x.Status == ApprovalStatus.Submitted)
|
||||
x.Id == id && x.Status == ApprovalStatus.Submitted && (super || x.ReviewerRoleSnapshot == null || x.ReviewerRoleSnapshot == "AnyManager" || (college && x.ReviewerRoleSnapshot == SystemRoles.CollegeAdmin) || (academic && x.ReviewerRoleSnapshot == SystemRoles.AcademicAdmin)))
|
||||
.Select(x => new ApprovalItem(x.Id, "CourseExemption", "免修",
|
||||
$"{x.Student!.Name} — 《{x.TeachingTask!.Course!.Name}》", x.Reason,
|
||||
x.SubmittedAt, x.TeachingTask.Course!.College!.Name))
|
||||
.FirstOrDefaultAsync(ct),
|
||||
"DeferredExam" => await Scoped<DeferredExam>(x =>
|
||||
x.Id == id && x.Status == ApprovalStatus.Submitted)
|
||||
x.Id == id && x.Status == ApprovalStatus.Submitted && (super || x.ReviewerRoleSnapshot == null || x.ReviewerRoleSnapshot == "AnyManager" || (college && x.ReviewerRoleSnapshot == SystemRoles.CollegeAdmin) || (academic && x.ReviewerRoleSnapshot == SystemRoles.AcademicAdmin)))
|
||||
.Select(x => new ApprovalItem(x.Id, "DeferredExam", "缓考",
|
||||
$"{x.Student!.Name} — 《{x.TeachingTask!.Course!.Name}》", x.Reason,
|
||||
x.SubmittedAt, x.TeachingTask.Course!.College!.Name))
|
||||
.FirstOrDefaultAsync(ct),
|
||||
"CourseSubstitution" => await Scoped<CourseSubstitution>(x =>
|
||||
x.Id == id && x.Status == ApprovalStatus.Submitted)
|
||||
x.Id == id && x.Status == ApprovalStatus.Submitted && (super || x.ReviewerRoleSnapshot == null || x.ReviewerRoleSnapshot == "AnyManager" || (college && x.ReviewerRoleSnapshot == SystemRoles.CollegeAdmin) || (academic && x.ReviewerRoleSnapshot == SystemRoles.AcademicAdmin)))
|
||||
.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))
|
||||
.FirstOrDefaultAsync(ct),
|
||||
"GradeModification" => await Scoped<GradeModification>(x =>
|
||||
x.Id == id && (x.Status == GradeModificationStatus.TeacherSubmitted ||
|
||||
x.Status == GradeModificationStatus.CollegeApproved))
|
||||
(canFinalReview && x.Status == GradeModificationStatus.CollegeApproved)))
|
||||
.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.GradeRecord.GradeSheet.TeachingTask.Course!.College!.Name,
|
||||
x.Status == GradeModificationStatus.TeacherSubmitted ? "college" : "final"))
|
||||
.FirstOrDefaultAsync(ct),
|
||||
_ => null
|
||||
};
|
||||
@@ -160,14 +376,14 @@ public sealed class ApprovalsController(
|
||||
return ConflictProblem("该课程不在您当前或已发布课表的修读课程中,请刷新课程列表后重试。");
|
||||
if (await db.CourseExemptions.AnyAsync(x => x.StudentId == studentId && x.TeachingTaskId == req.TeachingTaskId && x.Status == ApprovalStatus.Submitted, ct))
|
||||
return ConflictProblem("该课程已有免修申请在审核中。");
|
||||
var ex = new CourseExemption { StudentId = studentId.Value, TeachingTaskId = req.TeachingTaskId, Reason = req.Reason.Trim() };
|
||||
var ex = new CourseExemption { StudentId = studentId.Value, TeachingTaskId = req.TeachingTaskId, Reason = req.Reason.Trim(), ReviewerRoleSnapshot = await ReviewerRoleForNewRequest("CourseExemption", ct) };
|
||||
db.CourseExemptions.Add(ex);
|
||||
await db.SaveChangesAsync(ct);
|
||||
// Reload to get nav properties for notification
|
||||
var info = await db.CourseExemptions.Where(x => x.Id == ex.Id)
|
||||
.Select(x => new { StudentName = x.Student!.Name, CourseName = x.TeachingTask!.Course!.Name })
|
||||
.FirstAsync(ct);
|
||||
await NotifyManagers("CourseExemption", ex.Id, "免修申请", $"{info.StudentName} 申请免修《{info.CourseName}》", ct);
|
||||
await NotifyManagers("CourseExemption", ex.Id, "免修申请", $"{info.StudentName} 申请免修《{info.CourseName}》", ex.ReviewerRoleSnapshot, ct);
|
||||
return Created("", new { ex.Id });
|
||||
}
|
||||
|
||||
@@ -175,8 +391,10 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> ApproveExemption(Guid id, CancellationToken ct)
|
||||
{
|
||||
var ex = await db.CourseExemptions.Include(x => x.TeachingTask).ThenInclude(x => x!.Course).FirstOrDefaultAsync(x => x.Id == id, ct);
|
||||
var ex = await Scoped<CourseExemption>(x => x.Id == id).AsTracking().Include(x => x.TeachingTask).ThenInclude(x => x!.Course).FirstOrDefaultAsync(ct);
|
||||
if (ex is null) return NotFound();
|
||||
if (!CanReviewSnapshot(ex.ReviewerRoleSnapshot)) return Forbid();
|
||||
if (ex.Status != ApprovalStatus.Submitted) return ConflictProblem("申请已处理,不能重复审核。");
|
||||
ex.Status = ApprovalStatus.Approved; ex.ReviewedAt = DateTime.UtcNow; ex.ReviewedByUserId = scope.Current.UserId;
|
||||
// Auto-apply: mark grade record as exempt
|
||||
var sheet = await db.GradeSheets.FirstOrDefaultAsync(x => x.TeachingTaskId == ex.TeachingTaskId, ct);
|
||||
@@ -194,8 +412,10 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> RejectExemption(Guid id, [FromBody] ReviewBody body, CancellationToken ct)
|
||||
{
|
||||
var ex = await db.CourseExemptions.FindAsync([id], ct);
|
||||
var ex = await Scoped<CourseExemption>(x => x.Id == id).AsTracking().FirstOrDefaultAsync(ct);
|
||||
if (ex is null) return NotFound();
|
||||
if (!CanReviewSnapshot(ex.ReviewerRoleSnapshot)) return Forbid();
|
||||
if (ex.Status != ApprovalStatus.Submitted) return ConflictProblem("申请已处理,不能重复审核。");
|
||||
ex.Status = ApprovalStatus.Rejected; ex.ReviewedAt = DateTime.UtcNow; ex.ReviewComment = body.Comment?.Trim(); ex.ReviewedByUserId = scope.Current.UserId;
|
||||
await db.SaveChangesAsync(ct);
|
||||
await NotifyStudent(ex.StudentId, "免修申请已驳回", ex.ReviewComment ?? "审核未通过。", ct);
|
||||
@@ -224,13 +444,13 @@ public sealed class ApprovalsController(
|
||||
return ConflictProblem("该课程不在您当前或已发布课表的修读课程中,请刷新课程列表后重试。");
|
||||
if (await db.DeferredExams.AnyAsync(x => x.StudentId == sid && x.TeachingTaskId == req.TeachingTaskId && x.Status == ApprovalStatus.Submitted, ct))
|
||||
return ConflictProblem("该课程已有缓考申请在审核中。");
|
||||
var d = new DeferredExam { StudentId = sid.Value, TeachingTaskId = req.TeachingTaskId, Reason = req.Reason.Trim() };
|
||||
var d = new DeferredExam { StudentId = sid.Value, TeachingTaskId = req.TeachingTaskId, Reason = req.Reason.Trim(), ReviewerRoleSnapshot = await ReviewerRoleForNewRequest("DeferredExam", ct) };
|
||||
db.DeferredExams.Add(d);
|
||||
await db.SaveChangesAsync(ct);
|
||||
var info = await db.DeferredExams.Where(x => x.Id == d.Id)
|
||||
.Select(x => new { StudentName = x.Student!.Name, CourseName = x.TeachingTask!.Course!.Name })
|
||||
.FirstAsync(ct);
|
||||
await NotifyManagers("DeferredExam", d.Id, "缓考申请", $"{info.StudentName} 申请《{info.CourseName}》缓考", ct);
|
||||
await NotifyManagers("DeferredExam", d.Id, "缓考申请", $"{info.StudentName} 申请《{info.CourseName}》缓考", d.ReviewerRoleSnapshot, ct);
|
||||
return Created("", new { d.Id });
|
||||
}
|
||||
|
||||
@@ -238,8 +458,10 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> ApproveDeferred(Guid id, CancellationToken ct)
|
||||
{
|
||||
var d = await db.DeferredExams.Include(x => x.TeachingTask).ThenInclude(x => x!.Course).FirstOrDefaultAsync(x => x.Id == id, ct);
|
||||
var d = await Scoped<DeferredExam>(x => x.Id == id).AsTracking().Include(x => x.TeachingTask).ThenInclude(x => x!.Course).FirstOrDefaultAsync(ct);
|
||||
if (d is null) return NotFound();
|
||||
if (!CanReviewSnapshot(d.ReviewerRoleSnapshot)) return Forbid();
|
||||
if (d.Status != ApprovalStatus.Submitted) return ConflictProblem("申请已处理,不能重复审核。");
|
||||
d.Status = ApprovalStatus.Approved; d.ReviewedAt = DateTime.UtcNow; d.ReviewedByUserId = scope.Current.UserId;
|
||||
// Auto-apply: set grade record to deferred
|
||||
var sheet = await db.GradeSheets.FirstOrDefaultAsync(x => x.TeachingTaskId == d.TeachingTaskId, ct);
|
||||
@@ -257,8 +479,10 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> RejectDeferred(Guid id, [FromBody] ReviewBody body, CancellationToken ct)
|
||||
{
|
||||
var d = await db.DeferredExams.FindAsync([id], ct);
|
||||
var d = await Scoped<DeferredExam>(x => x.Id == id).AsTracking().FirstOrDefaultAsync(ct);
|
||||
if (d is null) return NotFound();
|
||||
if (!CanReviewSnapshot(d.ReviewerRoleSnapshot)) return Forbid();
|
||||
if (d.Status != ApprovalStatus.Submitted) return ConflictProblem("申请已处理,不能重复审核。");
|
||||
d.Status = ApprovalStatus.Rejected; d.ReviewedAt = DateTime.UtcNow; d.ReviewComment = body.Comment?.Trim(); d.ReviewedByUserId = scope.Current.UserId;
|
||||
await db.SaveChangesAsync(ct);
|
||||
await NotifyStudent(d.StudentId, "缓考申请已驳回", d.ReviewComment ?? "审核未通过。", ct);
|
||||
@@ -313,7 +537,10 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> CollegeApproveGradeMod(Guid id, CancellationToken ct)
|
||||
{
|
||||
var gm = await db.GradeModifications.Include(x => x.GradeRecord).ThenInclude(x => x!.GradeSheet).ThenInclude(x => x!.TeachingTask).ThenInclude(x => x!.Course).FirstOrDefaultAsync(x => x.Id == id, ct);
|
||||
var gm = await Scoped<GradeModification>(x => x.Id == id).AsTracking()
|
||||
.Include(x => x.GradeRecord).ThenInclude(x => x!.Student)
|
||||
.Include(x => x.GradeRecord).ThenInclude(x => x!.GradeSheet).ThenInclude(x => x!.TeachingTask).ThenInclude(x => x!.Course)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
if (gm is null) return NotFound();
|
||||
if (gm.Status != GradeModificationStatus.TeacherSubmitted) return ConflictProblem("状态不正确。");
|
||||
gm.Status = GradeModificationStatus.CollegeApproved; gm.CollegeReviewedAt = DateTime.UtcNow; gm.CollegeReviewedByUserId = scope.Current.UserId;
|
||||
@@ -333,14 +560,14 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = SystemRoles.SuperAdmin + "," + SystemRoles.AcademicAdmin)]
|
||||
public async Task<ActionResult> FinalApproveGradeMod(Guid id, CancellationToken ct)
|
||||
{
|
||||
var gm = await db.GradeModifications
|
||||
var gm = await Scoped<GradeModification>(x => x.Id == id).AsTracking()
|
||||
.Include(x => x.GradeRecord)
|
||||
.ThenInclude(x => x!.Student)
|
||||
.Include(x => x.GradeRecord)
|
||||
.ThenInclude(x => x!.GradeSheet)
|
||||
.ThenInclude(x => x!.TeachingTask)
|
||||
.ThenInclude(x => x!.Course)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, ct);
|
||||
.FirstOrDefaultAsync(ct);
|
||||
if (gm is null) return NotFound();
|
||||
if (gm.Status != GradeModificationStatus.CollegeApproved) return ConflictProblem("需先通过学院审核。");
|
||||
gm.Status = GradeModificationStatus.Approved; gm.FinalReviewedAt = DateTime.UtcNow; gm.FinalReviewedByUserId = scope.Current.UserId;
|
||||
@@ -392,8 +619,12 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> RejectGradeMod(Guid id, [FromBody] ReviewBody body, CancellationToken ct)
|
||||
{
|
||||
var gm = await db.GradeModifications.FindAsync([id], ct);
|
||||
var gm = await Scoped<GradeModification>(x => x.Id == id).AsTracking().FirstOrDefaultAsync(ct);
|
||||
if (gm is null) return NotFound();
|
||||
if (gm.Status != GradeModificationStatus.TeacherSubmitted &&
|
||||
(gm.Status != GradeModificationStatus.CollegeApproved ||
|
||||
!(scope.Current.IsInRole(SystemRoles.AcademicAdmin) || scope.Current.IsInRole(SystemRoles.SuperAdmin))))
|
||||
return ConflictProblem("当前角色或阶段不能驳回该申请。");
|
||||
var previousStatus = gm.Status;
|
||||
gm.Status = GradeModificationStatus.Rejected; gm.ReviewComment = body.Comment?.Trim();
|
||||
if (previousStatus == GradeModificationStatus.TeacherSubmitted) { gm.CollegeReviewedAt = DateTime.UtcNow; gm.CollegeReviewedByUserId = scope.Current.UserId; }
|
||||
@@ -586,13 +817,13 @@ public sealed class ApprovalsController(
|
||||
return ConflictProblem("该课程组合未配置适用的等价课程规则,暂不能申请替代。");
|
||||
if (await db.CourseSubstitutions.AnyAsync(x => x.StudentId == sid && x.OriginalCourseId == req.OriginalCourseId && x.Status == ApprovalStatus.Submitted, ct))
|
||||
return ConflictProblem("该课程已有替代申请在审核中。");
|
||||
var cs = new CourseSubstitution { StudentId = sid.Value, OriginalCourseId = req.OriginalCourseId, SubstituteCourseId = req.SubstituteCourseId, CourseEquivalencyRuleId = rule.Id, Reason = req.Reason.Trim() };
|
||||
var cs = new CourseSubstitution { StudentId = sid.Value, OriginalCourseId = req.OriginalCourseId, SubstituteCourseId = req.SubstituteCourseId, CourseEquivalencyRuleId = rule.Id, Reason = req.Reason.Trim(), ReviewerRoleSnapshot = await ReviewerRoleForNewRequest("CourseSubstitution", ct) };
|
||||
db.CourseSubstitutions.Add(cs);
|
||||
await db.SaveChangesAsync(ct);
|
||||
var info = await db.CourseSubstitutions.Where(x => x.Id == cs.Id)
|
||||
.Select(x => new { StudentName = x.Student!.Name, SubName = x.SubstituteCourse!.Name, OrigName = x.OriginalCourse!.Name })
|
||||
.FirstAsync(ct);
|
||||
await NotifyManagers("CourseSubstitution", cs.Id, "课程替代申请", $"{info.StudentName} 申请用《{info.SubName}》替代《{info.OrigName}》", ct);
|
||||
await NotifyManagers("CourseSubstitution", cs.Id, "课程替代申请", $"{info.StudentName} 申请用《{info.SubName}》替代《{info.OrigName}》", cs.ReviewerRoleSnapshot, ct);
|
||||
return Created("", new { cs.Id });
|
||||
}
|
||||
|
||||
@@ -600,8 +831,10 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> ApproveSubstitution(Guid id, CancellationToken ct)
|
||||
{
|
||||
var cs = await db.CourseSubstitutions.Include(x => x.Student).Include(x => x.OriginalCourse).Include(x => x.SubstituteCourse).FirstOrDefaultAsync(x => x.Id == id, ct);
|
||||
var cs = await Scoped<CourseSubstitution>(x => x.Id == id).AsTracking().Include(x => x.Student).Include(x => x.OriginalCourse).Include(x => x.SubstituteCourse).FirstOrDefaultAsync(ct);
|
||||
if (cs is null) return NotFound();
|
||||
if (!CanReviewSnapshot(cs.ReviewerRoleSnapshot)) return Forbid();
|
||||
if (cs.Status != ApprovalStatus.Submitted) return ConflictProblem("申请已处理,不能重复审核。");
|
||||
cs.Status = ApprovalStatus.Approved; cs.ReviewedAt = DateTime.UtcNow; cs.ReviewedByUserId = scope.Current.UserId;
|
||||
// Do not fabricate or edit a grade record. Formal curriculum and
|
||||
// graduation calculations resolve this approved rule from source data.
|
||||
@@ -614,8 +847,10 @@ public sealed class ApprovalsController(
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> RejectSubstitution(Guid id, [FromBody] ReviewBody body, CancellationToken ct)
|
||||
{
|
||||
var cs = await db.CourseSubstitutions.FindAsync([id], ct);
|
||||
var cs = await Scoped<CourseSubstitution>(x => x.Id == id).AsTracking().FirstOrDefaultAsync(ct);
|
||||
if (cs is null) return NotFound();
|
||||
if (!CanReviewSnapshot(cs.ReviewerRoleSnapshot)) return Forbid();
|
||||
if (cs.Status != ApprovalStatus.Submitted) return ConflictProblem("申请已处理,不能重复审核。");
|
||||
cs.Status = ApprovalStatus.Rejected; cs.ReviewedAt = DateTime.UtcNow; cs.ReviewComment = body.Comment?.Trim(); cs.ReviewedByUserId = scope.Current.UserId;
|
||||
await db.SaveChangesAsync(ct);
|
||||
await NotifyStudent(cs.StudentId, "课程替代申请已驳回", cs.ReviewComment ?? "审核未通过。", ct);
|
||||
@@ -711,6 +946,13 @@ public sealed class ApprovalsController(
|
||||
}
|
||||
|
||||
// ═══════════════ Helpers ═══════════════
|
||||
private async Task<string> ReviewerRoleForNewRequest(string type, CancellationToken ct) =>
|
||||
await db.ApprovalRouteSettings.AsNoTracking().Where(x => x.Type == type)
|
||||
.Select(x => x.ReviewerRole).FirstOrDefaultAsync(ct) ?? "AnyManager";
|
||||
|
||||
private bool CanReviewSnapshot(string? role) => role is null or "AnyManager" ||
|
||||
scope.Current.IsInRole(SystemRoles.SuperAdmin) || scope.Current.IsInRole(role);
|
||||
|
||||
private IQueryable<T> Scoped<T>(System.Linq.Expressions.Expression<Func<T, bool>> predicate) where T : class
|
||||
{
|
||||
var q = db.Set<T>().AsNoTracking().Where(predicate);
|
||||
@@ -724,7 +966,14 @@ public sealed class ApprovalsController(
|
||||
if (typeof(T) == typeof(CourseAdjustment)) return (IQueryable<T>)((IQueryable<CourseAdjustment>)(object)q).Where(x => x.TeachingTask!.Course!.CollegeId == cid);
|
||||
if (typeof(T) == typeof(GradeSheet)) return (IQueryable<T>)((IQueryable<GradeSheet>)(object)q).Where(x => x.TeachingTask!.Course!.CollegeId == cid);
|
||||
if (typeof(T) == typeof(AttendanceRecord)) return (IQueryable<T>)((IQueryable<AttendanceRecord>)(object)q).Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == cid);
|
||||
return q;
|
||||
if (typeof(T) == typeof(GradeSubmissionBatch)) return (IQueryable<T>)((IQueryable<GradeSubmissionBatch>)(object)q).Where(x => x.GradeSheet!.TeachingTask!.Course!.CollegeId == cid);
|
||||
if (typeof(T) == typeof(ExperimentGradeSheet)) return (IQueryable<T>)((IQueryable<ExperimentGradeSheet>)(object)q).Where(x => x.ExperimentProject!.TeachingTask!.Course!.CollegeId == cid);
|
||||
if (typeof(T) == typeof(CampusRegistrationApplication)) return (IQueryable<T>)((IQueryable<CampusRegistrationApplication>)(object)q).Where(x => x.Project!.CollegeId == null || x.Project.CollegeId == cid);
|
||||
if (typeof(T) == typeof(DormitoryApplication)) return (IQueryable<T>)((IQueryable<DormitoryApplication>)(object)q).Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == cid);
|
||||
if (typeof(T) == typeof(ComprehensiveAssessmentDeclaration)) return (IQueryable<T>)((IQueryable<ComprehensiveAssessmentDeclaration>)(object)q).Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == cid);
|
||||
if (typeof(T) == typeof(ComprehensiveAssessmentAppeal)) return (IQueryable<T>)((IQueryable<ComprehensiveAssessmentAppeal>)(object)q).Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == cid);
|
||||
if (typeof(T) == typeof(TeachingImprovementPlan)) return (IQueryable<T>)((IQueryable<TeachingImprovementPlan>)(object)q).Where(x => x.TeachingTask.Course!.CollegeId == cid);
|
||||
throw new InvalidOperationException($"No approval scope is defined for {typeof(T).Name}.");
|
||||
}
|
||||
|
||||
private async Task<Guid?> GetStudentIdAsync(CancellationToken ct) => await db.Students.Where(s => s.UserId == scope.Current.UserId).Select(s => (Guid?)s.Id).FirstOrDefaultAsync(ct);
|
||||
@@ -751,7 +1000,14 @@ public sealed class ApprovalsController(
|
||||
ct);
|
||||
private ActionResult StudentNotFound() => Conflict(new ProblemDetails { Title = "未关联学生档案", Detail = "当前账号未关联有效学生档案。", Status = 409 });
|
||||
|
||||
private async Task NotifyManagers(string type, Guid id, string title, string content, CancellationToken ct) { var linkUrl = $"/approvals?tab=pending&type={type}&id={id}"; await NotificationService.SendToRoleAsync(db, SystemRoles.CollegeAdmin, title, content, linkUrl: linkUrl, cancellationToken: ct, category: NotificationCategory.Approval); await NotificationService.SendToRoleAsync(db, SystemRoles.AcademicAdmin, title, content, linkUrl: linkUrl, cancellationToken: ct, category: NotificationCategory.Approval); }
|
||||
private async Task NotifyManagers(string type, Guid id, string title, string content, string? reviewerRole, CancellationToken ct)
|
||||
{
|
||||
var linkUrl = $"/approvals?tab=pending&type={type}&id={id}";
|
||||
if (reviewerRole is null or "AnyManager" or SystemRoles.CollegeAdmin)
|
||||
await NotificationService.SendToRoleAsync(db, SystemRoles.CollegeAdmin, title, content, linkUrl: linkUrl, cancellationToken: ct, category: NotificationCategory.Approval);
|
||||
if (reviewerRole is null or "AnyManager" or SystemRoles.AcademicAdmin)
|
||||
await NotificationService.SendToRoleAsync(db, SystemRoles.AcademicAdmin, title, content, linkUrl: linkUrl, cancellationToken: ct, category: NotificationCategory.Approval);
|
||||
}
|
||||
private async Task NotifyStudent(Guid sid, string title, string content, CancellationToken ct) { var uid = await db.Students.Where(s => s.Id == sid).Select(s => s.UserId).FirstOrDefaultAsync(ct); if (uid.HasValue) await NotificationService.SendAsync(db, uid.Value, title, content, "/approvals", ct, NotificationCategory.Approval); }
|
||||
private async Task NotifyCollege(GradeModification gm, CancellationToken ct) { await NotificationService.SendToRoleAsync(db, SystemRoles.CollegeAdmin, "成绩修改待审核", $"{gm.GradeRecord!.Student!.Name} — 《{gm.GradeRecord.GradeSheet!.TeachingTask!.Course!.Name}》{gm.CurrentScore}→{gm.RequestedScore}", cancellationToken: ct, category: NotificationCategory.Grade); }
|
||||
private async Task NotifyRole(string role, string title, string content, CancellationToken ct) { await NotificationService.SendToRoleAsync(db, role, title, content, cancellationToken: ct, category: NotificationCategory.Approval); }
|
||||
@@ -761,7 +1017,20 @@ public sealed class ApprovalsController(
|
||||
private ActionResult ConflictProblem(string d) => Conflict(new ProblemDetails { Title = "无法完成", Detail = d, Status = 409 });
|
||||
}
|
||||
|
||||
public sealed record ApprovalItem(Guid Id, string Type, string Label, string Title, string Desc, DateTime Time, string College);
|
||||
public sealed record ApprovalItem(Guid Id, string Type, string Label, string Title, string Desc, DateTime Time, string College, string? Stage = null, Guid? SecondaryId = null);
|
||||
public sealed record ApprovalPendingResult(IReadOnlyCollection<ApprovalItem> Items, int Total, int Page, int PageSize, IReadOnlyDictionary<string, int> Counts);
|
||||
public sealed record ApprovalRouteSettingRequest([Required] string ReviewerRole);
|
||||
|
||||
internal static class ApprovalOrderingExtensions
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
public sealed record StudentApprovalCourseOption(
|
||||
Guid TeachingTaskId,
|
||||
Guid CourseId,
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Jiaowu.Api.Domain.Academic;
|
||||
// ═══════════════ 免修 ═══════════════
|
||||
public sealed class CourseExemption : EntityBase
|
||||
{
|
||||
public string? ReviewerRoleSnapshot { get; set; }
|
||||
public Guid StudentId { get; set; }
|
||||
public Student? Student { get; set; }
|
||||
public Guid TeachingTaskId { get; set; }
|
||||
@@ -20,6 +21,7 @@ public sealed class CourseExemption : EntityBase
|
||||
// ═══════════════ 缓考 ═══════════════
|
||||
public sealed class DeferredExam : EntityBase
|
||||
{
|
||||
public string? ReviewerRoleSnapshot { get; set; }
|
||||
public Guid StudentId { get; set; }
|
||||
public Student? Student { get; set; }
|
||||
public Guid TeachingTaskId { get; set; }
|
||||
@@ -74,6 +76,7 @@ public sealed class GradeAppeal : EntityBase
|
||||
// ═══════════════ 课程替代 ═══════════════
|
||||
public sealed class CourseSubstitution : EntityBase
|
||||
{
|
||||
public string? ReviewerRoleSnapshot { get; set; }
|
||||
public Guid StudentId { get; set; }
|
||||
public Student? Student { get; set; }
|
||||
public Guid OriginalCourseId { get; set; }
|
||||
@@ -93,6 +96,13 @@ public sealed class CourseSubstitution : EntityBase
|
||||
public Guid? ReviewedByUserId { get; set; }
|
||||
}
|
||||
|
||||
// Applies only to new requests. Existing requests retain their role snapshot.
|
||||
public sealed class ApprovalRouteSetting : EntityBase
|
||||
{
|
||||
public required string Type { get; set; }
|
||||
public required string ReviewerRole { get; set; }
|
||||
}
|
||||
|
||||
// A formal, reusable replacement relationship. Applications may only use an
|
||||
// enabled rule; approval remains a student-specific decision.
|
||||
public sealed class CourseEquivalencyRule : EntityBase
|
||||
|
||||
@@ -14,6 +14,7 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
public DbSet<UserNavigationPreference> UserNavigationPreferences =>
|
||||
Set<UserNavigationPreference>();
|
||||
public DbSet<Campus> Campuses => Set<Campus>();
|
||||
public DbSet<ApprovalRouteSetting> ApprovalRouteSettings => Set<ApprovalRouteSetting>();
|
||||
public DbSet<College> Colleges => Set<College>();
|
||||
public DbSet<Major> Majors => Set<Major>();
|
||||
public DbSet<AdministrativeClass> AdministrativeClasses => Set<AdministrativeClass>();
|
||||
@@ -1599,6 +1600,7 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
|
||||
builder.Entity<CourseExemption>(entity =>
|
||||
{
|
||||
entity.Property(x => x.ReviewerRoleSnapshot).HasMaxLength(32);
|
||||
entity.Property(x => x.Reason).HasMaxLength(500);
|
||||
entity.Property(x => x.ReviewComment).HasMaxLength(500);
|
||||
entity.HasIndex(x => new { x.Status, x.CreatedAt });
|
||||
@@ -1610,6 +1612,7 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
});
|
||||
builder.Entity<DeferredExam>(entity =>
|
||||
{
|
||||
entity.Property(x => x.ReviewerRoleSnapshot).HasMaxLength(32);
|
||||
entity.Property(x => x.Reason).HasMaxLength(500);
|
||||
entity.Property(x => x.ReviewComment).HasMaxLength(500);
|
||||
entity.HasIndex(x => new { x.Status, x.CreatedAt });
|
||||
@@ -2154,6 +2157,7 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
|
||||
builder.Entity<CourseSubstitution>(entity =>
|
||||
{
|
||||
entity.Property(x => x.ReviewerRoleSnapshot).HasMaxLength(32);
|
||||
entity.Property(x => x.Reason).HasMaxLength(500);
|
||||
entity.Property(x => x.ReviewComment).HasMaxLength(500);
|
||||
entity.HasIndex(x => new { x.Status, x.CreatedAt });
|
||||
@@ -2168,6 +2172,13 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
.HasForeignKey(x => x.CourseEquivalencyRuleId).OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
builder.Entity<ApprovalRouteSetting>(entity =>
|
||||
{
|
||||
entity.Property(x => x.Type).HasMaxLength(40).IsRequired();
|
||||
entity.Property(x => x.ReviewerRole).HasMaxLength(32).IsRequired();
|
||||
entity.HasIndex(x => x.Type).IsUnique();
|
||||
});
|
||||
|
||||
builder.Entity<ClassroomEquipment>(entity =>
|
||||
{
|
||||
entity.Property(x => x.Name).HasMaxLength(80);
|
||||
|
||||
Loaded 3 of 14 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user