修改文章状态查询和更新逻辑:查询pending_review状态文章,挂图完成后更新为published_review
This commit is contained in:
@@ -104,7 +104,7 @@ class ArticleImageMatcher:
|
|||||||
SELECT 1 FROM ai_article_images ai
|
SELECT 1 FROM ai_article_images ai
|
||||||
WHERE ai.article_id = at.article_id
|
WHERE ai.article_id = at.article_id
|
||||||
)
|
)
|
||||||
AND a.status = 'approved'
|
AND a.status = 'pending_review'
|
||||||
ORDER BY at.id DESC
|
ORDER BY at.id DESC
|
||||||
LIMIT %s
|
LIMIT %s
|
||||||
"""
|
"""
|
||||||
@@ -296,6 +296,40 @@ class ArticleImageMatcher:
|
|||||||
self.log_to_database('ERROR', error_msg, traceback.format_exc())
|
self.log_to_database('ERROR', error_msg, traceback.format_exc())
|
||||||
return False, 0.0
|
return False, 0.0
|
||||||
|
|
||||||
|
def update_article_status(self, article_id: int, new_status: str) -> bool:
|
||||||
|
"""
|
||||||
|
更新文章状态
|
||||||
|
|
||||||
|
Args:
|
||||||
|
article_id: 文章ID
|
||||||
|
new_status: 新状态
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
是否更新成功
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
connection = self.db_manager.get_connection()
|
||||||
|
try:
|
||||||
|
with connection.cursor(pymysql.cursors.DictCursor) as cursor:
|
||||||
|
# 更新文章状态
|
||||||
|
update_sql = """
|
||||||
|
UPDATE ai_articles
|
||||||
|
SET status = %s
|
||||||
|
WHERE id = %s
|
||||||
|
"""
|
||||||
|
cursor.execute(update_sql, (new_status, article_id))
|
||||||
|
|
||||||
|
connection.commit()
|
||||||
|
logger.info(f"成功更新文章 {article_id} 状态为 {new_status}")
|
||||||
|
return True
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
except Exception as e:
|
||||||
|
error_msg = f"更新文章状态异常: {e}"
|
||||||
|
logger.error(error_msg)
|
||||||
|
self.log_to_database('ERROR', error_msg, traceback.format_exc())
|
||||||
|
return False
|
||||||
|
|
||||||
def insert_article_image_relation(self, article_id: int, image_data: Dict,
|
def insert_article_image_relation(self, article_id: int, image_data: Dict,
|
||||||
match_score: float) -> bool:
|
match_score: float) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -362,6 +396,9 @@ class ArticleImageMatcher:
|
|||||||
"""
|
"""
|
||||||
cursor.execute(update_image_status_sql, (image_data['image_id'],))
|
cursor.execute(update_image_status_sql, (image_data['image_id'],))
|
||||||
|
|
||||||
|
# 更新文章状态为published_review
|
||||||
|
self.update_article_status(article_id, 'published_review')
|
||||||
|
|
||||||
connection.commit()
|
connection.commit()
|
||||||
logger.info(f"成功插入文章图片关联 - 文章ID: {article_id}, 图片ID: {image_data['image_id']}, 分数: {match_score}")
|
logger.info(f"成功插入文章图片关联 - 文章ID: {article_id}, 图片ID: {image_data['image_id']}, 分数: {match_score}")
|
||||||
return True
|
return True
|
||||||
@@ -678,6 +715,9 @@ class ArticleImageMatcher:
|
|||||||
"""
|
"""
|
||||||
cursor.execute(update_image_status_sql, (image_id,))
|
cursor.execute(update_image_status_sql, (image_id,))
|
||||||
|
|
||||||
|
# 更新文章状态为published_review
|
||||||
|
self.update_article_status(article_id, 'published_review')
|
||||||
|
|
||||||
connection.commit()
|
connection.commit()
|
||||||
return article_image_id
|
return article_image_id
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user