You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
3.4 KiB

1 week ago
$ErrorActionPreference = 'Continue'
[Console]::OutputEncoding = [Text.Encoding]::UTF8
$base = 'http://localhost:8080'
$outDir = '.scratch\opportunity-e2e\env-raw'
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
function Save-Json($name, $obj) {
$obj | ConvertTo-Json -Depth 8 | Out-File -FilePath (Join-Path $outDir ("{0}.json" -f $name)) -Encoding utf8
Write-Host ("saved {0}" -f $name)
}
# 1. debug token(上轮默认 userId)
$uid = '739564171091247104'
$r = Invoke-RestMethod -Uri ("$base/api/auth/debug/token?userId=$uid")
$token = if ($r.data -is [string]) { $r.data } else { $r.data.token }
$h = @{ Authorization = "Bearer $token" }
Write-Host ("token ok, len={0}" -f $token.Length)
# 2. me(不猜字段,原样落盘+打印)
$me = Invoke-RestMethod -Uri "$base/api/auth/me" -Headers $h
Save-Json 'me' $me
Write-Host ("me.data = {0}" -f ($me.data | ConvertTo-Json -Depth 4 -Compress))
# 3. 部门树
try { $depts = Invoke-RestMethod -Uri "$base/api/system/depts/tree" -Headers $h; Save-Json 'depts' $depts } catch { Write-Host ("depts FAIL: {0}" -f $_.Exception.Message) }
# 4. 字典:启用分组 + 各组启用项
try {
$groups = Invoke-RestMethod -Uri "$base/api/dict/group/enabled-list" -Headers $h
Save-Json 'dict-groups' $groups
$dictItems = @{}
foreach ($g in $groups.data) {
try {
$items = Invoke-RestMethod -Uri ("$base/api/dict/item/enabled-list?groupCode={0}" -f [uri]::EscapeDataString([string]$g.groupCode)) -Headers $h
$dictItems[[string]$g.groupCode] = $items.data
} catch { Write-Host ("item FAIL {0}: {1}" -f $g.groupCode, $_.Exception.Message) }
}
Save-Json 'dict-items' $dictItems
Write-Host ("dict groups enabled = {0}" -f $groups.data.Count)
} catch { Write-Host ("dict FAIL: {0}" -f $_.Exception.Message) }
# 5. 用户分页(需 ADMIN;403 则记录,后续换路径)
try {
$users = Invoke-RestMethod -Uri "$base/api/system/users/page" -Method Post -Headers $h -Body @{ pageNum = 1; pageSize = 200 } -ContentType 'application/x-www-form-urlencoded'
Save-Json 'users' $users
Write-Host ("users total = {0}" -f $users.data.total)
} catch { Write-Host ("users/page FAIL: {0}" -f $_.Exception.Message) }
# 6. 商机六视图分页(pageSize=200 拉全量本地统计)
foreach ($v in @('RECENT','MINE','PARTICIPATED','FOLLOWED','MANAGE','PUBLIC_POOL')) {
try {
$p = Invoke-RestMethod -Uri "$base/api/opportunity/page" -Method Post -Headers $h -Body @{ viewType = $v; pageNum = 1; pageSize = 200 } -ContentType 'application/x-www-form-urlencoded'
Save-Json ("opp-page-{0}" -f $v) $p
$stat = ($p.data.list | Group-Object oppStatus | ForEach-Object { "s{0}x{1}" -f $_.Name, $_.Count }) -join ' '
Write-Host ("view {0}: total={1} [{2}]" -f $v, $p.data.total, $stat)
} catch { Write-Host ("opp {0} FAIL: {1}" -f $v, $_.Exception.Message) }
}
# 7. 规则三族分页
foreach ($f in @('opp-stage-template','opp-scheme-template','opp-pool-rule')) {
try {
$p = Invoke-RestMethod -Uri ("$base/api/rule/{0}/page" -f $f) -Method Post -Headers $h -Body @{ pageNum = 1; pageSize = 50 } -ContentType 'application/x-www-form-urlencoded'
Save-Json ("rule-{0}" -f $f) $p
$names = ($p.data.list | ForEach-Object { "{0}(v{1})" -f $_.code, $_.versionNo }) -join ', '
Write-Host ("rule {0}: total={1} [{2}]" -f $f, $p.data.total, $names)
} catch { Write-Host ("rule {0} FAIL: {1}" -f $f, $_.Exception.Message) }
}
Write-Host 'DONE'