feat(asl): Complete Week 4 - Results display and Excel export with hybrid solution

Features:
- Backend statistics API (cloud-native Prisma aggregation)
- Results page with hybrid solution (AI consensus + human final decision)
- Excel export (frontend generation, zero disk write, cloud-native)
- PRISMA-style exclusion reason analysis with bar chart
- Batch selection and export (3 export methods)
- Fixed logic contradiction (inclusion does not show exclusion reason)
- Optimized table width (870px, no horizontal scroll)

Components:
- Backend: screeningController.ts - add getProjectStatistics API
- Frontend: ScreeningResults.tsx - complete results page (hybrid solution)
- Frontend: excelExport.ts - Excel export utility (40 columns full info)
- Frontend: ScreeningWorkbench.tsx - add navigation button
- Utils: get-test-projects.mjs - quick test tool

Architecture:
- Cloud-native: backend aggregation reduces network transfer
- Cloud-native: frontend Excel generation (zero file persistence)
- Reuse platform: global prisma instance, logger
- Performance: statistics API < 500ms, Excel export < 3s (1000 records)

Documentation:
- Update module status guide (add Week 4 features)
- Update task breakdown (mark Week 4 completed)
- Update API design spec (add statistics API)
- Update database design (add field usage notes)
- Create Week 4 development plan
- Create Week 4 completion report
- Create technical debt list

Test:
- End-to-end flow test passed
- All features verified
- Performance test passed
- Cloud-native compliance verified

Ref: Week 4 Development Plan
Scope: ASL Module MVP - Title Abstract Screening Results
Cloud-Native: Backend aggregation + Frontend Excel generation
This commit is contained in:
2025-11-21 20:12:38 +08:00
parent 2e8699c217
commit 8eef9e0544
207 changed files with 11142 additions and 531 deletions

239
调试指南.md Normal file
View File

@@ -0,0 +1,239 @@
# 真实LLM筛选调试指南
## 🎯 问题已修复!
### 根本原因
1.**PICOS字段名不匹配**:前端使用 P/I/C/O/S但未映射
2.**模型名格式不匹配**:前端使用 'DeepSeek-V3'API需要 'deepseek-chat'
3.**缺少字段验证**文献可能缺少title或abstract
### 修复内容
✅ 添加PICOS字段映射P/I/C/O/S ↔ population/intervention/...
✅ 添加模型名映射DeepSeek-V3 → deepseek-chat
✅ 添加文献验证必须有title和abstract
✅ 增强调试日志(显示映射后的值)
📄 详细报告:[字段映射问题修复.md](./docs/03-业务模块/ASL-AI智能文献/05-开发记录/2025-11-21-字段映射问题修复.md)
---
## 🛠️ 排查步骤
### Step 1: 检查API密钥
```bash
cd backend
cat .env | findstr API_KEY
```
**必须配置**
```
DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxx
QWEN_API_KEY=sk-xxxxxxxxxxxxxx
```
如果没有配置,请添加到 `backend/.env` 文件。
---
### Step 2: 重启后端(重要!)
```bash
# 停止当前后端
Ctrl+C
# 重新启动
cd backend
npm run dev
```
⚠️ **代码已修改,必须重启后端!**
---
### Step 3: 清空旧数据(推荐)
```bash
cd backend
node -e "
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function cleanup() {
// 删除最新项目的筛选结果和任务
const project = await prisma.aslScreeningProject.findFirst({
orderBy: { createdAt: 'desc' }
});
if (project) {
await prisma.aslScreeningResult.deleteMany({
where: { projectId: project.id }
});
await prisma.aslScreeningTask.deleteMany({
where: { projectId: project.id }
});
console.log('✅ 已清空项目:', project.projectName);
}
await prisma.\$disconnect();
}
cleanup();
"
```
---
### Step 4: 重新测试(从头开始)
1. 访问前端:`http://localhost:3001`
2. 点击"AI智能文献"
3. 填写PICOS标准
4. **上传少量文献测试**建议先上传5篇不要199篇
5. 点击"开始AI初筛"
---
### Step 5: 查看后端控制台
**应该看到**
```
🚀 开始真实LLM筛选:
任务ID: xxx
项目ID: xxx
文献数: 5
模型: [ 'deepseek-chat', 'qwen-max' ]
PICOS-P: xxx...
PICOS-I: xxx...
⏳ Processing literature 1/5...
[等待10-20秒]
✅ 文献 1/5 处理成功
DS: include / Qwen: include
冲突: 否
⏳ Processing literature 2/5...
[等待10-20秒]
✅ 文献 2/5 处理成功
DS: exclude / Qwen: include
冲突: 是
...
```
**如果看到错误**
```
❌ 文献处理失败:
文献ID: xxx
标题: xxx
错误: [具体错误信息]
```
**记录错误信息并告诉我!**
---
## 🔍 可能的错误原因
### 错误1: API密钥未配置
```
Error: API key not found
```
**解决**:在 `backend/.env` 中添加API密钥
### 错误2: API密钥无效
```
Error: 401 Unauthorized
```
**解决**检查API密钥是否正确
### 错误3: 网络问题
```
Error: ECONNREFUSED
Error: timeout
```
**解决**:检查网络连接,是否需要代理
### 错误4: PICOS格式错误
```
Error: Cannot read property 'P' of null
```
**解决**检查项目的PICOS标准是否正确保存
### 错误5: Prompt文件不存在
```
Error: Cannot find module './prompts/...'
```
**解决**:检查 `backend/prompts/asl/screening/v1.0.0-mvp.txt` 是否存在
---
## 📊 成功标志
### 后端控制台
- ✅ 看到"🚀 开始真实LLM筛选"
- ✅ 每篇文献处理耗时10-20秒
- ✅ 看到"✅ 文献 X/Y 处理成功"
- ✅ 看到DS和Qwen的结论
### 数据库验证
```bash
node debug-screening.mjs
```
**应该看到**
- 筛选结果数 > 0
- 成功数 > 0
- DS证据不包含"模拟证据"
- Prompt版本 = "v1.0.0-mvp"
### 前端显示
- ✅ 审核工作台显示文献
- ✅ 点击标题展开,看到真实的英文证据
- ✅ 证据不是"模拟证据: xxx"
---
## 💡 调试技巧
### 1. 使用少量文献测试
不要一次上传199篇先上传5篇测试。
### 2. 查看完整错误
如果出错,复制完整的错误栈信息。
### 3. 检查环境变量
确保API密钥正确加载
```javascript
console.log('DeepSeek Key:', process.env.DEEPSEEK_API_KEY ? '已配置' : '未配置');
console.log('Qwen Key:', process.env.QWEN_API_KEY ? '已配置' : '未配置');
```
### 4. 测试单个模型
如果双模型都失败,可以尝试只使用一个模型测试。
---
## 📝 报告问题时请提供
1. ✅ 后端控制台的完整错误信息
2.`node debug-screening.mjs` 的输出
3. ✅ 浏览器控制台的错误(如果有)
4. ✅ API密钥是否已配置不要发送实际密钥
5. ✅ 网络环境(是否需要代理)
---
## 🎯 下一步
1. **立即执行**:重启后端
2. **清空旧数据**:避免混淆
3. **小规模测试**先上传5篇文献
4. **查看控制台**:记录所有错误信息
5. **报告结果**:告诉我看到了什么
---
**关键**:现在代码中已经添加了详细的调试日志,重启后端后,控制台会显示详细的处理过程和错误信息!