# P19 技术文库与问答 接口清单（规划）

> 前缀：`/api/knowledge`　鉴权：读接口匿名可访问，写接口需登录态
> 说明：平台当前通过数据表 + 代理 REST 读写，以下为业务接口规划，落地时按表映射为查询。

## 1. 文库

| 方法 | 路径 | 说明 | 主要参数 |
| --- | --- | --- | --- |
| GET | /standards | 标准列表 | `org` `keyword` `page` `size` |
| GET | /standards/{id} | 标准详情与目录 | `id` |
| GET | /standards/{id}/sections | 条款摘要列表 | `id` `keyword` |
| GET | /defect-map | 缺陷关键词 → 条款映射 | `keyword` |
| GET | /documents | 平台自编文档列表 | `category` `page` |

## 2. 问答

| 方法 | 路径 | 说明 | 主要参数 |
| --- | --- | --- | --- |
| GET | /questions | 问题列表 | `tag` `status` `sort` `page` |
| GET | /questions/{id} | 问题详情与回答 | `id` |
| POST | /questions | 发起提问 | `title` `body` `template` `tags[]` `standard_id` |
| POST | /questions/{id}/answers | 提交回答 | `body` `attachments[]` |
| POST | /questions/{id}/accept | 标记最佳答案 | `answer_id` |
| POST | /answers/{id}/vote | 有用/无用投票 | `value` |
| POST | /questions/{id}/merge | 合并重复问题 | `target_id` |

## 3. 运营

| 方法 | 路径 | 说明 |
| --- | --- | --- |
| GET | /admin/pending | 待审帖子、回复、文档 |
| POST | /admin/questions/{id}/review | 审核通过/驳回（需填理由） |
| POST | /admin/documents/{id}/publish | 文档发布，校验授权信息完整 |
| POST | /admin/documents/{id}/offline | 下线并记录原因 |

## 4. 字段要点

`tech_document`：`standard_no` `title` `organization` `version` `access_level(free/summary)` `license_source` `license_scope` `license_expire_at` `status`

`tech_question`：`title` `body` `template_type` `asker_id` `standard_id` `status(pending/published/closed/merged)` `merged_into` `view_count` `answer_count` `accepted_answer_id`

`tech_answer`：`question_id` `author_id` `body` `attachments` `is_accepted` `vote_up` `vote_down` `review_status`

## 5. 错误码

| 码 | 含义 | 处理建议 |
| --- | --- | --- |
| 20001 | 标准或文档不存在 | 展示已下线说明与相近文档 |
| 20002 | 授权信息不完整 | 禁止发布，提示补齐授权来源与范围 |
| 20003 | 内容命中导流或联系方式 | 驳回并提示修改 |
| 20004 | 无权标记最佳答案 | 仅提问者与品质专员可操作 |
| 20005 | 重复问题已合并 | 跳转到合并后的问题 |
| 20006 | 附件不可用 | 提示重新上传，仅保留文件名登记 |

## 6. 与数据表映射

| 接口 | 表 | 备注 |
| --- | --- | --- |
| /standards | tech_document | `where organization = ? and status = 'published'` |
| /standards/{id}/sections | tech_document_section | 按 `order_no` 排序 |
| /questions | tech_question | `status = 'published'`，按 `answer_count` 或 `created_at` |
| /questions/{id}/accept | tech_answer + tech_question | 事务内更新 `is_accepted` 与 `accepted_answer_id` |
