feat: keep undergraduate exams independent of course terms
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user