Compare commits
8
Commits
31ecf090b4
...
8b9f156dd4
No files matched your search
@@ -858,6 +858,15 @@ public sealed class ApprovalsController(
|
||||
.Select(x => new ApprovalReviewedItem { Id = x.Id, Type = "GraduationClearance", Title = x.Student!.Name + " — " + x.GraduationClearanceItem!.Name, Time = x.CompletedAt!.Value, Comment = x.Notes }));
|
||||
await Add(db.StudentStatusChangeEvents.AsNoTracking().Where(x => x.ActorUserId == userId && (x.ToState == StudentStatusChangeState.CounselorApproved || x.ToState == StudentStatusChangeState.CollegeApproved || x.ToState == StudentStatusChangeState.Approved || x.ToState == StudentStatusChangeState.Rejected))
|
||||
.Select(x => new ApprovalReviewedItem { Id = x.StudentStatusChangeId, Type = "StudentStatusChange", Title = x.StudentStatusChange!.Student!.Name, Time = x.OccurredAt, Comment = x.Comment }));
|
||||
// An approval by the receiving college does not change the status and
|
||||
// is stored on the request. Rejections already have an event above.
|
||||
await Add(db.StudentStatusChanges.AsNoTracking().Where(x => x.ReceivingCollegeReviewerId == userId && x.ReceivingCollegeReviewedAt != null &&
|
||||
!db.StudentStatusChangeEvents.Any(e => e.StudentStatusChangeId == x.Id && e.ActorUserId == userId && e.OccurredAt == x.ReceivingCollegeReviewedAt && e.ToState == StudentStatusChangeState.Rejected))
|
||||
.Select(x => new ApprovalReviewedItem { Id = x.Id, Type = "StudentStatusChange", Title = x.Student!.Name, Time = x.ReceivingCollegeReviewedAt!.Value, Comment = x.ReceivingCollegeReviewComment, Approved = true }));
|
||||
await Add(db.StudentDisciplineEvents.AsNoTracking().Where(x => x.ActorUserId == userId &&
|
||||
((x.FromState == StudentDisciplineState.Submitted && (x.ToState == StudentDisciplineState.CollegeApproved || x.ToState == StudentDisciplineState.Rejected)) ||
|
||||
(x.FromState == StudentDisciplineState.CollegeApproved && (x.ToState == StudentDisciplineState.Effective || x.ToState == StudentDisciplineState.Rejected))))
|
||||
.Select(x => new ApprovalReviewedItem { Id = x.StudentDisciplineId, Type = "StudentDiscipline", Title = x.StudentDiscipline!.Student!.Name + " — " + x.StudentDiscipline.DisciplineType, Time = x.OccurredAt, Comment = x.Comment, Approved = x.ToState != StudentDisciplineState.Rejected }));
|
||||
|
||||
return Ok(new ApprovalReviewedResult(items.OrderByDescending(x => x.Time).ThenBy(x => x.Type).ThenBy(x => x.Id).Skip((page - 1) * pageSize).Take(pageSize).ToList(), total));
|
||||
}
|
||||
@@ -891,6 +900,40 @@ public sealed class ApprovalsController(
|
||||
var current = scope.Current;
|
||||
var isManager = current.IsInRole(SystemRoles.SuperAdmin) || current.IsInRole(SystemRoles.AcademicAdmin) || current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
if (isManager)
|
||||
{
|
||||
var leaves = db.StudentLeaves.AsNoTracking().Where(x => x.Status == StudentLeaveStatus.Submitted);
|
||||
if (current.Scope != DataScope.All)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
{
|
||||
var school = current.IsInRole(SystemRoles.StudentAffairsAdmin) || current.IsInRole(SystemRoles.AcademicAdmin) || current.IsInRole(SystemRoles.SuperAdmin);
|
||||
var college = current.IsInRole(SystemRoles.CollegeAdmin) || current.IsInRole(SystemRoles.SuperAdmin);
|
||||
var disciplines = db.StudentDisciplines.AsNoTracking().Where(x => (college && x.State == StudentDisciplineState.Submitted) || (school && x.State == StudentDisciplineState.CollegeApproved));
|
||||
if (!current.IsInRole(SystemRoles.StudentAffairsAdmin))
|
||||
{
|
||||
if (current.IsInRole(SystemRoles.SuperAdmin) || current.IsInRole(SystemRoles.AcademicAdmin))
|
||||
{
|
||||
if (current.Scope != DataScope.All) disciplines = disciplines.Where(x => false);
|
||||
}
|
||||
else if (current.Scope == DataScope.College && current.IsInRole(SystemRoles.CollegeAdmin))
|
||||
{
|
||||
var collegeId = current.RestrictedCollegeId;
|
||||
disciplines = disciplines.Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == collegeId);
|
||||
}
|
||||
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));
|
||||
}
|
||||
if (isManager)
|
||||
{
|
||||
var super = current.IsInRole(SystemRoles.SuperAdmin);
|
||||
var college = current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
@@ -925,11 +968,25 @@ public sealed class ApprovalsController(
|
||||
AddCount("CourseSubstitution", await substitutions.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
var canCollegeReview = scope.Current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
items.AddRange(await Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved))
|
||||
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 Scoped<StudentStatusChange>(x => (canCollegeReview && x.State == StudentStatusChangeState.CounselorApproved) || (canFinalReview && x.State == StudentStatusChangeState.CollegeApproved)).WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
AddCount("StudentStatusChange", await statusChanges.WhereApprovalBefore(x => x.SubmittedAt, cutoff).CountAsync(ct));
|
||||
|
||||
if (canCollegeReview)
|
||||
{
|
||||
var receiving = db.StudentStatusChanges.AsNoTracking().Where(x => x.Type == StudentStatusChangeType.MajorTransfer && x.State == StudentStatusChangeState.CollegeApproved && x.ReceivingCollegeReviewedAt == null && x.OriginalClass != null && x.TargetClass != null && x.OriginalClass.Major!.CollegeId != x.TargetClass.Major!.CollegeId);
|
||||
if (current.Scope != DataScope.All)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -1058,8 +1115,10 @@ public sealed class ApprovalsController(
|
||||
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)
|
||||
else if (current.Scope == DataScope.College && current.RestrictedCollegeId is { } gradeCollegeId)
|
||||
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));
|
||||
|
||||
@@ -122,9 +122,10 @@ public sealed class CourseSelectionsController(
|
||||
var enrollments = await ProjectEnrollments(OrderEnrollments(source.Where(x =>
|
||||
pageStudentIds.Contains(x.StudentId))))
|
||||
.ToListAsync(cancellationToken);
|
||||
var enrollmentsByStudent = enrollments.ToLookup(x => x.StudentId);
|
||||
var summaries = pageStudents.Select(student =>
|
||||
{
|
||||
var courses = enrollments.Where(x => x.StudentId == student.StudentId).ToList();
|
||||
var courses = enrollmentsByStudent[student.StudentId].ToList();
|
||||
return new StudentEnrollmentSummary(
|
||||
student.StudentId, student.StudentNumber, student.StudentName,
|
||||
student.MajorName, student.ClassName, student.Grade, courses,
|
||||
@@ -1064,12 +1065,12 @@ public sealed class CourseSelectionsController(
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var enrolled = 0;
|
||||
var enrollmentsByStudent = existingEnrollments.ToLookup(x => x.StudentId);
|
||||
foreach (var student in students)
|
||||
{
|
||||
var isRetake = await IsEligibleForRetakeAsync(
|
||||
student.Id, task.CourseId, round.AcademicTermId, cancellationToken);
|
||||
var enrollment = existingEnrollments
|
||||
.FirstOrDefault(x => x.StudentId == student.Id);
|
||||
var enrollment = enrollmentsByStudent[student.Id].FirstOrDefault();
|
||||
if (enrollment is null)
|
||||
{
|
||||
enrollment = new CourseEnrollment
|
||||
@@ -1998,18 +1999,24 @@ public sealed class CourseSelectionsController(
|
||||
else entries.Add(username, (personId, role, new HashSet<string>(StringComparer.Ordinal) { group }));
|
||||
return true;
|
||||
}
|
||||
var taskIds = tasks.Select(task => task.Id).ToArray();
|
||||
var rosterByTask = (await TeachingTaskRosterQuery.LoadForTasksAsync(db, taskIds, cancellationToken))
|
||||
.ToLookup(student => student.TeachingTaskId);
|
||||
var teachersByTask = includeTeachers
|
||||
? (await db.TeachingTaskTeachers.AsNoTracking()
|
||||
.WhereIn(taskIds, teacher => teacher.TeachingTaskId)
|
||||
.Select(teacher => new { teacher.TeachingTaskId, teacher.Teacher!.Id, teacher.Teacher.TeacherNumber })
|
||||
.ToListAsync(cancellationToken)).ToLookup(teacher => teacher.TeachingTaskId)
|
||||
: null;
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
var group = "教学班 " + task.TaskNumber;
|
||||
var students = await LoadTeachingTaskRosterAsync(task.Id, cancellationToken);
|
||||
foreach (var student in students)
|
||||
foreach (var student in rosterByTask[task.Id])
|
||||
if (!AddPerson(student.StudentNumber, student.StudentId, "student", group))
|
||||
return BadRequest(new ProblemDetails { Detail = "人员编号为空或不同人员的小写账号重复,无法安全导出。", Status = 400 });
|
||||
if (includeTeachers)
|
||||
{
|
||||
var teachers = await db.TeachingTasks.AsNoTracking().Where(x => x.Id == task.Id)
|
||||
.SelectMany(x => x.Teachers.Select(t => new { t.Teacher!.Id, t.Teacher.TeacherNumber })).ToListAsync(cancellationToken);
|
||||
foreach (var teacher in teachers)
|
||||
foreach (var teacher in teachersByTask![task.Id])
|
||||
if (!AddPerson(teacher.TeacherNumber, teacher.Id, teacherRole!, group))
|
||||
return BadRequest(new ProblemDetails { Detail = "人员编号为空或不同人员的小写账号重复,无法安全导出。", Status = 400 });
|
||||
}
|
||||
|
||||
@@ -272,6 +272,7 @@ public sealed class ExperimentGradesController(
|
||||
headers.Add("实验合成总分(仅已发布项目)");
|
||||
if (columnsOnly) return Ok(headers);
|
||||
|
||||
var recordsBySheet = sheets.Select(sheet => sheet.Records.ToLookup(record => record.StudentId)).ToArray();
|
||||
var rows = students.Select(student =>
|
||||
{
|
||||
var values = new List<object?>
|
||||
@@ -285,8 +286,8 @@ public sealed class ExperimentGradesController(
|
||||
student.Name,
|
||||
student.AdministrativeClass!.Name
|
||||
};
|
||||
values.AddRange(sheets.Select(sheet => (object?)sheet.Records
|
||||
.FirstOrDefault(record => record.StudentId == student.Id)
|
||||
values.AddRange(recordsBySheet.Select(records => (object?)records[student.Id]
|
||||
.FirstOrDefault()
|
||||
?.TotalScore));
|
||||
values.Add(aggregate.Scores.GetValueOrDefault(student.Id));
|
||||
return (IReadOnlyList<object?>)values;
|
||||
|
||||
Loaded 3 of 16 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user