"""检查生产库中 UserUID 为空的用户"""
import pymysql

conn = pymysql.connect(
    host='gvsds.com', port=50030,
    user='root', password='sajksh.sdfGH3YUge.wjkd+',
    database='xaio_cheng_xu', charset='utf8mb4'
)
cur = conn.cursor()

# UserUID 为 NULL 的用户数
cur.execute("SELECT COUNT(*) FROM user WHERE UserUID IS NULL OR UserUID = ''")
print(f'UserUID为空的用户数: {cur.fetchone()[0]}')

# 总用户数
cur.execute("SELECT COUNT(*) FROM user")
print(f'总用户数: {cur.fetchone()[0]}')

# 抽样 UserUID 为 NULL 的用户
cur.execute("SELECT UserUUID, UserName, OpenID, Phone FROM user WHERE UserUID IS NULL OR UserUID = '' LIMIT 5")
rows = cur.fetchall()
if rows:
    print('\nUserUID为空的用户示例:')
    for r in rows:
        print(f'  UserName={r[1]}, OpenID={r[2]}, Phone={r[3]}')

conn.close()
