From 5304840c432ae0f5bb29332755935c216a6cd1bb Mon Sep 17 00:00:00 2001 From: shengyudong Date: Thu, 5 Feb 2026 13:18:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E7=89=87=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E9=80=BB=E8=BE=91=EF=BC=9A=E4=BD=BF=E7=94=A8departmen?= =?UTF-8?q?t=5Fid=E8=BF=9B=E8=A1=8C=E7=A7=91=E5=AE=A4=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=EF=BC=8C=E7=8A=B6=E6=80=81=E5=9C=A8ai=5Fimages=E8=A1=A8?= =?UTF-8?q?=E4=B8=AD=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- article_auto_image_matching.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/article_auto_image_matching.py b/article_auto_image_matching.py index 3c2e330..e7ee1a2 100644 --- a/article_auto_image_matching.py +++ b/article_auto_image_matching.py @@ -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) # 如果没有匹配科室的图片,则使用所有图片