423baff73b
- Docker bridge 网络隔离(8000 端口封死) - Gunicorn 4 Worker 多进程 - Alembic 数据库迁移基线 - 日志轮转 20m×3 - JWT 密钥 + DB 密码 + CORS 收紧 - 3-2-1 备份链路(NAS + R740-B 冷备) - 连接池 pool_pre_ping + pool_recycle=3600
65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
import psycopg2
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
try:
|
|
conn = psycopg2.connect(
|
|
host="192.168.1.85",
|
|
port=5432,
|
|
user="admin",
|
|
password="admin_password_2026",
|
|
dbname="lubrication_crm"
|
|
)
|
|
cur = conn.cursor()
|
|
|
|
# 1. 存在测试用的客户 ID (LogEntry.vue 默认写的)
|
|
test_client_uuid = "a37dbd8b-a9c0-4deb-ad76-83a0d29bbf28"
|
|
|
|
cur.execute(
|
|
"""
|
|
INSERT INTO clients (id, name, contact_person, phone)
|
|
VALUES (%s, '自动化联调测试客户', '张经理', '13800138000')
|
|
ON CONFLICT (id) DO NOTHING
|
|
""",
|
|
(test_client_uuid,)
|
|
)
|
|
|
|
# 2. 插入一些销售机会数据 (用于展示当月的 Dashboard AI 复盘效果)
|
|
current_year = datetime.now().year
|
|
current_month = datetime.now().month
|
|
created_str = f"{current_year}-{current_month:02d}-15 10:00:00"
|
|
|
|
opportunities = [
|
|
{"stage": "意向", "amount": 50000},
|
|
{"stage": "意向", "amount": 20000},
|
|
{"stage": "谈判", "amount": 150000},
|
|
{"stage": "成交", "amount": 300000},
|
|
{"stage": "流失", "amount": 10000},
|
|
]
|
|
|
|
for opp in opportunities:
|
|
cur.execute(
|
|
"""
|
|
INSERT INTO sales_opportunities (id, customer_id, stage, amount, created_at)
|
|
VALUES (%s, %s, %s, %s, %s)
|
|
""",
|
|
(
|
|
str(uuid.uuid4()),
|
|
test_client_uuid,
|
|
opp["stage"],
|
|
opp["amount"],
|
|
created_str,
|
|
)
|
|
)
|
|
|
|
conn.commit()
|
|
print("Seed data for logging and reports inserted successfully.")
|
|
|
|
except Exception as e:
|
|
print(f"Database error: {e}")
|
|
finally:
|
|
if 'cur' in locals():
|
|
cur.close()
|
|
if 'conn' in locals():
|
|
conn.close()
|