update pay ui
This commit is contained in:
60
app_vx.py
60
app_vx.py
@@ -1204,7 +1204,7 @@ class Event(db.Model):
|
||||
follower_count = db.Column(db.Integer, default=0)
|
||||
|
||||
# 关联信息
|
||||
related_industries = db.Column(db.JSON)
|
||||
related_industries = db.Column(db.String(20)) # 申万行业代码,如 "S640701"
|
||||
keywords = db.Column(db.JSON)
|
||||
files = db.Column(db.JSON)
|
||||
importance = db.Column(db.String(20))
|
||||
@@ -2962,37 +2962,14 @@ def api_get_events():
|
||||
code_prefixes = SYWG_INDUSTRY_CACHE[industry_level].get(industry_classification, [])
|
||||
|
||||
if code_prefixes:
|
||||
# 构建查询条件:查找related_industries中包含这些前缀的事件
|
||||
if isinstance(db.engine.dialect, MySQLDialect):
|
||||
# MySQL JSON查询
|
||||
conditions = []
|
||||
for prefix in code_prefixes:
|
||||
conditions.append(
|
||||
text("""
|
||||
JSON_SEARCH(
|
||||
related_industries,
|
||||
'one',
|
||||
CONCAT(:prefix, '%'),
|
||||
NULL,
|
||||
'$[*]."申银万国行业分类"'
|
||||
) IS NOT NULL
|
||||
""").params(prefix=prefix)
|
||||
)
|
||||
# 构建查询条件:查找related_industries以这些前缀开头的事件
|
||||
# related_industries 现在是 varchar 格式,如 "S640701"
|
||||
conditions = []
|
||||
for prefix in code_prefixes:
|
||||
conditions.append(Event.related_industries.like(f"{prefix}%"))
|
||||
|
||||
if conditions:
|
||||
query = query.filter(or_(*conditions))
|
||||
else:
|
||||
# 其他数据库
|
||||
pattern_conditions = []
|
||||
for prefix in code_prefixes:
|
||||
pattern_conditions.append(
|
||||
text("related_industries::text LIKE :pattern").params(
|
||||
pattern=f'%"申银万国行业分类": "{prefix}%'
|
||||
)
|
||||
)
|
||||
|
||||
if pattern_conditions:
|
||||
query = query.filter(or_(*pattern_conditions))
|
||||
if conditions:
|
||||
query = query.filter(or_(*conditions))
|
||||
else:
|
||||
# 没有找到匹配的行业代码,返回空结果
|
||||
query = query.filter(Event.id == -1)
|
||||
@@ -3019,25 +2996,8 @@ def api_get_events():
|
||||
if sector_result and sector_result[0]:
|
||||
industry_code_to_search = sector_result[0]
|
||||
|
||||
# 在related_industries JSON中查找包含该代码的事件
|
||||
if isinstance(db.engine.dialect, MySQLDialect):
|
||||
query = query.filter(
|
||||
text("""
|
||||
JSON_SEARCH(
|
||||
related_industries,
|
||||
'one',
|
||||
:industry_code,
|
||||
NULL,
|
||||
'$[*]."申银万国行业分类"'
|
||||
) IS NOT NULL
|
||||
""")
|
||||
).params(industry_code=industry_code_to_search)
|
||||
else:
|
||||
query = query.filter(
|
||||
text("""
|
||||
related_industries::text LIKE :pattern
|
||||
""")
|
||||
).params(pattern=f'%"申银万国行业分类": "{industry_code_to_search}"%')
|
||||
# related_industries 现在是 varchar 格式,直接匹配
|
||||
query = query.filter(Event.related_industries == industry_code_to_search)
|
||||
else:
|
||||
# 如果没有找到对应的行业代码,返回空结果
|
||||
query = query.filter(Event.id == -1)
|
||||
|
||||
Reference in New Issue
Block a user