## 1. AnalyticsService 时段权重接口 - [x] 1.1 在 `services/analytics_service.py` 新增 `get_time_weights() -> dict` 方法,返回 `time_weights` 字典;无数据时返回默认高流量时段 `{"08-11时": 70, "12-14时": 60, "18-21时": 85, "21-24时": 75}` ## 2. 智能排期引擎 (PublishQueue) - [x] 2.1 在 `services/publish_queue.py` 的 `PublishQueue` 类新增 `suggest_schedule_time(analytics, max_per_slot=2, max_per_day=5) -> str | None` 方法:查询未来 7 天各时段已排期数量,结合 `analytics.get_time_weights()` 权重,返回最优排期时间(格式 `%Y-%m-%d %H:%M:%S`),所有时段满时返回 `None` - [x] 2.2 在 `PublishQueue` 新增 `auto_schedule_item(item_id, analytics, max_per_slot=2, max_per_day=5) -> bool` 方法:调用 `suggest_schedule_time()` 并更新队列项的 `scheduled_time` + 状态为 `scheduled`,无可用时段返回 `False` - [x] 2.3 在 `PublishQueue` 新增 `get_slot_usage(days=7) -> dict` 辅助方法:查询未来 N 天各日期各时段已排期的数量,供排期引擎和 UI 热力图使用 ## 3. generate_to_queue 增加自动排期参数 - [x] 3.1 修改 `services/queue_ops.py` 中 `generate_to_queue()` 签名,新增 `auto_schedule: bool = False` 和 `auto_approve: bool = False` 参数 - [x] 3.2 在 `generate_to_queue` 入队循环中,`auto_schedule=True` 时调用 `_pub_queue.auto_schedule_item(item_id, _analytics)` 为每篇内容自动分配排期时间 - [x] 3.3 在 `generate_to_queue` 入队循环中,`auto_approve=True` 时调用 `_pub_queue.approve(item_id)` 自动审核通过 - [x] 3.4 修改 `queue_generate_and_refresh()` 签名,新增 `auto_schedule` 参数并传递给 `generate_to_queue` ## 4. 统一发布路径 (scheduler) - [x] 4.1 修改 `services/scheduler.py` 中 `_scheduler_loop` 的自动发布分支:将 `auto_publish_once(...)` 调用替换为 `generate_to_queue(auto_schedule=True, auto_approve=True, count=1, ...)`,记录入队日志 - [x] 4.2 重构 `auto_publish_once`:移除直接 MCP client 发布逻辑,改为调用 `generate_to_queue(auto_schedule=True, auto_approve=True, count=1)`,保留函数签名供向后兼容 - [x] 4.3 在 `queue_ops.py` 的 `configure()` 中新增 `_analytics` 注入(如尚未注入),确保 `auto_schedule_item` 可获取分析服务 ## 5. UI 排期增强 - [x] 5.1 在 `ui/app.py` 的「批量生成到队列」区域新增 `gr.Checkbox(label="🤖 自动排期", value=False)` 组件,勾选后隐藏手动排期输入框 - [x] 5.2 修改批量生成按钮事件绑定,将自动排期复选框状态作为参数传入 `queue_generate_and_refresh` - [x] 5.3 在日历视图旁新增「📊 推荐时段」`gr.Markdown` 面板,调用 `analytics.get_time_weights()` 展示各时段权重和建议 ## 6. 验证 - [x] 6.1 `ast.parse()` 验证所有修改文件语法正确 - [ ] 6.2 手动测试:生成内容到队列并启用自动排期,确认 `scheduled_time` 被正确分配且不冲突 - [ ] 6.3 手动测试:调度器自动发布走队列路径,确认内容出现在队列表格中