发布课表时,在同一事务内生成实际周次课次明细。

已审批的调课、停课、补课、代课后,会重建受影响教学任务所在已发布课表的明细投影。
This commit is contained in:
2026-08-09 16:02:27 +08:00 Unverified
parent 26a918a52a
commit e36a02ea59
2 changed files with 14 additions and 0 deletions
@@ -3,6 +3,7 @@ using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Domain.Identity; using Jiaowu.Api.Domain.Identity;
using Jiaowu.Api.Infrastructure.Auth; using Jiaowu.Api.Infrastructure.Auth;
using Jiaowu.Api.Infrastructure.Persistence; using Jiaowu.Api.Infrastructure.Persistence;
using Jiaowu.Api.Infrastructure.Timetables;
using Jiaowu.Api.Infrastructure.Scheduling; using Jiaowu.Api.Infrastructure.Scheduling;
using Jiaowu.Api.Infrastructure.Teaching; using Jiaowu.Api.Infrastructure.Teaching;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@@ -286,6 +287,8 @@ public sealed class CourseAdjustmentsController(
db.CourseAdjustments.Add(adj); db.CourseAdjustments.Add(adj);
await db.SaveChangesAsync(cancellationToken); await db.SaveChangesAsync(cancellationToken);
await new PublishedTimetableProjectionService(db)
.RebuildPublishedPlansForTaskAsync(adj.TeachingTaskId, cancellationToken);
if (request.Submit) if (request.Submit)
{ {
@@ -6,6 +6,17 @@ namespace Jiaowu.Api.Infrastructure.Timetables;
public sealed class PublishedTimetableProjectionService(AppDbContext db) public sealed class PublishedTimetableProjectionService(AppDbContext db)
{ {
public async Task RebuildPublishedPlansForTaskAsync(Guid teachingTaskId, CancellationToken cancellationToken)
{
var plans = await db.SchedulePlans
.Where(plan => plan.Status == SchedulePlanStatus.Published &&
plan.Entries.Any(entry => entry.TeachingTaskId == teachingTaskId))
.Include(plan => plan.Entries)
.ToListAsync(cancellationToken);
foreach (var plan in plans)
await RebuildAsync(plan, cancellationToken);
}
public async Task RebuildAsync(SchedulePlan plan, CancellationToken cancellationToken) public async Task RebuildAsync(SchedulePlan plan, CancellationToken cancellationToken)
{ {
var previous = db.PublishedScheduleOccurrences.Where(x => x.SchedulePlanId == plan.Id); var previous = db.PublishedScheduleOccurrences.Where(x => x.SchedulePlanId == plan.Id);