调课、停课、补课申请
This commit is contained in:
@@ -55,6 +55,8 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
public DbSet<ExamSession> ExamSessions => Set<ExamSession>();
|
||||
public DbSet<ExamSessionInvigilator> ExamSessionInvigilators =>
|
||||
Set<ExamSessionInvigilator>();
|
||||
public DbSet<CourseAdjustment> CourseAdjustments => Set<CourseAdjustment>();
|
||||
public DbSet<Notification> Notifications => Set<Notification>();
|
||||
public DbSet<StudentStatusChange> StudentStatusChanges =>
|
||||
Set<StudentStatusChange>();
|
||||
public DbSet<GraduationAuditBatch> GraduationAuditBatches =>
|
||||
@@ -668,6 +670,30 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
.HasForeignKey(x => x.StudentId).OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
builder.Entity<CourseAdjustment>(entity =>
|
||||
{
|
||||
entity.Property(x => x.Reason).HasMaxLength(500);
|
||||
entity.Property(x => x.ReviewComment).HasMaxLength(500);
|
||||
entity.HasIndex(x => new { x.TeachingTaskId, x.Status });
|
||||
entity.HasIndex(x => x.ApplicantUserId);
|
||||
entity.HasIndex(x => new { x.Status, x.CreatedAt });
|
||||
entity.HasOne(x => x.TeachingTask).WithMany()
|
||||
.HasForeignKey(x => x.TeachingTaskId).OnDelete(DeleteBehavior.Restrict);
|
||||
entity.HasOne(x => x.Classroom).WithMany()
|
||||
.HasForeignKey(x => x.ClassroomId).OnDelete(DeleteBehavior.SetNull);
|
||||
entity.HasOne(x => x.SubstituteTeacher).WithMany()
|
||||
.HasForeignKey(x => x.SubstituteTeacherId).OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
|
||||
builder.Entity<Notification>(entity =>
|
||||
{
|
||||
entity.Property(x => x.Title).HasMaxLength(200);
|
||||
entity.Property(x => x.Content).HasMaxLength(1000);
|
||||
entity.Property(x => x.LinkUrl).HasMaxLength(300);
|
||||
entity.HasIndex(x => new { x.UserId, x.IsRead });
|
||||
entity.HasIndex(x => x.CreatedAt);
|
||||
});
|
||||
|
||||
builder.Entity<AuditLog>(entity =>
|
||||
{
|
||||
entity.Property(x => x.Method).HasMaxLength(10);
|
||||
|
||||
@@ -36,6 +36,8 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
"20260725_20_exam_scheduling_optimization";
|
||||
private const string RetakeEnrollmentMigration =
|
||||
"20260725_21_retake_enrollment";
|
||||
private const string CourseAdjustmentsMigration =
|
||||
"20260725_22_course_adjustments";
|
||||
|
||||
public async Task MigrateAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -240,6 +242,19 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
RetakeEnrollmentMigration,
|
||||
retakeEnrollmentExists ? [] : RetakeEnrollmentStatements,
|
||||
cancellationToken);
|
||||
|
||||
var courseAdjustmentsExist = await db.Database
|
||||
.SqlQueryRaw<int>(
|
||||
"""
|
||||
SELECT COUNT(*) AS "Value"
|
||||
FROM sqlite_master
|
||||
WHERE type = 'table' AND name = 'CourseAdjustments'
|
||||
""")
|
||||
.AnyAsync(value => value > 0, cancellationToken);
|
||||
await ApplyMigrationAsync(
|
||||
CourseAdjustmentsMigration,
|
||||
courseAdjustmentsExist ? [] : CourseAdjustmentsStatements,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private async Task ApplyMigrationAsync(
|
||||
@@ -1484,4 +1499,58 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
ADD COLUMN "EnrollmentType" INTEGER NOT NULL DEFAULT 1;
|
||||
"""
|
||||
];
|
||||
|
||||
private static readonly string[] CourseAdjustmentsStatements =
|
||||
[
|
||||
"""
|
||||
CREATE TABLE "CourseAdjustments" (
|
||||
"Id" TEXT NOT NULL CONSTRAINT "PK_CourseAdjustments" PRIMARY KEY,
|
||||
"TeachingTaskId" TEXT NOT NULL,
|
||||
"Type" INTEGER NOT NULL,
|
||||
"Status" INTEGER NOT NULL,
|
||||
"ApplicantUserId" TEXT NOT NULL,
|
||||
"TargetDate" TEXT NULL,
|
||||
"DayOfWeek" INTEGER NULL,
|
||||
"StartPeriod" INTEGER NULL,
|
||||
"PeriodCount" INTEGER NULL,
|
||||
"ClassroomId" TEXT NULL,
|
||||
"SubstituteTeacherId" TEXT NULL,
|
||||
"CancelWeek" INTEGER NULL,
|
||||
"CancelDate" TEXT NULL,
|
||||
"Reason" TEXT NOT NULL,
|
||||
"ReviewComment" TEXT NULL,
|
||||
"SubmittedAt" TEXT NULL,
|
||||
"ReviewedAt" TEXT NULL,
|
||||
"ReviewedByUserId" TEXT NULL,
|
||||
"CreatedAt" TEXT NOT NULL,
|
||||
"UpdatedAt" TEXT NOT NULL,
|
||||
CONSTRAINT "FK_CourseAdjustments_TeachingTasks"
|
||||
FOREIGN KEY ("TeachingTaskId") REFERENCES "TeachingTasks" ("Id")
|
||||
ON DELETE RESTRICT,
|
||||
CONSTRAINT "FK_CourseAdjustments_Classrooms"
|
||||
FOREIGN KEY ("ClassroomId") REFERENCES "Classrooms" ("Id")
|
||||
ON DELETE SET NULL,
|
||||
CONSTRAINT "FK_CourseAdjustments_Teachers"
|
||||
FOREIGN KEY ("SubstituteTeacherId") REFERENCES "Teachers" ("Id")
|
||||
ON DELETE SET NULL
|
||||
);
|
||||
""",
|
||||
"""CREATE INDEX "IX_CourseAdjustments_TeachingTaskId_Status" ON "CourseAdjustments" ("TeachingTaskId", "Status");""",
|
||||
"""CREATE INDEX "IX_CourseAdjustments_ApplicantUserId" ON "CourseAdjustments" ("ApplicantUserId");""",
|
||||
"""CREATE INDEX "IX_CourseAdjustments_Status_CreatedAt" ON "CourseAdjustments" ("Status", "CreatedAt");""",
|
||||
"""
|
||||
CREATE TABLE "Notifications" (
|
||||
"Id" TEXT NOT NULL CONSTRAINT "PK_Notifications" PRIMARY KEY,
|
||||
"UserId" TEXT NOT NULL,
|
||||
"Title" TEXT NOT NULL,
|
||||
"Content" TEXT NOT NULL,
|
||||
"IsRead" INTEGER NOT NULL,
|
||||
"LinkUrl" TEXT NULL,
|
||||
"CreatedAt" TEXT NOT NULL,
|
||||
"UpdatedAt" TEXT NOT NULL
|
||||
);
|
||||
""",
|
||||
"""CREATE INDEX "IX_Notifications_UserId_IsRead" ON "Notifications" ("UserId", "IsRead");""",
|
||||
"""CREATE INDEX "IX_Notifications_CreatedAt" ON "Notifications" ("CreatedAt");"""
|
||||
];
|
||||
}
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class CourseAdjustments : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CourseAdjustments",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "char(36)", nullable: false),
|
||||
TeachingTaskId = table.Column<Guid>(type: "char(36)", nullable: false),
|
||||
Type = table.Column<int>(type: "int", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
ApplicantUserId = table.Column<Guid>(type: "char(36)", nullable: false),
|
||||
TargetDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
DayOfWeek = table.Column<int>(type: "int", nullable: true),
|
||||
StartPeriod = table.Column<int>(type: "int", nullable: true),
|
||||
PeriodCount = table.Column<int>(type: "int", nullable: true),
|
||||
ClassroomId = table.Column<Guid>(type: "char(36)", nullable: true),
|
||||
SubstituteTeacherId = table.Column<Guid>(type: "char(36)", nullable: true),
|
||||
CancelWeek = table.Column<int>(type: "int", nullable: true),
|
||||
CancelDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
Reason = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false),
|
||||
ReviewComment = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true),
|
||||
SubmittedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
ReviewedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
ReviewedByUserId = table.Column<Guid>(type: "char(36)", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CourseAdjustments", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_CourseAdjustments_Classrooms_ClassroomId",
|
||||
column: x => x.ClassroomId,
|
||||
principalTable: "Classrooms",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "FK_CourseAdjustments_Teachers_SubstituteTeacherId",
|
||||
column: x => x.SubstituteTeacherId,
|
||||
principalTable: "Teachers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "FK_CourseAdjustments_TeachingTasks_TeachingTaskId",
|
||||
column: x => x.TeachingTaskId,
|
||||
principalTable: "TeachingTasks",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Notifications",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "char(36)", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "char(36)", nullable: false),
|
||||
Title = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false),
|
||||
Content = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: false),
|
||||
IsRead = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
LinkUrl = table.Column<string>(type: "varchar(300)", maxLength: 300, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Notifications", x => x.Id);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CourseAdjustments_ApplicantUserId",
|
||||
table: "CourseAdjustments",
|
||||
column: "ApplicantUserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CourseAdjustments_ClassroomId",
|
||||
table: "CourseAdjustments",
|
||||
column: "ClassroomId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CourseAdjustments_Status_CreatedAt",
|
||||
table: "CourseAdjustments",
|
||||
columns: new[] { "Status", "CreatedAt" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CourseAdjustments_SubstituteTeacherId",
|
||||
table: "CourseAdjustments",
|
||||
column: "SubstituteTeacherId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CourseAdjustments_TeachingTaskId_Status",
|
||||
table: "CourseAdjustments",
|
||||
columns: new[] { "TeachingTaskId", "Status" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notifications_CreatedAt",
|
||||
table: "Notifications",
|
||||
column: "CreatedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Notifications_UserId_IsRead",
|
||||
table: "Notifications",
|
||||
columns: new[] { "UserId", "IsRead" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(name: "Notifications");
|
||||
migrationBuilder.DropTable(name: "CourseAdjustments");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user