实验排课
This commit is contained in:
@@ -27,7 +27,7 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
["classes"] = ["编码", "名称", "所属专业编码", "年级", "辅导员工号", "排序", "状态"],
|
||||
["terms"] = ["编码", "名称", "学年", "学期季", "开始日期", "结束日期", "当前学期", "状态"],
|
||||
["buildings"] = ["编码", "名称", "所属校区编码", "排序", "状态"],
|
||||
["classrooms"] = ["编码", "名称", "所属教学楼编码", "容量", "教室类型", "设备", "排序", "状态"],
|
||||
["classrooms"] = ["编码", "名称", "所属教学楼编码", "容量", "教室类型", "教学场地性质", "设备", "排序", "状态"],
|
||||
["course-categories"] = ["编码", "名称", "排序", "状态"]
|
||||
};
|
||||
|
||||
@@ -70,7 +70,10 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
IReadOnlyList<ExcelRow> rows;
|
||||
try
|
||||
{
|
||||
rows = await ExcelWorkbookHelper.ReadAsync(file, headers, cancellationToken);
|
||||
var requiredHeaders = kind.Equals("classrooms", StringComparison.OrdinalIgnoreCase)
|
||||
? headers.Where(x => x != "教学场地性质").ToArray()
|
||||
: headers;
|
||||
rows = await ExcelWorkbookHelper.ReadAsync(file, requiredHeaders, cancellationToken);
|
||||
}
|
||||
catch (InvalidDataException exception)
|
||||
{
|
||||
@@ -165,6 +168,7 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
"classrooms" => (await db.Classrooms.AsNoTracking().Include(x => x.Building)
|
||||
.OrderBy(x => x.Code).ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.Building!.Code, x.Capacity, x.RoomType,
|
||||
VenueNatureName(x.TeachingVenueNature),
|
||||
x.Equipment, x.SortOrder, Status(x.IsEnabled))).ToList(),
|
||||
"course-categories" => (await db.CourseCategories.AsNoTracking()
|
||||
.OrderBy(x => x.SortOrder).ThenBy(x => x.Code)
|
||||
@@ -473,8 +477,9 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
var buildingCode = Required(row, "所属教学楼编码", errors);
|
||||
var capacity = ParseInt(row, "容量", 1, 1000, errors);
|
||||
var roomType = Required(row, "教室类型", errors);
|
||||
var venueNature = ParseVenueNature(row, roomType, errors);
|
||||
if (code is null || name is null || buildingCode is null ||
|
||||
capacity is null || roomType is null) continue;
|
||||
capacity is null || roomType is null || venueNature is null) continue;
|
||||
if (!buildings.TryGetValue(buildingCode, out var building))
|
||||
{
|
||||
errors.Add($"第 {row.RowNumber} 行:所属教学楼编码“{buildingCode}”不存在。");
|
||||
@@ -488,7 +493,8 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
Code = code,
|
||||
Name = name,
|
||||
BuildingId = building.Id,
|
||||
RoomType = roomType
|
||||
RoomType = roomType,
|
||||
TeachingVenueNature = venueNature.Value
|
||||
};
|
||||
db.Classrooms.Add(entity);
|
||||
existing[code] = entity;
|
||||
@@ -499,6 +505,7 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
entity.BuildingId = building.Id;
|
||||
entity.Capacity = capacity.Value;
|
||||
entity.RoomType = roomType;
|
||||
entity.TeachingVenueNature = venueNature.Value;
|
||||
entity.Equipment = Optional(row, "设备");
|
||||
}
|
||||
return new(created, updated, rows.Count);
|
||||
@@ -597,6 +604,57 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
return true;
|
||||
}
|
||||
|
||||
private static TeachingVenueNature? ParseVenueNature(
|
||||
ExcelRow row,
|
||||
string? roomType,
|
||||
List<string> errors)
|
||||
{
|
||||
var value = Optional(row, "教学场地性质");
|
||||
if (value is null) return InferVenueNature(roomType ?? string.Empty);
|
||||
var result = (TeachingVenueNature)0;
|
||||
foreach (var part in value.Split(['、', ',', ',', ';', ';'],
|
||||
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
result |= part switch
|
||||
{
|
||||
"普通教室" => TeachingVenueNature.GeneralClassroom,
|
||||
"实验室" => TeachingVenueNature.Laboratory,
|
||||
"实训室" => TeachingVenueNature.TrainingRoom,
|
||||
"计算机机房" or "机房" => TeachingVenueNature.ComputerLab,
|
||||
"语音室" => TeachingVenueNature.LanguageLab,
|
||||
"体育场地" => TeachingVenueNature.SportsVenue,
|
||||
"艺术场地" => TeachingVenueNature.ArtsVenue,
|
||||
_ => (TeachingVenueNature)0
|
||||
};
|
||||
if (part is not ("普通教室" or "实验室" or "实训室" or "计算机机房" or "机房" or "语音室" or "体育场地" or "艺术场地"))
|
||||
errors.Add($"第 {row.RowNumber} 行:“教学场地性质”包含不支持的值“{part}”。");
|
||||
}
|
||||
return result == 0 ? null : result;
|
||||
}
|
||||
|
||||
private static TeachingVenueNature InferVenueNature(string roomType) =>
|
||||
roomType.Contains("机房", StringComparison.OrdinalIgnoreCase)
|
||||
? TeachingVenueNature.Laboratory | TeachingVenueNature.ComputerLab
|
||||
: roomType.Contains("语音", StringComparison.OrdinalIgnoreCase)
|
||||
? TeachingVenueNature.Laboratory | TeachingVenueNature.LanguageLab
|
||||
: roomType.Contains("实训", StringComparison.OrdinalIgnoreCase)
|
||||
? TeachingVenueNature.TrainingRoom
|
||||
: roomType.Contains("实验", StringComparison.OrdinalIgnoreCase)
|
||||
? TeachingVenueNature.Laboratory
|
||||
: TeachingVenueNature.GeneralClassroom;
|
||||
|
||||
private static string VenueNatureName(TeachingVenueNature value) => string.Join("、",
|
||||
new[]
|
||||
{
|
||||
(TeachingVenueNature.GeneralClassroom, "普通教室"),
|
||||
(TeachingVenueNature.Laboratory, "实验室"),
|
||||
(TeachingVenueNature.TrainingRoom, "实训室"),
|
||||
(TeachingVenueNature.ComputerLab, "计算机机房"),
|
||||
(TeachingVenueNature.LanguageLab, "语音室"),
|
||||
(TeachingVenueNature.SportsVenue, "体育场地"),
|
||||
(TeachingVenueNature.ArtsVenue, "艺术场地")
|
||||
}.Where(x => (value & x.Item1) != 0).Select(x => x.Item2));
|
||||
|
||||
private static bool ParseBoolean(
|
||||
ExcelRow row, string header, bool defaultValue, List<string> errors)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user