@echo off
chcp 65001 >nul
echo ========================================
echo 项目状态统计接口测试
echo ========================================
echo.

echo [步骤 1] 获取测试令牌...
curl -s -X POST "http://localhost:8080/login/test?username=admin&password=admin123" > token.json
type token.json
echo.

for /f "tokens=2 delims=:" %%a in ('type token.json ^| findstr "token"') do (
    set TOKEN=%%a
)
set TOKEN=%TOKEN:"=%
set TOKEN=%TOKEN:,=%
set TOKEN=%TOKEN: =%

if "%TOKEN%"=="" (
    echo ❌ 获取令牌失败
    pause
    exit /b 1
)

echo ✅ 令牌获取成功: %TOKEN%
echo.

echo [步骤 2] 测试项目状态统计接口...
echo ----------------------------------------
curl -s -X GET "http://localhost:8080/ccdi/project/status/counts" ^
     -H "Authorization: Bearer %TOKEN%" ^
     -H "Content-Type: application/json" ^
     > status_counts.json

type status_counts.json
echo.
echo.

echo [步骤 3] 验证响应数据...
echo ----------------------------------------

REM 检查是否包含预期的字段
type status_counts.json | findstr /C:"all" >nul
if %ERRORLEVEL% EQU 0 (
    echo ✅ 包含 "all" 字段
) else (
    echo ❌ 缺少 "all" 字段
)

type status_counts.json | findstr /C:"inProgress" >nul
if %ERRORLEVEL% EQU 0 (
    echo ✅ 包含 "inProgress" 字段
) else (
    echo ❌ 缺少 "inProgress" 字段
)

type status_counts.json | findstr /C:"completed" >nul
if %ERRORLEVEL% EQU 0 (
    echo ✅ 包含 "completed" 字段
) else (
    echo ❌ 缺少 "completed" 字段
)

type status_counts.json | findstr /C:"archived" >nul
if %ERRORLEVEL% EQU 0 (
    echo ✅ 包含 "archived" 字段
) else (
    echo ❌ 缺少 "archived" 字段
)

echo.

echo [步骤 4] 数据库数据验证...
echo ----------------------------------------
echo 预期统计数据（仅 del_flag='0'）：
echo   - 进行中（status=0）: 26 个
echo   - 已完成（status=1）: 1 个
echo   - 已归档（status=2）: 1 个
echo   - 总计: 28 个
echo.
echo 请检查上方接口返回的数据是否与预期一致！
echo.

echo ========================================
echo 测试完成
echo ========================================

del token.json status_counts.json 2>nul
pause
