69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
"""初始化测试数据:管理员账号 + 测试系统"""
|
|
import pymysql
|
|
|
|
conn = pymysql.connect(
|
|
host='db1.prod.zgitm.com', port=3306,
|
|
user='mokeegateway', password='mokee.',
|
|
database='mokeegateway', charset='utf8mb4'
|
|
)
|
|
cur = conn.cursor()
|
|
|
|
# 1. 管理员用户 (密码: admin123, BCrypt加密)
|
|
sql = """INSERT IGNORE INTO sys_user (username, password, real_name, email, phone, post, status)
|
|
VALUES ('admin', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVKIUi', '管理员', 'admin@mokee.com', '13800000000', '管理员', 1)"""
|
|
cur.execute(sql)
|
|
conn.commit()
|
|
print("1. 管理员用户 OK")
|
|
|
|
# 2. 测试系统
|
|
sql = """INSERT IGNORE INTO sys_system (system_code, system_name, front_url, backend_url, gateway_url, status, description)
|
|
VALUES ('test', '测试系统', 'http://127.0.0.1:5001', 'http://127.0.0.1:9000', 'http://127.0.0.1:9000', 1, '测试用业务系统')"""
|
|
cur.execute(sql)
|
|
conn.commit()
|
|
print("2. 测试系统 OK")
|
|
|
|
# 3. 绑定管理员到测试系统
|
|
sql = """INSERT IGNORE INTO sys_user_system (user_id, system_id)
|
|
SELECT u.id, s.id FROM sys_user u, sys_system s
|
|
WHERE u.username='admin' AND s.system_code='test'"""
|
|
cur.execute(sql)
|
|
conn.commit()
|
|
print("3. 用户系统绑定 OK")
|
|
|
|
# 4. 管理员角色
|
|
sql = """INSERT IGNORE INTO sys_role (system_id, role_name, role_code, description, status)
|
|
SELECT s.id, '管理员', 'admin', '系统管理员', 1 FROM sys_system s WHERE s.system_code='test'"""
|
|
cur.execute(sql)
|
|
conn.commit()
|
|
print("4. 管理员角色 OK")
|
|
|
|
# 5. 分配角色给用户
|
|
sql = """INSERT IGNORE INTO sys_user_role (user_id, role_id)
|
|
SELECT u.id, r.id FROM sys_user u, sys_role r, sys_system s
|
|
WHERE u.username='admin' AND r.role_code='admin' AND r.system_id=s.id AND s.system_code='test'"""
|
|
cur.execute(sql)
|
|
conn.commit()
|
|
print("5. 用户角色分配 OK")
|
|
|
|
# 6. 放行所有接口
|
|
apis = [
|
|
('GET', '/zgapi/v1/admin/**'),
|
|
('POST', '/zgapi/v1/admin/**'),
|
|
('PUT', '/zgapi/v1/admin/**'),
|
|
('DELETE', '/zgapi/v1/admin/**'),
|
|
('GET', '/zgapi/v1/auth/**'),
|
|
('POST', '/zgapi/v1/auth/**'),
|
|
('PUT', '/zgapi/v1/auth/**'),
|
|
]
|
|
for method, path in apis:
|
|
sql = """INSERT IGNORE INTO sys_api (system_id, api_path, api_method, api_name, status)
|
|
SELECT s.id, %s, %s, '放行接口', 1 FROM sys_system s WHERE s.system_code='test'"""
|
|
cur.execute(sql, (path, method))
|
|
conn.commit()
|
|
print(f"6. 放行接口 OK ({len(apis)} 条)")
|
|
|
|
cur.close()
|
|
conn.close()
|
|
print("\n===== 测试数据初始化完成 =====")
|
|
print("管理员账号: admin / admin123")
|