feat(iit-manager): 完成MVP闭环 - 企业微信集成与端到端测试

核心交付物:
- WechatService (314行): Access Token缓存 + 消息推送
- WechatCallbackController (501行): URL验证 + 消息接收
- 质控Worker完善: 质控逻辑 + 企业微信推送 + 审计日志
- Worker注册修复: initIitManager() 在启动时调用
- 数据库字段修复: action -> action_type
- 端到端测试通过: <2秒延迟, 100%成功率

性能指标:
- Webhook响应: 5.8ms (目标<10ms)
- Worker执行: ~50ms (目标<100ms)
- 端到端延迟: <2秒 (目标<5秒)
- 消息成功率: 100% (测试5次)

临时措施:
- UserID从环境变量获取 (Phase 2改进)
- 定时轮询暂时禁用 (Phase 2添加)
- 质控逻辑简化 (Phase 1.5集成Dify)

Closes #IIT-MVP-Day3
This commit is contained in:
2026-01-03 14:19:08 +08:00
parent 5f089516cb
commit 6a567f028f
8 changed files with 1338 additions and 43 deletions

View File

@@ -0,0 +1,90 @@
/**
* 检查项目配置脚本
* 用于查看数据库中是否已配置 notification_config
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function checkProjectConfig() {
console.log('🔍 检查项目配置...\n');
try {
// 查询所有项目
const projects = await prisma.$queryRaw<Array<{
id: string;
name: string;
redcap_project_id: string;
notification_config: any;
status: string;
}>>`
SELECT id, name, redcap_project_id, notification_config, status
FROM iit_schema.projects
ORDER BY created_at DESC
`;
if (projects.length === 0) {
console.log('❌ 数据库中没有项目记录');
console.log('\n💡 建议:请先运行 test-redcap-integration.ts 创建测试项目');
return;
}
console.log(`✅ 找到 ${projects.length} 个项目:\n`);
projects.forEach((project, index) => {
console.log(`\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
console.log(`项目 ${index + 1}:`);
console.log(` 名称: ${project.name}`);
console.log(` REDCap项目ID: ${project.redcap_project_id}`);
console.log(` 状态: ${project.status}`);
console.log(` 数据库ID: ${project.id}`);
if (project.notification_config) {
const config = project.notification_config;
console.log(` \n 📧 通知配置:`);
if (config.wechat_user_id) {
console.log(` ✅ 企业微信UserID: ${config.wechat_user_id}`);
console.log(` 📤 通知发送给: ${config.wechat_user_id}`);
} else {
console.log(` ⚠️ 未配置 wechat_user_id`);
console.log(` 📤 通知发送给: ${process.env.WECHAT_TEST_USER_ID || '未配置环境变量'} (环境变量)`);
}
// 显示完整配置
console.log(` \n 完整配置: ${JSON.stringify(config, null, 2)}`);
} else {
console.log(` \n ⚠️ notification_config 为空`);
console.log(` 📤 通知发送给: ${process.env.WECHAT_TEST_USER_ID || '未配置环境变量'} (环境变量)`);
}
});
console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
console.log('📋 配置优先级说明:');
console.log(' 1⃣ 项目配置 (notification_config.wechat_user_id) - 优先');
console.log(' 2⃣ 环境变量 (WECHAT_TEST_USER_ID) - 回退');
console.log(' 3⃣ 如果都没有 - 不发送通知\n');
console.log('💡 当前环境变量:');
console.log(` WECHAT_TEST_USER_ID = ${process.env.WECHAT_TEST_USER_ID || '未配置'}\n`);
console.log('🔧 如何添加项目配置:');
console.log(` UPDATE iit_schema.projects`);
console.log(` SET notification_config = jsonb_set(`);
console.log(` COALESCE(notification_config, '{}'::jsonb),`);
console.log(` '{wechat_user_id}',`);
console.log(` '"FengZhiBo"'`);
console.log(` )`);
console.log(` WHERE redcap_project_id = '16';\n`);
} catch (error: any) {
console.error('❌ 检查失败:', error.message);
} finally {
await prisma.$disconnect();
}
}
// 运行检查
checkProjectConfig().catch(console.error);