diff --git a/app.py b/app.py index 1c999aa8..9514afdf 100755 --- a/app.py +++ b/app.py @@ -11222,6 +11222,8 @@ def get_events_by_mainline(): # 获取所有 lv2 名称 lv2_names = [group['lv2_name'] for group in mainline_groups.values() if group.get('lv2_name')] if lv2_names: + # 数据库中的 concept_name 带有 "[二级] " 前缀,需要添加前缀来匹配 + lv2_names_with_prefix = [f'[二级] {name}' for name in lv2_names] # 查询 concept_daily_stats 表获取最新涨跌幅 price_sql = text(''' SELECT concept_name, avg_change_pct, trade_date @@ -11232,13 +11234,15 @@ def get_events_by_mainline(): SELECT MAX(trade_date) FROM concept_daily_stats WHERE concept_type = 'lv2' ) ''') - price_result = db.session.execute(price_sql, {'names': tuple(lv2_names)}).fetchall() + price_result = db.session.execute(price_sql, {'names': tuple(lv2_names_with_prefix)}).fetchall() for row in price_result: - lv2_price_map[row.concept_name] = { + # 去掉 "[二级] " 前缀,用原始名称作为 key + original_name = row.concept_name.replace('[二级] ', '') if row.concept_name else '' + lv2_price_map[original_name] = { 'avg_change_pct': float(row.avg_change_pct) if row.avg_change_pct else None, 'trade_date': str(row.trade_date) if row.trade_date else None } - app.logger.info(f'[mainline] 获取 lv2 涨跌幅: {len(lv2_price_map)} 条') + app.logger.info(f'[mainline] 获取 lv2 涨跌幅: {len(lv2_price_map)} 条, lv2_names 数量: {len(lv2_names)}') except Exception as price_err: app.logger.warning(f'[mainline] 获取 lv2 涨跌幅失败: {price_err}')