Files
AIclinicalresearch/docs/02-通用能力层/01-LLM大模型网关/README.md
HaHafeng 66255368b7 feat(admin): Add user management and upgrade to module permission system
Features - User Management (Phase 4.1):
- Database: Add user_modules table for fine-grained module permissions
- Database: Add 4 user permissions (view/create/edit/delete) to role_permissions
- Backend: UserService (780 lines) - CRUD with tenant isolation
- Backend: UserController + UserRoutes (648 lines) - 13 API endpoints
- Backend: Batch import users from Excel
- Frontend: UserListPage (412 lines) - list/filter/search/pagination
- Frontend: UserFormPage (341 lines) - create/edit with module config
- Frontend: UserDetailPage (393 lines) - details/tenant/module management
- Frontend: 3 modal components (592 lines) - import/assign/configure
- API: GET/POST/PUT/DELETE /api/admin/users/* endpoints

Architecture Upgrade - Module Permission System:
- Backend: Add getUserModules() method in auth.service
- Backend: Login API returns modules array in user object
- Frontend: AuthContext adds hasModule() method
- Frontend: Navigation filters modules based on user.modules
- Frontend: RouteGuard checks requiredModule instead of requiredVersion
- Frontend: Remove deprecated version-based permission system
- UX: Only show accessible modules in navigation (clean UI)
- UX: Smart redirect after login (avoid 403 for regular users)

Fixes:
- Fix UTF-8 encoding corruption in ~100 docs files
- Fix pageSize type conversion in userService (String to Number)
- Fix authUser undefined error in TopNavigation
- Fix login redirect logic with role-based access check
- Update Git commit guidelines v1.2 with UTF-8 safety rules

Database Changes:
- CREATE TABLE user_modules (user_id, tenant_id, module_code, is_enabled)
- ADD UNIQUE CONSTRAINT (user_id, tenant_id, module_code)
- INSERT 4 permissions + role assignments
- UPDATE PUBLIC tenant with 8 module subscriptions

Technical:
- Backend: 5 new files (~2400 lines)
- Frontend: 10 new files (~2500 lines)
- Docs: 1 development record + 2 status updates + 1 guideline update
- Total: ~4900 lines of code

Status: User management 100% complete, module permission system operational
2026-01-16 13:42:10 +08:00

150 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LLM大模型网关
> **能力定位:** 通用能力层核心能力
> **复用率:** 71% (5个模块依赖)
> **优先级:** P0最高
> **状态:** ❌ 待实现
---
## 📋 能力概述
LLM大模型网关是平台AI能力的核心中枢负责
- 统一管理所有LLM调用
- 根据用户版本动态切换模型
- 成本控制与限流
- Token计数与计费
---
## 🎯 核心价值
### 1. 商业模式技术基础 ⭐
```
专业版 → DeepSeek-V3便宜¥1/百万tokens
高级版 → DeepSeek + Qwen3
旗舰版 → DeepSeek + Qwen3 + Qwen-Long + Claude
```
### 2. 成本控制
- 统一监控所有LLM API调用
- 超出配额自动限流
- 按版本计费
### 3. 统一接口
- 屏蔽不同LLM API的差异
- 统一的调用接口
---
## 📊 依赖模块
**5个模块依赖71%复用率):**
1. **AIA** - AI智能问答
2. **ASL** - AI智能文献双模型判断
3. **PKB** - 个人知识库RAG问答
4. **DC** - 数据清洗NER提取
5. **RVW** - 稿件审查AI评估
---
## 💡 核心功能
### 1. 模型选择
```typescript
selectModel(userId: string, preferredModel?: string): string
// 根据用户版本和配额选择合适的模型
```
### 2. 统一调用
```typescript
chat(params: {
userId: string;
modelType?: ModelType;
messages: Message[];
stream?: boolean;
}): Promise<ChatResponse>
```
### 3. 配额管理
```typescript
checkQuota(userId: string): Promise<QuotaInfo>
// 检查用户剩余配额
```
### 4. Token计数
```typescript
countTokens(text: string): number
// 使用tiktoken计算Token数
```
---
## 📂 文档结构
```
01-LLM大模型网关/
├── [AI对接] LLM网关快速上下文.md # ✅ 已完成
├── 03-CloseAI集成指南.md # ✅ 已完成 ⭐
├── 00-需求分析/
│ └── README.md
├── 01-设计文档/
│ ├── 01-详细设计.md # ⏳ Week 5创建
│ ├── 02-数据库设计.md # ⏳ Week 5创建
│ ├── 03-API设计.md # ⏳ Week 5创建
│ └── README.md
└── README.md # ✅ 当前文档
```
### 快速入门文档 ⭐
| 文档 | 说明 | 状态 |
|------|------|------|
| **[AI对接] LLM网关快速上下文.md** | 快速了解LLM网关设计 | ✅ 已完成 |
| **03-CloseAI集成指南.md** | CloseAIGPT-5+Claude-4.5)集成文档 ⭐ | ✅ 已完成 |
---
## ⚠️ 开发计划调整
### 原计划Week 2完成LLM网关
**调整:** LLM网关完整实现推迟到Week 5 ✅
**理由:**
1. 现有LLM调用已经workDeepSeek、Qwen
2. CloseAI集成配置已完成可直接使用
3. ASL开发不阻塞先用简单调用
4. Week 5有多个模块实践后再抽取统一网关更合理
### 当前可用Week 3 ASL开发
- ✅ DeepSeek API直连
- ✅ GPT-5-Pro APICloseAI代理
- ✅ Claude-4.5 APICloseAI代理
- ✅ Qwen APIDashScope
- ✅ 4个模型的基础调用代码示例
### Week 5完善LLM网关统一
- 统一调用接口
- 版本分级(专业版/高级版/旗舰版)
- 配额管理和限流
- Token计数和计费
- 使用记录和监控
---
## 🔗 相关文档
- [通用能力层总览](../README.md)
- [系统架构分层设计](../../00-系统总体设计/01-系统架构分层设计.md)
---
**最后更新:** 2025-11-06
**维护人:** 技术架构师