refactor(backend): 后端重构初步设想

This commit is contained in:
sophie committed 2026-06-17 11:24:54 +08:00
1 parent b69d549b2c
commit 21b8c24815
96 files changed
+1592

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
"""
backend/app/services/admin/__init__.py
用途:管理后台业务服务包。
逻辑:Wave 3 从 api/admin/_legacy 抽取 users/agents/departments/settings 等。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/admin/agent_service.py
用途:Agent CRUD、权限、guide 配置。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/admin/dashboard_service.py
用途:管理后台仪表盘统计聚合。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/admin/department_service.py
用途:部门 CRUD。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/admin/permission_service.py
用途:权限申请、批量授权业务逻辑。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/admin/settings_service.py
用途:AppSetting、运行时配置管理业务逻辑。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/admin/user_service.py
用途:管理端用户 CRUD、权限分配。
"""
+6
View File
@@ -0,0 +1,6 @@
"""
backend/app/services/auth/__init__.py
用途:认证域业务(Casdoor OIDC、企微 OAuth)。
逻辑:Wave 3 从 api/user/_legacy auth 相关路由抽取。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/auth/casdoor_service.py
用途:Casdoor OIDC 登录、token 交换、用户同步业务逻辑。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/auth/wecom_auth_service.py
用途:企业微信 OAuth、绑定、解绑业务逻辑。
"""
+6
View File
@@ -0,0 +1,6 @@
"""
backend/app/services/chat/__init__.py
用途:聊天域业务服务包。
逻辑:Wave 3 从 api/chat/_legacy 与 chat.py 意图路由抽取。
"""
+5
View File
@@ -0,0 +1,5 @@
"""
backend/app/services/chat/log_service.py
用途:聊天历史、反馈业务逻辑。
"""
+6
View File
@@ -0,0 +1,6 @@
"""
backend/app/services/chat/perf.py
用途:聊天性能埋点(Wave 3 自 services/chat_perf.py 迁入)。
"""
from app.services.chat_perf import * # noqa: F403
@@ -0,0 +1,6 @@
"""
backend/app/services/chat/preview_service.py
用途:PLM/Excel 预览与文件转换(从 api/chat 抽出)。
逻辑:Wave 3 将 subprocess/openpyxl 逻辑迁入本模块。
"""
+27
View File
@@ -0,0 +1,27 @@
"""
backend/app/services/chat/router.py
用途:Chat Intent Router,按意图分流至 PLM/HR/Text2SQL/Dify。
依赖:integrations/* stream_chat 实现。
逻辑:api/chat/completions 调用本模块 select_stream_generator。
设计参考:docs/tec.md §4.1 Chat Intent Router。
"""
from __future__ import annotations
from typing import Any, Iterator
def select_stream_generator(*, user: Any, agent: Any, query: str, **kwargs: Any) -> Iterator[str]:
"""
根据 agent 配置与用户问题选择流式 generator。
核心逻辑:Wave 3 从 api/chat.py /completions 分支迁入。
Args:
user: 当前 User 模型实例。
agent: 当前 Agent 模型实例。
query: 用户问题文本。
Returns:
SSE 事件字符串迭代器。
Raises:
NotImplementedError: Wave 0 占位。
"""
raise NotImplementedError('ChatIntentRouter pending Wave 3 migration from api/chat.py')
@@ -0,0 +1,6 @@
"""
backend/app/services/chat/session_service.py
用途:聊天会话 CRUD 业务逻辑。
逻辑:Wave 3 从 api/chat/_legacy 抽取 sessions 相关路由逻辑。
"""
+6
View File
@@ -0,0 +1,6 @@
"""
backend/app/services/faq/__init__.py
用途:FAQ 缓存与热榜聚合(收敛 faq_*、hot_faq_* 模块)。
逻辑:Wave 4 自 services 根目录迁入。
"""
+2
View File
@@ -0,0 +1,2 @@
"""FAQ 热榜聚合(Wave 4 自 hot_faq_aggregator.py 迁入)。"""
from app.services import hot_faq_aggregator # noqa: F401
+2
View File
@@ -0,0 +1,2 @@
"""FAQ Redis 缓存(Wave 4 自 faq_cache.py 迁入)。"""
from app.services import faq_cache # noqa: F401
+2
View File
@@ -0,0 +1,2 @@
"""FAQ 热榜设置(Wave 4 自 faq_hot_settings.py 迁入)。"""
from app.services import faq_hot_settings # noqa: F401
@@ -0,0 +1,6 @@
"""
backend/app/services/integrations/__init__.py
用途:外部系统纯适配层(Dify、OA、PLM、WeCom、MinIO)。
逻辑:Wave 4 从 services 根目录迁入;禁止领域编排。
"""
@@ -0,0 +1,9 @@
"""
backend/app/services/integrations/dify.py
用途:Dify API 客户端(流式、上传、workflow)。
逻辑:Wave 4 自 app/services/dify.py 迁入。
"""
from app.services import dify # noqa: F401
__all__ = ['dify']
@@ -0,0 +1,8 @@
"""
backend/app/services/integrations/integration_api.py
用途:知识库源文件反查等集成 API 适配。
"""
from app.services import integration_api # noqa: F401
__all__ = ['integration_api']
@@ -0,0 +1,8 @@
"""
backend/app/services/integrations/minio.py
用途:MinIO 对象存储适配。
"""
from app.services import minio_service # noqa: F401
__all__ = ['minio_service']
@@ -0,0 +1,6 @@
"""
backend/app/services/integrations/oa/__init__.py
用途:OA 系统适配(SQL Server、请假 SOAP、企微同步)。
逻辑:Wave 4 自 oa_sqlserver、oa_leave_workflow、oa_wecom_sync 迁入。
"""
@@ -0,0 +1,2 @@
"""OA 请假 Workflow SOAP 适配(Wave 4 自 oa_leave_workflow.py 迁入)。"""
from app.services import oa_leave_workflow # noqa: F401
@@ -0,0 +1,2 @@
"""OA SQL Server 适配(Wave 4 自 oa_sqlserver.py 迁入)。"""
from app.services import oa_sqlserver # noqa: F401
@@ -0,0 +1,2 @@
"""OA 与企微同步适配(Wave 4 自 oa_wecom_sync.py 迁入)。"""
from app.services import oa_wecom_sync # noqa: F401
@@ -0,0 +1,5 @@
"""
backend/app/services/integrations/plm/__init__.py
用途:PLM Oracle 适配。
"""
@@ -0,0 +1,2 @@
"""PLM Oracle 流式查询适配(Wave 4 自 plm_oracle.py 迁入)。"""
from app.services import plm_oracle # noqa: F401
@@ -0,0 +1,8 @@
"""
backend/app/services/integrations/text2sql.py
用途:ERP 知识库 Text2SQL 流式服务。
"""
from app.services import text2sql # noqa: F401
__all__ = ['text2sql']
@@ -0,0 +1,5 @@
"""
backend/app/services/integrations/wecom/__init__.py
用途:企业微信 SDK 适配(通知、通讯录、加解密)。
"""
@@ -0,0 +1,2 @@
"""企微回调加解密(Wave 4 自 wecom_crypto.py 迁入)。"""
from app.services import wecom_crypto # noqa: F401
@@ -0,0 +1,2 @@
"""企微通讯录同步(Wave 4 自 wecom_directory_sync.py 迁入)。"""
from app.services import wecom_directory_sync # noqa: F401
@@ -0,0 +1,2 @@
"""企微消息通知(Wave 4 自 wecom_notify.py 迁入)。"""
from app.services import wecom_notify # noqa: F401
+9
View File
@@ -0,0 +1,9 @@
"""
backend/app/services/kb/__init__.py
用途:知识库域服务包(收敛 knowledge_cleaning/)。
逻辑:Wave 2–4 逐步 alias 至 knowledge_cleaning 子模块。
"""
from app.services import knowledge_cleaning # noqa: F401
__all__ = ['knowledge_cleaning']
+8
View File
@@ -0,0 +1,8 @@
"""
backend/app/services/speech/__init__.py
用途:语音 ASR 服务。
"""
from app.services import speech_asr # noqa: F401
__all__ = ['speech_asr']
+6
View File
@@ -0,0 +1,6 @@
"""
backend/app/services/user/__init__.py
用途:用户域业务服务(profile、homepage、admin 级联删除)。
逻辑:Wave 3 从 api/user/_legacy 与 user_admin.py 抽取。
"""
@@ -0,0 +1,9 @@
"""
backend/app/services/user/admin_service.py
用途:用户管理侧业务(删除级联、权限批量变更等)。
逻辑:Wave 3 收敛 app/services/user_admin.py。
"""
from app.services import user_admin # noqa: F401 — Wave 3: 实现迁入本模块
__all__ = ['user_admin']
+5
View File
@@ -0,0 +1,5 @@
"""
backend/app/services/user/faq_service.py
用途:常见问题(FAQ)业务逻辑。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/user/homepage_service.py
用途:首页布局、收藏 Agent、默认 Agent 业务逻辑。
"""
@@ -0,0 +1,5 @@
"""
backend/app/services/user/profile_service.py
用途:用户资料、密码修改等业务逻辑。
"""