实验排课再次修正
This commit is contained in:
1 parent
1e60e46c7b
commit
fb4e5ac4d5
11 files changed
+6933
-25
No files matched your search
@@ -133,6 +133,8 @@ public sealed class ScheduleSettingsController(AppDbContext db, IAppCache cache)
|
|||||||
: constraint?.RequiresClassroom ?? true,
|
: constraint?.RequiresClassroom ?? true,
|
||||||
constraint?.RequiredCampusId,
|
constraint?.RequiredCampusId,
|
||||||
constraint?.RequiredBuildingId,
|
constraint?.RequiredBuildingId,
|
||||||
|
constraint?.ExperimentRequiredCampusId,
|
||||||
|
constraint?.ExperimentRequiredBuildingId,
|
||||||
AllowedDayOfWeeks = ParseDays(constraint?.AllowedDayOfWeeks),
|
AllowedDayOfWeeks = ParseDays(constraint?.AllowedDayOfWeeks),
|
||||||
constraint?.EarliestPeriod,
|
constraint?.EarliestPeriod,
|
||||||
constraint?.LatestPeriod,
|
constraint?.LatestPeriod,
|
||||||
@@ -199,6 +201,22 @@ public sealed class ScheduleSettingsController(AppDbContext db, IAppCache cache)
|
|||||||
cancellationToken))
|
cancellationToken))
|
||||||
return ValidationProblem("指定校区不存在或已停用。");
|
return ValidationProblem("指定校区不存在或已停用。");
|
||||||
|
|
||||||
|
Building? experimentBuilding = null;
|
||||||
|
if (request.ExperimentRequiredBuildingId.HasValue)
|
||||||
|
{
|
||||||
|
experimentBuilding = await db.Buildings.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == request.ExperimentRequiredBuildingId && x.IsEnabled,
|
||||||
|
cancellationToken);
|
||||||
|
if (experimentBuilding is null) return ValidationProblem("指定实验教学楼不存在或已停用。");
|
||||||
|
if (request.ExperimentRequiredCampusId.HasValue &&
|
||||||
|
experimentBuilding.CampusId != request.ExperimentRequiredCampusId)
|
||||||
|
return ValidationProblem("指定实验教学楼不属于所选校区。");
|
||||||
|
}
|
||||||
|
if (request.ExperimentRequiredCampusId.HasValue &&
|
||||||
|
!await db.Campuses.AnyAsync(x => x.Id == request.ExperimentRequiredCampusId && x.IsEnabled,
|
||||||
|
cancellationToken))
|
||||||
|
return ValidationProblem("指定实验校区不存在或已停用。");
|
||||||
|
|
||||||
var allowedRooms = await db.Classrooms.AsNoTracking()
|
var allowedRooms = await db.Classrooms.AsNoTracking()
|
||||||
.Where(x => x.IsEnabled)
|
.Where(x => x.IsEnabled)
|
||||||
.WhereIn(request.AllowedClassroomIds, x => x.Id)
|
.WhereIn(request.AllowedClassroomIds, x => x.Id)
|
||||||
@@ -220,11 +238,11 @@ public sealed class ScheduleSettingsController(AppDbContext db, IAppCache cache)
|
|||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
if (allowedExperimentRooms.Count != allowedExperimentRoomIds.Length)
|
if (allowedExperimentRooms.Count != allowedExperimentRoomIds.Length)
|
||||||
return ValidationProblem("部分指定实验场地不存在或已停用。");
|
return ValidationProblem("部分指定实验场地不存在或已停用。");
|
||||||
if (building is not null && allowedExperimentRooms.Any(x => x.BuildingId != building.Id))
|
if (experimentBuilding is not null && allowedExperimentRooms.Any(x => x.BuildingId != experimentBuilding.Id))
|
||||||
return ValidationProblem("指定实验场地必须位于所选教学楼。");
|
return ValidationProblem("指定实验场地必须位于所选实验教学楼。");
|
||||||
if (request.RequiredCampusId.HasValue &&
|
if (request.ExperimentRequiredCampusId.HasValue &&
|
||||||
allowedExperimentRooms.Any(x => x.Building!.CampusId != request.RequiredCampusId))
|
allowedExperimentRooms.Any(x => x.Building!.CampusId != request.ExperimentRequiredCampusId))
|
||||||
return ValidationProblem("指定实验场地必须位于所选校区。");
|
return ValidationProblem("指定实验场地必须位于所选实验校区。");
|
||||||
|
|
||||||
var constraint = await db.TeachingTaskScheduleConstraints
|
var constraint = await db.TeachingTaskScheduleConstraints
|
||||||
.Include(x => x.AllowedClassrooms)
|
.Include(x => x.AllowedClassrooms)
|
||||||
@@ -242,6 +260,12 @@ public sealed class ScheduleSettingsController(AppDbContext db, IAppCache cache)
|
|||||||
constraint.RequiredBuildingId = request.RequiresClassroom
|
constraint.RequiredBuildingId = request.RequiresClassroom
|
||||||
? request.RequiredBuildingId
|
? request.RequiredBuildingId
|
||||||
: null;
|
: null;
|
||||||
|
constraint.ExperimentRequiredCampusId = request.RequiresClassroom
|
||||||
|
? request.ExperimentRequiredCampusId
|
||||||
|
: null;
|
||||||
|
constraint.ExperimentRequiredBuildingId = request.RequiresClassroom
|
||||||
|
? request.ExperimentRequiredBuildingId
|
||||||
|
: null;
|
||||||
constraint.AllowedDayOfWeeks = request.AllowedDayOfWeeks.Count == 0
|
constraint.AllowedDayOfWeeks = request.AllowedDayOfWeeks.Count == 0
|
||||||
? null
|
? null
|
||||||
: string.Join(',', request.AllowedDayOfWeeks.Distinct().Order());
|
: string.Join(',', request.AllowedDayOfWeeks.Distinct().Order());
|
||||||
@@ -461,6 +485,8 @@ public sealed class ScheduleSettingsController(AppDbContext db, IAppCache cache)
|
|||||||
constraint.RequiresClassroom = false;
|
constraint.RequiresClassroom = false;
|
||||||
constraint.RequiredCampusId = null;
|
constraint.RequiredCampusId = null;
|
||||||
constraint.RequiredBuildingId = null;
|
constraint.RequiredBuildingId = null;
|
||||||
|
constraint.ExperimentRequiredCampusId = null;
|
||||||
|
constraint.ExperimentRequiredBuildingId = null;
|
||||||
constraint.AllowedDayOfWeeks = null;
|
constraint.AllowedDayOfWeeks = null;
|
||||||
constraint.EarliestPeriod = null;
|
constraint.EarliestPeriod = null;
|
||||||
constraint.LatestPeriod = null;
|
constraint.LatestPeriod = null;
|
||||||
@@ -503,7 +529,9 @@ public sealed record TeachingTaskScheduleConstraintRequest(
|
|||||||
[Range(1, 30)] int? EarliestPeriod,
|
[Range(1, 30)] int? EarliestPeriod,
|
||||||
[Range(1, 30)] int? LatestPeriod,
|
[Range(1, 30)] int? LatestPeriod,
|
||||||
TeachingVenueNature AllowedExperimentVenueNatures = 0,
|
TeachingVenueNature AllowedExperimentVenueNatures = 0,
|
||||||
IReadOnlyList<Guid>? AllowedExperimentClassroomIds = null);
|
IReadOnlyList<Guid>? AllowedExperimentClassroomIds = null,
|
||||||
|
Guid? ExperimentRequiredCampusId = null,
|
||||||
|
Guid? ExperimentRequiredBuildingId = null);
|
||||||
|
|
||||||
public sealed record TeachingTaskScheduleConstraintBatchRequest(
|
public sealed record TeachingTaskScheduleConstraintBatchRequest(
|
||||||
Guid AcademicTermId,
|
Guid AcademicTermId,
|
||||||
|
|||||||
@@ -581,16 +581,26 @@ public sealed class SchedulesController(
|
|||||||
x => x.Id == request.ClassroomId && x.IsEnabled,
|
x => x.Id == request.ClassroomId && x.IsEnabled,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
if (classroom is null) return ValidationProblem("所选教室不存在或已停用。");
|
if (classroom is null) return ValidationProblem("所选教室不存在或已停用。");
|
||||||
if (constraint?.RequiredCampusId is Guid campusId &&
|
if (request.Kind != ScheduleEntryKind.Experiment &&
|
||||||
|
constraint?.RequiredCampusId is Guid campusId &&
|
||||||
classroom.Building!.CampusId != campusId)
|
classroom.Building!.CampusId != campusId)
|
||||||
return ValidationProblem("所选教室不在该课程指定的校区。");
|
return ValidationProblem("所选教室不在该课程指定的校区。");
|
||||||
if (constraint?.RequiredBuildingId is Guid buildingId &&
|
if (request.Kind != ScheduleEntryKind.Experiment &&
|
||||||
|
constraint?.RequiredBuildingId is Guid buildingId &&
|
||||||
classroom.BuildingId != buildingId)
|
classroom.BuildingId != buildingId)
|
||||||
return ValidationProblem("所选教室不在该课程指定的教学楼。");
|
return ValidationProblem("所选教室不在该课程指定的教学楼。");
|
||||||
|
if (request.Kind == ScheduleEntryKind.Experiment &&
|
||||||
|
constraint?.ExperimentRequiredCampusId is Guid experimentCampusId &&
|
||||||
|
classroom.Building!.CampusId != experimentCampusId)
|
||||||
|
return ValidationProblem("所选场地不在该实验课指定的校区。");
|
||||||
|
if (request.Kind == ScheduleEntryKind.Experiment &&
|
||||||
|
constraint?.ExperimentRequiredBuildingId is Guid experimentBuildingId &&
|
||||||
|
classroom.BuildingId != experimentBuildingId)
|
||||||
|
return ValidationProblem("所选场地不在该实验课指定的教学楼。");
|
||||||
var allowedClassroomIds = constraint?.AllowedClassrooms
|
var allowedClassroomIds = constraint?.AllowedClassrooms
|
||||||
.Select(x => x.ClassroomId)
|
.Select(x => x.ClassroomId)
|
||||||
.ToHashSet() ?? [];
|
.ToHashSet() ?? [];
|
||||||
if (allowedClassroomIds.Count > 0 &&
|
if (request.Kind != ScheduleEntryKind.Experiment && allowedClassroomIds.Count > 0 &&
|
||||||
!allowedClassroomIds.Contains(classroom.Id))
|
!allowedClassroomIds.Contains(classroom.Id))
|
||||||
return ValidationProblem("所选教室不在该课程指定的教室范围内。");
|
return ValidationProblem("所选教室不在该课程指定的教室范围内。");
|
||||||
if (request.Kind == ScheduleEntryKind.Experiment &&
|
if (request.Kind == ScheduleEntryKind.Experiment &&
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ public sealed class TeachingTaskScheduleConstraint : EntityBase
|
|||||||
public Campus? RequiredCampus { get; set; }
|
public Campus? RequiredCampus { get; set; }
|
||||||
public Guid? RequiredBuildingId { get; set; }
|
public Guid? RequiredBuildingId { get; set; }
|
||||||
public Building? RequiredBuilding { get; set; }
|
public Building? RequiredBuilding { get; set; }
|
||||||
|
public Guid? ExperimentRequiredCampusId { get; set; }
|
||||||
|
public Campus? ExperimentRequiredCampus { get; set; }
|
||||||
|
public Guid? ExperimentRequiredBuildingId { get; set; }
|
||||||
|
public Building? ExperimentRequiredBuilding { get; set; }
|
||||||
public string? AllowedDayOfWeeks { get; set; }
|
public string? AllowedDayOfWeeks { get; set; }
|
||||||
public int? EarliestPeriod { get; set; }
|
public int? EarliestPeriod { get; set; }
|
||||||
public int? LatestPeriod { get; set; }
|
public int? LatestPeriod { get; set; }
|
||||||
|
|||||||
Loaded 3 of 11 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user