# -*- 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)
