@echo off
REM ========================================
REM 批量创建信贷客户家庭关系测试数据
REM ========================================

setlocal EnableDelayedExpansion

echo ========================================
echo 批量创建信贷客户家庭关系测试数据
echo ========================================
echo.

set BASE_URL=http://localhost:8080

REM 步骤1: 登录获取token
echo [1/2] 正在登录...
curl -s -X POST "%BASE_URL%/login/test" ^
  -H "Content-Type: application/json" ^
  -d "{\"username\":\"admin\",\"password\":\"admin123\"}" ^
  > login_response.json

powershell -Command "$json = Get-Content login_response.json -Raw | ConvertFrom-Json; $token = $json.token; Set-Content -Path token.txt -Value $token"

set /p TOKEN=<token.txt
echo Token: %TOKEN:~0,30%...
echo.

REM 步骤2: 批量创建50条数据
echo [2/2] 正在批量创建50条测试数据...
echo.

set COUNT=0
for /L %%i in (1,1,50) do (
    set /a PERSON_ID_BASE=1990%%i
    set /a CERT_SUFFIX=1000+%%i

    curl -s -X POST "%BASE_URL%/ccdi/custFmyRelation" ^
      -H "Authorization: Bearer %TOKEN%" ^
      -H "Content-Type: application/json" ^
      -d "{\"personId\":\"11010119%PERSON_ID_BASE%01012\",\"relationType\":\"0%%i\",\"relationName\":\"测试用户%%i\",\"gender\":\"M\",\"relationCertType\":\"01\",\"relationCertNo\":\"11010119%PERSON_ID_BASE%0101!CERT_SUFFIX!\",\"mobilePhone1\":\"1380013800%%i\",\"remark\":\"批量测试数据-第%%i条\"}" ^
      > nul

    set /a COUNT+=1
    set /a REMAINDER=%%i%%5

    if !REMAINDER! equ 0 (
        echo 已创建: !COUNT!/50
    )
)

echo.
echo ========================================
echo 数据创建完成!
echo ========================================
echo 总计创建: 50 条测试数据
echo.

pause
