refactor(backend): 重构后端admin和schedule部分

This commit is contained in:
sophie committed 2026-07-01 13:34:29 +08:00
1 parent 9f5493185d
commit 4a14960e01
74 files changed
+5937 -3644

No files matched your search

+1 -1
View File
@@ -557,7 +557,7 @@ FAQ_HOT_ENABLED=false
| PG 候选存储 | `backend/app/services/hot_faq_candidate_store.py` |
| KB 失效标记 | `backend/app/services/faq_kb_invalidation.py` |
| CLI | `backend/app/cli/faq_commands.py` |
| 管理 API | `backend/app/api/admin.py` |
| 管理 API | `backend/app/api/admin/`(如 `quick_questions.py`、`faq_candidates.py`) |
| 对话入口 | `backend/app/api/chat.py`(Dify 前 `try_match`) |
| 管理 UI | `frontend/src/features/admin/modules/questions/` |
| 环境变量 | `.env.shared` → `FAQ_HOT_*` |
+1 -1
View File
@@ -36,7 +36,7 @@ hxops/
├── backend/ # Flask 后端
│ ├── app/
│ │ ├── api/ # API 路由 (Blueprint)
│ │ │ ├── admin.py # 管理员接口
│ │ │ ├── admin/ # 管理员接口(Wave 3 分包)
│ │ │ ├── chat.py # 对话接口 (SSE流式)
│ │ │ └── ...
│ │ ├── services/ # 业务逻辑 (DifyService)
@@ -56,7 +56,7 @@
| 问题 | 典型文件 | 约行数 |
| --- | --- | --- |
| API god 文件 | `api/user.py`、`api/chat.py`、`api/admin.py` | 1400–2200 |
| API god 文件 | `api/user.py`、`api/chat.py`(`api/admin.py` 已拆至 `api/admin/*`) | 1400–2200 |
| Service monolith | `services/text2sql.py`、`shipping_notice/tools.py` | 1200–2000 |
| 单文件模型 | `models.py` | 796(30+ 模型) |
| 错误响应不统一 | API 混用 `AppError` 与 `jsonify({'error':...})` | 300+ 处 |
@@ -134,7 +134,7 @@ backend/
│ │ │ ├── faq.py
│ │ │ └── wecom.py # 企微 OAuth / 绑定
│ │ │
│ │ ├── admin/ # ← 现有 api/admin.py,Wave 3
│ │ ├── admin/ # ✅ 已从 api/admin.py 迁包(Wave 3 完成)
│ │ │ ├── users.py
│ │ │ ├── agents.py
│ │ │ ├── departments.py
@@ -261,7 +261,7 @@ Python 3 中 **模块文件与同名包不能并存**,否则包覆盖模块、
| --- | --- |
| `models.py` 与 `models/` | Wave 1:拆入 `models/*.py` 后**删除** `models.py` |
| `api/chat.py` 与 `api/chat/` | 先 rename 为 `chat/_legacy.py`,再建包 |
| 同理 `user.py`、`admin.py`、`knowledge_base.py` | 标准步骤见 §9.2 |
| 同理 `user.py`、`knowledge_base.py` | 标准步骤见 §9.2(`admin.py` 已删除,仅保留 `api/admin/` 包) |
**Wave 0 已建、无冲突的分包**:`api/schedule/`、`api/workspace/`、`api/tools/`、`api/internal/`、`core/`、`jobs/`、`schemas/`、`services/{chat,user,admin,...}/`。
@@ -274,7 +274,7 @@ Python 3 中 **模块文件与同名包不能并存**,否则包覆盖模块、
| `app/models.py` | `models/*.py` | 1 |
| `app/api/user.py` | `api/user/*` + `services/user/*` | 3 |
| `app/api/chat.py` | `api/chat/*` + `services/chat/router.py` | 3 |
| `app/api/admin.py` | `api/admin/*` + `services/admin/*` | 3 |
| `app/api/admin.py` | `api/admin/*` + `services/admin/*` | 3 ✅ |
| `app/api/knowledge_base.py` | `api/kb/*` + `services/kb/*` | 3 |
| `app/api/schedule_admin.py` | `api/schedule/*` | 1 |
| `app/api/workspace_*.py` | `api/workspace/*` | 0→1 |
@@ -400,7 +400,7 @@ jobs/handlers/kb_clean.py # worker 执行 → services/kb → edkb_system
| --- | --- | --- | --- | --- |
| **chat** | `/api/chat` | `api/chat/` | `services/chat/router.py` | `chat.py` ~1882 行;SSE + 意图路由 |
| **user** | `/api/user` | `api/user/` | `services/auth/*`、`services/user/*` | `user.py` ~2223 行;Casdoor + 企微 |
| **admin** | `/api/admin` | `api/admin/` | `services/admin/*` | `admin.py` ~1455 行;54 路由 |
| **admin** | `/api/admin` | `api/admin/` | `services/admin/*` | ✅ 已迁包;原 `admin.py` 已删除 |
| **schedule** | `/api/admin` | `api/schedule/` | `services/schedule/*` | 与 admin 同前缀,勿路由冲突 |
| **kb** | `/api/kb` | `api/kb/` | `services/kb/*` | `knowledge_base.py`;异步清洗 |
| **agents** | `/api/agents` | `api/agents/` | 薄,可保留单文件 | ~118 行 |
+1 -1
View File
@@ -671,7 +671,7 @@ OA_STATUS_SYNC_BATCH_SIZE=100
- `backend/app/api/chat.py`
- `backend/app/models.py`
- `backend/app/api/admin.py`
- `backend/app/api/admin/`(users、agents、permissions、wecom 等子模块)
- `backend/app/services/wecom_notify.py`
- `backend/app/services/knowledge_cleaning/queue_service.py`