实验课现在直接进入普通排课流程,不再要求先到实验排课模块逐个安排。

普通“添加排课”新增“理论课 / 实验课”类型。
自动排课会分别补足理论学时和实验学时。
实验课只能安排到实验室、实训室、机房、语音室等场地。
发布课表时分别校验理论、实验学时;任一未排足都不能发布。
普通课表及 Excel 导出会标注“实验课”。
历史排课保持不变,迁移后默认识别为理论课;后续新建或修订版本时再补充实验课。
This commit is contained in:
2026-08-02 16:54:41 +08:00 Unverified
parent 9d525826ce
commit f0f59419d5
22 changed files with 6488 additions and 266 deletions
@@ -1,6 +1,7 @@
using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Infrastructure.Persistence;
using Jiaowu.Api.Infrastructure.Scheduling;
using Jiaowu.Api.Infrastructure.Teaching;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
@@ -157,6 +158,21 @@ public sealed class AutomaticScheduleGeneratorTests
EndDate = new DateOnly(2027, 1, 15)
};
var college = new College { Code = "LAB", Name = "实验学院" };
var campus = new Campus { Code = "LAB-CAMPUS", Name = "实验校区" };
var building = new Building
{
Code = "LAB-BUILDING",
Name = "实验楼",
Campus = campus
};
var laboratory = new Classroom
{
Code = "LAB-101",
Name = "实验室 101",
Building = building,
Capacity = 40,
RoomType = "实验室"
};
var course = new Course
{
Code = "LAB-01",
@@ -185,7 +201,7 @@ public sealed class AutomaticScheduleGeneratorTests
Name = "实验学时拆分测试",
Version = "V1"
};
db.AddRange(term, college, course, task, plan);
db.AddRange(term, college, campus, building, laboratory, course, task, plan);
db.ScheduleTimeSlots.AddRange(
new ScheduleTimeSlot
{
@@ -203,22 +219,22 @@ public sealed class AutomaticScheduleGeneratorTests
StartsAt = new TimeOnly(8, 55),
EndsAt = new TimeOnly(9, 40)
});
db.TeachingTaskScheduleConstraints.Add(
new TeachingTaskScheduleConstraint
{
TeachingTask = task,
RequiresClassroom = false
});
await db.SaveChangesAsync();
var result = await new AutomaticScheduleGenerator(db)
.GenerateAsync(plan, CancellationToken.None);
Assert.Equal(1, result.CreatedEntries);
Assert.Equal(2, result.CreatedEntries);
Assert.Equal(1, result.CompletedTasks);
Assert.Equal(
1,
(await db.ScheduleEntries.SingleAsync()).PeriodCount);
var entries = await db.ScheduleEntries.OrderBy(x => x.Kind).ToListAsync();
Assert.Equal(2, entries.Count);
Assert.Contains(entries, x =>
x.Kind == ScheduleEntryKind.Lecture &&
TeachingTaskHours.ScheduledHours(x) == 16);
Assert.Contains(entries, x =>
x.Kind == ScheduleEntryKind.Experiment &&
x.ClassroomId == laboratory.Id &&
TeachingTaskHours.ScheduledHours(x) == 16);
}
[Fact]
@@ -32,40 +32,41 @@ public sealed class SchedulePublishJobProcessorTests
Assert.Equal(SchedulePlanStatus.Draft, result.PlanStatus);
Assert.Null(result.ActiveAcademicTermId);
Assert.Equal("检查未通过", result.CurrentStep);
Assert.Contains("尚未达到每周 2 个普通排课学时", result.ErrorMessage);
Assert.Contains("理论课应安排 32 学时,当前已安排 16 学时", result.ErrorMessage);
Assert.Null(result.PublishedAt);
}
[Fact]
public async Task Processor_excludes_practice_hours_for_existing_tasks()
public async Task Processor_requires_experiment_hours_in_regular_schedule()
{
var result = await RunPublishAsync(
weeklyHours: 2,
scheduledHours: 1,
practiceHours: 16);
practiceHours: 16,
experimentScheduledHours: 1);
Assert.Equal(SchedulePublishJobStatus.Succeeded, result.JobStatus);
Assert.Equal(SchedulePlanStatus.Published, result.PlanStatus);
}
[Fact]
public async Task Processor_rejects_practice_hours_already_added_to_draft()
public async Task Processor_rejects_missing_experiment_hours()
{
var result = await RunPublishAsync(
weeklyHours: 2,
scheduledHours: 2,
scheduledHours: 1,
practiceHours: 16);
Assert.Equal(SchedulePublishJobStatus.Failed, result.JobStatus);
Assert.Equal(SchedulePlanStatus.Draft, result.PlanStatus);
Assert.Contains("普通课表应为 1 学时", result.ErrorMessage);
Assert.Contains("删除已包含的实践学时", result.ErrorMessage);
Assert.Contains("实验课应安排 16 学时,当前已安排 0 学时", result.ErrorMessage);
}
private static async Task<PublishResult> RunPublishAsync(
int weeklyHours,
int scheduledHours,
int practiceHours = 0)
int practiceHours = 0,
int experimentScheduledHours = 0)
{
var databasePath = Path.Combine(
Path.GetTempPath(),
@@ -97,6 +98,21 @@ public sealed class SchedulePublishJobProcessorTests
EndDate = new DateOnly(2027, 1, 15)
};
var college = new College { Code = "PUB", Name = "发布测试学院" };
var campus = new Campus { Code = "PUB-CAMPUS", Name = "发布测试校区" };
var building = new Building
{
Code = "PUB-BUILDING",
Name = "实验楼",
Campus = campus
};
var laboratory = new Classroom
{
Code = "PUB-LAB",
Name = "发布测试实验室",
Building = building,
Capacity = 80,
RoomType = "实验室"
};
var course = new Course
{
Code = "PUB-01",
@@ -135,6 +151,21 @@ public sealed class SchedulePublishJobProcessorTests
EndWeek = 16,
WeekPattern = WeekPattern.All
});
if (experimentScheduledHours > 0)
{
plan.Entries.Add(new ScheduleEntry
{
TeachingTask = task,
Kind = ScheduleEntryKind.Experiment,
Classroom = laboratory,
DayOfWeek = 2,
StartPeriod = 1,
PeriodCount = experimentScheduledHours,
StartWeek = 1,
EndWeek = 16,
WeekPattern = WeekPattern.All
});
}
var job = new SchedulePublishJob
{
SchedulePlan = plan,
@@ -143,7 +174,16 @@ public sealed class SchedulePublishJobProcessorTests
CurrentStep = "等待后台检查"
};
jobId = job.Id;
db.AddRange(term, college, course, task, plan, job);
db.AddRange(
term,
college,
campus,
building,
laboratory,
course,
task,
plan,
job);
db.ScheduleTimeSlots.AddRange(
new ScheduleTimeSlot
{
@@ -189,7 +189,7 @@ public sealed class ScheduleSettingsControllerTests
});
Assert.Contains("测试教师", json);
Assert.Contains(classroom.Id.ToString(), json);
Assert.Contains("\"WeeklyHours\":3", json);
Assert.Contains("\"WeeklyHours\":4", json);
Assert.Contains("\"CoursePracticeHours\":16", json);
}
@@ -13,7 +13,7 @@ namespace Jiaowu.Api.Tests;
public sealed class SchedulesControllerTests
{
[Fact]
public async Task Manual_entry_rejects_hours_reserved_for_experiments()
public async Task Manual_entry_adds_experiment_hours_to_regular_schedule()
{
await using var connection = new SqliteConnection("Data Source=:memory:");
await connection.OpenAsync();
@@ -33,6 +33,21 @@ public sealed class SchedulesControllerTests
EndDate = new DateOnly(2027, 1, 17)
};
var college = new College { Code = "LAB", Name = "实验学院" };
var campus = new Campus { Code = "LAB-CAMPUS", Name = "实验校区" };
var building = new Building
{
Code = "LAB-BUILDING",
Name = "实验楼",
Campus = campus
};
var laboratory = new Classroom
{
Code = "LAB-201",
Name = "实验室 201",
Building = building,
Capacity = 40,
RoomType = "实验室"
};
var course = new Course
{
Code = "LAB-01",
@@ -71,7 +86,7 @@ public sealed class SchedulesControllerTests
EndWeek = 16,
WeekPattern = WeekPattern.All
});
db.AddRange(term, college, course, task, plan);
db.AddRange(term, college, campus, building, laboratory, course, task, plan);
db.ScheduleTimeSlots.AddRange(
new ScheduleTimeSlot
{
@@ -102,22 +117,22 @@ public sealed class SchedulesControllerTests
plan.Id,
new ScheduleEntryRequest(
task.Id,
null,
2,
laboratory.Id,
2,
1,
1,
1,
16,
WeekPattern.All,
null),
null,
ScheduleEntryKind.Experiment),
CancellationToken.None);
var problem = Assert.IsType<ObjectResult>(result);
var details = Assert.IsType<ValidationProblemDetails>(problem.Value);
Assert.Contains(
"实践学时请在实验管理中安排",
details.Detail);
Assert.Single(await db.ScheduleEntries.ToListAsync());
Assert.IsType<CreatedResult>(result);
var entries = await db.ScheduleEntries.OrderBy(x => x.Kind).ToListAsync();
Assert.Equal(2, entries.Count);
Assert.Equal(ScheduleEntryKind.Experiment, entries[1].Kind);
Assert.Equal(laboratory.Id, entries[1].ClassroomId);
}
[Fact]
@@ -32,7 +32,7 @@ public sealed class TeachingTaskHoursTests
}
[Fact]
public void Standard_schedule_excludes_practice_hours()
public void Standard_schedule_includes_theory_and_experiment_hours()
{
var course = new Course
{
@@ -52,12 +52,12 @@ public sealed class TeachingTaskHoursTests
16,
out var weeklyHours));
Assert.Equal(3, weeklyHours);
Assert.Null(TeachingTaskHours.Validate(course, 1, 16, 3));
Assert.Null(TeachingTaskHours.Validate(course, 1, 16, 4));
var result = TeachingTaskHours.Validate(course, 1, 16, 4);
var result = TeachingTaskHours.Validate(course, 1, 16, 3);
Assert.NotNull(result);
Assert.Contains("普通课表应安排 48 学时", result);
Assert.Contains("实践学时 16", result);
Assert.Contains("理论课和实验课均应进入课表", result);
Assert.Contains("共 48 学时", result);
}
[Fact]
@@ -79,8 +79,6 @@ public sealed class TeachingTaskHoursTests
16,
1,
TeachingTaskSchedulingMode.Flexible));
Assert.Contains(
"无需进入普通课表",
TeachingTaskHours.Validate(course, 1, 16, 1)!);
Assert.Null(TeachingTaskHours.Validate(course, 1, 16, 1));
}
}