取消levels接口,限制classifications接口仅为申万行业接口

This commit is contained in:
2025-10-24 11:47:48 +08:00
parent 04d74a8ef2
commit 41a5ef626e
2 changed files with 90 additions and 143 deletions

21
app.py
View File

@@ -6521,10 +6521,25 @@ def api_get_events():
# 新增:行业代码过滤(申银万国行业分类)
if industry_code:
# related_industries 格式: [{"申银万国行业分类": "S370502"}, ...]
# 支持多个行业代码,用逗号分隔
json_path = '$[*]."申银万国行业分类"'
query = query.filter(
text("JSON_CONTAINS(JSON_EXTRACT(related_industries, :json_path), :industry_code)")
).params(json_path=json_path, industry_code=json.dumps(industry_code))
# 如果包含逗号,说明是多个行业代码
if ',' in industry_code:
codes = [code.strip() for code in industry_code.split(',') if code.strip()]
# 使用 OR 条件匹配任意一个行业代码
conditions = []
for code in codes:
conditions.append(
text("JSON_CONTAINS(JSON_EXTRACT(related_industries, :json_path), :code)")
.bindparams(json_path=json_path, code=json.dumps(code))
)
query = query.filter(db.or_(*conditions))
else:
# 单个行业代码
query = query.filter(
text("JSON_CONTAINS(JSON_EXTRACT(related_industries, :json_path), :industry_code)")
).params(json_path=json_path, industry_code=json.dumps(industry_code))
# 新增:关键词/全文搜索过滤MySQL JSON
if search_query:
like_pattern = f"%{search_query}%"