员工信息管理

- 新增员工信息CRUD功能
- 添加员工关联人员管理
- 配置MyBatis Plus审计字段
- 添加OpenSpec规范文档
- 新增测试脚本和数据

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wkc
2026-01-28 14:40:27 +08:00
parent 6946744ab9
commit 0cc8ef0fc3
32 changed files with 2841 additions and 9 deletions

80
test/batch_insert.ps1 Normal file
View File

@@ -0,0 +1,80 @@
# 批量插入100条员工数据
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$BASE_URL = "http://localhost:8080"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "批量插入100条员工数据" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 登录获取 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
Write-Host "登录成功" -ForegroundColor Green
Write-Host ""
$headers = @{
"Authorization" = "Bearer $TOKEN"
"Content-Type" = "application/json; charset=utf-8"
}
# 批量插入100条数据
Write-Host "[2] 开始批量插入100条员工数据..." -ForegroundColor Yellow
$successCount = 0
$failCount = 0
for ($i = 1; $i -le 100; $i++) {
try {
$tellerNo = "TEST" + $i.ToString("000")
$idCard = "110101199001011" + ($i + 200).ToString("000")
$addBody = @{
name = "测试员工" + $i
tellerNo = $tellerNo
orgNo = "1001"
idCard = $idCard
phone = "13800138" + ($i % 100).ToString("00")
status = "0"
relatives = @(
@{
relativeName = "亲属" + $i + "A"
relativeIdCard = "110101199001011" + ($i + 300).ToString("000")
relativePhone = "13900138" + ($i % 100).ToString("00")
relationship = "配偶"
}
)
} | ConvertTo-Json -Depth 10
$bodyBytes = [System.Text.Encoding]::UTF8.GetBytes($addBody)
$response = Invoke-RestMethod -Uri "$BASE_URL/dpc/employee" -Method Post -Headers $headers -Body $bodyBytes
if ($response.code -eq 200) {
$successCount++
Write-Host "[$i/100] 插入成功: 测试员工$i" -ForegroundColor Green
} else {
$failCount++
Write-Host "[$i/100] 插入失败: $($response.msg)" -ForegroundColor Red
}
} catch {
$failCount++
Write-Host "[$i/100] 插入异常: $_" -ForegroundColor Red
}
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "插入完成" -ForegroundColor Cyan
Write-Host "成功: $successCount" -ForegroundColor Green
Write-Host "失败: $failCount" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Cyan
Read-Host "按回车键退出"

75
test/batch_insert.py Normal file
View File

@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
import requests
import json
BASE_URL = "http://localhost:8080"
print("=" * 50)
print("批量插入100条员工数据")
print("=" * 50)
print()
# 登录获取 Token
print("[1] 正在登录...")
login_response = requests.post(
f"{BASE_URL}/login/test",
json={"username": "admin", "password": "admin123"}
)
token = login_response.json()["token"]
print("登录成功")
print()
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json; charset=utf-8"
}
# 批量插入
print("[2] 开始批量插入100条员工数据...")
success_count = 0
fail_count = 0
for i in range(1, 101):
try:
teller_no = f"TEST{i+200:03d}"
id_card = f"110101199001011{i+400:03d}"
data = {
"name": f"测试员工{i}",
"tellerNo": teller_no,
"orgNo": "1001",
"idCard": id_card,
"phone": f"138{10000000+i:08d}",
"status": "0",
"relatives": [
{
"relativeName": f"亲属{i}A",
"relativeIdCard": f"110101199001011{i+300:03d}",
"relativePhone": f"139{10000000+i:08d}",
"relationship": "配偶"
}
]
}
response = requests.post(
f"{BASE_URL}/dpc/employee",
headers=headers,
json=data
)
if response.json()["code"] == 200:
success_count += 1
print(f"[{i}/100] 插入成功: 测试员工{i}")
else:
fail_count += 1
print(f"[{i}/100] 插入失败: {response.json()['msg']}")
except Exception as e:
fail_count += 1
print(f"[{i}/100] 插入异常: {e}")
print()
print("=" * 50)
print("插入完成")
print(f"成功: {success_count}")
print(f"失败: {fail_count}")
print("=" * 50)

1
test/test_data.json Normal file
View File

@@ -0,0 +1 @@
{"name":"测试员工","tellerNo":"TEST002","orgNo":"1001","idCard":"110101199001011237","phone":"13800138000","status":"0","relatives":[{"relativeName":"李四","relativeIdCard":"110101199001011235","relativePhone":"13800138001","relationship":"配偶"}]}

View File

@@ -0,0 +1,66 @@
@echo off
chcp 65001 > nul
setlocal enabledelayedexpansion
echo ========================================
echo 员工信息管理 API 测试脚本
echo ========================================
echo.
set BASE_URL=http://localhost:8080
set TOKEN=
REM 1. 登录获取 Token
echo [1] 正在登录...
curl -s -X POST "%BASE_URL%/login/test" -H "Content-Type: application/json" -d "{\"username\":\"admin\",\"password\":\"admin123\"}" > login_response.json
REM 使用 PowerShell 提取 token
for /f "tokens=*" %%i in ('powershell -Command "$json = Get-Content login_response.json | ConvertFrom-Json; $json.token"') do (
set TOKEN=%%i
)
del login_response.json
if "%TOKEN%"=="" (
echo [错误] 获取 Token 失败,请检查登录接口
pause
exit /b 1
)
echo 登录成功Token: %TOKEN%
echo.
REM 2. 测试查询员工列表
echo [2] 测试查询员工列表...
curl -s -X GET "%BASE_URL%/dpc/employee/list" -H "Authorization: Bearer %TOKEN%"
echo.
echo.
REM 3. 测试新增员工
echo [3] 测试新增员工...
curl -s -X POST "%BASE_URL%/dpc/employee" -H "Authorization: Bearer %TOKEN%" -H "Content-Type: application/json" -d "{\"name\":\"测试员工\",\"tellerNo\":\"TEST001\",\"orgNo\":\"1001\",\"idCard\":\"110101199001011234\",\"phone\":\"13800138000\",\"status\":\"0\",\"relatives\":[{\"relativeName\":\"李四\",\"relativeIdCard\":\"110101199001011235\",\"relativePhone\":\"13800138001\",\"relationship\":\"配偶\"}]}"
echo.
echo.
REM 4. 测试查询员工详情
echo [4] 测试查询员工详情...
curl -s -X GET "%BASE_URL%/dpc/employee/1" -H "Authorization: Bearer %TOKEN%"
echo.
echo.
REM 5. 测试编辑员工
echo [5] 测试编辑员工...
curl -s -X PUT "%BASE_URL%/dpc/employee" -H "Authorization: Bearer %TOKEN%" -H "Content-Type: application/json" -d "{\"employeeId\":1,\"name\":\"测试员工-修改\",\"tellerNo\":\"TEST001\",\"orgNo\":\"1001\",\"idCard\":\"110101199001011234\",\"phone\":\"13800138000\",\"status\":\"0\",\"relatives\":[{\"relativeName\":\"王五\",\"relativeIdCard\":\"110101199001011236\",\"relativePhone\":\"13800138002\",\"relationship\":\"子女\"}]}"
echo.
echo.
REM 6. 测试删除员工
echo [6] 测试删除员工...
curl -s -X DELETE "%BASE_URL%/dpc/employee/1" -H "Authorization: Bearer %TOKEN%"
echo.
echo.
echo ========================================
echo 测试完成
echo ========================================
pause

119
test/test_employee_api.ps1 Normal file
View File

@@ -0,0 +1,119 @@
# 员工信息管理 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 "按回车键退出"