课程库 Excel 导入导出已完成:

支持下载标准导入模板。
导出严格沿用当前关键词、学院、分类、课程性质和状态筛选。
以课程编码为唯一键:存在则更新,不存在则新增。
校验学院编码、课程分类、课程性质、学分学时及考核方式。
整批原子导入,任一行错误则全部不写入,并提示具体行号。
学院管理员仍只能维护本学院的专业课和实践课,无法借 Excel 越权。
界面入口沿用现有课程库工具栏样式。
This commit is contained in:
2026-07-24 18:56:25 +08:00 Unverified
parent 5a7a8d530b
commit d7cf3f9e76
24 changed files with 3710 additions and 32 deletions
+38
View File
@@ -20,6 +20,9 @@ else {
}
$stdoutPath = Join-Path $env:TEMP 'jiaowu-api-smoke.out.log'
$stderrPath = Join-Path $env:TEMP 'jiaowu-api-smoke.err.log'
$courseExcelToken = [guid]::NewGuid().ToString('N')
$courseTemplatePath = Join-Path $env:TEMP "jiaowu-course-template-$courseExcelToken.xlsx"
$courseExportPath = Join-Path $env:TEMP "jiaowu-course-export-$courseExcelToken.xlsx"
$env:ASPNETCORE_ENVIRONMENT = 'Development'
$env:ASPNETCORE_URLS = 'http://localhost:5255'
$startParameters = @{
@@ -78,6 +81,37 @@ try {
$teachers = Invoke-RestMethod -Uri 'http://localhost:5255/api/personnel/teachers?page=1&pageSize=10' -Headers $headers
$students = Invoke-RestMethod -Uri 'http://localhost:5255/api/personnel/students?page=1&pageSize=10' -Headers $headers
$courses = Invoke-RestMethod -Uri 'http://localhost:5255/api/courses?page=1&pageSize=10' -Headers $headers
$courseCategories = Invoke-RestMethod `
-Uri 'http://localhost:5255/api/base-data/course-categories' `
-Headers $headers
if (@($courseCategories).Count -lt 10 -or
@($courses.items | Where-Object { $null -eq $_.courseCategoryId }).Count -gt 0) {
throw 'Course categories were not seeded or assigned to all courses.'
}
Invoke-WebRequest `
-Uri 'http://localhost:5255/api/courses/template' `
-Headers $headers `
-OutFile $courseTemplatePath |
Out-Null
Invoke-WebRequest `
-Uri 'http://localhost:5255/api/courses/export' `
-Headers $headers `
-OutFile $courseExportPath |
Out-Null
if ((Get-Item -LiteralPath $courseTemplatePath).Length -lt 1 -or
(Get-Item -LiteralPath $courseExportPath).Length -lt 1) {
throw 'Course Excel template or export is empty.'
}
$courseImport = Invoke-RestMethod `
-Method Post `
-Uri 'http://localhost:5255/api/courses/import' `
-Headers $headers `
-Form @{ file = Get-Item -LiteralPath $courseExportPath }
if ($courseImport.created -ne 0 -or
$courseImport.updated -ne $courses.total -or
$courseImport.total -ne $courses.total) {
throw 'Course Excel round-trip did not update the expected records.'
}
$curriculumPlans = Invoke-RestMethod -Uri 'http://localhost:5255/api/curriculum-plans?page=1&pageSize=10' -Headers $headers
if ($curriculumPlans.total -gt 0) {
$curriculumDetail = Invoke-RestMethod `
@@ -757,6 +791,8 @@ try {
Teachers = $teachers.total
Students = $students.total
Courses = $courses.total
CourseCategories = @($courseCategories).Count
CourseExcelRows = $courseImport.total
Plans = $curriculumPlans.total
PlanModules = if ($null -ne $curriculumDetail) { @($curriculumDetail.modules).Count } else { 0 }
TeachingTasks = $teachingTasks.total
@@ -790,4 +826,6 @@ finally {
if (-not $process.HasExited) {
Stop-Process -Id $process.Id -Force
}
Remove-Item -LiteralPath $courseTemplatePath -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $courseExportPath -Force -ErrorAction SilentlyContinue
}