From b9bee5287833cf413aa9fcf850f8014e66b40332 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Sat, 31 Oct 2026 10:12:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=AE=A1=E5=88=92):=20=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E5=8B=BE=E9=80=89=E9=A1=B9=20+=20=E5=BE=85?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ae_plan 新增 comment_mode(schema v26) - 计划编辑器勾「评论计划」:账号显示待评论 N、隐藏视频未发/素材区,段内禁止发布素材 - list_accounts 带 comment_pending;comment.pending_counts 按账号汇总 - 计划列表显示评论待处理总数与「评论」标签 - 测试 test_comment/test_plan --- core/account_folder.py | 8 ++++ core/comment.py | 21 ++++++++++ core/models.py | 6 +++ core/plan.py | 3 ++ doc/ACCOUNT_FOLDER.md | 7 +++- doc/API.md | 4 +- doc/CHANGES_2026-10.md | 18 ++++++++ doc/DATA_MODEL.md | 1 + scripts/tests/test_comment.py | 5 +++ scripts/tests/test_plan.py | 4 ++ static/admin/account_folder.js | 76 +++++++++++++++++++++++++++------- 11 files changed, 134 insertions(+), 19 deletions(-) diff --git a/core/account_folder.py b/core/account_folder.py index 8862060..83a1ef2 100644 --- a/core/account_folder.py +++ b/core/account_folder.py @@ -169,6 +169,11 @@ def list_accounts(prof=None): roster = {r["nickname"]: r for r in roster_rows() if r.get("nickname")} except Exception: roster = {} + try: + from core import comment as _comment + comment_counts = _comment.pending_counts() + except Exception: + comment_counts = {"by_id": {}, "by_name": {}} all_names = sorted(dirs | set(roster.keys())) for name in all_names: d = os.path.join(root, name) @@ -185,8 +190,11 @@ def list_accounts(prof=None): last = (AeRun.query.filter(AeRun.account == name) .order_by(AeRun.started_at.desc()).first()) rr = roster.get(name) or {} + cp = ((comment_counts.get("by_id") or {}).get(rr.get("id") or "") + or (comment_counts.get("by_name") or {}).get(name) or 0) out.append({"name": name, "media": media, "pending": pending, "done": done, "total": total, "need_text": need_text, + "comment_pending": int(cp or 0), "unscanned": max(0, media - total), "has_dir": has_dir, "device_name": rr.get("device_name") or "", diff --git a/core/comment.py b/core/comment.py index dba3e58..02a71a1 100644 --- a/core/comment.py +++ b/core/comment.py @@ -293,6 +293,27 @@ def pending_accounts(): for n, i, c in rows] +def pending_counts(): + """按账号汇总待评论(pending + failed),给资产/计划页面显示。 + + 返回 `{"by_id": {account_id: n}, "by_name": {nickname: n}}`;两种键都查, + 账号改名后 by_id 仍能对上。 + """ + with _ctx(): + rows = (db.session.query(CommentItem.account_id, CommentItem.account_name, + db.func.count(CommentItem.id)) + .filter(CommentItem.status.in_(("pending", "failed"))) + .group_by(CommentItem.account_id, CommentItem.account_name).all()) + by_id, by_name = {}, {} + for aid, name, n in rows: + n = int(n or 0) + if aid: + by_id[aid] = by_id.get(aid, 0) + n + if name: + by_name[name] = by_name.get(name, 0) + n + return {"by_id": by_id, "by_name": by_name} + + # ================== 原子领取 / 标记 ================== def _reclaim_stale_locked(): cutoff = time.strftime("%Y-%m-%d %H:%M:%S", diff --git a/core/models.py b/core/models.py index 1415ebf..cd3ca46 100644 --- a/core/models.py +++ b/core/models.py @@ -977,6 +977,9 @@ class AePlan(db.Model): action_id = db.Column(db.String(32), default="", index=True) # 业务动作组(引用,删除保护靠它) prep_action_id = db.Column(db.String(32), default="") # 准备动作组;空 = 用 App 的开场动作 prep_check = db.Column(db.Boolean, default=True) # 触发前预检(设备在线/账号可达) + # 2026-10-31:评论计划标记。勾选后页面按「评论数据」显示待评论数、不显示视频未发; + # 执行侧仍由任务里的 foreach_comment 取数(本字段不影响调度逻辑)。 + comment_mode = db.Column(db.Boolean, default=False) account_ids = db.Column(_long_text(), default="[]") # 手选账号(账号库 DeviceAccount.id) accounts = db.Column(_long_text(), default="[]") # 名字快照(账号被删/改名后仍能说明) target = db.Column(_long_text(), default="{}") # 可选:{"map": {"账号名": "A01"}} 人工指定 @@ -1023,6 +1026,7 @@ class AePlan(db.Model): "app_id": self.app_id or "", "action_id": self.action_id or "", "prep_action_id": self.prep_action_id or "", "prep_check": bool(self.prep_check), + "comment_mode": bool(self.comment_mode), "max_parallel": int(self.max_parallel or 0), "preempt": bool(self.preempt), "note": self.note or "", "created_at": self.created_at or "", "updated_at": self.updated_at or ""} @@ -1143,6 +1147,8 @@ SCHEMA_MIGRATIONS = [ "优先于任务自动写入的 account_status,对外 API 同时返回两者)", None), (25, "自动评论:新增 comment_item(视频链接/账号/评论内容/状态;" "pending/running/done/failed/unknown,failed 可重试、unknown 等人工裁决)", None), + (26, "评论计划标记:ae_plan 新增 comment_mode(勾选后页面显示评论待处理数、" + "不显示视频未发;不影响执行取数)", None), ] # 当前 schema 版本(备份/恢复用它判断新旧,也写进 app_meta.schema_version) diff --git a/core/plan.py b/core/plan.py index 5fcf37e..9f03a16 100644 --- a/core/plan.py +++ b/core/plan.py @@ -64,6 +64,7 @@ DEFAULT_PLAN = { "ready": {}, "prep_action_id": "", # 空 = 用该 App 的开场动作(opening_for) "prep_check": True, # 触发前预检:账号库没有 / 设备没入池 / 离线 → 跳过并写明原因 + "comment_mode": False, # 评论计划:页面按评论数据计数,不显示视频未发 "account_ids": [], # 账号库 DeviceAccount.id "accounts": [], # 名字(展示 + 账号被删后还能说明) "target": {}, # 可选 {"map": {"账号名": "A01"}} 人工指定设备 @@ -252,6 +253,8 @@ def save_plan(data, plan_id=""): row.set_json("ready", clean_ready(data.get("ready"))) row.prep_action_id = (data.get("prep_action_id") or "").strip() row.prep_check = bool(data.get("prep_check", True)) + if data.get("comment_mode") is not None: + row.comment_mode = bool(data.get("comment_mode")) row.preempt = bool(data.get("preempt", False)) row.max_parallel = max(0, int(data.get("max_parallel") or 0)) row.note = data.get("note") or "" diff --git a/doc/ACCOUNT_FOLDER.md b/doc/ACCOUNT_FOLDER.md index b478836..bd9173f 100644 --- a/doc/ACCOUNT_FOLDER.md +++ b/doc/ACCOUNT_FOLDER.md @@ -282,9 +282,12 @@ App 从每段的动作组/任务带出来(列表里显示"动作组 · App"或 链接可以是整段抖音分享文本,平台会抠出抖音链接。 - 「评论数据」看每条的状态:待评论 / 执行中 / 已评论 / 失败可重试 / 结果未知; 支持重置为待评论、人工标已发/未知、删除。 -- 建计划时选**评论任务**、**不勾「发布素材」**、勾有评论的账号、设时间点。 +- 建计划时勾 **「评论计划」**(计划名旁会显示「评论」标签):账号列表改成显示 + **待评论 N**(不再显示视频未发),「发什么」素材区自动隐藏;选评论任务、 + **不勾「发布素材」**、勾有评论的账号、设时间点。 运行时先切号,再跑任务里的 `foreach_comment`:按当前账号取一条 → 注入链接/评论 → 发送 → - 标记结果;一个号有多条就逐条跑。 + 标记结果;一个号有多条就逐条跑。评论计划**不需要视频素材**,`publish=false` 时 + `require_pending=false`,当天没有未发布视频也会跑。 - 评论不可逆:`failed` 会重试(最多 3 次),`unknown` **不自动重试**,要人工在「评论数据」里裁决。 ### 4.8 动作栏的三件事:内容一列 · 引用 · 标准件 diff --git a/doc/API.md b/doc/API.md index caf007d..476715a 100644 --- a/doc/API.md +++ b/doc/API.md @@ -1182,8 +1182,8 @@ POST /api/af/plans "selector_value": "首页", "what": "首页"}}, // none | exists | missing {"source": "task", "task_id": "6b77356a", "name": "发布视频111", "publish": false}], // 任务段:只取任务步骤(外层账号循环会拆掉) - "ready": {"enabled": true, "wait_after": 15, "max_attempts": 2, - "on_fail": "skip_account"}, // 内置「账号就绪/切号」参数覆盖;空 = 全局默认 + "ready": {"enabled": true, "use_global": true}, // 默认用全局 fleet.switch;false 才用本计划覆盖 + "comment_mode": false, // true = 评论计划:页面按 comment_item 计数,不取视频素材 "material": {"mode": "pool", "ids": []}, // ids = 第二个发布段以外的“勾具体几条”只作用第一发布段 "schedule": {"points": ["14:30", "20:00"], "jitter_sec": 600, "date_from": "", "date_to": ""}, // 固定点 + 每个点前后随机抖动(秒) diff --git a/doc/CHANGES_2026-10.md b/doc/CHANGES_2026-10.md index 3b78167..7a7ad58 100644 --- a/doc/CHANGES_2026-10.md +++ b/doc/CHANGES_2026-10.md @@ -1090,3 +1090,21 @@ A02 一度被记成 20.65(实际是 A11 的手机),自动认领把 A11 迁 不用逐个计划改。`clean_ready` 白名单增加 `use_global`。 - 测试:`test_plan.py` ②d(全局选择器生效 / 老计划仍用全局 / 显式覆盖); `test_roster.py` ⑪(导出 CSV 表头与账号)。 + +## 41. 2026-10-31 新增:计划「评论计划」勾选项(按评论数据计数) + +用户:"我现在的评论计划会调用评论数据吗?我看评论计划里面的未发都是 0。可以给计划加个勾选项是评论吗, +勾选了评论就不显示视频的未发、显示评论的未发了。" + +- 先回答:**会调用**。`2f557c41` 的计划段指向任务 `c2ef838e`,任务里是 + `foreach_comment`,运行时会按当前账号从 `comment_item` 取待评论;之前显示的「未发 0」 + 是**视频素材**待发数,不是评论数(评论计划不取视频素材)。 +- `ae_plan.comment_mode`(schema v26):计划编辑器新增 **「评论计划」** 勾选。 + - 账号勾选列表改为显示 **待评论 N**(`comment_item` pending+failed),按待评论数排序; + - 计划列表「发什么」显示「评论 · 待评论 N 条」,计划名旁有「评论」标签; + - 自动隐藏「发什么」素材区,并禁止/清除段里的「发布素材」; + - 执行逻辑不变(仍由任务的 `foreach_comment` 取数)。 +- `list_accounts` 新增 `comment_pending`(资产接口/计划编辑器共用); + `core/comment.pending_counts()` 按 `account_id`(改名也能对上)汇总。 +- 计划 `2f557c41` 已标记 `comment_mode=true`;账号列表会显示每个号真实的待评论数。 +- 注意:计划里勾的账号必须和导入评论的账号一致;不勾的账号不会跑。 diff --git a/doc/DATA_MODEL.md b/doc/DATA_MODEL.md index ec86767..4218a80 100644 --- a/doc/DATA_MODEL.md +++ b/doc/DATA_MODEL.md @@ -279,6 +279,7 @@ | `app_id` / `action_id` | **主 App + 老字段**:`action_id` 仍指向一个业务动作组(`segments` 为空时用它跑;非空时保存第一段,兼容老页面)。也是"删组合前提示引用"的引用点 | | **`ready`** | **内置「账号就绪(切号)」的参数覆盖**(2026-10-18 新增):`{"enabled":true,"use_global":true,"switch_selector_type","switch_selector_value","me_selector_type","me_selector_value","name_selector_type","name_selector_value","timeout","wait_after","max_attempts","on_login_page","on_fail"}`;**2026-10-31 起默认 `use_global=true`** → 用全局 `ae_profile.params.fleet.switch`(`GET /api/af/ready_defaults`),老计划没有该字段也按全局走;只有显式 `use_global=false` 才用本计划覆盖。`enabled=false` = 关闭内置切号(由用户在自己的编排里放切号动作组) | | **`segments`** | **动作编排**(2026-10-17 新增,2026-10-18 支持任务段):`[{"source":"action|task","action_id","task_id","app_id","name","publish","per_account","loop":{"mode":"none|rounds|time","rounds","seconds"},"home_before":"none|click|cold","home_after":…,"when":{"mode":"none|exists|missing","selector_type","selector_value","what"}}]` —— 一个账号按顺序跑多段;**action** = 引用动作组,**task** = 只取任务步骤(触发时现读、拆掉任务最外层 `foreach_account`);`publish=true` 的段走素材池(任务段通常不用) | +| `comment_mode` | **评论计划标记**(2026-10-31,v26):勾选后页面按 `comment_item` 显示「待评论 N」,不再显示视频「未发 N」;执行仍由任务里的 `foreach_comment` 取数,本字段不影响调度 | | `account_ids` / `accounts` | **给谁干**:账号库手选的 id + 名字快照(名字是真相,触发时现算在哪台手机) | | `material` | **发什么**:`{"mode":"pool|pick","per_account":N,"ids":[…],"date_source","fixed_date"}`;每段自己的条数在 `segments[].per_account`(0 = 全发),`ids` 只作用于**第一个发布段**(逐条按 id 占位,取不到就跳过) | | `schedule` | **什么时候**:`{"points": ["21:00"], "jitter_sec": 600, "date_from", "date_to", "window"}` | diff --git a/scripts/tests/test_comment.py b/scripts/tests/test_comment.py index 76e0878..9b39368 100644 --- a/scripts/tests/test_comment.py +++ b/scripts/tests/test_comment.py @@ -21,6 +21,7 @@ os.chdir(_ROOT) from flask import Flask # noqa: E402 from core.models import db, init_db, DeviceAccount, CommentItem # noqa: E402 from core import comment as cm # noqa: E402 +from core import account_folder as af # noqa: E402 from tasks.generic import task as gt # noqa: E402 fails = [] @@ -39,6 +40,7 @@ app.config["SQLALCHEMY_DATABASE_URI"] = os.environ["DATABASE_URL"] with app.app_context(): init_db(app) cm.init_app(app) +af._app = app def reset_db(): @@ -80,6 +82,9 @@ with app.app_context(): row = CommentItem.query.filter_by(account_name="号甲").first() check("入库 pending", row.status, "pending") check("account_id", row.account_id, "a1") +_accts = af.list_accounts() +_acct = [x for x in _accts if x["name"] == "号甲"][0] +check("资产表带待评论数", _acct.get("comment_pending"), 1) r = cm.import_comments(txt.replace("第一条", "改过的")) check("重复导入更新", (r["added"], r["updated"]), (0, 1)) with app.app_context(): diff --git a/scripts/tests/test_plan.py b/scripts/tests/test_plan.py index d025d00..cd162db 100644 --- a/scripts/tests/test_plan.py +++ b/scripts/tests/test_plan.py @@ -360,6 +360,10 @@ try: "action_id": "act1", "app_id": "app1", "material": {"per_account": 5}}, r["id"])["ok"], True) check("读回来是改后的", plan_mod.get_plan(r["id"])["material"]["per_account"], 5) + check("评论计划标记保存成功", + plan_mod.save_plan({"name": "夜间发布", "accounts": ["号甲"], + "comment_mode": True}, r["id"])["ok"], True) + check("评论计划标记读回", plan_mod.get_plan(r["id"])["comment_mode"], True) check("只有一条计划(没重复建)", len(plan_mod.list_plans()), 1) rseg = plan_mod.save_plan({"name": "编排计划", "accounts": ["号甲"], "segments": [ {"action_id": "act1", "app_id": "app1", "name": "发布", "publish": True, diff --git a/static/admin/account_folder.js b/static/admin/account_folder.js index b53cf3b..4c59241 100644 --- a/static/admin/account_folder.js +++ b/static/admin/account_folder.js @@ -1928,16 +1928,25 @@ function afHtmlPlan() { }).join(' → ') : (act.name || '(没选动作组)')); const pubs = segs.filter(function (s) { return s.publish; }); - const n = pubs.length - ? ('发布段 ' + pubs.length + ' · 每号 ' + (pubs[0].per_account || 0) + ' 条') - : (segs.length ? '只跑动作' - : ((mat.mode === 'pick' && (mat.ids || []).length) - ? ('指定 ' + mat.ids.length + ' 条') - : ((mat.per_account === 0 || mat.per_account === undefined) - ? '当天待发全发' : ('每人 ' + mat.per_account + ' 条')))); + const isComment = !!p.comment_mode; + const commentByName = {}; + (_af.accounts || []).forEach(function (a) { commentByName[a.name] = a.comment_pending || 0; }); + const commentTotal = (p.accounts || []).reduce(function (s, n) { + return s + (commentByName[n] || 0); + }, 0); + const n = isComment + ? ('评论 · 待评论 ' + commentTotal + ' 条') + : (pubs.length + ? ('发布段 ' + pubs.length + ' · 每号 ' + (pubs[0].per_account || 0) + ' 条') + : (segs.length ? '只跑动作' + : ((mat.mode === 'pick' && (mat.ids || []).length) + ? ('指定 ' + mat.ids.length + ' 条') + : ((mat.per_account === 0 || mat.per_account === undefined) + ? '当天待发全发' : ('每人 ' + mat.per_account + ' 条'))))); const last = p.last_run; return '