From 514f085c79814c9326b0feb83a37ab8ce25e4f95 Mon Sep 17 00:00:00 2001 From: shengyudong Date: Thu, 5 Feb 2026 11:45:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E7=AB=A0=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=9F=A5=E8=AF=A2=E5=92=8C=E6=9B=B4=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=9A=E6=9F=A5=E8=AF=A2pending=5Freview=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=96=87=E7=AB=A0=EF=BC=8C=E6=8C=82=E5=9B=BE=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=90=8E=E6=9B=B4=E6=96=B0=E4=B8=BApublished=5Freview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- article_auto_image_matching.py | 42 +++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/article_auto_image_matching.py b/article_auto_image_matching.py index 731cbee..3af036c 100644 --- a/article_auto_image_matching.py +++ b/article_auto_image_matching.py @@ -104,7 +104,7 @@ class ArticleImageMatcher: SELECT 1 FROM ai_article_images ai WHERE ai.article_id = at.article_id ) - AND a.status = 'approved' + AND a.status = 'pending_review' ORDER BY at.id DESC LIMIT %s """ @@ -296,6 +296,40 @@ class ArticleImageMatcher: self.log_to_database('ERROR', error_msg, traceback.format_exc()) 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, match_score: float) -> bool: """ @@ -362,6 +396,9 @@ class ArticleImageMatcher: """ cursor.execute(update_image_status_sql, (image_data['image_id'],)) + # 更新文章状态为published_review + self.update_article_status(article_id, 'published_review') + connection.commit() logger.info(f"成功插入文章图片关联 - 文章ID: {article_id}, 图片ID: {image_data['image_id']}, 分数: {match_score}") return True @@ -678,6 +715,9 @@ class ArticleImageMatcher: """ cursor.execute(update_image_status_sql, (image_id,)) + # 更新文章状态为published_review + self.update_article_status(article_id, 'published_review') + connection.commit() return article_image_id finally: