教学任务按 授课周数 × 周学时 = 课程总学时 双端校验,不匹配会显示具体差额并阻止保存;公共课批量生成同样校验。

排课约束增加课程、教师、学院、授课方式、场地要求、约束状态筛选,并支持批量修改当前筛选结果。
新增“非排时课程”授课方式:不进入自动排课
不占星期、节次和教室
不阻塞课表发布
允许正常选课
在班级课表和学生个人课表中单独展示
This commit is contained in:
2026-07-25 08:18:25 +08:00 Unverified
parent 30c15f89e5
commit fe508054d0
20 changed files with 3785 additions and 136 deletions
@@ -27,16 +27,92 @@ public sealed class AutomaticScheduleGeneratorTests
Assert.True(await db.ScheduleTimeSlots.CountAsync() == 0);
Assert.True(await db.AutomaticScheduleJobs.CountAsync() == 0);
Assert.True(await db.Database
.SqlQueryRaw<int>(
Assert.True(await db.Database
.SqlQueryRaw<int>(
"""
SELECT COUNT(*) AS "Value"
FROM pragma_table_info('ScheduleEntries')
WHERE name = 'ClassroomId' AND "notnull" = 0
""")
.AnyAsync(value => value > 0));
Assert.True(await db.Database
.SqlQueryRaw<int>(
"""
SELECT COUNT(*) AS "Value"
FROM pragma_table_info('TeachingTasks')
WHERE name = 'SchedulingMode'
""")
.AnyAsync(value => value > 0));
}
[Fact]
public async Task Generator_skips_flexible_courses()
{
await using var connection = new SqliteConnection("Data Source=:memory:");
await connection.OpenAsync();
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlite(connection)
.Options;
await using var db = new AppDbContext(options);
await db.Database.EnsureCreatedAsync();
var term = new AcademicTerm
{
Code = "2026-F",
Name = "2026 秋季",
AcademicYear = "2026-2027",
Season = TermSeason.Autumn,
StartDate = new DateOnly(2026, 9, 1),
EndDate = new DateOnly(2027, 1, 15)
};
var college = new College { Code = "PUBLIC", Name = "公共教学部" };
var course = new Course
{
Code = "FLEX-01",
Name = "社会实践",
College = college,
Credits = 1,
TotalHours = 16,
PracticeHours = 16
};
var task = new TeachingTask
{
TaskNumber = "TASK-FLEX",
Name = "社会实践教学班",
AcademicTerm = term,
Course = course,
Capacity = 100,
StartWeek = 1,
EndWeek = 16,
WeeklyHours = 1,
SchedulingMode = TeachingTaskSchedulingMode.Flexible,
Status = TeachingTaskStatus.Published
};
var plan = new SchedulePlan
{
AcademicTerm = term,
Name = "非排时课程测试",
Version = "V1"
};
db.AddRange(term, college, course, task, plan);
db.ScheduleTimeSlots.Add(new ScheduleTimeSlot
{
AcademicTerm = term,
PeriodNumber = 1,
Name = "第 1 节",
StartsAt = new TimeOnly(8, 0),
EndsAt = new TimeOnly(8, 45)
});
await db.SaveChangesAsync();
var result = await new AutomaticScheduleGenerator(db)
.GenerateAsync(plan, CancellationToken.None);
Assert.Equal(0, result.TotalTasks);
Assert.Equal(0, result.CreatedEntries);
Assert.Empty(await db.ScheduleEntries.ToListAsync());
}
[Fact]
public async Task Generator_schedules_roomless_course_within_allowed_time()
{
@@ -0,0 +1,33 @@
using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Infrastructure.Teaching;
namespace Jiaowu.Api.Tests;
public sealed class TeachingTaskHoursTests
{
private static readonly Course Course = new()
{
Code = "TEST-01",
Name = "测试课程",
CollegeId = Guid.NewGuid(),
Credits = 2,
TotalHours = 32,
LectureHours = 32
};
[Fact]
public void Validate_accepts_matching_week_range_and_weekly_hours()
{
Assert.Null(TeachingTaskHours.Validate(Course, 1, 16, 2));
}
[Fact]
public void Validate_reports_course_total_and_planned_hours_when_mismatched()
{
var result = TeachingTaskHours.Validate(Course, 1, 8, 2);
Assert.NotNull(result);
Assert.Contains("总学时为 32", result);
Assert.Contains("共 16 学时", result);
}
}