This commit is contained in:
biss committed 2026-09-07 19:34:03 +08:00
1 parent cec56564b5
commit ae075bda6d
32 files changed
+10052 -90

No files matched your search

@@ -369,6 +369,8 @@ public sealed class TeachingTasksController(
if (!CanManage(task.Course!)) return Forbid();
if (task.Status != TeachingTaskStatus.Closed)
return ConflictProblem("只有已归档的教学任务可以撤销归档。");
if (await HasArchivedDependenciesAsync([task.Id], cancellationToken))
return ConflictProblem("学期、课程或教师已归档,请先恢复后再启用教学任务。");
task.Status = TeachingTaskStatus.Published;
return await SaveAsync(id, false, cancellationToken);
}
@@ -423,6 +425,8 @@ public sealed class TeachingTasksController(
foreach (var task in tasks) task.Status = TeachingTaskStatus.Closed;
break;
case TeachingTaskBatchOperation.Unarchive:
if (await HasArchivedDependenciesAsync(ids, cancellationToken))
return ConflictProblem("学期、课程或教师已归档,请先恢复后再启用教学任务。");
if (tasks.Any(x => x.Status != TeachingTaskStatus.Closed))
return ConflictProblem(
$"教学任务“{tasks.First(x => x.Status != TeachingTaskStatus.Closed).Name}”不是已归档状态,整批未撤销归档。");
@@ -454,12 +458,12 @@ public sealed class TeachingTasksController(
return ValidationProblem("开始周不能晚于结束周。");
var term = await db.AcademicTerms.AsNoTracking()
.FirstOrDefaultAsync(
x => x.Id == request.AcademicTermId && x.IsEnabled,
x => x.Id == request.AcademicTermId && x.IsEnabled && !x.IsArchived,
cancellationToken);
if (term is null) return ValidationProblem("所选学期不存在或已停用。");
var course = await db.Courses.AsNoTracking()
.FirstOrDefaultAsync(
x => x.Id == request.CourseId && x.IsEnabled,
x => x.Id == request.CourseId && x.IsEnabled && !x.IsArchived,
cancellationToken);
if (course is null) return ValidationProblem("所选课程不存在或已停用。");
if (!CanManage(course)) return Forbid();
@@ -518,7 +522,7 @@ public sealed class TeachingTasksController(
x.AcademicTermId == request.AcademicTermId &&
x.CourseId == request.CourseId &&
x.Status == TeacherCourseApplicationStatus.Approved &&
x.Teacher!.Status == TeacherStatus.Active)
x.Teacher!.Status == TeacherStatus.Active && !x.Teacher.IsArchived)
.Where(x => !scopedCollegeId.HasValue ||
x.Teacher!.CollegeId == scopedCollegeId.Value)
.Select(x => x.Teacher!)
@@ -634,7 +638,7 @@ public sealed class TeachingTasksController(
if (request.StartWeek > request.EndWeek)
return ValidationProblem("开始周不能晚于结束周。");
var course = await db.Courses.AsNoTracking()
.FirstOrDefaultAsync(x => x.Id == request.CourseId && x.IsEnabled, cancellationToken);
.FirstOrDefaultAsync(x => x.Id == request.CourseId && x.IsEnabled && !x.IsArchived, cancellationToken);
if (course is null) return ValidationProblem("所选课程不存在或已停用。");
if (!CanManage(course)) return Forbid();
if (!Enum.IsDefined(request.SchedulingMode))
@@ -648,7 +652,7 @@ public sealed class TeachingTasksController(
if (hoursProblem is not null) return ValidationProblem(hoursProblem);
var collegeId = ScopedCollegeId();
if (!await db.AcademicTerms.AnyAsync(
x => x.Id == request.AcademicTermId && x.IsEnabled,
x => x.Id == request.AcademicTermId && x.IsEnabled && !x.IsArchived,
cancellationToken))
return ValidationProblem("所选学期不存在或已停用。");
@@ -657,7 +661,7 @@ public sealed class TeachingTasksController(
!teacherIds.Contains(request.PrimaryTeacherId.Value))
return ValidationProblem("主讲教师必须包含在授课教师中。");
if (await db.Teachers
.Where(x => x.Status == TeacherStatus.Active)
.Where(x => x.Status == TeacherStatus.Active && !x.IsArchived)
.WhereIn(teacherIds, x => x.Id)
.CountAsync(cancellationToken) != teacherIds.Length)
return ValidationProblem("存在无效或非在职授课教师。");
@@ -707,6 +711,8 @@ public sealed class TeachingTasksController(
IReadOnlyCollection<TeachingTask> tasks,
CancellationToken cancellationToken)
{
if (await HasArchivedDependenciesAsync(tasks.Select(x => x.Id).ToArray(), cancellationToken))
return "学期、课程或教师已归档,不能发布教学任务。";
var invalidStatus = tasks.FirstOrDefault(x => x.Status != TeachingTaskStatus.Draft);
if (invalidStatus is not null)
return PublishingProblem(
@@ -780,6 +786,10 @@ public sealed class TeachingTasksController(
course.CollegeId,
course.Nature);
private Task<bool> HasArchivedDependenciesAsync(Guid[] ids, CancellationToken ct) =>
db.TeachingTasks.WhereIn(ids, x => x.Id).AnyAsync(x =>
x.AcademicTerm!.IsArchived || x.Course!.IsArchived || x.Teachers.Any(t => t.Teacher!.IsArchived), ct);
private async Task<ActionResult> SaveAsync(
Guid id,
bool created,