|
@@ -0,0 +1,503 @@
|
|
|
|
|
+<#
|
|
|
|
|
+.SYNOPSIS
|
|
|
|
|
+ 健康服务人员助手 · M5 上线试点 · 端到端冒烟脚本(backend-engineer 产出)
|
|
|
|
|
+
|
|
|
|
|
+.DESCRIPTION
|
|
|
|
|
+ 配套 docs/M5_seed.sql 使用:先在试点库执行种子,再启动后端(STORAGE_TYPE=local),最后跑本脚本。
|
|
|
|
|
+ 覆盖 12 步全链路:管理端登录 → 机构核验 → 身份自举+加成员 → 建批次/发布 → 报名 → 发码签到
|
|
|
|
|
+ → 学时补跑 → 学时台账 → 派单建单(建单留痕)→ 指派(资质闸口放行/拒绝)→ 四层评价 → 晋升 + 证据包。
|
|
|
|
|
+
|
|
|
|
|
+.NOTES
|
|
|
|
|
+ 1) 毕业口径红线:学时一律「分钟」整数(120 而非 2.0),本脚本在 S6/S8 强校验。
|
|
|
|
|
+ 2) 登录自举:wechat test-mode(application.yml wechat.test-mode=true)下 openid = 'test_' + code,
|
|
|
|
|
+ 命中 seed 预置的 test_m5t1 / test_m5none / test_m5stu 三个用户,无需人工取 userId。
|
|
|
|
|
+ 3) 组织派单只走 assign,不调 /api/order/accept —— claimOrder 的 CAS 是
|
|
|
|
|
+ `status='pending' AND worker_id=#{userId}`,语义为「自接单」(建单时 worker_id 已=self);
|
|
|
|
|
+ 组织建单 worker_id=NULL,assignOrder 指派即置 accepted,不存在 accept 窗口(Q2 裁决:不改)。
|
|
|
|
|
+ 4) STORAGE_TYPE=local:默认 storage.type=jdcloud 会写生产 OSS bucket「aimate」;
|
|
|
|
|
+ 冒烟/测试启动必须 STORAGE_TYPE=local 让证据包落 ./uploads,严禁污染生产 OSS。
|
|
|
|
|
+ 5) 兼容 PowerShell 5.1,仅依赖 Invoke-RestMethod(不依赖 curl.exe / PS7)。
|
|
|
|
|
+
|
|
|
|
|
+.EXAMPLE
|
|
|
|
|
+ powershell -ExecutionPolicy Bypass -File docs/M5_smoke.ps1 -BaseUrl http://127.0.0.1:9083
|
|
|
|
|
+#>
|
|
|
|
|
+[CmdletBinding()]
|
|
|
|
|
+param(
|
|
|
|
|
+ [string]$BaseUrl = 'http://127.0.0.1:9083',
|
|
|
|
|
+ # 管理端账号(DatabaseInitializer 启动自举 admin/admin123)
|
|
|
|
|
+ [string]$AdminUser = 'admin',
|
|
|
|
|
+ [string]$AdminPass = 'admin123',
|
|
|
|
|
+ # 服务人员/学员 userId(可选)。留空 = 由 wechat-login 自举自动发现(推荐,配合 seed)。
|
|
|
|
|
+ # 如需显式注入(部署时替换 token 占位,勿留假 id):
|
|
|
|
|
+ # -T1WorkerUserId :T1_WORKER_USER_ID: -NoneWorkerUserId :NONE_WORKER_USER_ID: -StudentUserId :STUDENT_USER_ID:
|
|
|
|
|
+ [string]$T1WorkerUserId = '',
|
|
|
|
|
+ [string]$NoneWorkerUserId = '',
|
|
|
|
|
+ [string]$StudentUserId = '',
|
|
|
|
|
+ # 证据包轮询
|
|
|
|
|
+ [int]$PollTimes = 10,
|
|
|
|
|
+ [int]$PollIntervalSec = 2
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+$ErrorActionPreference = 'Stop'
|
|
|
|
|
+$script:BaseUrl = $BaseUrl
|
|
|
|
|
+$script:Step = 0
|
|
|
|
|
+$script:FailCount = 0
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# helpers
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+function Invoke-Api {
|
|
|
|
|
+ <# 统一 API 调用。后端契约:HTTP 200 + body{code,message,data},业务失败 code!=200。
|
|
|
|
|
+ 鉴权:Authorization 头直接放 token(admin token 已带 'admin:' 前缀,user token 为裸 JWT)。#>
|
|
|
|
|
+ param(
|
|
|
|
|
+ [Parameter(Mandatory=$true)][string]$Method,
|
|
|
|
|
+ [Parameter(Mandatory=$true)][string]$Path,
|
|
|
|
|
+ [string]$Token = '',
|
|
|
|
|
+ [object]$Body = $null
|
|
|
|
|
+ )
|
|
|
|
|
+ $url = $script:BaseUrl.TrimEnd('/') + $Path
|
|
|
|
|
+ $headers = @{ 'Accept' = 'application/json' }
|
|
|
|
|
+ if ($Token -ne '') { $headers['Authorization'] = $Token }
|
|
|
|
|
+ $invoke = @{ Uri = $url; Method = $Method; Headers = $headers; UseBasicParsing = $true; TimeoutSec = 30 }
|
|
|
|
|
+ if ($null -ne $Body) {
|
|
|
|
|
+ $invoke['Body'] = $Body | ConvertTo-Json -Depth 20 -Compress
|
|
|
|
|
+ $invoke['ContentType'] = 'application/json; charset=utf-8'
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Invoke-RestMethod @invoke
|
|
|
|
|
+ }
|
|
|
|
|
+ catch {
|
|
|
|
|
+ # HTTP 非 2xx:尝试读响应体(后端可能直接返回 Result JSON)
|
|
|
|
|
+ if ($_.Exception.Response) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $sr = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
|
|
|
|
|
+ $errBody = $sr.ReadToEnd()
|
|
|
|
|
+ if ($errBody) {
|
|
|
|
|
+ $parsed = $errBody | ConvertFrom-Json
|
|
|
|
|
+ if ($null -ne $parsed -and $null -ne $parsed.code) { return $parsed }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {}
|
|
|
|
|
+ }
|
|
|
|
|
+ return [pscustomobject]@{ code = -1; message = ('TRANSPORT_ERROR: ' + $_.Exception.Message); data = $null }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function Get-Arr($v) {
|
|
|
|
|
+ if ($null -eq $v) { return @() }
|
|
|
|
|
+ return @($v)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function Assert-Fail {
|
|
|
|
|
+ <# 断言失败:标红并立即退出(冒烟门禁语义)#>
|
|
|
|
|
+ param([string]$StepName, $Resp, [string]$Detail)
|
|
|
|
|
+ $httpCode = -1
|
|
|
|
|
+ if ($null -ne $Resp -and $null -ne $Resp.code) { $httpCode = [int]$Resp.code }
|
|
|
|
|
+ $msg = '(no message)'
|
|
|
|
|
+ if ($null -ne $Resp -and $null -ne $Resp.message) { $msg = [string]$Resp.message }
|
|
|
|
|
+ Write-Host ("S{0} [FAIL] {1} HTTP={2} {3} | msg={4}" -f $script:Step, $StepName, $httpCode, $Detail, $msg) -ForegroundColor Red
|
|
|
|
|
+ $script:FailCount = $script:FailCount + 1
|
|
|
|
|
+ exit 1
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function Assert-Pass {
|
|
|
|
|
+ param([string]$StepName, $Resp, [string]$Detail)
|
|
|
|
|
+ $httpCode = -1
|
|
|
|
|
+ if ($null -ne $Resp -and $null -ne $Resp.code) { $httpCode = [int]$Resp.code }
|
|
|
|
|
+ Write-Host ("S{0} [PASS] {1} HTTP={2} {3}" -f $script:Step, $StepName, $httpCode, $Detail) -ForegroundColor Green
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function Assert-True {
|
|
|
|
|
+ param([bool]$Cond, [string]$StepName, $Resp, [string]$Detail)
|
|
|
|
|
+ if ($Cond) { Assert-Pass -StepName $StepName -Resp $Resp -Detail $Detail }
|
|
|
|
|
+ else { Assert-Fail -StepName $StepName -Resp $Resp -Detail $Detail }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function Begin-Step([string]$Name) {
|
|
|
|
|
+ $script:Step = $script:Step + 1
|
|
|
|
|
+ Write-Host ("`n===== S{0} {1} =====" -f $script:Step, $Name) -ForegroundColor Cyan
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function Test-MinuteInteger($v) {
|
|
|
|
|
+ <# 分钟整数红线:值必须为非负整数(拒绝小时/浮点/负数)#>
|
|
|
|
|
+ if ($null -eq $v) { return $false }
|
|
|
|
|
+ $n = 0
|
|
|
|
|
+ if (-not [long]::TryParse([string]$v, [ref]$n)) { return $false }
|
|
|
|
|
+ if ($n -lt 0) { return $false }
|
|
|
|
|
+ $d = [double]$v
|
|
|
|
|
+ return ($d -eq [math]::Floor($d))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S1 管理端登录
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '管理端登录 /api/admin/auth/login'
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/auth/login' -Body @{ username = $AdminUser; password = $AdminPass }
|
|
|
|
|
+$adminToken = ''
|
|
|
|
|
+if ($resp.code -eq 200 -and $resp.data -and $resp.data.token) { $adminToken = [string]$resp.data.token }
|
|
|
|
|
+Assert-True ([bool]($resp.code -eq 200 -and $adminToken -ne '')) 'admin login 取 token' $resp ("tokenLen=" + $adminToken.Length)
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S2 机构核验 + 三身份登录自举
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '机构核验 /api/admin/org/list + 身份自举 /api/auth/wechat-login'
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/list' -Token $adminToken -Body @{}
|
|
|
|
|
+Assert-True ($resp.code -eq 200) 'org/list 可用' $resp ''
|
|
|
|
|
+
|
|
|
|
|
+$orgId = $null
|
|
|
|
|
+foreach ($row in (Get-Arr $resp.data.list)) {
|
|
|
|
|
+ if ($row.orgCode -eq 'PILOT-HS-001') { $orgId = [long]$row.id; break }
|
|
|
|
|
+}
|
|
|
|
|
+if ($null -eq $orgId) {
|
|
|
|
|
+ Assert-Fail '捕获种子机构 PILOT-HS-001' $resp '未找到 org_code=PILOT-HS-001,请先执行 docs/M5_seed.sql'
|
|
|
|
|
+}
|
|
|
|
|
+Assert-Pass '捕获种子机构 PILOT-HS-001' $resp ("orgId=" + $orgId)
|
|
|
|
|
+
|
|
|
|
|
+# 身份自举:test-mode openid='test_'+code 命中 seed 预置用户
|
|
|
|
|
+$loginUser = {
|
|
|
|
|
+ param([string]$code)
|
|
|
|
|
+ $r = Invoke-Api -Method 'POST' -Path '/api/auth/wechat-login' -Body @{ code = $code }
|
|
|
|
|
+ if ($r.code -ne 200 -or -not $r.data -or -not $r.data.token -or -not $r.data.userId) {
|
|
|
|
|
+ Assert-Fail ("wechat-login 自举 code=" + $code) $r 'token/userId 缺失'
|
|
|
|
|
+ }
|
|
|
|
|
+ return [pscustomobject]@{ token = [string]$r.data.token; userId = [long]$r.data.userId }
|
|
|
|
|
+}
|
|
|
|
|
+$uT1 = & $loginUser 'm5t1' # T1 已认证服务人员(seed: org_admin)
|
|
|
|
|
+$uNone = & $loginUser 'm5none' # 未认证服务人员(seed: dispatcher)
|
|
|
|
|
+$uStu = & $loginUser 'm5stu' # 培训学员
|
|
|
|
|
+
|
|
|
|
|
+# 显式参数覆盖(部署期注入时以参数为准)
|
|
|
|
|
+if ($T1WorkerUserId -ne '') { $uT1.userId = [long]$T1WorkerUserId }
|
|
|
|
|
+if ($NoneWorkerUserId -ne '') { $uNone.userId = [long]$NoneWorkerUserId }
|
|
|
|
|
+if ($StudentUserId -ne '') { $uStu.userId = [long]$StudentUserId }
|
|
|
|
|
+
|
|
|
|
|
+$t1Token = $uT1.token; $t1UserId = $uT1.userId
|
|
|
|
|
+$noneToken = $uNone.token; $noneUserId = $uNone.userId
|
|
|
|
|
+$stuToken = $uStu.token; $stuUserId = $uStu.userId
|
|
|
|
|
+Assert-Pass '三身份自举 m5t1/m5none/m5stu' $resp ("T1=$t1UserId none=$noneUserId stu=$stuUserId")
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S3 组织加成员(m5t1 以 org_admin 身份自加为 lecturer)
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '组织加成员 /api/admin/org/member/add(org_admin 身份,非 admin token)'
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/member/add' -Token $t1Token -Body @{
|
|
|
|
|
+ orgId = $orgId; userId = $t1UserId; role = 'lecturer'
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200) 'm5t1 自加为 lecturer(幂等 upsert)' $resp ''
|
|
|
|
|
+
|
|
|
|
|
+# member/list 复核
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/member/list' -Token $adminToken -Body @{ orgId = $orgId }
|
|
|
|
|
+$found = $false
|
|
|
|
|
+foreach ($row in (Get-Arr $resp.data)) {
|
|
|
|
|
+ if ([long]$row.userId -eq $t1UserId) { $found = $true; break }
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $found) 'member/list 含 m5t1' $resp ("memberId=" + $t1UserId)
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S4 课程自举 + 建批次 + 发布
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '课程自举 /api/admin/course/list → 建批次 /api/admin/cohort/create → publish'
|
|
|
|
|
+$courseId = $null
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/course/list' -Token $adminToken -Body @{}
|
|
|
|
|
+foreach ($c in (Get-Arr $resp.data)) {
|
|
|
|
|
+ if ($c.level -eq 'L9') { $courseId = [long]$c.id; break }
|
|
|
|
|
+}
|
|
|
|
|
+if ($null -eq $courseId) {
|
|
|
|
|
+ # seed 已建 L9;此处兜底(与 seed 的 uk_level 幂等配合:仅查不到才建)
|
|
|
|
|
+ $resp = Invoke-Api -Method 'POST' -Path '/api/admin/course/create' -Token $adminToken -Body @{
|
|
|
|
|
+ level = 'L9'; name = 'M5试点·健康服务人员认证实训'; status = 'active'
|
|
|
|
|
+ price = 0; memberPrice = 0
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($resp.code -ne 200 -or -not $resp.data -or -not $resp.data.id) {
|
|
|
|
|
+ Assert-Fail 'L9 课程缺失且创建失败' $resp '请确认 docs/M5_seed.sql 已执行'
|
|
|
|
|
+ }
|
|
|
|
|
+ $courseId = [long]$resp.data.id
|
|
|
|
|
+}
|
|
|
|
|
+Assert-Pass 'L9 课程就绪' $resp ("courseId=" + $courseId)
|
|
|
|
|
+
|
|
|
|
|
+$cohortName = 'M5试点-健康服务人员实训批次01'
|
|
|
|
|
+$cohortCode = 'M5-COHORT-001'
|
|
|
|
|
+$cohortId = $null
|
|
|
|
|
+# 先按 courseId 查已有批次(幂等:复用,避免 uk_code 冲突)
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/cohort/list' -Token $adminToken -Body @{ courseId = $courseId; page = 1; size = 20 }
|
|
|
|
|
+foreach ($c in (Get-Arr $resp.data)) {
|
|
|
|
|
+ if ($c.code -eq $cohortCode) { $cohortId = [long]$c.cohortId; break }
|
|
|
|
|
+}
|
|
|
|
|
+if ($null -eq $cohortId) {
|
|
|
|
|
+ # 学时一律分钟整数:理论 2400(=40h)、实践 1200(=20h)
|
|
|
|
|
+ $resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/create' -Token $adminToken -Body @{
|
|
|
|
|
+ courseId = $courseId
|
|
|
|
|
+ name = $cohortName
|
|
|
|
|
+ code = $cohortCode
|
|
|
|
|
+ capacity = 50
|
|
|
|
|
+ place = '浠艾福试点实训基地'
|
|
|
|
|
+ lecturerId = $t1UserId # 讲师=m5t1,供 S6 讲师侧发码走讲师兜底
|
|
|
|
|
+ creditHours = 3600 # 3600 分钟 = 60h
|
|
|
|
|
+ creditTheoryHours = 2400 # 2400 分钟(红线:分钟整数)
|
|
|
|
|
+ creditPracticeHours = 1200 # 1200 分钟(红线:分钟整数)
|
|
|
|
|
+ startAt = '2026-12-01 09:00:00'
|
|
|
|
|
+ endAt = '2026-12-31 18:00:00'
|
|
|
|
|
+ signupDeadline = '2026-11-30 23:59:59'
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($resp.code -ne 200 -or -not $resp.data -or -not $resp.data.cohortId) {
|
|
|
|
|
+ Assert-Fail '建批次失败' $resp ''
|
|
|
|
|
+ }
|
|
|
|
|
+ $cohortId = [long]$resp.data.cohortId
|
|
|
|
|
+}
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/detail' -Token $adminToken -Body @{ cohortId = $cohortId }
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $resp.data) '批次详情可查' $resp ("cohortId=" + $cohortId)
|
|
|
|
|
+$theory = [long]$resp.data.creditTheoryHours
|
|
|
|
|
+$practice = [long]$resp.data.creditPracticeHours
|
|
|
|
|
+Assert-True (($theory -eq 2400) -and ($practice -eq 1200)) '批次学时=理论2400/实践1200(分钟)' $resp ("theory=$theory practice=$practice")
|
|
|
|
|
+
|
|
|
|
|
+if ($resp.data.status -eq 'draft') {
|
|
|
|
|
+ $resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/publish' -Token $adminToken -Body @{ cohortId = $cohortId }
|
|
|
|
|
+ Assert-True ($resp.code -eq 200 -and $resp.data.status -eq 'published') '发布批次 draft→published' $resp ''
|
|
|
|
|
+} else {
|
|
|
|
|
+ Assert-True ($resp.data.status -eq 'published') '批次已处于 published(幂等复用)' $resp ("status=" + $resp.data.status)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S5 学员报名 + 幂等复跑
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '学员报名 /api/cohort/signup(幂等)'
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/cohort/signup' -Token $stuToken -Body @{ cohortId = $cohortId }
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $resp.data) '学员首次报名' $resp ("signupId=" + $resp.data.signupId + " status=" + $resp.data.status)
|
|
|
|
|
+$signupId = [long]$resp.data.signupId
|
|
|
|
|
+
|
|
|
|
|
+# 幂等复跑:二次报名应返回「已报名」的成功体,而非业务报错
|
|
|
|
|
+$resp2 = Invoke-Api -Method 'POST' -Path '/api/cohort/signup' -Token $stuToken -Body @{ cohortId = $cohortId }
|
|
|
|
|
+Assert-True ($resp2.code -eq 200 -and $resp2.data.signupId -eq $signupId) '报名幂等(二次调用返回同 signupId)' $resp2 ("signupId=" + $resp2.data.signupId)
|
|
|
|
|
+
|
|
|
|
|
+# 管理端审核通过 pending→approved(签到前置)
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/auditSignup' -Token $adminToken -Body @{ signupId = $signupId; pass = $true }
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $resp.data.status -eq 'approved') '报名审核 approved' $resp ("status=" + $resp.data.status)
|
|
|
|
|
+
|
|
|
|
|
+# 报名列表复核
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/cohort/signupList' -Token $adminToken -Body @{ cohortId = $cohortId; page = 1; size = 10 }
|
|
|
|
|
+$approvedCnt = 0
|
|
|
|
|
+foreach ($row in (Get-Arr $resp.data.list)) {
|
|
|
|
|
+ if ($row.status -eq 'approved') { $approvedCnt = $approvedCnt + 1 }
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $approvedCnt -ge 1) 'signupList 含 approved' $resp ("approved=" + $approvedCnt)
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S6 发码(讲师侧)+ 学员签到
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '发码 /api/attendance/session/code → 学员签到 /api/attendance/scan'
|
|
|
|
|
+$sessionId = "${cohortId}:1"
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/attendance/session/code' -Token $t1Token -Body @{
|
|
|
|
|
+ sessionId = $sessionId; sessionHours = 120; category = 'theory'
|
|
|
|
|
+}
|
|
|
|
|
+if ($resp.code -ne 200) {
|
|
|
|
|
+ # 兜底:复用历史批次可能未设 lecturerId=m5t1(讲师兜底失效)→ 用 admin 放行
|
|
|
|
|
+ Write-Host ("S{0} [WARN] 讲师发码失败({1}),回退 admin 发码" -f $script:Step, $resp.message) -ForegroundColor Yellow
|
|
|
|
|
+ $resp = Invoke-Api -Method 'POST' -Path '/api/attendance/session/code' -Token $adminToken -Body @{
|
|
|
|
|
+ sessionId = $sessionId; sessionHours = 120; category = 'theory'
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $resp.data -and $resp.data.code) '讲师/组织者发码' $resp ("sessionId=" + $sessionId)
|
|
|
|
|
+$attendCode = [string]$resp.data.code
|
|
|
|
|
+$codeHours = [long]$resp.data.hours
|
|
|
|
|
+Assert-True ($codeHours -eq 120) '签到码 sessionHours=120(分钟整数红线)' $resp ("hours=$codeHours")
|
|
|
|
|
+
|
|
|
|
|
+# 学员扫码签到(幂等):断言 hours=120 且入 pending 台账
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/attendance/scan' -Token $stuToken -Body @{ code = $attendCode }
|
|
|
|
|
+$attHours = if ($resp.data -and $null -ne $resp.data.hours) { [long]$resp.data.hours } else { -1 }
|
|
|
|
|
+$attStatus = if ($resp.data -and $resp.data.status) { [string]$resp.data.status } else { '' }
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $attHours -eq 120) '学员签到 hours=120' $resp ("attendanceId=" + $resp.data.attendanceId + " hours=$attHours status=$attStatus")
|
|
|
|
|
+Assert-True ($attStatus -eq 'pending') '签到台账 status=pending(T+3 生效)' $resp ("status=$attStatus")
|
|
|
|
|
+
|
|
|
|
|
+# 幂等复扫:不重复入账
|
|
|
|
|
+$resp2 = Invoke-Api -Method 'POST' -Path '/api/attendance/scan' -Token $stuToken -Body @{ code = $attendCode }
|
|
|
|
|
+$dupHours = if ($resp2.data -and $null -ne $resp2.data.hours) { [long]$resp2.data.hours } else { -1 }
|
|
|
|
|
+$dupFlag = if ($resp2.data -and $null -ne $resp2.data.alreadyExists) { [bool]$resp2.data.alreadyExists } else { $false }
|
|
|
|
|
+Assert-True ($resp2.code -eq 200 -and $dupHours -eq 120 -and $dupFlag) '签到幂等(alreadyExists=true)' $resp2 ("alreadyExists=$dupFlag")
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S7 admin 补跑学时(T+3 到期生效 + 异议回滚 + cfc 重推)
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step 'admin 补跑 /api/admin/credit/scan'
|
|
|
|
|
+# 注意:签到当刻 effective_at = now + 3 天,补跑不会把新台账置 effective(符合 T+3 设计)。
|
|
|
|
|
+# 本步断言的是「补跑端点可执行、返回计数」,而非 effectiveCount 必须≥1。
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/credit/scan' -Token $adminToken -Body @{}
|
|
|
|
|
+$effCnt = -1
|
|
|
|
|
+if ($resp.code -eq 200 -and $resp.data -and $null -ne $resp.data.effectiveCount) { $effCnt = [long]$resp.data.effectiveCount }
|
|
|
|
|
+Assert-True ($resp.code -eq 200) 'credit/scan 可执行(T+3 未到期容差:effectiveCount 可为 0)' $resp ("effectiveCount=$effCnt")
|
|
|
|
|
+
|
|
|
|
|
+# 待生效台账复核(admin 视角)
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/credit/ledgerPending' -Token $adminToken -Body @{ page = 1; size = 10 }
|
|
|
|
|
+$pendRows = Get-Arr $resp.data.list
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $pendRows.Count -ge 1) 'admin 待生效台账非空' $resp ("rows=" + $pendRows.Count)
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S8 学员查学时(分钟整数红线)
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '学员学时 /api/credit/mine(分钟整数红线)'
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/credit/mine' -Token $stuToken -Body @{}
|
|
|
|
|
+if ($resp.code -ne 200 -or -not $resp.data) { Assert-Fail 'credit/mine 可用' $resp '' }
|
|
|
|
|
+$total = [long]$resp.data.totalHours
|
|
|
|
|
+$theoryH = [long]$resp.data.theoryHours
|
|
|
|
|
+$practice = [long]$resp.data.practiceHours
|
|
|
|
|
+$effH = [long]$resp.data.effectiveHours
|
|
|
|
|
+$pendH = [long]$resp.data.pendingHours
|
|
|
|
|
+$allInt = (Test-MinuteInteger $total) -and (Test-MinuteInteger $theoryH) -and (Test-MinuteInteger $practice) -and (Test-MinuteInteger $effH) -and (Test-MinuteInteger $pendH)
|
|
|
|
|
+Assert-True $allInt '学时五字段均为分钟整数(非小时/浮点)' $resp ("total=$total theory=$theoryH practice=$practice effective=$effH pending=$pendH")
|
|
|
|
|
+Assert-True ($pendH -ge 120) '待生效学时 ≥ 120 分钟(签到入账)' $resp ("pending=$pendH")
|
|
|
|
|
+
|
|
|
|
|
+# 待生效明细
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/credit/pending' -Token $stuToken -Body @{}
|
|
|
|
|
+$ok = $resp.code -eq 200
|
|
|
|
|
+$matched = $false
|
|
|
|
|
+foreach ($row in (Get-Arr $resp.data)) {
|
|
|
|
|
+ if ([long]$row.hours -eq 120 -and $row.status -eq 'pending') { $matched = $true; break }
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($ok -and $matched) 'credit/pending 含 120 分钟 pending 明细' $resp ''
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S9 派单建单(建单留痕:dispatchId 必非空)
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '派单建单 /api/admin/org/dispatch/create(断言 dispatchId 非空)'
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/create' -Token $adminToken -Body @{
|
|
|
|
|
+ orgId = $orgId
|
|
|
|
|
+ familyName = '王阿姨家'
|
|
|
|
|
+ contactPhone = '13900000009'
|
|
|
|
|
+ address = '湖北省黄冈市浠水县试点路 1 号'
|
|
|
|
|
+ serviceType = 'cleaning'
|
|
|
|
|
+ orderDate = '2026-12-05'
|
|
|
|
|
+ amount = 18000 # 整数分
|
|
|
|
|
+ platformFee = 1800 # 整数分
|
|
|
|
|
+ remark = 'M5 冒烟建单'
|
|
|
|
|
+}
|
|
|
|
|
+if ($resp.code -ne 200 -or -not $resp.data) { Assert-Fail '组织建单失败' $resp '' }
|
|
|
|
|
+$orderId = [long]$resp.data.orderId
|
|
|
|
|
+$orderNo = [string]$resp.data.orderNo
|
|
|
|
|
+$dispatchId = $resp.data.dispatchId
|
|
|
|
|
+Assert-True ($null -ne $dispatchId -and [long]$dispatchId -gt 0) '建单留痕 dispatchId 非空(created 行同事务落库)' $resp ("orderId=$orderId orderNo=$orderNo dispatchId=$dispatchId")
|
|
|
|
|
+Assert-True ([string]$resp.data.status -eq 'pending') '建单只置 pending(不置 accepted)' $resp ("status=" + $resp.data.status)
|
|
|
|
|
+
|
|
|
|
|
+# 派单列表可见
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/list' -Token $adminToken -Body @{ orgId = $orgId; page = 1; size = 10 }
|
|
|
|
|
+$seen = $false
|
|
|
|
|
+foreach ($row in (Get-Arr $resp.data.list)) {
|
|
|
|
|
+ if ([long]$row.id -eq $orderId) { $seen = $true; break }
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $seen) 'dispatch/list 可见新单' $resp ''
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S10 指派(资质闸口:m5none 拒绝 / m5t1 放行);只走 assign 不走 accept
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '指派 /api/admin/org/dispatch/assign(资质闸口放行/拒绝)'
|
|
|
|
|
+# 反例:未认证 m5none → 资质不符
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/assign' -Token $adminToken -Body @{
|
|
|
|
|
+ orderId = $orderId; workerId = $noneUserId; serviceType = 'cleaning'
|
|
|
|
|
+}
|
|
|
|
|
+$rejectMsg = if ($resp.message) { [string]$resp.message } else { '' }
|
|
|
|
|
+Assert-True (($resp.code -ne 200) -and ($rejectMsg -match '资质不符')) '未认证 m5none 被资质闸口拒绝' $resp ("msg=$rejectMsg")
|
|
|
|
|
+
|
|
|
|
|
+# 正例:T1 m5t1 → 放行($T1WorkerUserId 空则已由自举补齐,必非空)
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/assign' -Token $adminToken -Body @{
|
|
|
|
|
+ orderId = $orderId; workerId = $t1UserId; serviceType = 'cleaning'; remark = '指派 T1 服务人员'
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and [string]$resp.data.status -eq 'accepted' -and [long]$resp.data.workerId -eq $t1UserId) 'T1 m5t1 指派放行 → accepted' $resp ("workerId=" + $resp.data.workerId + " status=" + $resp.data.status)
|
|
|
|
|
+
|
|
|
|
|
+# 可选服务人员候选(含 m5t1,含 rating=450)
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/org/dispatch/workers' -Token $adminToken -Body @{ orgId = $orgId }
|
|
|
|
|
+$hasT1 = $false
|
|
|
|
|
+foreach ($w in (Get-Arr $resp.data.list)) {
|
|
|
|
|
+ if ([long]$w.userId -eq $t1UserId -and $w.authLevel -eq 'T1') { $hasT1 = $true; break }
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $hasT1) 'workers 候选含 T1 m5t1' $resp ''
|
|
|
|
|
+
|
|
|
|
|
+# 组织派单只走 assign 不调 accept(Q2 裁决:claimOrder 仅自接单场景)
|
|
|
|
|
+# worker 侧可见该单(accepted 分组)
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/order/mine' -Token $t1Token -Body @{}
|
|
|
|
|
+$mineOk = $resp.code -eq 200
|
|
|
|
|
+Assert-True $mineOk 'worker /api/order/mine 可查' $resp ''
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S11 四层评价(机构绩效)
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '机构绩效评价 /api/eval/org → 汇总 /api/eval/mine'
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/eval/org' -Token $t1Token -Body @{
|
|
|
|
|
+ userId = $t1UserId; score = 90; dimension = 'punctuality'; comment = 'M5 冒烟绩效评价'
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $resp.data) 'eval/org 提交' $resp ("evalId=" + $resp.data.evalId)
|
|
|
|
|
+
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/eval/mine' -Token $t1Token -Body @{}
|
|
|
|
|
+$hasComposite = $false
|
|
|
|
|
+$hasOrg = $false
|
|
|
|
|
+if ($resp.code -eq 200 -and $resp.data) {
|
|
|
|
|
+ if ($null -ne $resp.data.PSObject.Properties['composite']) { $hasComposite = $true }
|
|
|
|
|
+ if ($resp.data.org -and [long]$resp.data.org.count -ge 1) { $hasOrg = $true }
|
|
|
|
|
+}
|
|
|
|
|
+$compVal = 0
|
|
|
|
|
+if ($hasComposite) { $compVal = [double]$resp.data.composite }
|
|
|
|
|
+Assert-True ($hasComposite -and $hasOrg -and $compVal -gt 0) 'eval/mine composite>0 且 org 评价计数≥1' $resp ("composite=$compVal")
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# S12 晋升 + 证据包
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Begin-Step '晋升规则/记录 /api/admin/promotion + 闸口 /api/promotion/unlock + 证据包 /api/evidence'
|
|
|
|
|
+
|
|
|
|
|
+# T2 规则(seed 预置:serve_count>=10 且 rating>=450)
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/admin/promotion/rule/list' -Token $adminToken -Body @{ page = 1; size = 20 }
|
|
|
|
|
+$hasT2Rule = $false
|
|
|
|
|
+foreach ($r in (Get-Arr $resp.data.list)) {
|
|
|
|
|
+ if ($r.authLevel -eq 'T2' -and [int]$r.enabled -eq 1) { $hasT2Rule = $true; break }
|
|
|
|
|
+}
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $hasT2Rule) 'T2 晋升规则存在且启用(seed 预置)' $resp ''
|
|
|
|
|
+
|
|
|
|
|
+# T1 晋升断言:rating=450 达标、serve_count 不足 → unmet 应只含 serve_count
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/promotion/apply' -Token $t1Token -Body @{ authLevel = 'T2' }
|
|
|
|
|
+$unmetMetrics = @()
|
|
|
|
|
+if ($resp.code -eq 200 -and $resp.data -and $resp.data.unmet) { $unmetMetrics = Get-Arr $resp.data.unmet | ForEach-Object { [string]$_.metric } }
|
|
|
|
|
+$expectUnmet = ($resp.code -eq 200) -and ($resp.data.eligible -eq $false) -and ($unmetMetrics -contains 'serve_count') -and (-not ($unmetMetrics -contains 'rating'))
|
|
|
|
|
+Assert-True $expectUnmet 'apply T2 未达标:unmet 仅 serve_count(rating 450 已达标)' $resp ("eligible=" + $resp.data.eligible + " unmet=[" + ($unmetMetrics -join ',') + "]")
|
|
|
|
|
+
|
|
|
|
|
+# 晋升履历
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/promotion/records' -Token $t1Token -Body @{ page = 1; size = 10 }
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $null -ne $resp.data) 'promotion/records 可查' $resp ''
|
|
|
|
|
+
|
|
|
|
|
+# 闸口:T1 放行 / 未认证拒绝
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/promotion/unlock' -Token $t1Token -Body @{ serviceType = 'cleaning' }
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $resp.data.allowed -eq $true) 'unlock T1 allowed=true(闸口双值容错放行)' $resp ("authLevel=" + $resp.data.authLevel)
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/promotion/unlock' -Token $noneToken -Body @{ serviceType = 'cleaning' }
|
|
|
|
|
+Assert-True ($resp.code -eq 200 -and $resp.data.allowed -eq $false) 'unlock m5none allowed=false' $resp ("reason=" + $resp.data.reason)
|
|
|
|
|
+
|
|
|
|
|
+# 证据包:发起 + 轮询
|
|
|
|
|
+$resp = Invoke-Api -Method 'POST' -Path '/api/evidence/export' -Token $t1Token -Body @{ type = 'training' }
|
|
|
|
|
+if ($resp.code -ne 200 -or -not $resp.data -or -not $resp.data.taskNo) { Assert-Fail '发起证据包导出失败' $resp '' }
|
|
|
|
|
+$taskNo = [string]$resp.data.taskNo
|
|
|
|
|
+Assert-Pass '发起培训证据包导出' $resp ("taskNo=$taskNo status=" + $resp.data.status)
|
|
|
|
|
+
|
|
|
|
|
+$taskStatus = ''
|
|
|
|
|
+$taskProgress = -1
|
|
|
|
|
+$fileUrl = ''
|
|
|
|
|
+$seenStates = @()
|
|
|
|
|
+for ($i = 0; $i -lt [Math]::Max($PollTimes, 1); $i++) {
|
|
|
|
|
+ Start-Sleep -Seconds $PollIntervalSec
|
|
|
|
|
+ $sr2 = Invoke-Api -Method 'POST' -Path '/api/evidence/status' -Token $t1Token -Body @{ taskNo = $taskNo }
|
|
|
|
|
+ if ($sr2.code -eq 200 -and $sr2.data) {
|
|
|
|
|
+ $taskStatus = [string]$sr2.data.status
|
|
|
|
|
+ $taskProgress = [long]$sr2.data.progress
|
|
|
|
|
+ $fileUrl = if ($sr2.data.fileUrl) { [string]$sr2.data.fileUrl } else { '' }
|
|
|
|
|
+ if (-not ($seenStates -contains $taskStatus)) { $seenStates = $seenStates + $taskStatus }
|
|
|
|
|
+ if ($taskStatus -in @('done', 'failed')) { break }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+$stateOk = ($seenStates.Count -gt 0) -and (($seenStates | Where-Object { $_ -in @('pending','processing','done') }).Count -gt 0)
|
|
|
|
|
+Assert-True $stateOk '证据包状态流转 ∈ {pending,processing,done}' $resp ("seen=[" + ($seenStates -join ',') + "] progress=$taskProgress")
|
|
|
|
|
+if ($taskStatus -eq 'done') {
|
|
|
|
|
+ Assert-True (($taskProgress -eq 100) -and ($fileUrl -ne '')) '证据包 done:progress=100 且 fileUrl 非空' $resp ("fileUrl=$fileUrl")
|
|
|
|
|
+} else {
|
|
|
|
|
+ Write-Host ("S{0} [INFO] 轮询结束时 status={1}(异步导出未完成,不阻断;可手动复跑观察 done)" -f $script:Step, $taskStatus) -ForegroundColor Yellow
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+# 总结
|
|
|
|
|
+# ============================================================
|
|
|
|
|
+Write-Host "`n========================================" -ForegroundColor Cyan
|
|
|
|
|
+Write-Host ("冒烟完成:12 步全部通过(orgId=$orgId cohortId=$cohortId orderId=$orderId dispatchId=$dispatchId)") -ForegroundColor Green
|
|
|
|
|
+Write-Host "关键断言:学时分钟整数 ✓ 建单留痕 dispatchId ✓ 资质闸口放行/拒绝 ✓" -ForegroundColor Green
|
|
|
|
|
+Write-Host "========================================" -ForegroundColor Cyan
|
|
|
|
|
+exit 0
|