2026-09-20 04:31:42 +08:00
|
|
|
|
import os
|
2026-07-03 02:45:00 +08:00
|
|
|
|
import pymysql
|
|
|
|
|
|
import random
|
|
|
|
|
|
|
2026-09-20 04:31:42 +08:00
|
|
|
|
# 默认指向 SSH 隧道(tools/dev-tunnel.ps1),不再使用已移除的 ZeroTier/nginx 转发
|
|
|
|
|
|
conn = pymysql.connect(
|
|
|
|
|
|
host=os.environ.get('PMS_MYSQL_HOST', '127.0.0.1'),
|
|
|
|
|
|
port=int(os.environ.get('PMS_MYSQL_PORT', '13306')),
|
|
|
|
|
|
user='root', password='Hbhyg731024@', database='pms',
|
|
|
|
|
|
)
|
2026-07-03 02:45:00 +08:00
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
# 添加ICCID字段
|
|
|
|
|
|
try:
|
|
|
|
|
|
cur.execute("ALTER TABLE cabinets ADD COLUMN iccid VARCHAR(20) DEFAULT NULL COMMENT 'SIM卡ICCID' AFTER imei")
|
|
|
|
|
|
print("✓ ICCID字段添加成功")
|
|
|
|
|
|
except:
|
|
|
|
|
|
print("✓ ICCID字段已存在")
|
|
|
|
|
|
|
|
|
|
|
|
# 更新IMEI和ICCID为正确的格式
|
|
|
|
|
|
cur.execute("SELECT id FROM cabinets ORDER BY id")
|
|
|
|
|
|
cabinet_ids = [row[0] for row in cur.fetchall()]
|
|
|
|
|
|
|
|
|
|
|
|
for i, cab_id in enumerate(cabinet_ids):
|
|
|
|
|
|
# IMEI: 15位数字,86开头(中国TAC)
|
|
|
|
|
|
imei = f"86{random.randint(10000000000000, 99999999999999)}"[:15]
|
|
|
|
|
|
# ICCID: 20位数字,898600开头(中国移动)
|
|
|
|
|
|
iccid = f"898600{random.randint(100000000000000000, 999999999999999999)}"[:20]
|
|
|
|
|
|
cur.execute(f"UPDATE cabinets SET imei='{imei}', iccid='{iccid}' WHERE id={cab_id}")
|
|
|
|
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
|
|
print(f"✓ 更新了 {len(cabinet_ids)} 个柜子的IMEI和ICCID")
|
|
|
|
|
|
|
|
|
|
|
|
# 验证
|
|
|
|
|
|
cur.execute("SELECT imei, iccid FROM cabinets LIMIT 3")
|
|
|
|
|
|
for row in cur.fetchall():
|
|
|
|
|
|
print(f" IMEI: {row[0]} ({len(row[0])}位), ICCID: {row[1]} ({len(row[1])}位)")
|
|
|
|
|
|
|
|
|
|
|
|
conn.close()
|