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