预演
This commit is contained in:
@@ -0,0 +1,621 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Graduation;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jiaowu.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize(Roles = SystemRoles.Student)]
|
||||
[Route("api/student/academic-planning")]
|
||||
public sealed class AcademicPlanningController(
|
||||
AppDbContext db,
|
||||
ICurrentUserDataScope currentUserDataScope) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
var loaded = await LoadAsync(cancellationToken);
|
||||
if (loaded.Error is not null) return loaded.Error;
|
||||
var context = loaded.Context!;
|
||||
|
||||
var completion = CurriculumCompletionRules.Evaluate(
|
||||
context.Plan.Modules,
|
||||
context.PassedCourseIds);
|
||||
var planCompletedCredits = context.Courses
|
||||
.Where(x => context.PassedCourseIds.Contains(x.CourseId))
|
||||
.Sum(x => x.Credits);
|
||||
var suggestionIds = AcademicPlanningRules.SuggestNextSemester(
|
||||
context.CourseSnapshots,
|
||||
context.PassedCourseIds,
|
||||
context.InProgressCourseIds,
|
||||
context.NextSemester);
|
||||
var suggestionIdSet = suggestionIds.ToHashSet();
|
||||
var latestAudit = await db.GraduationAuditResults.AsNoTracking()
|
||||
.Where(x =>
|
||||
x.StudentId == context.Student.Id &&
|
||||
x.GraduationAuditBatch!.Status ==
|
||||
GraduationAuditBatchStatus.Published)
|
||||
.OrderByDescending(x => x.GraduationAuditBatch!.GraduationYear)
|
||||
.ThenByDescending(x => x.GraduationAuditBatch!.PublishedAt)
|
||||
.Select(x => new
|
||||
{
|
||||
BatchName = x.GraduationAuditBatch!.Name,
|
||||
x.GraduationAuditBatch.GraduationYear,
|
||||
x.RequiredCredits,
|
||||
x.EarnedCredits,
|
||||
x.RequiredCourseCount,
|
||||
x.PassedRequiredCourseCount,
|
||||
x.FailedCourseCount,
|
||||
x.MissingCourseNames,
|
||||
x.Conclusion,
|
||||
x.IsOverridden,
|
||||
x.ReviewComment,
|
||||
x.GraduationAuditBatch.PublishedAt
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
var endSemester = Math.Max(
|
||||
context.Plan.Major!.SchoolingYears * 2,
|
||||
context.NextSemester + 3);
|
||||
return Ok(new
|
||||
{
|
||||
Student = new
|
||||
{
|
||||
context.Student.Id,
|
||||
context.Student.StudentNumber,
|
||||
context.Student.Name,
|
||||
context.Student.EnrollmentYear,
|
||||
context.Student.Status,
|
||||
ClassName = context.Student.AdministrativeClass!.Name,
|
||||
MajorName = context.Student.AdministrativeClass.Major!.Name,
|
||||
CollegeName =
|
||||
context.Student.AdministrativeClass.Major.College!.Name
|
||||
},
|
||||
Plan = new
|
||||
{
|
||||
context.Plan.Id,
|
||||
context.Plan.Name,
|
||||
context.Plan.Version,
|
||||
context.Plan.TotalCredits,
|
||||
SchoolingYears = context.Plan.Major.SchoolingYears,
|
||||
CurrentSemester = context.CurrentSemester,
|
||||
NextSemester = context.NextSemester,
|
||||
StandardGraduationSemester =
|
||||
context.Plan.Major.SchoolingYears * 2
|
||||
},
|
||||
Baseline = new
|
||||
{
|
||||
EarnedCredits = context.EarnedCredits,
|
||||
PlanCompletedCredits = planCompletedCredits,
|
||||
CreditGap = Math.Max(
|
||||
context.Plan.TotalCredits - context.EarnedCredits,
|
||||
0),
|
||||
CompletionRate = context.Plan.TotalCredits <= 0
|
||||
? 0
|
||||
: Math.Min(100, Math.Round(
|
||||
planCompletedCredits / context.Plan.TotalCredits * 100,
|
||||
1)),
|
||||
completion.RequirementCount,
|
||||
completion.PassedRequirementCount,
|
||||
completion.MissingRequirements,
|
||||
InProgressCredits = context.Courses
|
||||
.Where(x => context.InProgressCourseIds.Contains(x.CourseId))
|
||||
.Sum(x => x.Credits)
|
||||
},
|
||||
Terms = Enumerable.Range(
|
||||
context.NextSemester,
|
||||
endSemester - context.NextSemester + 1)
|
||||
.Select(semester => new
|
||||
{
|
||||
Semester = semester,
|
||||
Label = FormatSemester(
|
||||
context.Student.EnrollmentYear,
|
||||
semester),
|
||||
IsBeyondStandard =
|
||||
semester > context.Plan.Major.SchoolingYears * 2
|
||||
}),
|
||||
Courses = context.Courses
|
||||
.OrderBy(x => x.RecommendedSemester)
|
||||
.ThenBy(x => x.CourseCode)
|
||||
.Select(course => new
|
||||
{
|
||||
course.CourseId,
|
||||
course.CourseCode,
|
||||
course.CourseName,
|
||||
course.Credits,
|
||||
course.RecommendedSemester,
|
||||
course.Type,
|
||||
course.ModuleCode,
|
||||
course.ModuleName,
|
||||
Status = context.StatusByCourse[course.CourseId],
|
||||
IsSuggested = suggestionIdSet.Contains(course.CourseId),
|
||||
Prerequisites = course.Prerequisites.Select(item => new
|
||||
{
|
||||
item.CourseId,
|
||||
item.CourseCode,
|
||||
item.CourseName,
|
||||
IsCompleted =
|
||||
context.PassedCourseIds.Contains(item.CourseId),
|
||||
IsInProgress =
|
||||
context.InProgressCourseIds.Contains(item.CourseId)
|
||||
})
|
||||
}),
|
||||
NextSemesterSuggestion = suggestionIds.Select(courseId =>
|
||||
{
|
||||
var course = context.CourseById[courseId];
|
||||
return new
|
||||
{
|
||||
course.CourseId,
|
||||
course.CourseCode,
|
||||
course.CourseName,
|
||||
course.Credits,
|
||||
course.Type,
|
||||
Reason = course.Type == CurriculumCourseType.Required &&
|
||||
course.RecommendedSemester <= context.NextSemester
|
||||
? "计划学期已到,且先修条件已满足"
|
||||
: course.Type == CurriculumCourseType.Required
|
||||
? "必修课程,按培养方案顺序推进"
|
||||
: "用于补足培养模块与总学分"
|
||||
};
|
||||
}),
|
||||
LatestGraduationAudit = latestAudit,
|
||||
Assumptions = new[]
|
||||
{
|
||||
"模拟课程按顺利通过计算,不会写入成绩或正式选课。",
|
||||
$"预计毕业学期按每学期最多 {AcademicPlanningRules.RecommendedSemesterCreditLimit:0} 学分估算。",
|
||||
"当前在读课程按本学期顺利完成计入预测。"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("simulate")]
|
||||
public async Task<ActionResult> Simulate(
|
||||
AcademicPlanningRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var loaded = await LoadAsync(cancellationToken);
|
||||
if (loaded.Error is not null) return loaded.Error;
|
||||
var context = loaded.Context!;
|
||||
|
||||
var selections = request.Terms
|
||||
.SelectMany(term => term.CourseIds.Select(courseId => new
|
||||
{
|
||||
term.Semester,
|
||||
CourseId = courseId
|
||||
}))
|
||||
.ToList();
|
||||
var duplicate = selections
|
||||
.GroupBy(x => x.CourseId)
|
||||
.FirstOrDefault(group => group.Count() > 1);
|
||||
if (duplicate is not null)
|
||||
return ValidationProblem("同一门课程不能安排在多个学期。");
|
||||
if (request.Terms.Any(x =>
|
||||
x.Semester < context.NextSemester ||
|
||||
x.Semester > context.NextSemester + 12))
|
||||
return ValidationProblem("模拟学期超出了可规划范围。");
|
||||
|
||||
var invalidCourse = selections.FirstOrDefault(x =>
|
||||
!context.CourseById.ContainsKey(x.CourseId));
|
||||
if (invalidCourse is not null)
|
||||
return ValidationProblem("模拟计划包含不属于当前培养方案的课程。");
|
||||
var alreadyHandled = selections.FirstOrDefault(x =>
|
||||
context.PassedCourseIds.Contains(x.CourseId) ||
|
||||
context.InProgressCourseIds.Contains(x.CourseId));
|
||||
if (alreadyHandled is not null)
|
||||
return ValidationProblem("已完成或当前在读课程无需重复安排。");
|
||||
|
||||
var plannedSemesters = selections.ToDictionary(
|
||||
x => x.CourseId,
|
||||
x => x.Semester);
|
||||
var projectedCourseIds = context.PassedCourseIds
|
||||
.Concat(context.InProgressCourseIds)
|
||||
.Concat(plannedSemesters.Keys)
|
||||
.ToHashSet();
|
||||
var completion = CurriculumCompletionRules.Evaluate(
|
||||
context.Plan.Modules,
|
||||
projectedCourseIds);
|
||||
var addedCredits = context.Courses
|
||||
.Where(x =>
|
||||
!context.PassedCourseIds.Contains(x.CourseId) &&
|
||||
(context.InProgressCourseIds.Contains(x.CourseId) ||
|
||||
plannedSemesters.ContainsKey(x.CourseId)))
|
||||
.Sum(x => x.Credits);
|
||||
var projectedEarnedCredits = context.EarnedCredits + addedCredits;
|
||||
var creditGap = Math.Max(
|
||||
context.Plan.TotalCredits - projectedEarnedCredits,
|
||||
0);
|
||||
var prerequisiteIssues = AcademicPlanningRules.FindPrerequisiteIssues(
|
||||
context.CourseSnapshots,
|
||||
context.PassedCourseIds,
|
||||
context.InProgressCourseIds,
|
||||
plannedSemesters);
|
||||
var conflicts = prerequisiteIssues.Select(issue =>
|
||||
{
|
||||
var course = context.CourseById[issue.CourseId];
|
||||
var prerequisite = context.AllCourseLabels.GetValueOrDefault(
|
||||
issue.PrerequisiteCourseId,
|
||||
new CourseLabel(
|
||||
issue.PrerequisiteCourseId,
|
||||
"未知课程",
|
||||
"未找到的先修课程"));
|
||||
return new
|
||||
{
|
||||
Type = "Prerequisite",
|
||||
issue.CourseId,
|
||||
course.CourseName,
|
||||
PrerequisiteCourseId = prerequisite.CourseId,
|
||||
PrerequisiteCourseName = prerequisite.CourseName,
|
||||
issue.PlannedSemester,
|
||||
issue.PrerequisitePlannedSemester,
|
||||
Message = issue.PrerequisitePlannedSemester.HasValue
|
||||
? $"《{prerequisite.CourseName}》必须安排在《{course.CourseName}》之前。"
|
||||
: $"《{course.CourseName}》的先修课程《{prerequisite.CourseName}》尚未完成或安排。"
|
||||
};
|
||||
}).ToList();
|
||||
var workloadWarnings = request.Terms
|
||||
.Select(term => new
|
||||
{
|
||||
term.Semester,
|
||||
Credits = term.CourseIds.Sum(courseId =>
|
||||
context.CourseById.GetValueOrDefault(courseId)?.Credits ?? 0)
|
||||
})
|
||||
.Where(x =>
|
||||
x.Credits > AcademicPlanningRules.HeavySemesterCreditLimit)
|
||||
.Select(x => new
|
||||
{
|
||||
Type = "Workload",
|
||||
x.Semester,
|
||||
x.Credits,
|
||||
Message =
|
||||
$"第 {x.Semester} 学期安排了 {x.Credits:0.#} 学分,超过建议上限 {AcademicPlanningRules.HeavySemesterCreditLimit:0.#} 学分。"
|
||||
})
|
||||
.ToList();
|
||||
var timingWarnings = selections
|
||||
.Select(item => new
|
||||
{
|
||||
item.Semester,
|
||||
Course = context.CourseById[item.CourseId]
|
||||
})
|
||||
.Where(x => x.Semester < x.Course.RecommendedSemester)
|
||||
.Select(x => new
|
||||
{
|
||||
Type = "EarlyCourse",
|
||||
x.Course.CourseId,
|
||||
x.Course.CourseName,
|
||||
x.Semester,
|
||||
x.Course.RecommendedSemester,
|
||||
Message =
|
||||
$"《{x.Course.CourseName}》早于培养方案建议学期修读,请确认课程开设条件。"
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var unresolvedFailedCourseCount = context.FailedCourseIds.Count(
|
||||
courseId => !projectedCourseIds.Contains(courseId));
|
||||
var conclusion = GraduationAuditRules.Evaluate(
|
||||
true,
|
||||
context.Student.Status,
|
||||
context.Plan.TotalCredits,
|
||||
projectedEarnedCredits,
|
||||
completion.RequirementCount,
|
||||
completion.PassedRequirementCount,
|
||||
unresolvedFailedCourseCount);
|
||||
var latestPlannedSemester = plannedSemesters.Count == 0
|
||||
? context.NextSemester - 1
|
||||
: plannedSemesters.Values.Max();
|
||||
var estimatedSemester =
|
||||
AcademicPlanningRules.EstimateCompletionSemester(
|
||||
context.NextSemester,
|
||||
latestPlannedSemester,
|
||||
creditGap,
|
||||
completion.RequirementCount -
|
||||
completion.PassedRequirementCount);
|
||||
var remainingRequiredSemesterFloor = context.Courses
|
||||
.Where(course =>
|
||||
course.Type == CurriculumCourseType.Required &&
|
||||
!projectedCourseIds.Contains(course.CourseId))
|
||||
.Select(course => course.RecommendedSemester)
|
||||
.DefaultIfEmpty(estimatedSemester)
|
||||
.Max();
|
||||
estimatedSemester = Math.Max(
|
||||
estimatedSemester,
|
||||
remainingRequiredSemesterFloor);
|
||||
var planCompletedCredits = context.Courses
|
||||
.Where(x => projectedCourseIds.Contains(x.CourseId))
|
||||
.Sum(x => x.Credits);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
Projected = new
|
||||
{
|
||||
EarnedCredits = projectedEarnedCredits,
|
||||
PlanCompletedCredits = planCompletedCredits,
|
||||
CreditGap = creditGap,
|
||||
CompletionRate = context.Plan.TotalCredits <= 0
|
||||
? 0
|
||||
: Math.Min(100, Math.Round(
|
||||
planCompletedCredits / context.Plan.TotalCredits * 100,
|
||||
1)),
|
||||
completion.RequirementCount,
|
||||
completion.PassedRequirementCount,
|
||||
completion.MissingRequirements,
|
||||
UnresolvedFailedCourseCount = unresolvedFailedCourseCount,
|
||||
GraduationConclusion = conclusion,
|
||||
EstimatedGraduationSemester = estimatedSemester,
|
||||
EstimatedGraduationTerm = FormatSemester(
|
||||
context.Student.EnrollmentYear,
|
||||
estimatedSemester),
|
||||
IsBeyondStandard =
|
||||
estimatedSemester >
|
||||
context.Plan.Major!.SchoolingYears * 2
|
||||
},
|
||||
Conflicts = conflicts,
|
||||
Warnings = workloadWarnings.Cast<object>()
|
||||
.Concat(timingWarnings)
|
||||
.ToList(),
|
||||
TermSummaries = request.Terms
|
||||
.OrderBy(x => x.Semester)
|
||||
.Select(term => new
|
||||
{
|
||||
term.Semester,
|
||||
Label = FormatSemester(
|
||||
context.Student.EnrollmentYear,
|
||||
term.Semester),
|
||||
CourseCount = term.CourseIds.Count,
|
||||
Credits = term.CourseIds.Sum(courseId =>
|
||||
context.CourseById.GetValueOrDefault(courseId)?.Credits ??
|
||||
0)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<LoadResult> LoadAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = currentUserDataScope.Current.UserId;
|
||||
var student = await db.Students.AsNoTracking()
|
||||
.Include(x => x.AdministrativeClass)
|
||||
.ThenInclude(x => x!.Major)
|
||||
.ThenInclude(x => x!.College)
|
||||
.FirstOrDefaultAsync(x => x.UserId == userId, cancellationToken);
|
||||
if (student is null)
|
||||
return new LoadResult(
|
||||
null,
|
||||
ConflictProblem("当前账号尚未关联学生档案。"));
|
||||
|
||||
var plan = await db.CurriculumPlans.AsNoTracking()
|
||||
.AsSplitQuery()
|
||||
.Include(x => x.Major)
|
||||
.Include(x => x.Modules)
|
||||
.ThenInclude(x => x.Courses)
|
||||
.ThenInclude(x => x.Course)
|
||||
.ThenInclude(x => x!.Prerequisites)
|
||||
.ThenInclude(x => x.PrerequisiteCourse)
|
||||
.Where(x =>
|
||||
x.MajorId == student.AdministrativeClass!.MajorId &&
|
||||
x.EffectiveGrade == student.EnrollmentYear &&
|
||||
x.Status == CurriculumPlanStatus.Published)
|
||||
.OrderByDescending(x => x.PublishedAt)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if (plan is null)
|
||||
return new LoadResult(
|
||||
null,
|
||||
ConflictProblem(
|
||||
$"{student.EnrollmentYear} 级{student.AdministrativeClass!.Major!.Name}尚未发布培养方案。"));
|
||||
|
||||
var courses = plan.Modules
|
||||
.SelectMany(module => module.Courses.Select(item =>
|
||||
new PlanningCourse(
|
||||
item.CourseId,
|
||||
item.Course!.Code,
|
||||
item.Course.Name,
|
||||
item.Course.Credits,
|
||||
item.RecommendedSemester,
|
||||
item.Type,
|
||||
module.Code,
|
||||
module.Name,
|
||||
item.Course.Prerequisites
|
||||
.Select(prerequisite => new CourseLabel(
|
||||
prerequisite.PrerequisiteCourseId,
|
||||
prerequisite.PrerequisiteCourse!.Code,
|
||||
prerequisite.PrerequisiteCourse.Name))
|
||||
.OrderBy(x => x.CourseCode)
|
||||
.ToList())))
|
||||
.GroupBy(x => x.CourseId)
|
||||
.Select(group => group.First())
|
||||
.ToList();
|
||||
var planCourseIds = courses.Select(x => x.CourseId).ToArray();
|
||||
|
||||
var gradeAttempts = await db.GradeRecords.AsNoTracking()
|
||||
.Where(x =>
|
||||
x.StudentId == student.Id &&
|
||||
x.GradeSheet!.Status == GradeSheetStatus.Published)
|
||||
.Select(x => new GradeAttempt(
|
||||
x.GradeSheet!.TeachingTask!.CourseId,
|
||||
x.GradeSheet.TeachingTask.Course!.Credits,
|
||||
x.TotalScore,
|
||||
x.ExamStatus))
|
||||
.ToListAsync(cancellationToken);
|
||||
var passedCourseIds = gradeAttempts
|
||||
.Where(x => StudentCourseProgressRules.IsPassed(
|
||||
new StudentCourseAttemptSnapshot(x.TotalScore, x.ExamStatus)))
|
||||
.Select(x => x.CourseId)
|
||||
.Distinct()
|
||||
.ToHashSet();
|
||||
var failedCourseIds = gradeAttempts
|
||||
.GroupBy(x => x.CourseId)
|
||||
.Where(group => !group.Any(x =>
|
||||
StudentCourseProgressRules.IsPassed(
|
||||
new StudentCourseAttemptSnapshot(
|
||||
x.TotalScore,
|
||||
x.ExamStatus))))
|
||||
.Select(group => group.Key)
|
||||
.ToHashSet();
|
||||
var earnedCredits = gradeAttempts
|
||||
.Where(x => passedCourseIds.Contains(x.CourseId))
|
||||
.GroupBy(x => x.CourseId)
|
||||
.Sum(group => group.Max(x => x.Credits));
|
||||
|
||||
var inProgressCourseIds = await db.TeachingTasks.AsNoTracking()
|
||||
.Where(task =>
|
||||
task.Status == TeachingTaskStatus.Published &&
|
||||
task.AcademicTerm!.IsCurrent &&
|
||||
(task.Classes.Any(item =>
|
||||
item.AdministrativeClassId ==
|
||||
student.AdministrativeClassId) ||
|
||||
db.CourseEnrollments.Any(enrollment =>
|
||||
enrollment.StudentId == student.Id &&
|
||||
enrollment.Status == CourseEnrollmentStatus.Enrolled &&
|
||||
enrollment.CourseSelectionOffering!.TeachingTaskId ==
|
||||
task.Id)))
|
||||
.Select(x => x.CourseId)
|
||||
.Distinct()
|
||||
.ToListAsync(cancellationToken);
|
||||
var inProgressSet = inProgressCourseIds
|
||||
.Where(planCourseIds.Contains)
|
||||
.Where(courseId => !passedCourseIds.Contains(courseId))
|
||||
.ToHashSet();
|
||||
|
||||
var attemptsByCourse = gradeAttempts
|
||||
.Where(x => planCourseIds.Contains(x.CourseId))
|
||||
.GroupBy(x => x.CourseId)
|
||||
.ToDictionary(x => x.Key, x => x.ToList());
|
||||
var statuses = courses.ToDictionary(
|
||||
x => x.CourseId,
|
||||
x => StudentCourseProgressRules.Evaluate(
|
||||
attemptsByCourse.GetValueOrDefault(x.CourseId, [])
|
||||
.Select(attempt => new StudentCourseAttemptSnapshot(
|
||||
attempt.TotalScore,
|
||||
attempt.ExamStatus)),
|
||||
inProgressSet.Contains(x.CourseId)).Status);
|
||||
var currentTerm = await db.AcademicTerms.AsNoTracking()
|
||||
.Where(x => x.IsCurrent)
|
||||
.OrderByDescending(x => x.StartDate)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
var currentSemester = CalculateCurrentSemester(
|
||||
student.EnrollmentYear,
|
||||
currentTerm);
|
||||
var snapshots = courses.Select(x =>
|
||||
new AcademicPlanningCourseSnapshot(
|
||||
x.CourseId,
|
||||
x.CourseName,
|
||||
x.Credits,
|
||||
x.RecommendedSemester,
|
||||
x.Type,
|
||||
x.Prerequisites.Select(p => p.CourseId).ToArray()))
|
||||
.ToList();
|
||||
var allLabels = courses
|
||||
.Select(x => new CourseLabel(
|
||||
x.CourseId,
|
||||
x.CourseCode,
|
||||
x.CourseName))
|
||||
.Concat(courses.SelectMany(x => x.Prerequisites))
|
||||
.GroupBy(x => x.CourseId)
|
||||
.ToDictionary(x => x.Key, x => x.First());
|
||||
|
||||
return new LoadResult(
|
||||
new PlanningContext(
|
||||
student,
|
||||
plan,
|
||||
courses,
|
||||
courses.ToDictionary(x => x.CourseId),
|
||||
snapshots,
|
||||
allLabels,
|
||||
passedCourseIds,
|
||||
inProgressSet,
|
||||
failedCourseIds,
|
||||
statuses,
|
||||
earnedCredits,
|
||||
currentSemester,
|
||||
currentSemester + 1),
|
||||
null);
|
||||
}
|
||||
|
||||
private static int CalculateCurrentSemester(
|
||||
int enrollmentYear,
|
||||
AcademicTerm? currentTerm)
|
||||
{
|
||||
if (currentTerm is not null)
|
||||
{
|
||||
return Math.Max(
|
||||
1,
|
||||
currentTerm.Season == TermSeason.Autumn
|
||||
? (currentTerm.StartDate.Year - enrollmentYear) * 2 + 1
|
||||
: (currentTerm.StartDate.Year - enrollmentYear - 1) * 2 + 2);
|
||||
}
|
||||
|
||||
var today = DateOnly.FromDateTime(DateTime.Today);
|
||||
return Math.Max(
|
||||
1,
|
||||
today.Month >= 8
|
||||
? (today.Year - enrollmentYear) * 2 + 1
|
||||
: (today.Year - enrollmentYear - 1) * 2 + 2);
|
||||
}
|
||||
|
||||
private static string FormatSemester(int enrollmentYear, int semester)
|
||||
{
|
||||
var startYear = enrollmentYear + (semester - 1) / 2;
|
||||
var season = semester % 2 == 1 ? "秋季学期" : "春季学期";
|
||||
return $"{startYear}—{startYear + 1} 学年{season}";
|
||||
}
|
||||
|
||||
private ActionResult ConflictProblem(string detail) =>
|
||||
Conflict(new ProblemDetails
|
||||
{
|
||||
Title = "无法进行学业规划",
|
||||
Detail = detail,
|
||||
Status = StatusCodes.Status409Conflict
|
||||
});
|
||||
|
||||
private sealed record GradeAttempt(
|
||||
Guid CourseId,
|
||||
decimal Credits,
|
||||
decimal? TotalScore,
|
||||
GradeExamStatus ExamStatus);
|
||||
|
||||
private sealed record CourseLabel(
|
||||
Guid CourseId,
|
||||
string CourseCode,
|
||||
string CourseName);
|
||||
|
||||
private sealed record PlanningCourse(
|
||||
Guid CourseId,
|
||||
string CourseCode,
|
||||
string CourseName,
|
||||
decimal Credits,
|
||||
int RecommendedSemester,
|
||||
CurriculumCourseType Type,
|
||||
string ModuleCode,
|
||||
string ModuleName,
|
||||
IReadOnlyList<CourseLabel> Prerequisites);
|
||||
|
||||
private sealed record PlanningContext(
|
||||
Student Student,
|
||||
CurriculumPlan Plan,
|
||||
IReadOnlyList<PlanningCourse> Courses,
|
||||
IReadOnlyDictionary<Guid, PlanningCourse> CourseById,
|
||||
IReadOnlyList<AcademicPlanningCourseSnapshot> CourseSnapshots,
|
||||
IReadOnlyDictionary<Guid, CourseLabel> AllCourseLabels,
|
||||
IReadOnlySet<Guid> PassedCourseIds,
|
||||
IReadOnlySet<Guid> InProgressCourseIds,
|
||||
IReadOnlySet<Guid> FailedCourseIds,
|
||||
IReadOnlyDictionary<Guid, StudentCourseProgressStatus> StatusByCourse,
|
||||
decimal EarnedCredits,
|
||||
int CurrentSemester,
|
||||
int NextSemester);
|
||||
|
||||
private sealed record LoadResult(
|
||||
PlanningContext? Context,
|
||||
ActionResult? Error);
|
||||
}
|
||||
|
||||
public sealed record AcademicPlanningRequest(
|
||||
IReadOnlyCollection<AcademicPlanningTermRequest> Terms);
|
||||
|
||||
public sealed record AcademicPlanningTermRequest(
|
||||
[Range(1, 30)] int Semester,
|
||||
IReadOnlyCollection<Guid> CourseIds);
|
||||
@@ -84,6 +84,17 @@ public sealed class CoursesController(
|
||||
x.Nature,
|
||||
x.AssessmentMethod,
|
||||
x.Description,
|
||||
PrerequisiteCourseIds = x.Prerequisites
|
||||
.OrderBy(item => item.PrerequisiteCourse!.Code)
|
||||
.Select(item => item.PrerequisiteCourseId),
|
||||
Prerequisites = x.Prerequisites
|
||||
.OrderBy(item => item.PrerequisiteCourse!.Code)
|
||||
.Select(item => new
|
||||
{
|
||||
item.PrerequisiteCourseId,
|
||||
item.PrerequisiteCourse!.Code,
|
||||
item.PrerequisiteCourse.Name
|
||||
}),
|
||||
x.IsEnabled,
|
||||
x.SortOrder,
|
||||
x.CreatedAt,
|
||||
@@ -146,9 +157,6 @@ public sealed class CoursesController(
|
||||
CourseRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var validation = await ValidateAsync(request, cancellationToken);
|
||||
if (validation is not null) return validation;
|
||||
|
||||
var entity = new Course
|
||||
{
|
||||
Code = request.Code.Trim(),
|
||||
@@ -166,6 +174,16 @@ public sealed class CoursesController(
|
||||
IsEnabled = request.IsEnabled,
|
||||
SortOrder = request.SortOrder
|
||||
};
|
||||
var validation = await ValidateAsync(entity.Id, request, cancellationToken);
|
||||
if (validation is not null) return validation;
|
||||
|
||||
entity.Prerequisites = NormalizePrerequisiteIds(request)
|
||||
.Select(prerequisiteId => new CoursePrerequisite
|
||||
{
|
||||
CourseId = entity.Id,
|
||||
PrerequisiteCourseId = prerequisiteId
|
||||
})
|
||||
.ToList();
|
||||
db.Courses.Add(entity);
|
||||
return await SaveAsync(entity.Id, true, cancellationToken);
|
||||
}
|
||||
@@ -177,10 +195,12 @@ public sealed class CoursesController(
|
||||
CourseRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await db.Courses.FindAsync([id], cancellationToken);
|
||||
var entity = await db.Courses
|
||||
.Include(x => x.Prerequisites)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
if (entity is null) return NotFound();
|
||||
if (!CanManage(entity.CollegeId, entity.Nature)) return Forbid();
|
||||
var validation = await ValidateAsync(request, cancellationToken);
|
||||
var validation = await ValidateAsync(id, request, cancellationToken);
|
||||
if (validation is not null) return validation;
|
||||
|
||||
entity.Code = request.Code.Trim();
|
||||
@@ -197,6 +217,19 @@ public sealed class CoursesController(
|
||||
entity.Description = Normalize(request.Description);
|
||||
entity.IsEnabled = request.IsEnabled;
|
||||
entity.SortOrder = request.SortOrder;
|
||||
var prerequisiteIds = NormalizePrerequisiteIds(request).ToHashSet();
|
||||
db.CoursePrerequisites.RemoveRange(
|
||||
entity.Prerequisites.Where(x =>
|
||||
!prerequisiteIds.Contains(x.PrerequisiteCourseId)));
|
||||
foreach (var prerequisiteId in prerequisiteIds.Except(
|
||||
entity.Prerequisites.Select(x => x.PrerequisiteCourseId)))
|
||||
{
|
||||
entity.Prerequisites.Add(new CoursePrerequisite
|
||||
{
|
||||
CourseId = entity.Id,
|
||||
PrerequisiteCourseId = prerequisiteId
|
||||
});
|
||||
}
|
||||
return await SaveAsync(entity.Id, false, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -212,6 +245,7 @@ public sealed class CoursesController(
|
||||
}
|
||||
|
||||
private async Task<ActionResult?> ValidateAsync(
|
||||
Guid courseId,
|
||||
CourseRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -224,9 +258,62 @@ public sealed class CoursesController(
|
||||
return ValidationProblem("所选课程分类不存在或已停用。");
|
||||
if (request.LectureHours + request.PracticeHours > request.TotalHours)
|
||||
return ValidationProblem("讲授学时与实践学时之和不能超过总学时。");
|
||||
|
||||
var prerequisiteIds = NormalizePrerequisiteIds(request).ToArray();
|
||||
if (prerequisiteIds.Contains(courseId))
|
||||
return ValidationProblem("课程不能把自身设置为先修课程。");
|
||||
var accessiblePrerequisiteCount = await ScopedCourses()
|
||||
.CountAsync(x =>
|
||||
prerequisiteIds.Contains(x.Id) &&
|
||||
x.IsEnabled,
|
||||
cancellationToken);
|
||||
if (accessiblePrerequisiteCount != prerequisiteIds.Length)
|
||||
return ValidationProblem("包含不存在、已停用或不在当前数据范围内的先修课程。");
|
||||
if (await CreatesPrerequisiteCycleAsync(
|
||||
courseId,
|
||||
prerequisiteIds,
|
||||
cancellationToken))
|
||||
return ValidationProblem("先修关系不能形成循环依赖。");
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task<bool> CreatesPrerequisiteCycleAsync(
|
||||
Guid courseId,
|
||||
IReadOnlyCollection<Guid> prerequisiteIds,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (prerequisiteIds.Count == 0) return false;
|
||||
|
||||
var edges = await db.CoursePrerequisites.AsNoTracking()
|
||||
.Where(x => x.CourseId != courseId)
|
||||
.Select(x => new { x.CourseId, x.PrerequisiteCourseId })
|
||||
.ToListAsync(cancellationToken);
|
||||
var prerequisitesByCourse = edges
|
||||
.GroupBy(x => x.CourseId)
|
||||
.ToDictionary(
|
||||
group => group.Key,
|
||||
group => group.Select(x => x.PrerequisiteCourseId).ToArray());
|
||||
|
||||
foreach (var prerequisiteId in prerequisiteIds)
|
||||
{
|
||||
var pending = new Stack<Guid>();
|
||||
var visited = new HashSet<Guid>();
|
||||
pending.Push(prerequisiteId);
|
||||
while (pending.TryPop(out var candidate))
|
||||
{
|
||||
if (candidate == courseId) return true;
|
||||
if (!visited.Add(candidate) ||
|
||||
!prerequisitesByCourse.TryGetValue(candidate, out var next))
|
||||
continue;
|
||||
foreach (var item in next) pending.Push(item);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static IEnumerable<Guid> NormalizePrerequisiteIds(CourseRequest request) =>
|
||||
(request.PrerequisiteCourseIds ?? []).Distinct();
|
||||
|
||||
private IQueryable<Course> ScopedCourses()
|
||||
{
|
||||
var scope = currentUserDataScope.Current;
|
||||
@@ -307,4 +394,5 @@ public sealed record CourseRequest(
|
||||
AssessmentMethod AssessmentMethod,
|
||||
[MaxLength(1000)] string? Description,
|
||||
bool IsEnabled,
|
||||
int SortOrder);
|
||||
int SortOrder,
|
||||
IReadOnlyCollection<Guid>? PrerequisiteCourseIds = null);
|
||||
|
||||
@@ -50,6 +50,16 @@ public sealed class Course : CatalogEntity
|
||||
public CourseNature Nature { get; set; }
|
||||
public AssessmentMethod AssessmentMethod { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public ICollection<CoursePrerequisite> Prerequisites { get; set; } = [];
|
||||
public ICollection<CoursePrerequisite> RequiredByCourses { get; set; } = [];
|
||||
}
|
||||
|
||||
public sealed class CoursePrerequisite : EntityBase
|
||||
{
|
||||
public Guid CourseId { get; set; }
|
||||
public Course? Course { get; set; }
|
||||
public Guid PrerequisiteCourseId { get; set; }
|
||||
public Course? PrerequisiteCourse { get; set; }
|
||||
}
|
||||
|
||||
public sealed class CourseCategory : CatalogEntity
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Graduation;
|
||||
|
||||
public sealed record AcademicPlanningCourseSnapshot(
|
||||
Guid CourseId,
|
||||
string CourseName,
|
||||
decimal Credits,
|
||||
int RecommendedSemester,
|
||||
CurriculumCourseType Type,
|
||||
IReadOnlyCollection<Guid> PrerequisiteCourseIds);
|
||||
|
||||
public sealed record AcademicPlanningPrerequisiteIssue(
|
||||
Guid CourseId,
|
||||
Guid PrerequisiteCourseId,
|
||||
int PlannedSemester,
|
||||
int? PrerequisitePlannedSemester);
|
||||
|
||||
public static class AcademicPlanningRules
|
||||
{
|
||||
public const decimal RecommendedSemesterCreditLimit = 24;
|
||||
public const decimal HeavySemesterCreditLimit = 30;
|
||||
|
||||
public static IReadOnlyList<AcademicPlanningPrerequisiteIssue>
|
||||
FindPrerequisiteIssues(
|
||||
IEnumerable<AcademicPlanningCourseSnapshot> courses,
|
||||
IReadOnlySet<Guid> completedCourseIds,
|
||||
IReadOnlySet<Guid> inProgressCourseIds,
|
||||
IReadOnlyDictionary<Guid, int> plannedSemesters)
|
||||
{
|
||||
var issues = new List<AcademicPlanningPrerequisiteIssue>();
|
||||
foreach (var course in courses.Where(x =>
|
||||
plannedSemesters.ContainsKey(x.CourseId)))
|
||||
{
|
||||
var plannedSemester = plannedSemesters[course.CourseId];
|
||||
foreach (var prerequisiteId in course.PrerequisiteCourseIds)
|
||||
{
|
||||
if (completedCourseIds.Contains(prerequisiteId) ||
|
||||
inProgressCourseIds.Contains(prerequisiteId))
|
||||
continue;
|
||||
|
||||
if (!plannedSemesters.TryGetValue(
|
||||
prerequisiteId,
|
||||
out var prerequisiteSemester) ||
|
||||
prerequisiteSemester >= plannedSemester)
|
||||
{
|
||||
issues.Add(new AcademicPlanningPrerequisiteIssue(
|
||||
course.CourseId,
|
||||
prerequisiteId,
|
||||
plannedSemester,
|
||||
plannedSemesters.GetValueOrDefault(prerequisiteId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<Guid> SuggestNextSemester(
|
||||
IEnumerable<AcademicPlanningCourseSnapshot> courses,
|
||||
IReadOnlySet<Guid> completedCourseIds,
|
||||
IReadOnlySet<Guid> inProgressCourseIds,
|
||||
int nextSemester,
|
||||
decimal targetCredits = RecommendedSemesterCreditLimit)
|
||||
{
|
||||
var available = courses
|
||||
.Where(x =>
|
||||
!completedCourseIds.Contains(x.CourseId) &&
|
||||
!inProgressCourseIds.Contains(x.CourseId) &&
|
||||
x.RecommendedSemester <= nextSemester &&
|
||||
x.PrerequisiteCourseIds.All(prerequisiteId =>
|
||||
completedCourseIds.Contains(prerequisiteId) ||
|
||||
inProgressCourseIds.Contains(prerequisiteId)))
|
||||
.OrderBy(x => x.Type == CurriculumCourseType.Required ? 0 : 1)
|
||||
.ThenBy(x => x.RecommendedSemester > nextSemester ? 1 : 0)
|
||||
.ThenBy(x => x.RecommendedSemester)
|
||||
.ThenBy(x => x.CourseName)
|
||||
.ToList();
|
||||
|
||||
var selected = new List<Guid>();
|
||||
decimal credits = 0;
|
||||
foreach (var course in available)
|
||||
{
|
||||
var isOverdueRequired =
|
||||
course.Type == CurriculumCourseType.Required &&
|
||||
course.RecommendedSemester <= nextSemester;
|
||||
if (!isOverdueRequired &&
|
||||
selected.Count > 0 &&
|
||||
credits + course.Credits > targetCredits)
|
||||
continue;
|
||||
|
||||
selected.Add(course.CourseId);
|
||||
credits += course.Credits;
|
||||
if (credits >= targetCredits) break;
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
public static int EstimateCompletionSemester(
|
||||
int nextSemester,
|
||||
int latestPlannedSemester,
|
||||
decimal remainingCredits,
|
||||
int remainingRequirementCount)
|
||||
{
|
||||
if (remainingCredits <= 0 && remainingRequirementCount <= 0)
|
||||
return Math.Max(nextSemester - 1, latestPlannedSemester);
|
||||
|
||||
var byCredits = (int)Math.Ceiling(
|
||||
Math.Max(remainingCredits, 0) / RecommendedSemesterCreditLimit);
|
||||
var byRequirements = (int)Math.Ceiling(
|
||||
Math.Max(remainingRequirementCount, 0) / 6m);
|
||||
var additionalSemesters = Math.Max(1, Math.Max(byCredits, byRequirements));
|
||||
return Math.Max(nextSemester - 1, latestPlannedSemester) +
|
||||
additionalSemesters;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
public DbSet<Student> Students => Set<Student>();
|
||||
public DbSet<CourseCategory> CourseCategories => Set<CourseCategory>();
|
||||
public DbSet<Course> Courses => Set<Course>();
|
||||
public DbSet<CoursePrerequisite> CoursePrerequisites => Set<CoursePrerequisite>();
|
||||
public DbSet<CurriculumPlan> CurriculumPlans => Set<CurriculumPlan>();
|
||||
public DbSet<CurriculumModule> CurriculumModules => Set<CurriculumModule>();
|
||||
public DbSet<CurriculumCourse> CurriculumCourses => Set<CurriculumCourse>();
|
||||
@@ -247,6 +248,20 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
builder.Entity<CoursePrerequisite>(entity =>
|
||||
{
|
||||
entity.HasIndex(x => new { x.CourseId, x.PrerequisiteCourseId })
|
||||
.IsUnique();
|
||||
entity.HasOne(x => x.Course)
|
||||
.WithMany(x => x.Prerequisites)
|
||||
.HasForeignKey(x => x.CourseId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
entity.HasOne(x => x.PrerequisiteCourse)
|
||||
.WithMany(x => x.RequiredByCourses)
|
||||
.HasForeignKey(x => x.PrerequisiteCourseId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
builder.Entity<CurriculumPlan>(entity =>
|
||||
{
|
||||
entity.Property(x => x.Name).HasMaxLength(120);
|
||||
|
||||
@@ -62,6 +62,8 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
"20260726_33_background_job_outbox";
|
||||
private const string CourseAdjustmentOccurrencesMigration =
|
||||
"20260727_34_course_adjustment_occurrences";
|
||||
private const string AcademicPlanningPrerequisitesMigration =
|
||||
"20260727_35_academic_planning_prerequisites";
|
||||
|
||||
public async Task MigrateAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -453,6 +455,19 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
BackgroundJobOutboxMigration,
|
||||
backgroundJobOutboxExists ? [] : BackgroundJobOutboxStatements,
|
||||
cancellationToken);
|
||||
|
||||
var coursePrerequisitesExist = await db.Database
|
||||
.SqlQueryRaw<int>(
|
||||
"""
|
||||
SELECT COUNT(*) AS "Value"
|
||||
FROM sqlite_master
|
||||
WHERE type = 'table' AND name = 'CoursePrerequisites'
|
||||
""")
|
||||
.AnyAsync(value => value > 0, cancellationToken);
|
||||
await ApplyMigrationAsync(
|
||||
AcademicPlanningPrerequisitesMigration,
|
||||
coursePrerequisitesExist ? [] : AcademicPlanningPrerequisiteStatements,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private async Task ApplyMigrationAsync(
|
||||
@@ -2090,4 +2105,31 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
ON "BackgroundJobOutboxMessages" ("State", "CompletedAt");
|
||||
"""
|
||||
];
|
||||
|
||||
private static readonly string[] AcademicPlanningPrerequisiteStatements =
|
||||
[
|
||||
"""
|
||||
CREATE TABLE "CoursePrerequisites" (
|
||||
"Id" TEXT NOT NULL CONSTRAINT "PK_CoursePrerequisites" PRIMARY KEY,
|
||||
"CourseId" TEXT NOT NULL,
|
||||
"PrerequisiteCourseId" TEXT NOT NULL,
|
||||
"CreatedAt" TEXT NOT NULL,
|
||||
"UpdatedAt" TEXT NOT NULL,
|
||||
CONSTRAINT "FK_CoursePrerequisites_Courses_CourseId"
|
||||
FOREIGN KEY ("CourseId") REFERENCES "Courses" ("Id")
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT "FK_CoursePrerequisites_Courses_PrerequisiteCourseId"
|
||||
FOREIGN KEY ("PrerequisiteCourseId") REFERENCES "Courses" ("Id")
|
||||
ON DELETE RESTRICT
|
||||
);
|
||||
""",
|
||||
"""
|
||||
CREATE UNIQUE INDEX "IX_CoursePrerequisites_CourseId_PrerequisiteCourseId"
|
||||
ON "CoursePrerequisites" ("CourseId", "PrerequisiteCourseId");
|
||||
""",
|
||||
"""
|
||||
CREATE INDEX "IX_CoursePrerequisites_PrerequisiteCourseId"
|
||||
ON "CoursePrerequisites" ("PrerequisiteCourseId");
|
||||
"""
|
||||
];
|
||||
}
|
||||
|
||||
+4921
File diff suppressed because it is too large
Load Diff
+61
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AcademicPlanningPrerequisites : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CoursePrerequisites",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "char(36)", nullable: false),
|
||||
CourseId = table.Column<Guid>(type: "char(36)", nullable: false),
|
||||
PrerequisiteCourseId = table.Column<Guid>(type: "char(36)", nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CoursePrerequisites", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_CoursePrerequisites_Courses_CourseId",
|
||||
column: x => x.CourseId,
|
||||
principalTable: "Courses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_CoursePrerequisites_Courses_PrerequisiteCourseId",
|
||||
column: x => x.PrerequisiteCourseId,
|
||||
principalTable: "Courses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CoursePrerequisites_CourseId_PrerequisiteCourseId",
|
||||
table: "CoursePrerequisites",
|
||||
columns: new[] { "CourseId", "PrerequisiteCourseId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CoursePrerequisites_PrerequisiteCourseId",
|
||||
table: "CoursePrerequisites",
|
||||
column: "PrerequisiteCourseId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "CoursePrerequisites");
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -908,6 +908,34 @@ namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
b.ToTable("CourseExemptions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Jiaowu.Api.Domain.Academic.CoursePrerequisite", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<Guid>("CourseId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<Guid>("PrerequisiteCourseId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PrerequisiteCourseId");
|
||||
|
||||
b.HasIndex("CourseId", "PrerequisiteCourseId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("CoursePrerequisites");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Jiaowu.Api.Domain.Academic.CourseSelectionOffering", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -3818,6 +3846,25 @@ namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
b.Navigation("TeachingTask");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Jiaowu.Api.Domain.Academic.CoursePrerequisite", b =>
|
||||
{
|
||||
b.HasOne("Jiaowu.Api.Domain.Academic.Course", "Course")
|
||||
.WithMany("Prerequisites")
|
||||
.HasForeignKey("CourseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Jiaowu.Api.Domain.Academic.Course", "PrerequisiteCourse")
|
||||
.WithMany("RequiredByCourses")
|
||||
.HasForeignKey("PrerequisiteCourseId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Course");
|
||||
|
||||
b.Navigation("PrerequisiteCourse");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Jiaowu.Api.Domain.Academic.CourseSelectionOffering", b =>
|
||||
{
|
||||
b.HasOne("Jiaowu.Api.Domain.Academic.CourseSelectionRound", "CourseSelectionRound")
|
||||
@@ -4734,6 +4781,13 @@ namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
b.Navigation("Records");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Jiaowu.Api.Domain.Academic.Course", b =>
|
||||
{
|
||||
b.Navigation("Prerequisites");
|
||||
|
||||
b.Navigation("RequiredByCourses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Jiaowu.Api.Domain.Academic.CourseSelectionOffering", b =>
|
||||
{
|
||||
b.Navigation("Enrollments");
|
||||
|
||||
Reference in New Issue
Block a user