课程库 Excel 导入导出已完成:
支持下载标准导入模板。 导出严格沿用当前关键词、学院、分类、课程性质和状态筛选。 以课程编码为唯一键:存在则更新,不存在则新增。 校验学院编码、课程分类、课程性质、学分学时及考核方式。 整批原子导入,任一行错误则全部不写入,并提示具体行号。 学院管理员仍只能维护本学院的专业课和实践课,无法借 Excel 越权。 界面入口沿用现有课程库工具栏样式。
This commit is contained in:
@@ -26,7 +26,8 @@ public sealed class BaseDataExcelController(AppDbContext db) : ControllerBase
|
||||
["classes"] = ["编码", "名称", "所属专业编码", "年级", "辅导员工号", "排序", "状态"],
|
||||
["terms"] = ["编码", "名称", "学年", "学期季", "开始日期", "结束日期", "当前学期", "状态"],
|
||||
["buildings"] = ["编码", "名称", "所属校区编码", "排序", "状态"],
|
||||
["classrooms"] = ["编码", "名称", "所属教学楼编码", "容量", "教室类型", "设备", "排序", "状态"]
|
||||
["classrooms"] = ["编码", "名称", "所属教学楼编码", "容量", "教室类型", "设备", "排序", "状态"],
|
||||
["course-categories"] = ["编码", "名称", "排序", "状态"]
|
||||
};
|
||||
|
||||
[HttpGet("{kind}/template")]
|
||||
@@ -90,6 +91,8 @@ public sealed class BaseDataExcelController(AppDbContext db) : ControllerBase
|
||||
"terms" => await ImportTermsAsync(rows, errors, cancellationToken),
|
||||
"buildings" => await ImportBuildingsAsync(rows, errors, cancellationToken),
|
||||
"classrooms" => await ImportClassroomsAsync(rows, errors, cancellationToken),
|
||||
"course-categories" => await ImportCourseCategoriesAsync(
|
||||
rows, errors, cancellationToken),
|
||||
_ => throw new InvalidOperationException()
|
||||
};
|
||||
|
||||
@@ -147,6 +150,10 @@ public sealed class BaseDataExcelController(AppDbContext db) : ControllerBase
|
||||
.OrderBy(x => x.Code).ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.Building!.Code, x.Capacity, x.RoomType,
|
||||
x.Equipment, x.SortOrder, Status(x.IsEnabled))).ToList(),
|
||||
"course-categories" => (await db.CourseCategories.AsNoTracking()
|
||||
.OrderBy(x => x.SortOrder).ThenBy(x => x.Code)
|
||||
.ToListAsync(cancellationToken))
|
||||
.Select(x => Row(x.Code, x.Name, x.SortOrder, Status(x.IsEnabled))).ToList(),
|
||||
_ => []
|
||||
};
|
||||
|
||||
@@ -471,6 +478,36 @@ public sealed class BaseDataExcelController(AppDbContext db) : ControllerBase
|
||||
return new(created, updated, rows.Count);
|
||||
}
|
||||
|
||||
private async Task<ExcelImportResult> ImportCourseCategoriesAsync(
|
||||
IReadOnlyList<ExcelRow> rows,
|
||||
List<string> errors,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var existing = await db.CourseCategories.ToDictionaryAsync(
|
||||
x => x.Code,
|
||||
StringComparer.OrdinalIgnoreCase,
|
||||
cancellationToken);
|
||||
var created = 0;
|
||||
var updated = 0;
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var code = Required(row, "编码", errors);
|
||||
var name = Required(row, "名称", errors);
|
||||
if (code is null || name is null) continue;
|
||||
var entity = existing.GetValueOrDefault(code);
|
||||
if (entity is null)
|
||||
{
|
||||
entity = new CourseCategory { Code = code, Name = name };
|
||||
db.CourseCategories.Add(entity);
|
||||
existing[code] = entity;
|
||||
created++;
|
||||
}
|
||||
else updated++;
|
||||
ApplyCatalog(entity, row, name, errors);
|
||||
}
|
||||
return new(created, updated, rows.Count);
|
||||
}
|
||||
|
||||
private ActionResult ImportValidationProblem(IReadOnlyList<string> errors)
|
||||
{
|
||||
foreach (var error in errors.Take(50))
|
||||
@@ -582,6 +619,7 @@ public sealed class BaseDataExcelController(AppDbContext db) : ControllerBase
|
||||
"terms" => "学期",
|
||||
"buildings" => "教学楼",
|
||||
"classrooms" => "教室",
|
||||
"course-categories" => "课程分类",
|
||||
_ => "基础数据"
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user