Files
ccdi/test/test_employee_api.ps1
wkc 0cc8ef0fc3 员工信息管理
- 新增员工信息CRUD功能
- 添加员工关联人员管理
- 配置MyBatis Plus审计字段
- 添加OpenSpec规范文档
- 新增测试脚本和数据

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-28 14:40:27 +08:00

120 lines
3.9 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 员工信息管理 API 测试脚本
# 需要使用 UTF-8 with BOM 编码保存
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$BASE_URL = "http://localhost:8080"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "员工信息管理 API 测试脚本" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 1. 登录获取 Token
Write-Host "[1] 正在登录..." -ForegroundColor Yellow
$loginBody = @{
username = "admin"
password = "admin123"
} | ConvertTo-Json
$loginResponse = Invoke-RestMethod -Uri "$BASE_URL/login/test" -Method Post -ContentType "application/json; charset=utf-8" -Body ([System.Text.Encoding]::UTF8.GetBytes($loginBody))
$TOKEN = $loginResponse.token
if ([string]::IsNullOrEmpty($TOKEN)) {
Write-Host "[错误] 获取 Token 失败,请检查登录接口" -ForegroundColor Red
Read-Host "按回车键退出"
exit 1
}
Write-Host "登录成功Token: $TOKEN" -ForegroundColor Green
Write-Host ""
# 2. 测试查询员工列表
Write-Host "[2] 测试查询员工列表..." -ForegroundColor Yellow
$headers = @{
"Authorization" = "Bearer $TOKEN"
}
$response = Invoke-RestMethod -Uri "$BASE_URL/dpc/employee/list" -Method Get -Headers $headers
Write-Host ($response | ConvertTo-Json -Depth 10)
Write-Host ""
# 3. 测试新增员工
Write-Host "[3] 测试新增员工..." -ForegroundColor Yellow
$addBody = @{
name = "测试员工"
tellerNo = "TEST001"
orgNo = "1001"
idCard = "110101199001011234"
phone = "13800138000"
status = "0"
relatives = @(
@{
relativeName = "李四"
relativeIdCard = "110101199001011235"
relativePhone = "13800138001"
relationship = "配偶"
}
)
} | ConvertTo-Json -Depth 10
$headers = @{
"Authorization" = "Bearer $TOKEN"
"Content-Type" = "application/json; charset=utf-8"
}
$bodyBytes = [System.Text.Encoding]::UTF8.GetBytes($addBody)
$response = Invoke-RestMethod -Uri "$BASE_URL/dpc/employee" -Method Post -Headers $headers -Body $bodyBytes
Write-Host ($response | ConvertTo-Json -Depth 10)
Write-Host ""
# 4. 测试查询员工详情
Write-Host "[4] 测试查询员工详情..." -ForegroundColor Yellow
$headers = @{
"Authorization" = "Bearer $TOKEN"
}
$response = Invoke-RestMethod -Uri "$BASE_URL/dpc/employee/1" -Method Get -Headers $headers
Write-Host ($response | ConvertTo-Json -Depth 10)
Write-Host ""
# 5. 测试编辑员工
Write-Host "[5] 测试编辑员工..." -ForegroundColor Yellow
$editBody = @{
employeeId = 1
name = "测试员工-修改"
tellerNo = "TEST001"
orgNo = "1001"
idCard = "110101199001011234"
phone = "13800138000"
status = "0"
relatives = @(
@{
relativeName = "王五"
relativeIdCard = "110101199001011236"
relativePhone = "13800138002"
relationship = "子女"
}
)
} | ConvertTo-Json -Depth 10
$headers = @{
"Authorization" = "Bearer $TOKEN"
"Content-Type" = "application/json; charset=utf-8"
}
$bodyBytes = [System.Text.Encoding]::UTF8.GetBytes($editBody)
$response = Invoke-RestMethod -Uri "$BASE_URL/dpc/employee" -Method Put -Headers $headers -Body $bodyBytes
Write-Host ($response | ConvertTo-Json -Depth 10)
Write-Host ""
# 6. 测试删除员工
Write-Host "[6] 测试删除员工..." -ForegroundColor Yellow
$headers = @{
"Authorization" = "Bearer $TOKEN"
}
$response = Invoke-RestMethod -Uri "$BASE_URL/dpc/employee/1" -Method Delete -Headers $headers
Write-Host ($response | ConvertTo-Json -Depth 10)
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "测试完成" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Read-Host "按回车键退出"