feat(admin): Complete Phase 3.5.1-3.5.4 Prompt Management System (83%)

Summary:
- Implement Prompt management infrastructure and core services
- Build admin portal frontend with light theme
- Integrate CodeMirror 6 editor for non-technical users

Phase 3.5.1: Infrastructure Setup
- Create capability_schema for Prompt storage
- Add prompt_templates and prompt_versions tables
- Add prompt:view/edit/debug/publish permissions
- Migrate RVW prompts to database (RVW_EDITORIAL, RVW_METHODOLOGY)

Phase 3.5.2: PromptService Core
- Implement gray preview logic (DRAFT for debuggers, ACTIVE for users)
- Module-level debug control (setDebugMode)
- Handlebars template rendering
- Variable extraction and validation (extractVariables, validateVariables)
- Three-level disaster recovery (database -> cache -> hardcoded fallback)

Phase 3.5.3: Management API
- 8 RESTful endpoints (/api/admin/prompts/*)
- Permission control (PROMPT_ENGINEER can edit, SUPER_ADMIN can publish)

Phase 3.5.4: Frontend Management UI
- Build admin portal architecture (AdminLayout, OrgLayout)
- Add route system (/admin/*, /org/*)
- Implement PromptListPage (filter, search, debug switch)
- Implement PromptEditor (CodeMirror 6 simplified for clinical users)
- Implement PromptEditorPage (edit, save, publish, test, version history)

Technical Details:
- Backend: 6 files, ~2044 lines (prompt.service.ts 596 lines)
- Frontend: 9 files, ~1735 lines (PromptEditorPage.tsx 399 lines)
- CodeMirror 6: Line numbers, auto-wrap, variable highlight, search, undo/redo
- Chinese-friendly: 15px font, 1.8 line-height, system fonts

Next Step: Phase 3.5.5 - Integrate RVW module with PromptService

Tested: Backend API tests passed (8/8), Frontend pending user testing
Status: Ready for Phase 3.5.5 RVW integration
This commit is contained in:
2026-01-11 21:25:16 +08:00
parent cdfbc9927a
commit 5523ef36ea
297 changed files with 15914 additions and 1266 deletions

View File

@@ -1,11 +1,12 @@
# AIclinicalresearch 系统当前状态与开发指南
> **文档版本:** v3.1
> **文档版本:** v3.3
> **创建日期:** 2025-11-28
> **维护者:** 开发团队
> **最后更新:** 2026-01-10
> **重大进展:** 🎉 **RVW稿件审查模块开发完成(95%** - 后端迁移+数据库扩展+前端重构+Word导出+Schema隔离全部完成
> **最后更新:** 2026-01-11
> **重大进展:** 🎉 **运营管理端 Prompt 管理系统开发完成(83%** - 基础架构+PromptService+管理API+前端界面全部完成
> **部署状态:** ✅ 生产环境运行中 | 公网地址http://8.140.53.236/
> **⚠️ 重要更新:** 2026-01-11 新增[数据库开发规范](../04-开发规范/09-数据库开发规范.md)(基于事故教训)
> **文档目的:** 快速了解系统当前状态为新AI助手提供上下文
---
@@ -46,6 +47,7 @@
| **SSA** | 智能统计分析 | 队列/预测模型/RCT分析 | ⭐⭐⭐⭐⭐ | 📋 规划中 | P2 |
| **ST** | 统计分析工具 | 100+轻量化统计工具 | ⭐⭐⭐⭐ | 📋 规划中 | P2 |
| **RVW** | 稿件审查系统 | 方法学评估、审稿流程、Word导出 | ⭐⭐⭐⭐ | ✅ **开发完成95%** | P3 |
| **ADMIN** | 运营管理端 | Prompt管理、租户管理、用户管理 | ⭐⭐⭐⭐⭐ | 🚧 **Prompt管理83%完成** | **P0** |
---
@@ -61,9 +63,9 @@
↓ 依赖
┌─────────────────────────────────────────────────────────┐
│ 通用能力层 (Capability Layer) │
│ 后端LLM网关 | 文档处理 | RAG引擎 | ETL引擎 | 医学NLP
│ ✅ ✅ ✅ 🚧 📋
│ 前端Chat组件Ant Design X🎉 新增!
│ 后端LLM网关 | 文档处理 | RAG引擎 | ETL引擎 | Prompt管理✨
│ ✅ ✅ ✅ 🚧 ✅ 🆕
│ 前端Chat组件Ant Design X
└─────────────────────────────────────────────────────────┘
↓ 依赖
┌─────────────────────────────────────────────────────────┐
@@ -96,7 +98,7 @@
**数据库**
- PostgreSQL 15 Docker: postgres:15-alpine
- 11个Schema隔离platform/aia/pkb/asl/dc/iit/ssa/st/rvw/admin/common
- 12个Schema隔离platform/aia/pkb/asl/dc/iit/ssa/st/rvw/admin/common/capability ✅新增
**云原生部署**
- 阿里云 SAE (Serverless 应用引擎)
@@ -115,7 +117,46 @@
---
## 🚀 当前开发状态2026-01-07
## 🚀 当前开发状态2026-01-11
### 🎉 最新进展ADMIN 运营管理端2026-01-11
#### ✅ Phase 3.5.1-3.5.4 已完成83%
**Phase 3.5.1: 基础设施搭建**
- ✅ 创建 `capability_schema`
- ✅ 添加 `prompt_templates``prompt_versions`
- ✅ 添加 `prompt:view/edit/debug/publish` 权限
- ✅ 迁移 RVW Prompt 到数据库2个RVW_EDITORIAL, RVW_METHODOLOGY
**Phase 3.5.2: PromptService 核心服务**
- ✅ 灰度预览逻辑(调试者看 DRAFT用户看 ACTIVE
- ✅ 模块级调试控制(`setDebugMode(userId, ['RVW'], true)`
- ✅ Handlebars 模板渲染
- ✅ 变量提取与校验(自动从 `{{xxx}}` 提取)
- ✅ 三级容灾(数据库→缓存→兜底 hardcoded
**Phase 3.5.3: 管理 API**
- ✅ 8个 RESTful 接口(`/api/admin/prompts/*`
- ✅ 权限控制PROMPT_ENGINEER 只能编辑SUPER_ADMIN 才能发布)
**Phase 3.5.4: 前端管理界面**
- ✅ 管理端基础架构AdminLayout, OrgLayout
- ✅ 路由系统(`/admin/*`, `/org/*`
- ✅ 头像下拉菜单切换入口
- ✅ PromptListPage筛选、搜索、调试开关
- ✅ PromptEditorCodeMirror 6 简化版中文友好15px字体
- ✅ PromptEditorPage编辑、保存、发布、测试、版本历史
**⏳ Phase 3.5.5 待完成**
- [ ] 改造 RVW 服务使用 `promptService.get()`(替代文件读取)
- [ ] 端到端测试
**📄 相关文档**
- 详细计划:`docs/03-业务模块/ADMIN-运营管理端/04-开发计划/02-Prompt管理系统开发计划.md`
- TODO清单`docs/03-业务模块/ADMIN-运营管理端/04-开发计划/01-TODO清单可追踪.md`
---
### ✅ 已完成模块
@@ -738,8 +779,9 @@ AIclinicalresearch/
1. ⭐⭐⭐ **本文档** - 系统当前状态
2. ⭐⭐⭐ [前后端模块化架构设计-V2.md](./前后端模块化架构设计-V2.md) - 架构总纲
3. ⭐⭐⭐ [云原生开发规范.md](../04-开发规范/08-云原生开发规范.md) - 开发规范(必读)
4. ⭐⭐ [01-系统架构分层设计.md](./01-系统架构分层设计.md) - 三层架构详解
5. ⭐⭐ [09-总体需求文档(PRD).md](./09-总体需求文档\(PRD\).md) - 产品需求
4. 🔴⭐⭐⭐ [数据库开发规范.md](../04-开发规范/09-数据库开发规范.md) - **数据库操作安全(必读!)**
5. ⭐⭐ [01-系统架构分层设计.md](./01-系统架构分层设计.md) - 三层架构详解
6. ⭐⭐ [09-总体需求文档(PRD).md](./09-总体需求文档\(PRD\).md) - 产品需求
### 🚀 当前开发相关
- [ASL模块当前状态](../03-业务模块/ASL-AI智能文献/00-模块当前状态与开发指南.md)
@@ -804,6 +846,28 @@ npm run dev # http://localhost:3000
3.**不要依赖本地文件系统**使用OSS或内存处理
4.**不要创建新的Prisma实例**:使用全局 `prisma` 实例
### 🔴 数据库操作安全2026-01-11 事故教训)
> ⚠️ **严重警告**2026-01-11 因误用 `prisma db push --force-reset` 导致数据库事故,详见 [事故总结报告](../08-项目管理/2026-01-11-数据库事故总结.md)
**禁止使用的危险命令:**
| 命令 | 危险等级 | 说明 |
|------|----------|------|
| `prisma db push --force-reset` | 🔴 **极高** | 会删除所有数据和非Prisma管理的对象 |
| `prisma migrate reset` | 🔴 **极高** | 重置整个数据库 |
**必须遵守的规范:**
1.**操作前必须备份**`docker exec ai-clinical-postgres pg_dump -U postgres -d ai_clinical_research > backup.sql`
2.**使用安全命令**`prisma migrate dev`(开发)或 `prisma migrate deploy`(生产)
3.**了解 Prisma 管理边界**pg-boss 的 `job_common` 表和函数不由 Prisma 管理
**Prisma 不管理的对象(需手动恢复):**
- `platform_schema.job_common` 表 → 恢复脚本:`restore_job_common.sql`
- `platform_schema.create_queue()` 函数 → 恢复脚本:`restore_pgboss_functions.sql`
- `platform_schema.delete_queue()` 函数
📚 **完整规范**[数据库开发规范](../04-开发规范/09-数据库开发规范.md)
---
## 📊 项目统计