更新Company页面的UI为FUI风格
This commit is contained in:
@@ -245,10 +245,17 @@ def update_event_statistics(start_date=None, end_date=None, force_update=False,
|
||||
debug_mode: 是否开启调试模式
|
||||
"""
|
||||
try:
|
||||
print("[DEBUG] 开始 update_event_statistics")
|
||||
print(f"[DEBUG] 参数: start_date={start_date}, end_date={end_date}, force_update={force_update}")
|
||||
|
||||
mysql_engine = get_mysql_engine()
|
||||
print("[DEBUG] MySQL 引擎创建成功")
|
||||
|
||||
ch_client = get_clickhouse_client()
|
||||
print("[DEBUG] ClickHouse 客户端创建成功")
|
||||
|
||||
with mysql_engine.connect() as mysql_conn:
|
||||
print("[DEBUG] MySQL 连接已建立")
|
||||
# 构建SQL查询
|
||||
query = """
|
||||
SELECT e.id, \
|
||||
@@ -284,8 +291,12 @@ def update_event_statistics(start_date=None, end_date=None, force_update=False,
|
||||
ORDER BY e.created_at DESC
|
||||
"""
|
||||
|
||||
print(f"[DEBUG] 执行查询SQL:\n{query}")
|
||||
print(f"[DEBUG] 查询参数: {params}")
|
||||
|
||||
events = mysql_conn.execute(text(query), params).fetchall()
|
||||
|
||||
print(f"[DEBUG] 查询返回 {len(events)} 条事件记录")
|
||||
print(f"Found {len(events)} events to update (force_update={force_update})")
|
||||
if debug_mode and len(events) > 0:
|
||||
print(f"Date range: {events[-1][1]} to {events[0][1]}")
|
||||
@@ -324,6 +335,11 @@ def update_event_statistics(start_date=None, end_date=None, force_update=False,
|
||||
"week_chg": week_change,
|
||||
"event_id": event_id
|
||||
})
|
||||
if idx <= 5: # 前5条显示详情
|
||||
print(f"[DEBUG] 事件 {event_id}: avg={avg_change}, max={max_change}, week={week_change}")
|
||||
else:
|
||||
if idx <= 5:
|
||||
print(f"[DEBUG] 事件 {event_id}: 计算结果全为None,跳过")
|
||||
|
||||
# 每处理10个事件打印一次进度
|
||||
if idx % 10 == 0:
|
||||
@@ -337,16 +353,29 @@ def update_event_statistics(start_date=None, end_date=None, force_update=False,
|
||||
continue
|
||||
|
||||
# 批量更新MySQL
|
||||
print(f"\n[DEBUG] ====== 准备写入数据库 ======")
|
||||
print(f"[DEBUG] update_data 长度: {len(update_data)}")
|
||||
if update_data:
|
||||
mysql_conn.execute(text("""
|
||||
print(f"[DEBUG] 前3条待更新数据: {update_data[:3]}")
|
||||
print(f"[DEBUG] 执行 UPDATE 语句...")
|
||||
|
||||
result = mysql_conn.execute(text("""
|
||||
UPDATE event
|
||||
SET related_avg_chg = :avg_chg,
|
||||
related_max_chg = :max_chg,
|
||||
related_week_chg = :week_chg
|
||||
WHERE id = :event_id
|
||||
"""), update_data)
|
||||
# SQLAlchemy 1.4 的 connect() 会在上下文管理器退出时自动提交
|
||||
print(f"[DEBUG] UPDATE 执行完成, rowcount={result.rowcount}")
|
||||
|
||||
# 关键:显式提交事务!SQLAlchemy 2.0 需要手动 commit
|
||||
print("[DEBUG] 准备提交事务 (commit)...")
|
||||
mysql_conn.commit()
|
||||
print("[DEBUG] 事务已提交!")
|
||||
|
||||
print(f"Successfully updated {len(update_data)} events")
|
||||
else:
|
||||
print("[DEBUG] update_data 为空,没有数据需要更新!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error in update_event_statistics: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user