已完成“选课候补与自动递补”完整流程。
学生端:满员后可加入/取消候补,展示候补顺位和当前候补人数。 自动递补:退课释放名额后,按候补时间顺序重新校验学籍、范围、学分及时间冲突;不合格者自动失效并继续下一位。 管理端:教学班显示候补人数,名单抽屉提供候补队列及移出操作。 状态通知:递补成功、资格失效、批次关闭、管理员移出均会通知学生。 并发安全:退课和递补放在 Serializable 事务中执行。 数据库:已补充 SQLite 开发迁移和 MySQL 正式迁移。
This commit is contained in:
@@ -14,6 +14,10 @@ public static class CourseSelectionRules
|
||||
round.Status == CourseSelectionRoundStatus.Open &&
|
||||
nowUtc <= round.WithdrawalEndsAt;
|
||||
|
||||
public static bool CanPromoteWaitlist(CourseSelectionRound round, DateTime nowUtc) =>
|
||||
round.Status == CourseSelectionRoundStatus.Open &&
|
||||
nowUtc <= round.WithdrawalEndsAt;
|
||||
|
||||
public static bool SupportsProxyEnrollment(CourseNature nature) =>
|
||||
nature == CourseNature.GeneralRequired;
|
||||
|
||||
@@ -68,4 +72,7 @@ public static class CourseSelectionRules
|
||||
/// <summary>Retake expanded capacity: ceiling(original * 1.15).</summary>
|
||||
public static int RetakeCapacity(int originalCapacity) =>
|
||||
(int)Math.Ceiling(originalCapacity * 1.15);
|
||||
|
||||
public static int EffectiveCapacity(int originalCapacity, bool isRetake) =>
|
||||
isRetake ? RetakeCapacity(originalCapacity) : originalCapacity;
|
||||
}
|
||||
|
||||
@@ -500,6 +500,12 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
entity.HasIndex(x => new { x.CourseSelectionOfferingId, x.StudentId })
|
||||
.IsUnique();
|
||||
entity.HasIndex(x => new { x.StudentId, x.Status });
|
||||
entity.HasIndex(x => new
|
||||
{
|
||||
x.CourseSelectionOfferingId,
|
||||
x.Status,
|
||||
x.WaitlistedAt
|
||||
});
|
||||
entity.HasOne(x => x.CourseSelectionOffering)
|
||||
.WithMany(x => x.Enrollments)
|
||||
.HasForeignKey(x => x.CourseSelectionOfferingId)
|
||||
|
||||
@@ -48,6 +48,8 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
"20260725_25_academic_warnings";
|
||||
private const string AcademicTermArchivingMigration =
|
||||
"20260726_27_academic_term_archiving";
|
||||
private const string CourseSelectionWaitlistMigration =
|
||||
"20260726_28_course_selection_waitlist";
|
||||
|
||||
public async Task MigrateAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -344,6 +346,19 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
AcademicTermArchivingMigration,
|
||||
academicTermArchivingExists ? [] : AcademicTermArchivingStatements,
|
||||
cancellationToken);
|
||||
|
||||
var courseSelectionWaitlistExists = await db.Database
|
||||
.SqlQueryRaw<int>(
|
||||
"""
|
||||
SELECT COUNT(*) AS "Value"
|
||||
FROM pragma_table_info('CourseEnrollments')
|
||||
WHERE name = 'WaitlistedAt'
|
||||
""")
|
||||
.AnyAsync(value => value > 0, cancellationToken);
|
||||
await ApplyMigrationAsync(
|
||||
CourseSelectionWaitlistMigration,
|
||||
courseSelectionWaitlistExists ? [] : CourseSelectionWaitlistStatements,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private async Task ApplyMigrationAsync(
|
||||
@@ -1589,6 +1604,18 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
"""
|
||||
];
|
||||
|
||||
private static readonly string[] CourseSelectionWaitlistStatements =
|
||||
[
|
||||
"""
|
||||
ALTER TABLE "CourseEnrollments"
|
||||
ADD COLUMN "WaitlistedAt" TEXT NULL;
|
||||
""",
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS "IX_CourseEnrollments_CourseSelectionOfferingId_Status_WaitlistedAt"
|
||||
ON "CourseEnrollments" ("CourseSelectionOfferingId", "Status", "WaitlistedAt");
|
||||
"""
|
||||
];
|
||||
|
||||
private static readonly string[] CourseAdjustmentsStatements =
|
||||
[
|
||||
"""
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql;
|
||||
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20260726170000_CourseSelectionWaitlist")]
|
||||
public partial class CourseSelectionWaitlist : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "WaitlistedAt",
|
||||
table: "CourseEnrollments",
|
||||
type: "datetime(6)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CourseEnrollments_CourseSelectionOfferingId_Status_WaitlistedAt",
|
||||
table: "CourseEnrollments",
|
||||
columns: new[] { "CourseSelectionOfferingId", "Status", "WaitlistedAt" });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_CourseEnrollments_CourseSelectionOfferingId_Status_WaitlistedAt",
|
||||
table: "CourseEnrollments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "WaitlistedAt",
|
||||
table: "CourseEnrollments");
|
||||
}
|
||||
}
|
||||
+5
@@ -732,6 +732,9 @@ namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTime?>("WaitlistedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTime?>("WithdrawnAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
@@ -740,6 +743,8 @@ namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
b.HasIndex("CourseSelectionOfferingId", "StudentId")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("CourseSelectionOfferingId", "Status", "WaitlistedAt");
|
||||
|
||||
b.HasIndex("StudentId", "Status");
|
||||
|
||||
b.ToTable("CourseEnrollments");
|
||||
|
||||
Reference in New Issue
Block a user