Support class and within-college major transfers
This commit is contained in:
1 parent
ec4d581af6
commit
31c25ed19e
7 files changed
+96
-32
No files matched your search
@@ -1363,7 +1363,7 @@ public sealed class ApprovalsController(
|
||||
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); }
|
||||
|
||||
private static string SSCLabel(StudentStatusChangeType t) => t switch { StudentStatusChangeType.Suspension => "休学", StudentStatusChangeType.Resumption => "复学", StudentStatusChangeType.Withdrawal => "退学", StudentStatusChangeType.Enlistment => "入伍保留学籍", StudentStatusChangeType.Demotion => "降级", _ => "异动" };
|
||||
private static string SSCLabel(StudentStatusChangeType t) => t switch { StudentStatusChangeType.Suspension => "休学", StudentStatusChangeType.Resumption => "复学", StudentStatusChangeType.Withdrawal => "退学", StudentStatusChangeType.Enlistment => "入伍保留学籍", StudentStatusChangeType.Demotion => "降级", StudentStatusChangeType.ClassTransfer => "转班", StudentStatusChangeType.MajorTransfer => "院内转专业", _ => "异动" };
|
||||
private static string CALabel(CourseAdjustmentType t) => t switch { CourseAdjustmentType.Reschedule => "调课", CourseAdjustmentType.Cancel => "停课", CourseAdjustmentType.Makeup => "补课", CourseAdjustmentType.Substitute => "代课", _ => "调停课" };
|
||||
private ActionResult ConflictProblem(string d) => Conflict(new ProblemDetails { Title = "无法完成", Detail = d, Status = 409 });
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public sealed class StudentStatusChangesController(
|
||||
{
|
||||
var userId = currentUserDataScope.Current.UserId;
|
||||
var student = await db.Students.AsNoTracking()
|
||||
.Include(x => x.AdministrativeClass)
|
||||
.Include(x => x.AdministrativeClass).ThenInclude(x => x!.Major)
|
||||
.FirstOrDefaultAsync(x => x.UserId == userId, token);
|
||||
if (student is null) return ConflictProblem("当前账号未关联学生档案。");
|
||||
|
||||
@@ -89,6 +89,8 @@ public sealed class StudentStatusChangesController(
|
||||
StudentStatusChangeType.Suspension,
|
||||
StudentStatusChangeType.Enlistment,
|
||||
StudentStatusChangeType.Demotion,
|
||||
StudentStatusChangeType.ClassTransfer,
|
||||
StudentStatusChangeType.MajorTransfer,
|
||||
StudentStatusChangeType.Withdrawal
|
||||
},
|
||||
StudentStatus.Suspended or StudentStatus.Retained => new[]
|
||||
@@ -107,7 +109,8 @@ public sealed class StudentStatusChangesController(
|
||||
x.StudentId == student.Id && x.Type == StudentStatusChangeType.Enlistment && x.State == StudentStatusChangeState.Approved, token);
|
||||
return Ok(new { student.Status, Types = types, HasPending = hasPending,
|
||||
CurrentClassId = student.AdministrativeClassId, MajorId = student.AdministrativeClass!.MajorId,
|
||||
CurrentGrade = student.AdministrativeClass.Grade, RequiresDischargeDate = hasEnlistment });
|
||||
CurrentGrade = student.AdministrativeClass.Grade, CollegeId = student.AdministrativeClass.Major!.CollegeId,
|
||||
RequiresDischargeDate = hasEnlistment });
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}/course-impact")]
|
||||
@@ -116,7 +119,7 @@ public sealed class StudentStatusChangesController(
|
||||
var change = await ScopedChanges().Include(x => x.Student)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, token);
|
||||
if (change is null) return NotFound();
|
||||
if (change.Type is not (StudentStatusChangeType.Suspension or StudentStatusChangeType.Withdrawal or StudentStatusChangeType.Enlistment or StudentStatusChangeType.Demotion))
|
||||
if (change.Type is not (StudentStatusChangeType.Suspension or StudentStatusChangeType.Withdrawal or StudentStatusChangeType.Enlistment or StudentStatusChangeType.Demotion or StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer))
|
||||
return Ok(new { Items = Array.Empty<CourseImpactItem>() });
|
||||
if (change.AffectedTermId is null)
|
||||
return ConflictProblem("该申请缺少受影响学期,请重新提交申请。");
|
||||
@@ -143,6 +146,8 @@ public sealed class StudentStatusChangesController(
|
||||
StudentStatus.Retained,
|
||||
StudentStatusChangeType.Demotion when student.Status == StudentStatus.Active =>
|
||||
StudentStatus.Active,
|
||||
StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer when student.Status == StudentStatus.Active =>
|
||||
StudentStatus.Active,
|
||||
StudentStatusChangeType.Resumption when student.Status is StudentStatus.Suspended or StudentStatus.Retained =>
|
||||
StudentStatus.Active,
|
||||
StudentStatusChangeType.Withdrawal when student.Status is StudentStatus.Active or StudentStatus.Suspended or StudentStatus.Retained =>
|
||||
@@ -163,7 +168,7 @@ public sealed class StudentStatusChangesController(
|
||||
request.DischargeDate < lastEnlistment.ServiceStartDate))
|
||||
return ValidationProblem("退役复学须填写不晚于今天且不早于入伍日期的退役日期。");
|
||||
}
|
||||
if (request.Type is StudentStatusChangeType.Suspension or StudentStatusChangeType.Withdrawal or StudentStatusChangeType.Enlistment or StudentStatusChangeType.Resumption or StudentStatusChangeType.Demotion)
|
||||
if (request.Type is StudentStatusChangeType.Suspension or StudentStatusChangeType.Withdrawal or StudentStatusChangeType.Enlistment or StudentStatusChangeType.Resumption or StudentStatusChangeType.Demotion or StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer)
|
||||
{
|
||||
var term = await db.AcademicTerms.AsNoTracking().FirstOrDefaultAsync(
|
||||
x => x.Id == request.AffectedTermId, token);
|
||||
@@ -172,14 +177,16 @@ public sealed class StudentStatusChangesController(
|
||||
if (term.StartDate > DateOnly.FromDateTime(DateTime.UtcNow))
|
||||
return ValidationProblem("异动当前在批准后立即生效,不能选择尚未开始的学期。");
|
||||
}
|
||||
if (request.Type is StudentStatusChangeType.Resumption or StudentStatusChangeType.Demotion)
|
||||
if (request.Type is StudentStatusChangeType.Resumption or StudentStatusChangeType.Demotion or StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer)
|
||||
{
|
||||
var originalClass = await db.AdministrativeClasses.AsNoTracking()
|
||||
.Include(x => x.Major)
|
||||
.SingleAsync(x => x.Id == student.AdministrativeClassId, token);
|
||||
var targetClass = await db.AdministrativeClasses.AsNoTracking()
|
||||
.Include(x => x.Major)
|
||||
.FirstOrDefaultAsync(x => x.Id == request.TargetClassId && x.IsEnabled, token);
|
||||
if (targetClass is null || targetClass.MajorId != originalClass.MajorId)
|
||||
return ValidationProblem("须选择本专业的有效目标班级;跨专业调整需另行审批。");
|
||||
if (targetClass is null || !ValidTargetClass(request.Type, originalClass, targetClass))
|
||||
return ValidationProblem("目标班级不符合异动类型要求;跨学院转专业须另行办理。");
|
||||
if (request.Type == StudentStatusChangeType.Demotion && targetClass.Grade <= originalClass.Grade)
|
||||
return ValidationProblem("降级目标班级须属于本专业的较低年级。");
|
||||
}
|
||||
@@ -194,7 +201,7 @@ public sealed class StudentStatusChangesController(
|
||||
OriginalStatus = student.Status, TargetStatus = target.Value,
|
||||
Reason = request.Reason.Trim(), AffectedTermId = request.AffectedTermId,
|
||||
OriginalClassId = student.AdministrativeClassId,
|
||||
TargetClassId = request.Type is StudentStatusChangeType.Resumption or StudentStatusChangeType.Demotion ? request.TargetClassId : null,
|
||||
TargetClassId = request.Type is StudentStatusChangeType.Resumption or StudentStatusChangeType.Demotion or StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer ? request.TargetClassId : null,
|
||||
ServiceStartDate = request.Type == StudentStatusChangeType.Enlistment ? request.ServiceStartDate : null,
|
||||
DischargeDate = request.Type == StudentStatusChangeType.Resumption ? request.DischargeDate : null
|
||||
};
|
||||
@@ -294,14 +301,14 @@ public sealed class StudentStatusChangesController(
|
||||
}
|
||||
change.Student.AdministrativeClassId = targetClass.Id;
|
||||
}
|
||||
if (change.Type == StudentStatusChangeType.Demotion)
|
||||
if (change.Type is StudentStatusChangeType.Demotion or StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer)
|
||||
{
|
||||
var originalClass = await db.AdministrativeClasses.AsNoTracking().SingleAsync(x => x.Id == change.Student.AdministrativeClassId, token);
|
||||
var targetClass = await db.AdministrativeClasses.AsNoTracking().FirstOrDefaultAsync(x => x.Id == change.TargetClassId &&
|
||||
x.IsEnabled && x.MajorId == originalClass.MajorId && x.Grade > originalClass.Grade, token);
|
||||
if (targetClass is null) return ConflictProblem("降级目标班级已不可用或不符合年级要求。");
|
||||
var originalClass = await db.AdministrativeClasses.AsNoTracking().Include(x => x.Major).SingleAsync(x => x.Id == change.Student.AdministrativeClassId, token);
|
||||
var targetClass = await db.AdministrativeClasses.AsNoTracking().Include(x => x.Major).FirstOrDefaultAsync(x => x.Id == change.TargetClassId && x.IsEnabled, token);
|
||||
if (targetClass is null || !ValidTargetClass(change.Type, originalClass, targetClass))
|
||||
return ConflictProblem("目标班级已不可用或不符合异动要求。");
|
||||
}
|
||||
if (change.Type is StudentStatusChangeType.Suspension or StudentStatusChangeType.Withdrawal or StudentStatusChangeType.Enlistment or StudentStatusChangeType.Demotion)
|
||||
if (change.Type is StudentStatusChangeType.Suspension or StudentStatusChangeType.Withdrawal or StudentStatusChangeType.Enlistment or StudentStatusChangeType.Demotion or StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer)
|
||||
{
|
||||
if (change.AffectedTermId is null)
|
||||
return ConflictProblem("该申请缺少受影响学期,请驳回后重新提交。");
|
||||
@@ -345,7 +352,7 @@ public sealed class StudentStatusChangesController(
|
||||
enrollment.WithdrawnAt = reviewedAt;
|
||||
}
|
||||
}
|
||||
if (change.Type == StudentStatusChangeType.Demotion)
|
||||
if (change.Type is StudentStatusChangeType.Demotion or StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer)
|
||||
{
|
||||
var start = (await db.AcademicTerms.AsNoTracking().SingleAsync(x => x.Id == change.AffectedTermId, token)).StartDate;
|
||||
var oldTargetTasks = await db.TeachingTasks.AsNoTracking().Where(x => x.AcademicTerm!.StartDate < start &&
|
||||
@@ -393,11 +400,11 @@ public sealed class StudentStatusChangesController(
|
||||
var term = await db.AcademicTerms.AsNoTracking().SingleAsync(x => x.Id == change.AffectedTermId, token);
|
||||
var studentId = change.StudentId;
|
||||
var classId = change.Student!.AdministrativeClassId;
|
||||
var isDemotion = change.Type == StudentStatusChangeType.Demotion;
|
||||
var isClassMove = change.Type is StudentStatusChangeType.Demotion or StudentStatusChangeType.ClassTransfer or StudentStatusChangeType.MajorTransfer;
|
||||
var targetClassId = change.TargetClassId;
|
||||
var tasks = await db.TeachingTasks.AsNoTracking()
|
||||
.Where(x => x.AcademicTerm!.StartDate >= term.StartDate &&
|
||||
(isDemotion
|
||||
(isClassMove
|
||||
? x.Classes.Any(c => c.AdministrativeClassId == classId) &&
|
||||
!x.Classes.Any(c => c.AdministrativeClassId == targetClassId)
|
||||
: x.Classes.Any(c => c.AdministrativeClassId == classId) ||
|
||||
@@ -492,6 +499,15 @@ public sealed class StudentStatusChangesController(
|
||||
_ => false
|
||||
};
|
||||
|
||||
private static bool ValidTargetClass(StudentStatusChangeType type, AdministrativeClass original, AdministrativeClass target) => type switch
|
||||
{
|
||||
StudentStatusChangeType.Resumption => target.MajorId == original.MajorId,
|
||||
StudentStatusChangeType.Demotion => target.MajorId == original.MajorId && target.Grade > original.Grade,
|
||||
StudentStatusChangeType.ClassTransfer => target.Id != original.Id && target.MajorId == original.MajorId && target.Grade == original.Grade,
|
||||
StudentStatusChangeType.MajorTransfer => target.MajorId != original.MajorId && target.Major!.CollegeId == original.Major!.CollegeId,
|
||||
_ => false
|
||||
};
|
||||
|
||||
private ActionResult ConflictProblem(string detail) => Conflict(new ProblemDetails
|
||||
{
|
||||
Title = "无法完成学籍异动操作", Detail = detail,
|
||||
|
||||
@@ -53,7 +53,9 @@ public enum StudentStatusChangeType
|
||||
Resumption = 2,
|
||||
Withdrawal = 3,
|
||||
Enlistment = 4,
|
||||
Demotion = 5
|
||||
Demotion = 5,
|
||||
ClassTransfer = 6,
|
||||
MajorTransfer = 7
|
||||
}
|
||||
|
||||
public enum StudentStatusChangeState
|
||||
|
||||
Loaded 3 of 7 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user