feat(admin): Implement System Knowledge Base management module

Features:

- Backend: SystemKbService with full CRUD (knowledge bases + documents)

- Backend: 8 RESTful API endpoints (list/detail/create/update/delete/upload/download)

- Backend: OSS storage integration (system/knowledge-bases/{kbId}/{docId})

- Backend: RAG engine integration (document parsing, chunking, vectorization)

- Frontend: SystemKbListPage with card-based layout

- Frontend: SystemKbDetailPage with document management table

- Frontend: Master-Detail UX pattern for better user experience

- Document upload (single/batch), download (preserving original filename), delete

Technical:

- Database migration for system_knowledge_bases and system_kb_documents tables

- OSSAdapter.getSignedUrl with Content-Disposition for original filename

- Reuse RAG engine from common/rag for document processing

Tested: Local environment verified, all features working
This commit is contained in:
2026-01-28 21:57:44 +08:00
parent 3a4aa9123c
commit 0d9e6b9922
28 changed files with 2827 additions and 247 deletions

View File

@@ -1265,12 +1265,13 @@ enum VerificationType {
/// Prompt模板 - 存储Prompt的元信息
model prompt_templates {
id Int @id @default(autoincrement())
code String @unique /// 唯一标识符,如 'RVW_EDITORIAL'
name String /// 人类可读名称,如 "稿约规范性评估"
module String /// 所属模块: RVW, ASL, DC, IIT, PKB, AIA
description String? /// 描述
variables Json? /// 预期变量列表,如 ["title", "abstract"]
id Int @id @default(autoincrement())
code String @unique /// 唯一标识符,如 'RVW_EDITORIAL'
name String /// 人类可读名称,如 "稿约规范性评估"
module String /// 所属模块: RVW, ASL, DC, IIT, PKB, AIA
description String? /// 描述
variables Json? /// 预期变量列表,如 ["title", "abstract"]
knowledge_config Json? @map("knowledge_config") /// 知识库增强配置
versions prompt_versions[]
@@ -1312,6 +1313,52 @@ enum PromptStatus {
@@schema("capability_schema")
}
/// 系统知识库 - 运营管理的公共知识库,供 Prompt 引用
model system_knowledge_bases {
id String @id @default(uuid())
code String @unique @db.VarChar(50) /// 唯一编码,如 'CONSORT_2010'
name String @db.VarChar(100) /// 名称,如 'CONSORT 2010 声明'
description String? @db.Text /// 描述
category String? @db.VarChar(50) /// 分类: methodology, statistics, crf
document_count Int @default(0) @map("document_count") /// 文档数量
total_tokens Int @default(0) @map("total_tokens") /// 总 Token 数
status String @default("active") @db.VarChar(20) /// 状态: active, archived
documents system_kb_documents[]
created_at DateTime @default(now()) @map("created_at")
updated_at DateTime @updatedAt @map("updated_at")
@@index([category], map: "idx_system_kb_category")
@@index([status], map: "idx_system_kb_status")
@@map("system_knowledge_bases")
@@schema("capability_schema")
}
/// 系统知识库文档 - 知识库中的文档
model system_kb_documents {
id String @id @default(uuid())
kb_id String @map("kb_id") /// 所属知识库ID
filename String @db.VarChar(255) /// 原始文件名
file_path String? @db.VarChar(500) @map("file_path") /// OSS 存储路径
file_size Int? @map("file_size") /// 文件大小(字节)
file_type String? @db.VarChar(50) @map("file_type") /// 文件类型: pdf, docx, md, txt
content String? @db.Text /// 解析后的文本内容
token_count Int @default(0) @map("token_count") /// Token 数量
status String @default("pending") @db.VarChar(20) /// 状态: pending, processing, ready, failed
error_message String? @db.Text @map("error_message") /// 错误信息
knowledge_base system_knowledge_bases @relation(fields: [kb_id], references: [id], onDelete: Cascade)
created_at DateTime @default(now()) @map("created_at")
updated_at DateTime @updatedAt @map("updated_at")
@@index([kb_id], map: "idx_system_kb_docs_kb_id")
@@index([status], map: "idx_system_kb_docs_status")
@@map("system_kb_documents")
@@schema("capability_schema")
}
// ============================================================
// EKB Schema - 知识库引擎 (Enterprise Knowledge Base)
// 参考文档: docs/02-通用能力层/03-RAG引擎/04-数据模型设计.md