@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
