# OPT-08: 一键完整生成 API

## 任务状态: 已完成

## 实现内容

### 1. 新增文件

- `server/src/modules/book-generator/book-generator.service.ts` - 编排服务
  - `BatchGenerationOrchestrator` 类：按顺序执行各生成步骤
  - 取消标志管理
  - 实时进度推送

- `server/src/modules/book-generator/book-generator.controller.ts` - 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` - 查询状态

### 2. 修改文件

- `server/src/app.ts` - 添加路由挂载

### 3. 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 | 查询任务状态 |

### 4. Request/Response

**POST /api/book-generator/books/:id/batch-generate**

Request:
```json
{
  "steps": ["generate_content", "generate_audio", "merge_audio", "generate_video", "merge_video"]
}
```

Response:
```json
{
  "code": 0,
  "message": "批量生成任务已启动",
  "data": {
    "taskId": "batch_123_1234567890",
    "bookId": "123",
    "status": "started",
    "steps": ["generate_content", "generate_audio", "merge_audio", "generate_video", "merge_video"]
  }
}
```

### 5. WebSocket 事件

`batch_generation_progress` - 实时推送生成进度
```json
{ "taskId": "batch_123_1234567890", "step": "generate_content", "progress": 50 }
```

### 6. 支持的步骤

- `generate_content` - 生成书籍内容
- `generate_audio` - 生成章节音频
- `merge_audio` - 合并音频
- `generate_video` - 生成章节视频
- `merge_video` - 合并视频

### 7. 文档更新

- `.plans/audiobook-v2-ux/docs/api-contracts.md` - 已更新 API 契约
- `.plans/audiobook-v2-ux/backend-dev/findings.md` - 已记录实现要点