修改图片过滤逻辑:使用department_id进行科室匹配,状态在ai_images表中判断

This commit is contained in:
2026-02-05 13:18:09 +08:00
parent affa815fe1
commit 5304840c43

View File

@@ -154,13 +154,15 @@ class ArticleImageMatcher:
it.image_source
FROM ai_image_tags it
WHERE it.image_attached_article_count < 5
AND it.image_id IN (
SELECT id FROM ai_images
WHERE status = 'generate'
AND EXISTS (
SELECT 1 FROM ai_images i
WHERE i.id = it.image_id
AND i.status = 'generate'
)
ORDER BY it.image_attached_article_count ASC, it.id DESC
"""
cursor.execute(sql)
cursor.execute(sql)
results = cursor.fetchall()
if results:
@@ -758,11 +760,13 @@ class ArticleImageMatcher:
logger.info(f"开始为文章 {article_id} 匹配图片 - 标题: {article_title}, 标签: {article_tags}, 科室: {article_department}")
# 根据文章科室缩小图片范围
# 根据文章科室ID缩小图片范围
department_filtered_images = []
article_dept_id = article_data.get('department_id', 0)
for img in available_images:
# 优先匹配科室相同的图片
if article_department and img.get('department_name', '').lower() == article_department.lower():
# 匹配科室ID相同的图片
if img.get('department_id', 0) == article_dept_id:
department_filtered_images.append(img)
# 如果没有匹配科室的图片,则使用所有图片