feat: keep undergraduate exams independent of course terms

This commit is contained in:
Codex
2026-10-14 23:19:11 +08:00
parent 48367b8273
commit 141436f545
9 changed files with 419 additions and 99 deletions
+24 -1
View File
@@ -1,5 +1,6 @@
import '../domain/course.dart';
import '../domain/school_term.dart';
import '../domain/school_identity.dart';
import 'dart:convert';
@@ -61,9 +62,31 @@ class JsonScheduleImport {
? SchoolTerm(int.parse(termIds.single))
: null;
if (termIds.length > 1 ||
(term != null && termIds.any((id) => id != term.id.toString()))) {
(term != null &&
termIds.any(
(id) =>
id != term.id.toString() ||
term.school != SupportedSchool.uestcGraduate,
))) {
throw const FormatException('文件中包含不同学期的课程');
}
final undergraduateIds = courses
.map(
(c) =>
RegExp(r'^uestc-undergraduate-(\d+)-')
.firstMatch(c.id)
?.group(1),
)
.whereType<String>()
.toSet();
if (undergraduateIds.isNotEmpty &&
(term?.school != SupportedSchool.uestcUndergraduate ||
undergraduateIds.any((id) => id != term!.id.toString())) ||
courses.any((c) => c.endPeriod > 11) &&
(source == CourseSource.demo ||
term?.school != SupportedSchool.uestcUndergraduate)) {
throw const FormatException('本科课表来源或学期无效');
}
return ImportDraft(
courses: List.unmodifiable(courses),
explicitlyEmpty: json['explicitlyEmpty'] == true,