update pay ui

This commit is contained in:
2025-12-05 14:56:38 +08:00
parent bf1e9d3ae6
commit 525e9d16f7
2 changed files with 468 additions and 301 deletions

View File

@@ -755,7 +755,7 @@ async def get_hierarchy_price_early(
trade_date: Optional[date] = Query(None, description="交易日期,默认最新"),
lv1_filter: Optional[str] = Query(None, description="筛选特定一级分类")
):
"""获取层级概念(lv1/lv2/lv3)的涨跌幅数据"""
"""获取所有概念的涨跌幅数据(包含母概念lv1/lv2/lv3和叶子概念leaf"""
logger.info(f"[hierarchy/price] 请求参数: trade_date={trade_date}, lv1_filter={lv1_filter}")
if not mysql_pool:
@@ -768,22 +768,11 @@ async def get_hierarchy_price_early(
# 获取交易日期
query_date = trade_date
if query_date is None:
# 优先从母概念查最新日期
await cursor.execute(
"SELECT MAX(trade_date) as max_date FROM concept_daily_stats WHERE concept_type IN ('lv1', 'lv2', 'lv3')"
)
await cursor.execute("SELECT MAX(trade_date) as max_date FROM concept_daily_stats")
result = await cursor.fetchone()
logger.info(f"[hierarchy/price] 查询母概念最新日期: {result}")
if result and result['max_date']:
query_date = result['max_date']
else:
# 尝试从全部数据获取
await cursor.execute("SELECT MAX(trade_date) as max_date FROM concept_daily_stats")
result = await cursor.fetchone()
logger.info(f"[hierarchy/price] 查询全部最新日期: {result}")
if not result or not result['max_date']:
raise HTTPException(status_code=404, detail="无涨跌幅数据")
query_date = result['max_date']
if not result or not result['max_date']:
raise HTTPException(status_code=404, detail="无涨跌幅数据")
query_date = result['max_date']
logger.info(f"[hierarchy/price] 使用查询日期: {query_date}")
@@ -802,15 +791,14 @@ async def get_hierarchy_price_early(
lv1_concepts = []
lv2_concepts = []
lv3_concepts = []
leaf_concepts = []
# 查询 lv1
if lv1_filter:
await cursor.execute(base_query, (query_date, 'lv1', f"%{lv1_filter}%"))
else:
await cursor.execute(base_query, (query_date, 'lv1'))
lv1_rows = await cursor.fetchall()
logger.info(f"[hierarchy/price] lv1查询结果数量: {len(lv1_rows)}")
for row in lv1_rows:
for row in await cursor.fetchall():
lv1_concepts.append({
"concept_id": row['concept_id'],
"concept_name": row['concept_name'],
@@ -825,9 +813,7 @@ async def get_hierarchy_price_early(
await cursor.execute(base_query, (query_date, 'lv2', f"%{lv1_filter}%"))
else:
await cursor.execute(base_query, (query_date, 'lv2'))
lv2_rows = await cursor.fetchall()
logger.info(f"[hierarchy/price] lv2查询结果数量: {len(lv2_rows)}")
for row in lv2_rows:
for row in await cursor.fetchall():
lv2_concepts.append({
"concept_id": row['concept_id'],
"concept_name": row['concept_name'],
@@ -842,9 +828,7 @@ async def get_hierarchy_price_early(
await cursor.execute(base_query, (query_date, 'lv3', f"%{lv1_filter}%"))
else:
await cursor.execute(base_query, (query_date, 'lv3'))
lv3_rows = await cursor.fetchall()
logger.info(f"[hierarchy/price] lv3查询结果数量: {len(lv3_rows)}")
for row in lv3_rows:
for row in await cursor.fetchall():
lv3_concepts.append({
"concept_id": row['concept_id'],
"concept_name": row['concept_name'],
@@ -854,13 +838,37 @@ async def get_hierarchy_price_early(
"stock_count": row['stock_count']
})
logger.info(f"[hierarchy/price] 返回结果: lv1={len(lv1_concepts)}, lv2={len(lv2_concepts)}, lv3={len(lv3_concepts)}")
# 查询叶子概念 leaf
await cursor.execute(base_query, (query_date, 'leaf'))
for row in await cursor.fetchall():
# 获取层级信息
hierarchy_info = get_concept_hierarchy(row['concept_name'])
leaf_concepts.append({
"concept_id": row['concept_id'],
"concept_name": row['concept_name'],
"concept_type": 'leaf',
"trade_date": str(row['trade_date']),
"avg_change_pct": float(row['avg_change_pct']) if row['avg_change_pct'] else None,
"stock_count": row['stock_count'],
"hierarchy": hierarchy_info
})
total = len(lv1_concepts) + len(lv2_concepts) + len(lv3_concepts) + len(leaf_concepts)
logger.info(f"[hierarchy/price] 返回结果: lv1={len(lv1_concepts)}, lv2={len(lv2_concepts)}, lv3={len(lv3_concepts)}, leaf={len(leaf_concepts)}")
return {
"trade_date": str(query_date),
"lv1_concepts": lv1_concepts,
"lv2_concepts": lv2_concepts,
"lv3_concepts": lv3_concepts,
"total_count": len(lv1_concepts) + len(lv2_concepts) + len(lv3_concepts)
"leaf_concepts": leaf_concepts,
"total_count": total,
"summary": {
"lv1_count": len(lv1_concepts),
"lv2_count": len(lv2_concepts),
"lv3_count": len(lv3_concepts),
"leaf_count": len(leaf_concepts)
}
}
except HTTPException as he: