update pay ui
This commit is contained in:
@@ -1030,3 +1030,51 @@ async def get_stock_intraday_statistics(
|
||||
except Exception as e:
|
||||
logger.error(f"[ClickHouse] 日内统计失败: {e}", exc_info=True)
|
||||
return {"success": False, "error": str(e)}
|
||||
|
||||
|
||||
async def get_stock_code_by_name(stock_name: str) -> Dict[str, Any]:
|
||||
"""
|
||||
根据股票名称查询股票代码
|
||||
|
||||
Args:
|
||||
stock_name: 股票名称(支持模糊匹配)
|
||||
|
||||
Returns:
|
||||
匹配的股票列表,包含代码和名称
|
||||
"""
|
||||
pool = await get_pool()
|
||||
|
||||
async with pool.acquire() as conn:
|
||||
async with conn.cursor(aiomysql.DictCursor) as cursor:
|
||||
# 使用 LIKE 进行模糊匹配
|
||||
query = """
|
||||
SELECT DISTINCT
|
||||
SECCODE as code,
|
||||
SECNAME as name,
|
||||
F030V as industry
|
||||
FROM ea_baseinfo
|
||||
WHERE SECNAME LIKE %s
|
||||
OR SECNAME = %s
|
||||
ORDER BY
|
||||
CASE WHEN SECNAME = %s THEN 0 ELSE 1 END,
|
||||
SECCODE
|
||||
LIMIT 10
|
||||
"""
|
||||
|
||||
# 精确匹配和模糊匹配
|
||||
like_pattern = f"%{stock_name}%"
|
||||
|
||||
await cursor.execute(query, (like_pattern, stock_name, stock_name))
|
||||
results = await cursor.fetchall()
|
||||
|
||||
if not results:
|
||||
return {
|
||||
"success": False,
|
||||
"error": f"未找到名称包含 '{stock_name}' 的股票"
|
||||
}
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"data": results,
|
||||
"count": len(results)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user