30 lines
973 B
Python
30 lines
973 B
Python
|
|
import pymysql
|
||
|
|
import random
|
||
|
|
|
||
|
|
conn = pymysql.connect(host='10.8.0.252', user='root', password='Hbhyg731024@', database='pms')
|
||
|
|
cur = conn.cursor()
|
||
|
|
|
||
|
|
# 获取所有项目ID
|
||
|
|
cur.execute('SELECT id FROM projects')
|
||
|
|
proj_ids = [row[0] for row in cur.fetchall()]
|
||
|
|
|
||
|
|
# 为每个项目添加2-3个柜子
|
||
|
|
count = 0
|
||
|
|
for proj_id in proj_ids:
|
||
|
|
num = random.randint(2, 3)
|
||
|
|
for j in range(num):
|
||
|
|
count += 1
|
||
|
|
abstract_id = f'10-{count:08d}'
|
||
|
|
imei = f'86{random.randint(10000000000000, 99999999999999)}'
|
||
|
|
auth = ''.join(random.choices('abcdefghijklmnopqrstuvwxyz0123456789', k=8))
|
||
|
|
name = f'CAB-{count:03d}'
|
||
|
|
try:
|
||
|
|
cur.execute(f"INSERT IGNORE INTO cabinets (project_id, abstract_id, imei, auth_str, name, status) VALUES ({proj_id}, '{abstract_id}', '{imei}', '{auth}', '{name}', 1)")
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
conn.commit()
|
||
|
|
cur.execute('SELECT COUNT(*) FROM cabinets')
|
||
|
|
print(f'柜子总数: {cur.fetchone()[0]}')
|
||
|
|
conn.close()
|