# 策略概览与选择机制

<cite>
**本文档引用的文件**
- [server/src/modules/book-generator/index.ts](file://server/src/modules/book-generator/index.ts)
- [server/src/modules/book-generator/graph.ts](file://server/src/modules/book-generator/graph.ts)
- [server/src/modules/book-generator/strategies/base.ts](file://server/src/modules/book-generator/strategies/base.ts)
- [server/src/modules/book-generator/strategies/selector.ts](file://server/src/modules/book-generator/strategies/selector.ts)
- [server/src/modules/book-generator/strategies/types.ts](file://server/src/modules/book-generator/strategies/types.ts)
- [server/src/modules/book-generator/strategies/sequential.strategy.ts](file://server/src/modules/book-generator/strategies/sequential.strategy.ts)
- [server/src/modules/book-generator/strategies/one-step-outline.strategy.ts](file://server/src/modules/book-generator/strategies/one-step-outline.strategy.ts)
- [server/src/modules/book-generator/strategies/per-chapter.strategy.ts](file://server/src/modules/book-generator/strategies/per-chapter.strategy.ts)
- [server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts](file://server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts)
- [server/src/modules/book-generator/fault-tolerance.ts](file://server/src/modules/book-generator/fault-tolerance.ts)
- [server/src/modules/book-generator/book-generator.service.ts](file://server/src/modules/book-generator/book-generator.service.ts)
- [server/src/modules/book-generator/book-generator.controller.ts](file://server/src/modules/book-generator/book-generator.controller.ts)
- [server/src/modules/book-generator/test/strategy-compare.ts](file://server/src/modules/book-generator/test/strategy-compare.ts)
- [server/src/modules/book-generator/README.md](file://server/src/modules/book-generator/README.md)
- [server/src/modules/book-generator/FAULT_TOLERANCE.md](file://server/src/modules/book-generator/FAULT_TOLERANCE.md)
</cite>

## 目录
1. [引言](#引言)
2. [项目结构](#项目结构)
3. [核心组件](#核心组件)
4. [架构总览](#架构总览)
5. [详细组件分析](#详细组件分析)
6. [依赖关系分析](#依赖关系分析)
7. [性能考量](#性能考量)
8. [故障排查指南](#故障排查指南)
9. [结论](#结论)
10. [附录](#附录)

## 引言
本文件围绕“生成策略概览与选择机制”展开，系统性阐述策略系统的设计理念、接口规范、选择器工作机制、配置参数、执行条件与性能监控，并提供最佳实践、常见问题解决方案与性能优化建议。策略系统采用策略模式与LangGraph工作流结合，支持多种生成路径（串行、一步大纲+并行内容、逐章内聚、DeepPlan+富大纲+并发+连贯性编辑），并通过统一的门面类对外暴露生成能力。

## 项目结构
策略系统位于后端模块 server/src/modules/book-generator 下，核心文件组织如下：
- 策略门面与入口：index.ts
- LangGraph状态定义：graph.ts
- 策略基类与通用执行封装：strategies/base.ts
- 策略选择器：strategies/selector.ts
- 策略接口与类型：strategies/types.ts
- 具体策略实现：sequential/one-step-outline/per-chapter/deep-plan-parallel
- 容错与监控：fault-tolerance.ts
- 批量生成编排：book-generator.service.ts
- API路由：book-generator.controller.ts
- 测试与说明文档：test/strategy-compare.ts、README.md、FAULT_TOLERANCE.md

```mermaid
graph TB
subgraph "策略系统"
IDX["index.ts<br/>策略门面"]
SEL["selector.ts<br/>策略选择器"]
BASE["base.ts<br/>基础策略执行"]
TYPES["types.ts<br/>接口与类型"]
STRAT_SEQ["sequential.strategy.ts"]
STRAT_ONE["one-step-outline.strategy.ts"]
STRAT_PER["per-chapter.strategy.ts"]
STRAT_DEEP["deep-plan-parallel.strategy.ts"]
FT["fault-tolerance.ts<br/>容错与监控"]
GRAPH["graph.ts<br/>LangGraph状态"]
end
IDX --> SEL
SEL --> STRAT_SEQ
SEL --> STRAT_ONE
SEL --> STRAT_PER
SEL --> STRAT_DEEP
STRAT_SEQ --> BASE
STRAT_ONE --> BASE
STRAT_PER --> BASE
STRAT_DEEP --> BASE
BASE --> FT
BASE --> GRAPH
```

**图表来源**
- [server/src/modules/book-generator/index.ts:74-91](file://server/src/modules/book-generator/index.ts#L74-L91)
- [server/src/modules/book-generator/strategies/selector.ts:14-77](file://server/src/modules/book-generator/strategies/selector.ts#L14-L77)
- [server/src/modules/book-generator/strategies/base.ts:26-72](file://server/src/modules/book-generator/strategies/base.ts#L26-L72)
- [server/src/modules/book-generator/strategies/types.ts:8-22](file://server/src/modules/book-generator/strategies/types.ts#L8-L22)
- [server/src/modules/book-generator/strategies/sequential.strategy.ts:21-59](file://server/src/modules/book-generator/strategies/sequential.strategy.ts#L21-L59)
- [server/src/modules/book-generator/strategies/one-step-outline.strategy.ts:21-55](file://server/src/modules/book-generator/strategies/one-step-outline.strategy.ts#L21-L55)
- [server/src/modules/book-generator/strategies/per-chapter.strategy.ts:21-55](file://server/src/modules/book-generator/strategies/per-chapter.strategy.ts#L21-L55)
- [server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts:32-73](file://server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts#L32-L73)
- [server/src/modules/book-generator/fault-tolerance.ts:17-51](file://server/src/modules/book-generator/fault-tolerance.ts#L17-L51)
- [server/src/modules/book-generator/graph.ts:23-82](file://server/src/modules/book-generator/graph.ts#L23-L82)

**章节来源**
- [server/src/modules/book-generator/index.ts:1-119](file://server/src/modules/book-generator/index.ts#L1-L119)
- [server/src/modules/book-generator/README.md:1-215](file://server/src/modules/book-generator/README.md#L1-L215)

## 核心组件
- 策略接口与类型
  - 策略名称枚举：sequential、one-step-outline、per-chapter、deep-plan-parallel
  - GenerationStrategy 接口：包含 name、description、generate 方法
  - StrategyConfig：当前激活策略配置
- 策略门面 LangGraphBookGenerator
  - 提供 generate 入口，解析大纲层级 genLevel，委派给当前策略执行
- 基础策略执行 runGraphWorkflow
  - 统一编译与流式执行 LangGraph 工作流
  - 初始化进度与阶段，处理最终状态推进与发布
  - 异常捕获并标记失败
- 策略选择器 StrategySelector
  - 注册策略映射表
  - 提供当前策略查询、运行时切换、默认策略与类型导出
- LangGraph 状态定义
  - 定义 bookId、topic、bookScale、genLevel、progress、finished、error、completedChapters、failedChapters 等字段及其 reducer
  - 确保进度只增不减、章节完成列表合并等语义
- 容错与监控
  - AI调用重试（指数退避）、节点超时控制、进度监控、自动恢复
  - WebSocket通知类型丰富，覆盖重试、失败、超时、告警、恢复等场景

**章节来源**
- [server/src/modules/book-generator/strategies/types.ts:5-29](file://server/src/modules/book-generator/strategies/types.ts#L5-L29)
- [server/src/modules/book-generator/index.ts:74-91](file://server/src/modules/book-generator/index.ts#L74-L91)
- [server/src/modules/book-generator/strategies/base.ts:10-72](file://server/src/modules/book-generator/strategies/base.ts#L10-L72)
- [server/src/modules/book-generator/strategies/selector.ts:14-77](file://server/src/modules/book-generator/strategies/selector.ts#L14-L77)
- [server/src/modules/book-generator/graph.ts:23-82](file://server/src/modules/book-generator/graph.ts#L23-L82)
- [server/src/modules/book-generator/fault-tolerance.ts:17-332](file://server/src/modules/book-generator/fault-tolerance.ts#L17-L332)

## 架构总览
策略系统采用“门面 + 策略 + 工作流”的分层架构：
- 门面层：LangGraphBookGenerator 负责参数解析与策略委派
- 策略层：四种具体策略实现不同的节点组合与并发策略
- 执行层：runGraphWorkflow 统一编译与流式执行，配合容错监控
- 状态层：GraphState 定义跨节点共享的状态与语义约束

```mermaid
classDiagram
class GenerationStrategy {
+name : StrategyName
+description : string
+generate(bookId, topic, bookScale, genLevel) Promise~void~
}
class SequentialStrategy {
+name : "sequential"
+description : string
+generate(...)
}
class OneStepOutlineStrategy {
+name : "one-step-outline"
+description : string
+generate(...)
}
class PerChapterStrategy {
+name : "per-chapter"
+description : string
+generate(...)
}
class DeepPlanParallelStrategy {
+name : "deep-plan-parallel"
+description : string
+generate(...)
}
class LangGraphBookGenerator {
+generate(bookId, topic, bookScale, genLevel) Promise~void~
}
class StrategySelector {
+getCurrentStrategy() GenerationStrategy
+setCurrentStrategy(name) void
+getAllStrategies() GenerationStrategy[]
+getCurrentStrategyName() StrategyName
}
GenerationStrategy <|.. SequentialStrategy
GenerationStrategy <|.. OneStepOutlineStrategy
GenerationStrategy <|.. PerChapterStrategy
GenerationStrategy <|.. DeepPlanParallelStrategy
LangGraphBookGenerator --> StrategySelector : "委派"
StrategySelector --> GenerationStrategy : "实例化"
```

**图表来源**
- [server/src/modules/book-generator/strategies/types.ts:8-22](file://server/src/modules/book-generator/strategies/types.ts#L8-L22)
- [server/src/modules/book-generator/strategies/sequential.strategy.ts:21-59](file://server/src/modules/book-generator/strategies/sequential.strategy.ts#L21-L59)
- [server/src/modules/book-generator/strategies/one-step-outline.strategy.ts:21-55](file://server/src/modules/book-generator/strategies/one-step-outline.strategy.ts#L21-L55)
- [server/src/modules/book-generator/strategies/per-chapter.strategy.ts:21-55](file://server/src/modules/book-generator/strategies/per-chapter.strategy.ts#L21-L55)
- [server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts:32-73](file://server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts#L32-L73)
- [server/src/modules/book-generator/index.ts:74-91](file://server/src/modules/book-generator/index.ts#L74-L91)
- [server/src/modules/book-generator/strategies/selector.ts:58-77](file://server/src/modules/book-generator/strategies/selector.ts#L58-L77)

## 详细组件分析

### BaseStrategy 基类设计理念与通用接口
- 设计理念
  - 将所有策略共有的工作流编译、流式执行、进度推进、阶段推进、失败标记等逻辑抽象到基础执行函数中
  - 策略差异仅体现在节点图构建，从而降低重复代码与提高一致性
- 通用接口
  - runGraphWorkflow(bookId, initialState, workflow)：统一的执行入口
  - 基础选项 BaseStrategyOptions：包含 name、description、buildGraph
- 关键行为
  - 初始化 genStage 与进度
  - 编译并流式执行 StateGraph
  - 监控最终状态，推进至 content_completed/audio_generating/audio_completed/video_completed 等阶段
  - 失败时标记 failed 并记录失败阶段与错误信息
  - 释放进度监控器

```mermaid
sequenceDiagram
participant Caller as "调用方"
participant Facade as "LangGraphBookGenerator"
participant Selector as "StrategySelector"
participant Strategy as "GenerationStrategy"
participant Base as "runGraphWorkflow"
participant Graph as "StateGraph"
participant Monitor as "进度监控"
Caller->>Facade : generate(bookId, topic, bookScale, genLevel)
Facade->>Selector : getCurrentStrategy()
Selector-->>Facade : Strategy 实例
Facade->>Strategy : generate(...)
Strategy->>Graph : 构建节点与边
Strategy->>Base : 传入 workflow 与 initialState
Base->>Monitor : startProgressMonitor(bookId)
Base->>Graph : compile() + stream(initialState)
Graph-->>Base : 步进事件
Base->>Base : 推进进度/阶段
Base-->>Strategy : 执行完成
Strategy-->>Facade : Promise<void>
Facade-->>Caller : Promise<void>
```

**图表来源**
- [server/src/modules/book-generator/index.ts:74-91](file://server/src/modules/book-generator/index.ts#L74-L91)
- [server/src/modules/book-generator/strategies/selector.ts:58-77](file://server/src/modules/book-generator/strategies/selector.ts#L58-L77)
- [server/src/modules/book-generator/strategies/base.ts:26-72](file://server/src/modules/book-generator/strategies/base.ts#L26-L72)

**章节来源**
- [server/src/modules/book-generator/strategies/base.ts:10-72](file://server/src/modules/book-generator/strategies/base.ts#L10-L72)
- [server/src/modules/book-generator/strategies/types.ts:8-22](file://server/src/modules/book-generator/strategies/types.ts#L8-L22)

### StrategySelector 策略选择器工作原理
- 策略注册
  - 通过 STRATEGIES 映射表集中注册策略实例
  - 支持 sequential、one-step-outline、per-chapter、deep-plan-parallel
- 默认策略
  - DEFAULT_STRATEGY 指定当前推荐策略（deep-plan-parallel）
- 运行时切换
  - setCurrentStrategy(name)：立即生效，打印切换日志
  - 未知策略时保持当前策略并输出警告
- 查询接口
  - getCurrentStrategy()/getStrategy(name)/getAllStrategies()

```mermaid
flowchart TD
Start(["选择策略"]) --> CheckDefault["检查默认策略"]
CheckDefault --> SetCurrent["setCurrentStrategy(name)"]
SetCurrent --> Validate{"策略是否存在?"}
Validate --> |是| Update["更新 currentStrategy"]
Validate --> |否| Warn["输出警告并保持当前"]
Update --> Log["记录切换日志"]
Log --> End(["完成"])
Warn --> End
```

**图表来源**
- [server/src/modules/book-generator/strategies/selector.ts:37-56](file://server/src/modules/book-generator/strategies/selector.ts#L37-L56)

**章节来源**
- [server/src/modules/book-generator/strategies/selector.ts:14-77](file://server/src/modules/book-generator/strategies/selector.ts#L14-L77)

### 策略配置参数与执行条件
- 配置参数
  - 策略名称：StrategyName（枚举）
  - 策略描述：description（用于 UI/日志展示）
  - 大纲层级：genLevel（1=章；2=章→节；3=章→节→小节）
  - 书籍规模：bookScale（用于推断 genLevel 与资源分配）
- 执行条件
  - 门面层 resolveGenLevel 与 mapBookTypeToGenLevel 提供 genLevel 推断
  - 选择器 getCurrentStrategy 返回当前策略实例
  - 策略 generate 方法接收 bookId、topic、bookScale、genLevel 并构建对应 StateGraph

**章节来源**
- [server/src/modules/book-generator/index.ts:48-65](file://server/src/modules/book-generator/index.ts#L48-L65)
- [server/src/modules/book-generator/index.ts:25-42](file://server/src/modules/book-generator/index.ts#L25-L42)
- [server/src/modules/book-generator/strategies/types.ts:24-28](file://server/src/modules/book-generator/strategies/types.ts#L24-L28)

### 策略评估标准、优先级排序与动态切换机制
- 评估标准
  - 生成效率：并发度、节点数量、单次调用次数
  - 内容质量：富大纲、连贯性编辑、写作指导
  - 稳定性：容错、超时控制、自动恢复
- 优先级排序
  - 默认策略：deep-plan-parallel（推荐）
  - 其他策略作为对比与回退备选
- 动态切换
  - 运行时切换 setCurrentStrategy 即刻生效
  - 日志记录切换动作与描述
  - 适合 A/B 对比与紧急回退

**章节来源**
- [server/src/modules/book-generator/strategies/selector.ts:23-33](file://server/src/modules/book-generator/strategies/selector.ts#L23-L33)
- [server/src/modules/book-generator/strategies/selector.ts:49-56](file://server/src/modules/book-generator/strategies/selector.ts#L49-L56)

### 性能监控指标
- 进度监控
  - startProgressMonitor：周期性检查 book.progress，超过阈值发出告警与自动恢复
  - 告警级别：warning（10分钟）、critical（20分钟）、auto-recovery（30分钟）
- 节点超时
  - 不同节点设置不同超时阈值，超时触发自动恢复
- AI调用重试
  - 指数退避重试（最多3次），记录失败并通知用户

**章节来源**
- [server/src/modules/book-generator/fault-tolerance.ts:188-261](file://server/src/modules/book-generator/fault-tolerance.ts#L188-L261)
- [server/src/modules/book-generator/fault-tolerance.ts:131-180](file://server/src/modules/book-generator/fault-tolerance.ts#L131-L180)
- [server/src/modules/book-generator/fault-tolerance.ts:68-123](file://server/src/modules/book-generator/fault-tolerance.ts#L68-L123)

### 策略切换的日志记录、错误处理与回退机制
- 日志记录
  - 策略切换：输出新策略名称与描述
  - 容错：AI重试、节点超时、进度告警、自动恢复均有日志
- 错误处理
  - runGraphWorkflow 捕获异常并标记 failed，保留失败阶段与错误信息
  - 容错层统一包装 AI 调用与节点执行，失败后尝试自动恢复
- 回退机制
  - 自动恢复：最多2次，间隔5分钟
  - 用户通知：通过 WebSocket 推送多种通知类型

**章节来源**
- [server/src/modules/book-generator/strategies/selector.ts:50-55](file://server/src/modules/book-generator/strategies/selector.ts#L50-L55)
- [server/src/modules/book-generator/strategies/base.ts:62-71](file://server/src/modules/book-generator/strategies/base.ts#L62-L71)
- [server/src/modules/book-generator/fault-tolerance.ts:268-323](file://server/src/modules/book-generator/fault-tolerance.ts#L268-L323)

### 各策略实现要点与差异
- Sequential（串行）
  - 节点链：plan → outline → sections → subsections → content
  - 特点：严格串行，调用量较大
- One-Step Outline（一步大纲+并行内容）
  - 节点链：plan → full_outline → write_chapters
  - 特点：一次性生成完整树形大纲，随后批量写内容
- Per-Chapter（逐章内聚）
  - 节点链：plan → outline → per_chapter
  - 特点：先生成章大纲，每章独立生成内部结构与内容，支持并发
- DeepPlan Parallel（推荐）
  - 节点链：deep_plan → rich_outline → parallel_content → continuity_edit
  - 特点：AI深度规划、富大纲、并发生成、全局连贯性编辑

```mermaid
flowchart LR
S["Sequential"] --> O["One-Step Outline"]
S --> P["Per-Chapter"]
S --> D["DeepPlan Parallel"]
O --> P
O --> D
P --> D
```

**图表来源**
- [server/src/modules/book-generator/strategies/sequential.strategy.ts:33-44](file://server/src/modules/book-generator/strategies/sequential.strategy.ts#L33-L44)
- [server/src/modules/book-generator/strategies/one-step-outline.strategy.ts:33-40](file://server/src/modules/book-generator/strategies/one-step-outline.strategy.ts#L33-L40)
- [server/src/modules/book-generator/strategies/per-chapter.strategy.ts:33-40](file://server/src/modules/book-generator/strategies/per-chapter.strategy.ts#L33-L40)
- [server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts:44-53](file://server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts#L44-L53)

**章节来源**
- [server/src/modules/book-generator/strategies/sequential.strategy.ts:21-59](file://server/src/modules/book-generator/strategies/sequential.strategy.ts#L21-L59)
- [server/src/modules/book-generator/strategies/one-step-outline.strategy.ts:21-55](file://server/src/modules/book-generator/strategies/one-step-outline.strategy.ts#L21-L55)
- [server/src/modules/book-generator/strategies/per-chapter.strategy.ts:21-55](file://server/src/modules/book-generator/strategies/per-chapter.strategy.ts#L21-L55)
- [server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts:32-73](file://server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts#L32-L73)

## 依赖关系分析
- 组件耦合
  - 门面层仅依赖选择器，策略层彼此解耦
  - 基础执行函数被所有策略复用，降低重复
  - 容错层与执行层松耦合，通过回调与监控器接入
- 外部依赖
  - LangGraph StateGraph 作为工作流引擎
  - book-store 与数据库交互
  - WebSocket 通知（在容错层与批量编排中使用）

```mermaid
graph TB
IDX["index.ts"] --> SEL["selector.ts"]
SEL --> BASE["base.ts"]
BASE --> FT["fault-tolerance.ts"]
BASE --> GRAPH["graph.ts"]
STRATS["各策略实现"] --> BASE
BATCH["book-generator.service.ts"] --> IDX
BATCH --> FT
```

**图表来源**
- [server/src/modules/book-generator/index.ts:74-91](file://server/src/modules/book-generator/index.ts#L74-L91)
- [server/src/modules/book-generator/strategies/selector.ts:58-77](file://server/src/modules/book-generator/strategies/selector.ts#L58-L77)
- [server/src/modules/book-generator/strategies/base.ts:26-72](file://server/src/modules/book-generator/strategies/base.ts#L26-L72)
- [server/src/modules/book-generator/fault-tolerance.ts:188-261](file://server/src/modules/book-generator/fault-tolerance.ts#L188-L261)
- [server/src/modules/book-generator/graph.ts:23-82](file://server/src/modules/book-generator/graph.ts#L23-L82)
- [server/src/modules/book-generator/book-generator.service.ts:45-143](file://server/src/modules/book-generator/book-generator.service.ts#L45-L143)

**章节来源**
- [server/src/modules/book-generator/index.ts:74-91](file://server/src/modules/book-generator/index.ts#L74-L91)
- [server/src/modules/book-generator/strategies/selector.ts:14-77](file://server/src/modules/book-generator/strategies/selector.ts#L14-L77)
- [server/src/modules/book-generator/strategies/base.ts:17-20](file://server/src/modules/book-generator/strategies/base.ts#L17-L20)
- [server/src/modules/book-generator/book-generator.service.ts:45-143](file://server/src/modules/book-generator/book-generator.service.ts#L45-L143)

## 性能考量
- 并发策略
  - DeepPlan Parallel 通过并行内容生成与连贯性编辑提升吞吐
  - Per-Chapter 支持每章独立并发，适合大规模书籍
- 调用次数优化
  - One-Step Outline 将多次调用压缩为一次完整大纲生成 + N次内容生成
- 超时与重试
  - 节点级超时避免长时间阻塞，指数退避减少抖动
- 进度只增不减
  - GraphState.reducer 确保进度与完成列表不会回退，利于前端展示与审计

**章节来源**
- [server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts:32-73](file://server/src/modules/book-generator/strategies/deep-plan-parallel.strategy.ts#L32-L73)
- [server/src/modules/book-generator/strategies/per-chapter.strategy.ts:21-55](file://server/src/modules/book-generator/strategies/per-chapter.strategy.ts#L21-L55)
- [server/src/modules/book-generator/strategies/one-step-outline.strategy.ts:21-55](file://server/src/modules/book-generator/strategies/one-step-outline.strategy.ts#L21-L55)
- [server/src/modules/book-generator/graph.ts:12-21](file://server/src/modules/book-generator/graph.ts#L12-L21)

## 故障排查指南
- 常见问题
  - AI调用失败：通过容错重试与自动恢复解决
  - 节点超时：检查对应节点超时阈值与资源配额
  - 长时间无响应：确认进度监控是否正常，必要时手动干预
- 排查步骤
  - 查看策略切换日志与当前策略名称
  - 检查 bookStore 中 genStage 与 errorMsg 字段
  - 观察 WebSocket 通知类型（ai_retry/ai_failed/node_timeout/progress_*）
  - 必要时回退到 sequential 策略验证问题是否与策略相关
- 回退机制
  - 运行时切换到 sequential 或 one-step-outline
  - 容错层自动恢复最多2次，失败后标记 failed 并提示手动操作

**章节来源**
- [server/src/modules/book-generator/strategies/selector.ts:49-56](file://server/src/modules/book-generator/strategies/selector.ts#L49-L56)
- [server/src/modules/book-generator/fault-tolerance.ts:268-323](file://server/src/modules/book-generator/fault-tolerance.ts#L268-L323)
- [server/src/modules/book-generator/FAULT_TOLERANCE.md:256-334](file://server/src/modules/book-generator/FAULT_TOLERANCE.md#L256-L334)

## 结论
策略系统通过清晰的接口与统一的执行框架，实现了策略的可插拔与可演进。选择器提供运行时切换能力，容错层确保稳定性与可观测性，而多种策略满足不同规模与质量要求的生成需求。建议在生产环境默认使用推荐策略，并在出现问题时快速回退到串行策略，同时利用监控与通知机制提升用户体验。

## 附录

### 策略对比测试
- 用途：对比 sequential、one-step-outline、per-chapter 三策略在同一小书上的耗时与产出
- 方法：通过 setCurrentStrategy 切换策略，创建相同书籍，记录耗时与完成情况

**章节来源**
- [server/src/modules/book-generator/test/strategy-compare.ts:12-83](file://server/src/modules/book-generator/test/strategy-compare.ts#L12-L83)

### 批量生成编排与 API
- 批量生成编排器 BatchGenerationOrchestrator
  - 顺序执行 generate_content/generate_audio/merge_audio/generate_video/merge_video
  - 支持取消标志与进度推送
- API
  - POST /api/book-generator/books/:id/batch-generate
  - POST /api/book-generator/books/:id/batch-generate/cancel
  - GET /api/book-generator/books/:id/batch-generate/status

**章节来源**
- [server/src/modules/book-generator/book-generator.service.ts:45-143](file://server/src/modules/book-generator/book-generator.service.ts#L45-L143)
- [server/src/modules/book-generator/book-generator.controller.ts:24-197](file://server/src/modules/book-generator/book-generator.controller.ts#L24-L197)