refactor: refactor of backend
This commit is contained in:
1 parent
d4cb8c5def
commit
14e5af0c9c
55 files changed
+2251
-1805
No files matched your search
@@ -115,10 +115,11 @@ raise AppError(code="WECOM_NOT_IN_AGENT_SCOPE", message="...", http_status=401)
|
||||
|
||||
| 蓝图 | 前缀 |
|
||||
|------|------|
|
||||
| `api/file_check_tools.py` | `/api/file-check/tools/*` |
|
||||
| `api/shipping_notice_tools.py` | `/api/shipping-notice/tools/*` |
|
||||
| `api/tools/file_check.py` | `/api/file-check/tools/*` |
|
||||
| `api/tools/shipping_notice.py` | `/api/shipping-notice/tools/*` |
|
||||
|
||||
**禁止**将上述 Tool 路由改为标准 envelope;契约测试见 `backend/tests/test_api_error_contract.py`。
|
||||
根路径 `api/*_tools.py` 仅为兼容 shim,真实现已收口到 `api/tools/`。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
| **技术方案** | 研发 | [technical.md](technical.md) |
|
||||
| **履历共享盘挂载命令**(test/prod) | 运维 | [history-share-mount.md](history-share-mount.md) |
|
||||
|
||||
**代码**:`backend/app/services/text2sql.py`(查询)、固资快照同步任务 · **状态**:见 [funclist.md](../../funclist.md)(固资管理)
|
||||
**代码**:`backend/app/services/integrations/text2sql.py`(查询)、`fixed_assets_snapshot.py` + `workers/worker_fixed_assets.py`(快照同步,Compose:`hxops-fixed-assets-worker`) · **状态**:见 [funclist.md](../../funclist.md)(固资管理)
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
## 2. 背景与问题
|
||||
|
||||
当前固资查询主要依赖 `backend/app/services/text2sql.py` 在聊天过程中实时访问 ERP Oracle,并结合规则与 LLM 生成 SQL。该方案已经支持资产编号、资产名称、规格型号、保管人、保管部门、存放位置、资产状态、供应厂商、资产性质等维度的查询,但在客户个性化问法持续增加后,逐渐暴露出以下问题:
|
||||
当前固资查询主要依赖 `backend/app/services/integrations/text2sql.py` 在聊天过程中实时访问 ERP Oracle,并结合规则与 LLM 生成 SQL。该方案已经支持资产编号、资产名称、规格型号、保管人、保管部门、存放位置、资产状态、供应厂商、资产性质等维度的查询,但在客户个性化问法持续增加后,逐渐暴露出以下问题:
|
||||
|
||||
- 用户自然语言问法复杂且频繁变化,实时 Text2SQL 可控性不足。
|
||||
- 每次查询依赖 ERP Oracle 在线可用,链路长、故障点多。
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
### 4.1 现有固资查询现状
|
||||
|
||||
当前固资查询能力集中在 `backend/app/services/text2sql.py`,具备以下特点:
|
||||
当前固资查询能力集中在 `backend/app/services/integrations/text2sql.py`,具备以下特点:
|
||||
|
||||
- 已支持固资专用字段映射、值翻译、结果重排与预览。
|
||||
- 已支持资产编号、资产名称、规格型号等组合查询。
|
||||
@@ -294,6 +294,8 @@ docker exec hxops-backend ls -la /mnt/hxops-fixed-asset-history-<env>
|
||||
|
||||
建议新增“固资快照同步任务”,不要复用聊天 Text2SQL 逻辑。
|
||||
|
||||
**运行时(已落地)**:同步主循环在独立进程 `backend/workers/worker_fixed_assets.py`(Compose 服务 `hxops-fixed-assets-worker`),与 Web/Gunicorn 隔离;快照落盘目录与 `hxops-backend` 共享 `hxops_runtime_data`。平台排程 job `fixed-assets-snapshot` 仍可手动触发 `sync_once`。
|
||||
|
||||
建议新增独立服务:
|
||||
|
||||
- `FixedAssetsSnapshotService`
|
||||
|
||||
@@ -794,7 +794,7 @@ AI:正在检查已选来源实例的收料文件;缺失来源会实时抓取
|
||||
| `backend/app/services/in_transit_transfer/precheck_service.py` | 成熟过滤、ERP查询、匹配和Hash |
|
||||
| `backend/app/services/in_transit_transfer/chat_actions.py` | 文件准备、预检、查询Action |
|
||||
| `backend/app/jobs/handlers/in_transit_transfer_precheck.py` | 异步文件和预检Handler |
|
||||
| `backend/app/api/in_transit_transfer.py` | 预检、进度和明细API |
|
||||
| `backend/app/api/in_transit_transfer/` | 预检、进度和明细API |
|
||||
| `frontend/src/features/chat/api/transfer.api.ts` | 前端API |
|
||||
| `frontend/src/features/chat/types/transfer.types.ts` | DTO类型 |
|
||||
| `frontend/src/features/chat/components/messages/TransferFileProgressCard.vue` | 来源级文件进度 |
|
||||
|
||||
@@ -231,7 +231,7 @@ ERP契约和结果未知SOP未关闭时,可以完成纯领域和前端Mock工
|
||||
| 计划新增 | `backend/app/services/in_transit_transfer/precheck_service.py` | D+1、ERP查询、数量匹配、快照和Hash |
|
||||
| 计划新增 | `backend/app/services/in_transit_transfer/chat_actions.py` | 调拨查询/预检Action处理 |
|
||||
| 计划新增 | `backend/app/jobs/handlers/in_transit_transfer_precheck.py` | 持久化异步阶段和来源级状态 |
|
||||
| 计划新增 | `backend/app/api/in_transit_transfer.py` | 预检创建、恢复、明细和证据API |
|
||||
| 计划新增 | `backend/app/api/in_transit_transfer/` | 预检创建、恢复、明细和证据API |
|
||||
|
||||
### 5.4 前端工作包
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
|
||||
**(A)服务端:`user_attachments` 是「终态后懒写」字段(主因,≈65%)**
|
||||
|
||||
- SSE 路径落库:`DifyService._persist_stream_chat_record`(`backend/app/services/dify.py:1465-1526`)在终态创建 ChatLog,`payload=message_payload`(`dify.py:1524`),**不含** `user_attachments`。
|
||||
- 合并时机:relay 层仅在终态事件(`error`/`message_end`/`workflow_finished`)且事件携带本地 `chat_log_id` 时,调用 `_merge_user_attachments_from_terminal_event`(`backend/app/api/chat.py:98-134`、`:1794-1825`)→ `merge_chat_log_payload`(`backend/app/services/chat/log_service.py:77-132`)把 `{user_attachments}` 补写进该 log 的 payload。
|
||||
- SSE 路径落库:`DifyService._persist_stream_chat_record`(`backend/app/services/integrations/dify.py:1465-1526`)在终态创建 ChatLog,`payload=message_payload`(`dify.py:1524`),**不含** `user_attachments`。
|
||||
- 合并时机:relay 层仅在终态事件(`error`/`message_end`/`workflow_finished`)且事件携带本地 `chat_log_id` 时,调用 `_merge_user_attachments_from_terminal_event`(`backend/app/api/chat/:98-134`、`:1794-1825`)→ `merge_chat_log_payload`(`backend/app/services/chat/log_service.py:77-132`)把 `{user_attachments}` 补写进该 log 的 payload。
|
||||
- 后果:该 ChatLog 的附件「先无后有」。窗口期内 `GET /api/chat/messages`(`chat.py:1286-1348`,读 `payload.user_attachments` 于 `:1310-1319`)返回的用户消息**无附件**;若该轮是「仅附件、display_query 为空」导致 `log.query == ''`,`chat.py:1316` 判定不成立,**用户消息整条消失**。
|
||||
- 已核实不成立项:`chat_log_id` 归属正确(`persist_stream_chat` 把本地 `ChatLog.id` 回写同一终态事件,`dify.py:999-1000`;executor 路径 `executors/dify_workflow.py:14-17` 仍汇入 `DifyService.stream_chat`);默认路径下前端 `refreshConversationAfterSend` 不会抢跑 merge(前端 `useChat.ts:682-683` 等到 SSE EOF 才 resolve,服务端 `chat.py:1815-1825` 先 commit 再 yield)。
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
| 优先级 | 改动 | 位置 | 影响面 |
|
||||
| --- | --- | --- | --- |
|
||||
| P0 | 后端落库即写:`_persist_stream_chat_record` 落库 payload 时直接带上 `user_attachments`(由 `/api/chat/completions` 传入 `persist_stream_chat`,而非仅依赖 relay 终态合并);终态合并仅作兜底幂等 | `backend/app/services/dify.py:1524`(`_persist_stream_chat_record`/`persist_stream_chat` 签名)+`backend/app/api/chat.py:1583,1794-1825` | 低:写入路径同事务;需同步单测 `test_*stream*`,注意 `message_payload` 为 None 时的纯文本请求不注入附件 |
|
||||
| P0 | 后端落库即写:`_persist_stream_chat_record` 落库 payload 时直接带上 `user_attachments`(由 `/api/chat/completions` 传入 `persist_stream_chat`,而非仅依赖 relay 终态合并);终态合并仅作兜底幂等 | `backend/app/services/integrations/dify.py:1524`(`_persist_stream_chat_record`/`persist_stream_chat` 签名)+`backend/app/api/chat/:1583,1794-1825` | 低:写入路径同事务;需同步单测 `test_*stream*`,注意 `message_payload` 为 None 时的纯文本请求不注入附件 |
|
||||
| P0 | 前端快照覆盖保护:`shouldApplyServerConversationSnapshot`(及 `saveLocalMessageToBackend` 同源审查)增加附件维度——本地用户消息 `attachments` 非空而服务端对应消息缺失时,保留本地(不整体替换) | `frontend/src/features/chat/composables/useChatPage.ts:69-84`、`useChatPageSend.ts:172-175` 补充合并策略(仅以服务端**新增**助手消息做增量合并) | 中:需覆盖 `useChatPageSend.spec.ts`、`useChatPageConversation.spec.ts` 既有断言 |
|
||||
| P1 | 货代自动流:解析完成后自动续跑「确认建单」,或首次点击即落「等待解析」占位气泡(附件快照 + 状态卡),避免「点击无反馈」 | `useChatShippingSendHandler.ts:104-156`、`useShippingNoticeIntakes.ts`(`allReadyForConfirmation` 补 watch → `startOrderExtractionRun`) | 中:涉及「点击语义」变更,需产品确认(提示文案 `chat.shippingNoticeWaitingForParse`/`ConfirmBatchHint` 同步调整) |
|
||||
| P1 | 工作台接收解析面板:Case 快照 `loading_context`(`ShippingOrderReviewCaseLoadingContext`,`shipping.api.types.ts:2696-2706`)附带附件元数据(文件名/类型/大小),面板先展示附件信息,正文/PDF 预览异步加载 | `backend/app/api/workspace/shipping_notice.py`(case 投影)+`ReviewIntakeParsePanel.vue` | 中:需后端快照字段扩展 + 前端占位态 |
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
- **【立即新增任务补推】**(原"立即推送下一批"):按现有游标逻辑对**所选周**任务增推一批(数量 = 每周任务数量),无需等待每周一排程;点击时若表单勾选/规则与已保存任务不一致,前端自动先保存再推送(避免按旧冻结清单推送而误报"全部视频已推送完毕");可用于发布失败后的补发。若当前无待推视频则返回"全部视频已推送完毕"。发布/补推后按任务 ID 刷新所选周上下文(不跳回最新周)。
|
||||
- **推送记录**:展示每轮推送的触发来源(发布推送/每周排程/手动推送)、批次数量、企微发送/失败统计与失败明细。
|
||||
|
||||
管理端接口:`POST /api/admin/lean-training/weekly-tasks`(创建/更新并发布所选周任务)、`GET /api/admin/lean-training/weekly-tasks/<id>`(按 ID 读取指定周任务)、`POST /api/admin/lean-training/weekly-tasks/<id>/push`(补推)、`GET /api/admin/lean-training/weekly-tasks/<id>/push-logs`、`POST /api/admin/lean-training/weekly-tasks/<id>/reminders`、`GET /api/admin/lean-training/dashboard`、`GET /api/admin/lean-training/dashboard/export?task_id=<id>`(导出当前期全部看板数据)([backend/app/api/training.py](../../../backend/app/api/training.py))。
|
||||
管理端接口:`POST /api/admin/lean-training/weekly-tasks`(创建/更新并发布所选周任务)、`GET /api/admin/lean-training/weekly-tasks/<id>`(按 ID 读取指定周任务)、`POST /api/admin/lean-training/weekly-tasks/<id>/push`(补推)、`GET /api/admin/lean-training/weekly-tasks/<id>/push-logs`、`POST /api/admin/lean-training/weekly-tasks/<id>/reminders`、`GET /api/admin/lean-training/dashboard`、`GET /api/admin/lean-training/dashboard/export?task_id=<id>`(导出当前期全部看板数据)([backend/app/api/training/](../../../backend/app/api/training/))。
|
||||
|
||||
---
|
||||
|
||||
|
||||
+1
-1
@@ -265,7 +265,7 @@
|
||||
| 功能项 | 状态 | 说明 |
|
||||
| -------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 固资实时查询规则抽取 | 已实现 | `text2sql.py` 已支持资产编号、资产名称、规格型号、状态、供应厂商等多维查询 |
|
||||
| 固资快照后台同步 | 已实现 | 每天 03:00 自动从 ERP Oracle 同步全量固资到本地快照 |
|
||||
| 固资快照后台同步 | 已实现 | 独立进程 `hxops-fixed-assets-worker`(`workers/worker_fixed_assets.py`)每天 03:00 从 ERP Oracle 同步全量固资到本地快照;Web 不再起线程 |
|
||||
| 固资同步超时与重试 | 已实现 | 支持同步超时、30 分钟间隔重试、最多 3 次补偿 |
|
||||
| 固资备注模糊检索 | 已实现 | 同步时生成 `备注` 与标准化备注,查询时作为结构化条件兜底 |
|
||||
| 固资本地快照查询 | 已实现 | `固资管理` Agent 优先查询 SQLite 最新快照,减少实时 ERP 压力 |
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
| 文件 | 用途 | 使用方 |
|
||||
| --- | --- | --- |
|
||||
| `text2sql_schema.md` | ERP Oracle 表、字段及业务含义,作为 Text2SQL 生成 SQL 的上下文 | `backend/app/services/text2sql.py` |
|
||||
| `text2sql_schema.md` | ERP Oracle 表、字段及业务含义,作为 Text2SQL 生成 SQL 的上下文 | `backend/app/services/integrations/text2sql.py` |
|
||||
|
||||
更新 Schema 后,应同步验证 Text2SQL 查询,并重新构建后端镜像。
|
||||
@@ -85,7 +85,7 @@
|
||||
| 检核 | `services/file_check_tools/task_resolver.py` | 1 | 读 `bound_schedule_task_id` |
|
||||
| 检核 | `api/workspace/file_check.py` | 3 | 进度 API 读 capabilities 列 |
|
||||
| 排程 | `services/schedule/*` | 3 | 仅当 Admin 绑定排程联动需调整 |
|
||||
| Dify 封装 | `services/dify.py` | 4 | 仅普通应用对话 Executor 调用;订单抽取不使用 |
|
||||
| Dify 封装 | `services/integrations/dify.py` | 4 | 仅普通应用对话 Executor 调用;订单抽取不使用 |
|
||||
|
||||
### 0.6 前端(可改)
|
||||
|
||||
|
||||
@@ -468,7 +468,7 @@ verify_duplicate # 确认重复 Invoice 对应原单
|
||||
- 模型:`app/models/integration_connector.py`(ClientInstance / 按版本存储的 InterfaceDefinition / Binding / CredentialReference / IntegrationCall;异步能力启用后再增加 IntegrationAsyncTask)
|
||||
- 服务:`app/services/integration_connector/`(`capability.py` / `binding.py` / `engine.py` / `mapping.py` / `transports/rest.py` / `transports/soap.py` / `descriptors.py` / `security.py`)
|
||||
- 域能力声明:`app/services/<domain>/capabilities.py`(如 `in_transit_transfer/capabilities.py`;框架只留注册/校验机制,域契约随域代码版本化,应用组合根每次 `create_app` 幂等注册,2026-09-22 起)
|
||||
- API:`app/api/integration_connector.py`(Admin CRUD + 能力调用端点 + 工具清单)
|
||||
- API:`app/api/integration_connector/`(Admin CRUD + 能力调用端点 + 工具清单)
|
||||
- Admin UI:`frontend/src/features/admin/modules/integration-connector/`(客户端配置作业)
|
||||
- 迁移:Alembic 新迁移,挂在当前 head 后
|
||||
|
||||
|
||||
@@ -15,12 +15,13 @@
|
||||
| 新增 API / 业务功能 | §2 目标目录总览 → §3 分层 → §6 新功能清单 |
|
||||
| 修改现有路由 / service | §4 设计原则 → §5 各域速查 → 对照同域已有代码 |
|
||||
| AI Agent 写代码 | §4.1 依赖红线 + §7 禁止项 + §8 import 规范 |
|
||||
| 拆 god 文件 | §2.2 映射关系 + §9.2 API 迁包步骤 |
|
||||
| 后台异步任务 | §5.8 jobs 域 + §9 Wave 2 |
|
||||
| 拆 god 文件 | §2.3 映射关系 + §9.6 API 迁包步骤 |
|
||||
| 后台异步任务 | §5.2 jobs 域 + §9.3 Wave 2 |
|
||||
| 各 Wave 任务清单 | §9.1–§9.5 |
|
||||
|
||||
**合并前自检**:`pytest backend/tests` 通过;改表结构须配套 Alembic 迁移;对外 URL 保持不变。
|
||||
|
||||
**当前进度**:Wave 1–3 已完成;Wave 4 已完成(排程迁出 Web;`integrations/` 真迁移;根路径兼容 shim 已删除;`FILE_CHECK_RUN` / `WECOM_DIRECTORY_SYNC` 由 schedule worker 执行;`services/` 不再直接 `import flask.request`,HTTP 读取收口到 `core/http_context.py`)。残留:固资快照线程仍在 Web 进程(另行治理)。
|
||||
**当前进度**:Wave 1–4 已完成;固资快照已迁出 Web(`hxops-fixed-assets-worker`);Tool API 真实现收口到 `api/tools/`;其余扁平 API 已迁为同名包;`before_request` 配置热更新改为进程内 TTL(`APP_SETTINGS_REFRESH_SECONDS`,默认 30s),不再每请求全量读 `app_settings`。
|
||||
|
||||
---
|
||||
|
||||
@@ -57,7 +58,7 @@
|
||||
| 问题 | 典型文件 | 约行数 |
|
||||
| --- | --- | --- |
|
||||
| API god 文件 | `api/chat.py`、`api/user.py`、`api/admin.py` 均已拆包 | 原单体 1400–2200 |
|
||||
| Service monolith | `services/text2sql.py`、`shipping_notice/tools.py` | 1200–2000 |
|
||||
| Service monolith | `services/integrations/text2sql.py`、`shipping_notice/tools.py` | 1200–2000 |
|
||||
| 单文件模型 | `models.py` | 796(30+ 模型) |
|
||||
| 错误响应不统一 | API 混用 `AppError` 与 `jsonify({'error':...})` | 300+ 处 |
|
||||
| 后台执行分散 | scheduler 线程、API 内 `threading`、`worker_kb.py` | — |
|
||||
@@ -156,22 +157,33 @@ backend/
|
||||
│ │ │ ├── upload.py
|
||||
│ │ │ └── jobs.py # 触发清洗、查 job 状态
|
||||
│ │ │
|
||||
│ │ ├── agents/ # ← 现有 agents.py(体量小,可单文件)
|
||||
│ │ ├── integration/ # ← 现有 integration.py
|
||||
│ │ ├── agents/ # ← 已迁包
|
||||
│ │ ├── integration/ # ← 已迁包
|
||||
│ │ ├── maintenance/
|
||||
│ │ ├── speech/
|
||||
│ │ ├── sso/
|
||||
│ │ ├── linked_services/
|
||||
│ │ ├── training/
|
||||
│ │ ├── contract_payment/
|
||||
│ │ ├── in_transit_transfer/
|
||||
│ │ ├── integration_connector/
|
||||
│ │ │
|
||||
│ │ ├── workspace/ # Wave 0 骨架已建
|
||||
│ │ ├── workspace/ # 已迁包
|
||||
│ │ │ ├── schedule.py
|
||||
│ │ │ ├── shipping_notice.py
|
||||
│ │ │ └── file_check.py
|
||||
│ │ │
|
||||
│ │ ├── tools/ # Dify HTTP Tool API;Wave 0 骨架已建
|
||||
│ │ ├── tools/ # Dify HTTP Tool API(真实现已收口)
|
||||
│ │ │ ├── shipping_notice.py # /api/shipping-notice
|
||||
│ │ │ └── file_check.py # /api/file-check
|
||||
│ │ │ ├── file_check.py # /api/file-check
|
||||
│ │ │ ├── maintenance.py # /api/maintenance/tools
|
||||
│ │ │ ├── agent_runtime_context.py
|
||||
│ │ │ └── procurement_contract.py
|
||||
│ │ │
|
||||
│ │ ├── internal/
|
||||
│ │ │ └── jobs.py # /api/internal/jobs
|
||||
│ │ │
|
||||
│ │ └── speech/ # ← 现有 speech.py
|
||||
│ │ └── files/
|
||||
│ │
|
||||
│ ├── services/ # 业务逻辑层(禁止 flask.request)
|
||||
│ │ ├── chat/
|
||||
@@ -261,7 +273,7 @@ Python 3 中 **模块文件与同名包不能并存**,否则包覆盖模块、
|
||||
| --- | --- |
|
||||
| `models.py` 与 `models/` | Wave 1:拆入 `models/*.py` 后**删除** `models.py` |
|
||||
| `api/chat.py` 与 `api/chat/` | 先 rename 为 `chat/_legacy.py`,再建包 |
|
||||
| 同理 `user.py`、`knowledge_base.py` | 标准步骤见 §9.2(`admin.py` 已删除,仅保留 `api/admin/` 包) |
|
||||
| 同理 `user.py`、`knowledge_base.py` | 标准步骤见 §9.6(`admin.py` 已删除,仅保留 `api/admin/` 包) |
|
||||
|
||||
**Wave 0 已建、无冲突的分包**:`api/schedule/`、`api/workspace/`、`api/tools/`、`api/internal/`、`core/`、`jobs/`、`schemas/`、`services/{chat,user,admin,...}/`。
|
||||
|
||||
@@ -405,7 +417,7 @@ jobs/handlers/kb_clean.py # worker 执行 → services/kb → edkb_system
|
||||
| **kb** | `/api/kb` | `api/kb/` | `services/kb/*` | `knowledge_base.py`;异步清洗 |
|
||||
| **agents** | `/api/agents` | `api/agents/` | 薄,可保留单文件 | ~118 行 |
|
||||
| **workspace** | `/api/workspace` | `api/workspace/` | 各域 query_service | 骨架已建 |
|
||||
| **tools** | `/api/shipping-notice`、`/api/file-check` | `api/tools/` | `shipping_notice/`、`file_check_tools/` | 已有 OpenAPI |
|
||||
| **tools** | `/api/shipping-notice`、`/api/file-check`、`/api/maintenance`、`/api/agent-runtime-context`、`/api/procurement-contract` | `api/tools/` | `shipping_notice/`、`file_check_tools/`、`maintenance_*` | 真实现已在 `api/tools/`;根路径 `*_tools.py` 为兼容 shim |
|
||||
| **integration** | `/api/integration` | `api/integration/` | `integration_api.py` | 源文件反查 |
|
||||
| **speech** | `/api/speech` | `api/speech/` | `speech/asr.py` | 体量小 |
|
||||
| **internal** | `/api/internal/jobs` | `api/internal/` | jobs 回调 | 骨架已建 |
|
||||
@@ -511,26 +523,80 @@ from app.models import User, Agent # Wave 1 后仍保持此入口
|
||||
|
||||
## 9. 分阶段迁移
|
||||
|
||||
主线 Wave 0–4 **均已完成**。下表为总览;各 Wave 细项见 §9.1–§9.5。迁包操作规程见 §9.6;完成定义见 §9.7。
|
||||
|
||||
```text
|
||||
Wave 0 骨架建立 ✅ 目录 + 占位(行为不变)
|
||||
Wave 1 基础设施 ✅ register_blueprints / extensions / core / AppError / models
|
||||
Wave 2 任务层 ✅ jobs/ 接 KB / shipping / schedule 等 worker
|
||||
Wave 3 拆 god 文件 admin ✅ → user ✅ → chat ✅ → kb ✅
|
||||
Wave 4 集成收敛 ✅ scheduler 迁出 web;integrations/ 真迁移;根路径 shim 已删除;file-check / 企微通讯录入队
|
||||
Wave 3 拆 god 文件 ✅ admin → user → chat → kb 迁包
|
||||
Wave 4 集成收敛 ✅ scheduler 迁出 web;integrations/ 真迁移;file-check / 企微入队
|
||||
后续 深化收口 ✅ 固资 worker / Tool API / 扁平 API 包 / 配置 TTL(非原 Wave 编号)
|
||||
```
|
||||
|
||||
### 9.1 Wave 1 任务清单
|
||||
### 9.1 Wave 0 — 骨架建立
|
||||
|
||||
| # | 任务 | 风险 | 状态 |
|
||||
| --- | --- | --- | --- |
|
||||
| 1 | 建立 `core/`、`jobs/`、`schemas/`、`api/{schedule,workspace,tools,internal}/` 目录与占位 | 低 | ✅ |
|
||||
| 2 | 建立 `services/{chat,user,admin,auth,kb,integrations,...}/` 骨架(多为 re-export) | 低 | ✅ |
|
||||
| 3 | 增加 `worker.py` / `workers/` 兼容入口骨架 | 低 | ✅ |
|
||||
| 4 | **不改** `create_app` 行为(零行为变更) | — | ✅ |
|
||||
|
||||
### 9.2 Wave 1 — 基础设施
|
||||
|
||||
| # | 任务 | 风险 | 状态 |
|
||||
| --- | --- | --- | --- |
|
||||
| 1 | `create_app` 改用 `register_blueprints(app)` | 低 | ✅ |
|
||||
| 2 | 修复 `deploy/gunicorn_config.py` workers 未赋值 | 低 | ✅ |
|
||||
| 3 | `extensions.py` 抽离 `db` / `migrate` | 低 | ✅ |
|
||||
| 4 | `core/*` 迁入 + 删除根 shim | 低 | ✅ |
|
||||
| 5 | `AppError` 统一 + 契约测试 | 中 | ✅ |
|
||||
| 6 | `models/` 按域拆分 | 中 | ✅ |
|
||||
| 4 | `core/*` 迁入 + 删除根 shim(`errors` / `auth_jwt` 等) | 低 | ✅ |
|
||||
| 5 | `AppError` 统一 + 契约测试(Tool API 保留例外格式) | 中 | ✅ |
|
||||
| 6 | `models/` 按域拆分,删除单体 `models.py` | 中 | ✅ |
|
||||
|
||||
### 9.2 API 单体迁包标准步骤
|
||||
### 9.3 Wave 2 — 统一任务层
|
||||
|
||||
| # | 任务 | 风险 | 状态 |
|
||||
| --- | --- | --- | --- |
|
||||
| 1 | 落地 `jobs/{types,registry,queue,store,runner,context}` | 中 | ✅ |
|
||||
| 2 | KB 清洗 / Dify sync 经 `jobs` + `worker.py` / `worker_kb.py` | 中 | ✅ |
|
||||
| 3 | shipping / transfer 等业务 handler 入 `jobs/handlers` | 中 | ✅ |
|
||||
| 4 | Compose / 本地脚本接 kb / shipping / transfer worker | 低 | ✅ |
|
||||
|
||||
### 9.4 Wave 3 — 拆 god 文件(API 迁包)
|
||||
|
||||
| # | 任务 | 风险 | 状态 |
|
||||
| --- | --- | --- | --- |
|
||||
| 1 | `api/admin.py` → `api/admin/*` + `services/admin/*` | 中 | ✅ |
|
||||
| 2 | `api/user.py` → `api/user/*`(local / Casdoor / 企微 / 密码重置)+ `auth_support` | 高 | ✅ |
|
||||
| 3 | `api/chat.py` → `api/chat/*`(SSE / 会话 / 预览 / 上传 / 反馈) | 高 | ✅ |
|
||||
| 4 | `knowledge_base.py` → `api/kb/*` + `services/kb/*` | 中 | ✅ |
|
||||
| 5 | 删除被包遮蔽的残留单体(如旧 `chat.py`) | 低 | ✅ |
|
||||
|
||||
迁包操作步骤见 §9.6。
|
||||
|
||||
### 9.5 Wave 4 — 集成收敛
|
||||
|
||||
| # | 任务 | 风险 | 状态 |
|
||||
| --- | --- | --- | --- |
|
||||
| 1 | 排程迁出 Web:`hxops-schedule-worker`;无 in-process scheduler 线程 | 中 | ✅ |
|
||||
| 2 | `FILE_CHECK_RUN` / `WECOM_DIRECTORY_SYNC` handler 落地,去掉 API 内 `threading` | 中 | ✅ |
|
||||
| 3 | `services/integrations/` 真迁移(dify / oa / plm / wecom / minio / text2sql 等) | 高 | ✅ |
|
||||
| 4 | 调用方 import 翻转到 `app.services.integrations.*`;根路径 shim 已删除 | 中 | ✅ |
|
||||
| 5 | `services/` 去 `flask.request`;HTTP 读口收到 `core/http_context.py` | 中 | ✅ |
|
||||
|
||||
### 9.5.1 Wave 4 之后的深化(已做,非原 Wave 编号)
|
||||
|
||||
| # | 任务 | 状态 |
|
||||
| --- | --- | --- |
|
||||
| 1 | 固资快照迁出 Web → `workers/worker_fixed_assets.py` / `hxops-fixed-assets-worker` | ✅ |
|
||||
| 2 | Tool API 真实现收口到 `api/tools/`(根路径 `*_tools.py` 为兼容 shim) | ✅ |
|
||||
| 3 | 其余扁平 API 迁同名包(agents / training / integration / contract_payment 等) | ✅ |
|
||||
| 4 | `before_request` 配置热更新:进程内 TTL(`APP_SETTINGS_REFRESH_SECONDS`,默认 30s) | ✅ |
|
||||
|
||||
仍开放:业务大文件持续拆分(>800 行,尤其 `shipping_notice/`),见 §9.7。
|
||||
|
||||
### 9.6 API 单体迁包标准步骤
|
||||
|
||||
```text
|
||||
1. app/api/user.py → app/api/user/_legacy.py
|
||||
@@ -539,15 +605,17 @@ Wave 4 集成收敛 ✅ scheduler 迁出 web;integrations/ 真迁移
|
||||
4. _legacy 归零后删除
|
||||
```
|
||||
|
||||
较小平坦模块也可直接 `git mv api/foo.py → api/foo/__init__.py`(import 路径不变)。
|
||||
|
||||
`monkeypatch('app.api.user._get_current_user')` 须在 `__init__.py` 显式 re-export 保持可用。
|
||||
|
||||
### 9.3 完成定义
|
||||
### 9.7 完成定义
|
||||
|
||||
- [ ] 无 >800 行业务源文件(`edkb_system/` 除外)
|
||||
- [ ] 无 >800 行业务源文件(`edkb_system/` 除外)— **未完成**,域内持续拆分
|
||||
- [x] API 统一 `AppError`(Tool API 除外,见 `docs/convention/error_handling.md` §2.5)
|
||||
- [x] `services/` 无 `flask.request`(HTTP 头/Host 经 `app.core.http_context`)
|
||||
- [x] 后台任务统一经 `jobs/`(file-check、企微通讯录同步已入队;固资快照线程另行治理)
|
||||
- [x] web 进程无 scheduler thread(排程由 `hxops-schedule-worker` 执行;固资快照线程另行治理)
|
||||
- [x] 后台任务统一经 `jobs/`(file-check、企微通讯录同步已入队;固资快照为独立常驻 worker,非 Web 线程)
|
||||
- [x] web 进程无 scheduler / 固资同步线程(排程 → `hxops-schedule-worker`;固资快照 → `hxops-fixed-assets-worker`)
|
||||
|
||||
---
|
||||
|
||||
|
||||
+5
-5
@@ -360,9 +360,9 @@ PDF 证据锚定优先使用现有 `pypdfium2` 逐字文本坐标定位,并由
|
||||
|
||||
### 2.x 已有固资查询与快照演进能力
|
||||
|
||||
- `backend/app/services/text2sql.py` 已具备固资管理专用规则抽取、字段映射、结果预览与分页能力。
|
||||
- `backend/app/services/integrations/text2sql.py` 已具备固资管理专用规则抽取、字段映射、结果预览与分页能力。
|
||||
- 新增 `backend/app/services/fixed_assets_snapshot.py` 后,可承接“ERP 固资全量同步 -> SQLite 本地快照 -> Excel 导出 -> 聊天查询优先走快照”的闭环。
|
||||
- 后端应用启动时可拉起固定资产快照后台线程,按配置在 `Asia/Shanghai` 时区每天 03:00 执行同步任务。
|
||||
- 固资快照同步由独立进程 `workers/worker_fixed_assets.py`(Compose:`hxops-fixed-assets-worker`)运行,按配置在 `Asia/Shanghai` 时区每天 03:00 执行;Web 进程不再起同步线程。
|
||||
- 同步结果默认落到 `backend/data/fixed_assets/`,并可额外导出 `FixedAssets_latest.xlsx` 到 `docs/` 目录供人工核查。
|
||||
- 历史快照目录默认仅保留最近 3 份有效版本,额外旧版文件与 `~$` 临时锁文件会在同步成功后自动清理;`docs/` 下的 `FixedAssets_*.xlsx` 导出副本也会同步执行相同保留策略,固定保留 `FixedAssets_latest.xlsx`。
|
||||
|
||||
@@ -972,8 +972,8 @@ OA_STATUS_SYNC_BATCH_SIZE=100
|
||||
|
||||
### 建议新增文件
|
||||
|
||||
- `backend/app/services/oa_user_directory.py`
|
||||
- `backend/app/services/oa_leave_workflow.py`
|
||||
- `backend/app/services/integrations/oa/ (目录相关)`
|
||||
- `backend/app/services/integrations/oa/leave_workflow.py`
|
||||
- `backend/app/services/leave_request_service.py`
|
||||
- `backend/app/services/leave_status_sync.py`
|
||||
- `backend/app/services/leave_intent_router.py`
|
||||
@@ -1394,7 +1394,7 @@ Dify
|
||||
|
||||
## 接口与前端
|
||||
|
||||
- 后端新增 `backend/app/api/maintenance.py`,统一挂载在 `/api/maintenance`。
|
||||
- 后端新增 `backend/app/api/maintenance/`,统一挂载在 `/api/maintenance`。
|
||||
- 台账接口:`/api/maintenance/ledger/devices`、`/api/maintenance/ledger/import-template`、`/api/maintenance/ledger/import`。
|
||||
- 维修记录接口:`/api/maintenance/records`,支持查询详情、分页查询和新增。
|
||||
- 前端新增 `features/maintenance` 业务域,包含台账 API、维修记录 API、类型定义和右侧固定面板组件。
|
||||
|
||||
Reference in new issue
Block a user