Files
AIclinicalresearch/docs/03-业务模块/ADMIN-运营管理端/00-给新AI的快速指南.md
HaHafeng d595037316 feat(admin): Complete tenant management and module access control system
Major Features:
- Tenant management CRUD (list, create, edit, delete, module configuration)
- Dynamic module management system (modules table with 8 modules)
- Multi-tenant module permission merging (ModuleService)
- Module access control middleware (requireModule)
- User module permission API (GET /api/v1/auth/me/modules)
- Frontend module permission filtering (HomePage + TopNavigation)

Module Integration:
- RVW module integrated with PromptService (editorial + methodology)
- All modules (RVW/PKB/ASL/DC) added authenticate + requireModule middleware
- Fixed ReviewTask foreign key constraint (cross-schema issue)
- Removed all MOCK_USER_ID, unified to request.user?.userId

Prompt Management Enhancements:
- Module names displayed in Chinese (RVW -> 智能审稿)
- Enhanced version history with view content and rollback features
- List page shows both activeVersion and draftVersion columns

Database Changes:
- Added platform_schema.modules table
- Modified tenant_modules table (added index and UUID)
- Removed ReviewTask foreign key to public.users (cross-schema fix)
- Seeded 8 modules: RVW, PKB, ASL, DC, IIT, AIA, SSA, ST

Documentation Updates:
- Updated ADMIN module development status
- Updated TODO checklist (89% progress)
- Updated Prompt management plan (Phase 3.5.5 completed)
- Added module authentication specification

Files Changed: 80+
Status: All features tested and verified locally
Next: User management module development
2026-01-13 07:34:30 +08:00

5.0 KiB
Raw Blame History

🚀 给新AI助手的快速指南

更新时间: 2026-01-12
当前状态: Phase 3.5.5 代码改造已完成,待端到端测试


30秒了解当前状态

✅ Phase 3.5.1-3.5.5 代码改造已完成95%
⏳ 待完成:端到端测试验证

已完成:
  ✅ 数据库capability_schema + prompt_templates + prompt_versions
  ✅ 后端PromptService596行+ 8个API接口
  ✅ 前端:管理端架构 + Prompt列表 + 编辑器CodeMirror 6
  ✅ 测试:后端单元测试全部通过
  ✅ RVW集成editorialService + methodologyService 已改造2026-01-12

下一步:
  → 启动后端服务测试
  → 端到端测试灰度预览功能
  → 更新完成度文档

📁 关键文件位置

核心文件(必读)

文件 说明 行数
backend/src/common/prompt/prompt.service.ts PromptService 核心逻辑 596
backend/src/modules/rvw/services/editorialService.ts RVW 稿约评估服务 已改造 83
backend/src/modules/rvw/services/methodologyService.ts RVW 方法学评估服务 已改造 83
backend/src/modules/rvw/workers/reviewWorker.ts RVW Worker 已更新传递userId 193
frontend-v2/src/pages/admin/PromptEditorPage.tsx Prompt 编辑器页面 399

文档(必读)

文档 内容
04-开发计划/01-TODO清单可追踪.md 详细任务清单79/110 完成)
04-开发计划/02-Prompt管理系统开发计划.md 完整开发计划
00-Phase3.5完成总结.md 已完成工作总结

🎯 Phase 3.5.5 任务详解( 代码改造已完成 2026-01-12

任务 1改造 editorialService.ts - 已完成

改造前(文件读取)

const PROMPT_PATH = path.join(__dirname, '../../../../prompts/review_editorial_system.txt');
const prompt = fs.readFileSync(PROMPT_PATH, 'utf-8');

改造后PromptService

import { prisma } from '../../../config/database.js';
import { getPromptService } from '../../../common/prompt/index.js';

const promptService = getPromptService(prisma);
const { content: systemPrompt, isDraft } = await promptService.get('RVW_EDITORIAL', {}, { userId });

if (isDraft) {
  logger.info('[RVW:Editorial] 使用 DRAFT 版本 Prompt调试模式', { userId });
}

任务 2改造 methodologyService.ts - 已完成

改造后

const { content: systemPrompt, isDraft } = await promptService.get('RVW_METHODOLOGY', {}, { userId });

任务 3更新 reviewWorker.ts - 已完成

改造后 - 传递 userId 支持灰度预览

// ✅ Phase 3.5.5: 传递 userId 支持灰度预览
editorialResult = await reviewEditorialStandards(extractedText, modelType, userId);
methodologyResult = await reviewMethodology(extractedText, modelType, userId);

任务 4端到端测试 - 待验证

测试步骤

  1. 登录 Prompt工程师13800000002 / 123456
  2. 进入 /admin/prompts
  3. 编辑 RVW_EDITORIAL,修改一处内容(如添加"测试"
  4. 保存草稿
  5. 开启调试模式,选择 RVW 模块
  6. 切换到业务端 /rvw
  7. 上传一个文档,查看审查结果是否使用了修改后的 Prompt
  8. 验证普通用户仍使用旧版本

🔑 关键代码示例

PromptService.get() 用法

// 获取 Prompt自动灰度
const result = await promptService.get(
  'RVW_EDITORIAL',      // code
  {},                   // variablesRVW无变量
  { userId: req.user.id } // 用于判断调试模式
);

// 使用渲染后的内容
const messages = [
  { role: 'system', content: result.content },
  { role: 'user', content: documentText },
];

// 使用模型配置
const llmResponse = await llm.chat(messages, {
  temperature: result.modelConfig.temperature,
  model: result.modelConfig.model,
});

调试模式 API

// 开启调试(只调试 RVW
POST /api/admin/prompts/debug
{
  "modules": ["RVW"],
  "enabled": true
}

// 关闭调试
POST /api/admin/prompts/debug
{
  "modules": [],
  "enabled": false
}

🛠️ 环境信息

数据库

Host: localhost
Port: 5432
Database: ai_clinical_research
User: postgres
Password: postgres123

后端服务

端口: 3001
启动: cd backend && npm run dev

前端服务

端口: 3000
启动: cd frontend-v2 && npm run dev
代理: /api -> http://localhost:3001 (已配置)

⚠️ 常见问题

1. Prisma Client 找不到 prompt_templates

解决:运行 npx prisma generate

2. 前端调用 API 401

解决检查是否已登录JWT Token 是否有效

3. CodeMirror 不显示

解决:检查是否安装了 codemirror@codemirror/* 依赖


📞 联系信息

如有疑问,请查阅:

  • 技术设计:02-技术设计/03-Prompt管理系统快速参考.md
  • 开发规范:../../04-开发规范/

祝开发顺利! 🚀