feat(计划): 评论计划勾选项 + 待评论计数
- ae_plan 新增 comment_mode(schema v26) - 计划编辑器勾「评论计划」:账号显示待评论 N、隐藏视频未发/素材区,段内禁止发布素材 - list_accounts 带 comment_pending;comment.pending_counts 按账号汇总 - 计划列表显示评论待处理总数与「评论」标签 - 测试 test_comment/test_plan
This commit is contained in:
@@ -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 "",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 ""
|
||||
|
||||
Reference in New Issue
Block a user