luojunhui 2 tuần trước cách đây
mục cha
commit
a6b0e9e6d4

+ 2 - 2
app/domains/monitor_tasks/auto_reply_cards_monitor/_mapper.py

@@ -29,7 +29,7 @@ class AutoReplyCardsMonitorMapper(AutoReplyCardsMonitorConst):
         query = """
             SELECT partner_name, partner_id, gh_id, status, follow_status
             FROM cooperate_accounts
-            WHERE account_name = %s;
+            WHERE account_name = %s AND status = 1;
         """
         return await self.pool.async_fetch(query=query, params=(account_name,))
 
@@ -182,7 +182,7 @@ class AutoReplyCardsMonitorMapper(AutoReplyCardsMonitorConst):
                    t1.name AS account_name, t1.gh_id
             FROM content_platform_gzh_account t1 JOIN content_platform_account t2
             ON t1.create_account_id = t2.id
-            WHERE t1.name =  %s;
+            WHERE t1.name = %s AND t1.status = 1;
         """
         fetch_response = await self.pool.async_fetch(
             query=fetch_query, db_name="growth", params=(account_name,)

+ 48 - 11
app/domains/monitor_tasks/auto_reply_cards_monitor/entrance.py

@@ -583,34 +583,71 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
                     continue
 
                 account_detail = fetch_response[0]
-                status = account_detail.get("status")
-                if not status:
+                gh_id = account_detail.get("gh_id")
+                if not gh_id:
+                    await self.log_service.log(
+                        contents={
+                            "task": "auto_reply_cards_monitor",
+                            "function": "follow_gzh_task",
+                            "status": "fail",
+                            "message": f"账号缺少 gh_id: {account_name}",
+                        }
+                    )
+                    continue
+
+                # 调用 blogger 接口检查账号实时状态(违规/迁移)
+                blogger_response = await get_article_list_from_account(
+                    gh_id, is_cache=False
+                )
+                if not blogger_response:
                     await self.log_service.log(
                         contents={
                             "task": "auto_reply_cards_monitor",
                             "function": "follow_gzh_task",
                             "status": "warn",
-                            "message": f"账号已经迁移或者封禁: {account_name}",
+                            "message": f"blogger 接口无响应, 跳过: {account_name}, gh_id={gh_id}",
                         }
                     )
                     continue
 
-                gh_id = account_detail.get("gh_id")
-                if not gh_id:
+                blogger_code = blogger_response.get("code")
+                if blogger_code != 0:
+                    blogger_msg = blogger_response.get("msg", "")
+                    if blogger_code == 25013:
+                        alert_title = f"自动回复卡片-账号违规: {account_name}"
+                    else:
+                        alert_title = f"自动回复卡片-账号异常(可能已迁移): {account_name}"
+
+                    await self.mapper.set_account_as_invalid(gh_id)
+                    try:
+                        await feishu_robot.bot(
+                            title=alert_title,
+                            detail={
+                                "account_name": account_name,
+                                "gh_id": gh_id,
+                                "code": blogger_code,
+                                "msg": blogger_msg,
+                            },
+                            mention=True,
+                            env="long_articles_task",
+                        )
+                    except Exception:
+                        pass
+
                     await self.log_service.log(
                         contents={
                             "task": "auto_reply_cards_monitor",
                             "function": "follow_gzh_task",
-                            "status": "fail",
-                            "message": f"账号缺少 gh_id: {account_name}",
+                            "status": "warn",
+                            "message": f"账号状态异常, 已标记无效并跳过: {account_name}, gh_id={gh_id}, code={blogger_code}, msg={blogger_msg}",
                         }
                     )
                     continue
 
-                # print(gh_id, account_name, uv, priority)
-                await self.create_auto_reply_single_account_task(
-                    gh_id, account_name, priority
-                )
+                print(gh_id, account_name, priority)
+                # await self.create_auto_reply_single_account_task(
+                #     gh_id, account_name, priority
+                # )
 
             except Exception as e:
                 await self.log_service.log(