把 XH巡课 的当前可运行版本放进仓库,方便后续继续改并同步。

This commit is contained in:
itxiaohui committed 2026-11-21 12:31:01 +08:00
commit 6e5107f1b6
134 files changed
+11284

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
# 用已启动的后端跑通建校、审核、开播和权限隔离。Java 仍在容器内。
$ErrorActionPreference = "Stop"
$base = "http://localhost:8080/api"
function Api($method, $path, $body, $token) {
$headers = @{ "X-XH-Request" = "1" }
if ($token) { $headers.Authorization = "Bearer $token" }
$params = @{ Method = $method; Uri = "$base$path"; Headers = $headers }
if ($null -ne $body) { $params.Body = ($body | ConvertTo-Json -Compress); $params.ContentType = "application/json" }
return Invoke-RestMethod @params
}
$stamp = Get-Date -Format "HHmmss"
$admin = Api POST "/auth/login" @{ account = "admin"; password = "ChangeMe_Admin_2026!" } $null
$adminToken = $admin.data.accessToken
if (-not $adminToken) { throw "管理员登录失败" }
$school = Api POST "/schools" @{ name = "实验小学$stamp"; code = "EXP$stamp"; liveEnabled = $true; recordEnabled = $true } $adminToken
$schoolId = $school.data.id
$grade = Api POST "/grades" @{ schoolId = $schoolId; name = "一年级"; sortOrder = 1 } $adminToken
$class = Api POST "/classes" @{ schoolId = $schoolId; gradeId = $grade.data.id; name = "1班" } $adminToken
$teacher = Api POST "/users" @{ username = "teacher$stamp"; displayName = "张老师"; password = "Teacher123"; schoolId = $schoolId; role = "TEACHER" } $adminToken
Api POST "/classes/$($class.data.id)/teachers" @{ teacherId = $teacher.data.id; subject = "语文"; head = $true } $adminToken | Out-Null
$student = Api POST "/students" @{ classId = $class.data.id; name = "小明"; studentNo = "S$stamp" } $adminToken
$course = Api POST "/courses" @{ classId = $class.data.id; teacherId = $teacher.data.id; name = "语文"; allowLive = $true; allowRecord = $true } $adminToken
$reg = Api POST "/auth/register" @{ username = "parent$stamp"; displayName = "明爸"; email = "parent$stamp@example.com"; phone = "138$stamp"; password = "Parent123" } $null
if ($reg.data.status -ne "PENDING") { throw "注册后不应直接激活" }
$pendingLogin = $false
try { Api POST "/auth/login" @{ account = "parent$stamp"; password = "Parent123" } $null | Out-Null } catch { $pendingLogin = $true }
if (-not $pendingLogin) { throw "待审核家长不应登录" }
$users = Api GET "/users?status=PENDING" $null $adminToken
$parent = $users.data.items | Where-Object { $_.username -eq "parent$stamp" }
Api POST "/users/$($parent.id)/review" @{ approve = $true; note = "身份已核" } $adminToken | Out-Null
$parentLogin = Api POST "/auth/login" @{ account = "parent$stamp"; password = "Parent123" } $null
$parentToken = $parentLogin.data.accessToken
$denied = $false
try { Api POST "/schools" @{ name = "越权"; code = "NOPE" } $parentToken | Out-Null } catch { $denied = $true }
if (-not $denied) { throw "家长不应能创建学校" }
$bind = Api POST "/bindings" @{ classId = $class.data.id; studentNo = "S$stamp"; studentName = "小明"; relationship = "父亲"; requestLive = $true; requestReplay = $true } $parentToken
Api POST "/bindings/$($bind.data.id)/review" @{ approve = $true; liveGranted = $true; replayGranted = $false; note = "先开直播" } $adminToken | Out-Null
$teacherLogin = Api POST "/auth/login" @{ account = "teacher$stamp"; password = "Teacher123" } $null
$teacherToken = $teacherLogin.data.accessToken
$live = Api POST "/live/sessions" @{ classId = $class.data.id; courseId = $course.data.id; videoDevice = "cam"; audioDevice = "mic" } $teacherToken
if ($live.data.session.status -ne "PREPARING") { throw "未确认推流前不能是直播中" }
$early = $false
try { Api POST "/live/sessions/$($live.data.session.id)/token" @{ publish = $false } $parentToken | Out-Null } catch { $early = $true }
if (-not $early) { throw "未开播时家长不应拿到播放令牌" }
Api POST "/live/sessions/$($live.data.session.id)/ack" $null $teacherToken | Out-Null
$token = Api POST "/live/sessions/$($live.data.session.id)/token" @{ publish = $false } $parentToken
if ($token.data.role -ne "SUBSCRIBE") { throw "家长令牌必须是订阅" }
Api POST "/live/sessions/$($live.data.session.id)/stop" @{ reason = "MANUAL" } $teacherToken | Out-Null
Api PUT "/admin/settings" @{ "reg.enabled" = "false" } $adminToken | Out-Null
$closed = $false
try { Api POST "/auth/register" @{ username = "closed$stamp"; displayName = "乙"; email = "closed$stamp@example.com"; password = "Parent123" } $null | Out-Null } catch { $closed = $true }
if (-not $closed) { throw "关闭注册后仍能注册" }
$dash = Api GET "/dashboard" $null $adminToken
Write-Output "ACCEPTANCE_OK school=$schoolId class=$($class.data.id) course=$($course.data.id) users=$($dash.data.users) liveToday=$($dash.data.liveToday)"
+23
View File
@@ -0,0 +1,23 @@
# 对已登录的管理接口做小规模并发,记录成功数和耗时。这不是 300 路直播测试。
$ErrorActionPreference = "Stop"
$login = Invoke-RestMethod -Method POST -Uri "http://localhost:8080/api/auth/login" -ContentType "application/json" -Headers @{ "X-XH-Request" = "1" } -Body '{"account":"admin","password":"ChangeMe_Admin_2026!"}'
$token = $login.data.accessToken
$jobs = 1..50 | ForEach-Object {
Start-Job -ScriptBlock {
param($token)
$watch = [Diagnostics.Stopwatch]::StartNew()
try {
Invoke-RestMethod -Method GET -Uri "http://localhost:8080/api/dashboard" -Headers @{ Authorization = "Bearer $token"; "X-XH-Request" = "1" } | Out-Null
"ok $($watch.ElapsedMilliseconds)"
} catch {
"fail $($watch.ElapsedMilliseconds)"
}
} -ArgumentList $token
}
$results = $jobs | Wait-Job | Receive-Job
$jobs | Remove-Job | Out-Null
$ok = @($results | Where-Object { $_ -like "ok *" })
$times = $ok | ForEach-Object { [int]($_ -split " ")[1] }
$sorted = $times | Sort-Object
$p95 = if ($sorted.Count -gt 0) { $sorted[[Math]::Min($sorted.Count - 1, [Math]::Floor($sorted.Count * 0.95))] } else { 0 }
Write-Output "LOAD_OK success=$($ok.Count) fail=$($results.Count - $ok.Count) max=$($sorted[-1]) p95=$p95"
+17
View File
@@ -0,0 +1,17 @@
# Java 只在这个容器里运行,不安装到 Windows。
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$MavenArgs
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $PSScriptRoot
$backend = Join-Path $root "backend"
if (-not $MavenArgs -or $MavenArgs.Count -eq 0) {
$MavenArgs = @("test")
}
docker run --rm `
-v "${backend}:/app" `
-v xuenke-m2:/root/.m2 `
-w /app `
maven:3.9.11-eclipse-temurin-21 `
mvn -B @MavenArgs