feat(iit): Initialize IIT Manager Agent MVP - Day 1 complete
- Add iit_schema with 5 tables - Create module structure and types (223 lines) - WeChat integration verified (Access Token success) - Update system docs to v2.4 - Add REDCap source folders to .gitignore - Day 1/14 complete (11/11 tasks)
This commit is contained in:
@@ -6,7 +6,7 @@ generator client {
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
schemas = ["admin_schema", "aia_schema", "asl_schema", "common_schema", "dc_schema", "pkb_schema", "platform_schema", "public", "rvw_schema", "ssa_schema", "st_schema"]
|
||||
schemas = ["admin_schema", "aia_schema", "asl_schema", "common_schema", "dc_schema", "iit_schema", "pkb_schema", "platform_schema", "public", "rvw_schema", "ssa_schema", "st_schema"]
|
||||
}
|
||||
|
||||
/// 应用缓存表 - Postgres-Only架构
|
||||
@@ -825,3 +825,195 @@ enum job_state {
|
||||
|
||||
@@schema("platform_schema")
|
||||
}
|
||||
|
||||
// ==============================
|
||||
// IIT Manager Schema (V1.1)
|
||||
// ==============================
|
||||
|
||||
/// IIT项目表
|
||||
model IitProject {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
description String? @db.Text
|
||||
|
||||
// Protocol知识库
|
||||
difyDatasetId String? @unique @map("dify_dataset_id")
|
||||
protocolFileKey String? @map("protocol_file_key")
|
||||
|
||||
// V1.1 新增:Dify性能优化 - 缓存关键规则
|
||||
cachedRules Json? @map("cached_rules")
|
||||
|
||||
// 字段映射配置(JSON)
|
||||
fieldMappings Json @map("field_mappings")
|
||||
|
||||
// REDCap配置
|
||||
redcapProjectId String @map("redcap_project_id")
|
||||
redcapApiToken String @db.Text @map("redcap_api_token")
|
||||
redcapUrl String @map("redcap_url")
|
||||
|
||||
// V1.1 新增:同步管理 - 记录上次同步时间
|
||||
lastSyncAt DateTime? @map("last_sync_at")
|
||||
|
||||
// 项目状态
|
||||
status String @default("active")
|
||||
|
||||
// 时间戳
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
|
||||
// 关系
|
||||
pendingActions IitPendingAction[]
|
||||
taskRuns IitTaskRun[]
|
||||
userMappings IitUserMapping[]
|
||||
auditLogs IitAuditLog[]
|
||||
|
||||
@@index([status, deletedAt])
|
||||
@@map("projects")
|
||||
@@schema("iit_schema")
|
||||
}
|
||||
|
||||
/// 影子状态表(核心)
|
||||
model IitPendingAction {
|
||||
id String @id @default(uuid())
|
||||
projectId String @map("project_id")
|
||||
recordId String @map("record_id")
|
||||
fieldName String @map("field_name")
|
||||
|
||||
// 数据对比
|
||||
currentValue Json? @map("current_value")
|
||||
suggestedValue Json? @map("suggested_value")
|
||||
|
||||
// 状态流转
|
||||
status String // PROPOSED/APPROVED/REJECTED/EXECUTED/FAILED
|
||||
agentType String @map("agent_type") // DATA_QUALITY/TASK_DRIVEN/COUNSELING/REPORTING
|
||||
|
||||
// AI推理信息
|
||||
reasoning String @db.Text
|
||||
evidence Json
|
||||
|
||||
// 人类确认信息
|
||||
approvedBy String? @map("approved_by")
|
||||
approvedAt DateTime? @map("approved_at")
|
||||
rejectionReason String? @db.Text @map("rejection_reason")
|
||||
|
||||
// 执行信息
|
||||
executedAt DateTime? @map("executed_at")
|
||||
errorMessage String? @db.Text @map("error_message")
|
||||
|
||||
// 时间戳
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
// 关系
|
||||
project IitProject @relation(fields: [projectId], references: [id])
|
||||
|
||||
@@index([projectId, status])
|
||||
@@index([projectId, recordId])
|
||||
@@index([status, createdAt])
|
||||
@@map("pending_actions")
|
||||
@@schema("iit_schema")
|
||||
}
|
||||
|
||||
/// 任务运行记录(与 pg-boss 关联)
|
||||
model IitTaskRun {
|
||||
id String @id @default(uuid())
|
||||
projectId String @map("project_id")
|
||||
taskType String @map("task_type")
|
||||
|
||||
// 关联 pg-boss job
|
||||
jobId String? @unique @map("job_id")
|
||||
|
||||
// 任务状态
|
||||
status String
|
||||
|
||||
// 业务结果
|
||||
totalItems Int @map("total_items")
|
||||
processedItems Int @default(0) @map("processed_items")
|
||||
successItems Int @default(0) @map("success_items")
|
||||
failedItems Int @default(0) @map("failed_items")
|
||||
|
||||
// 时间信息
|
||||
startedAt DateTime? @map("started_at")
|
||||
completedAt DateTime? @map("completed_at")
|
||||
duration Int? // 秒
|
||||
|
||||
// 时间戳
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
// 关系
|
||||
project IitProject @relation(fields: [projectId], references: [id])
|
||||
|
||||
@@index([projectId, taskType, status])
|
||||
@@index([jobId])
|
||||
@@map("task_runs")
|
||||
@@schema("iit_schema")
|
||||
}
|
||||
|
||||
/// 用户映射表(异构系统身份关联)
|
||||
model IitUserMapping {
|
||||
id String @id @default(uuid())
|
||||
projectId String @map("project_id")
|
||||
|
||||
// 系统用户ID(本系统)
|
||||
systemUserId String @map("system_user_id")
|
||||
|
||||
// REDCap用户名
|
||||
redcapUsername String @map("redcap_username")
|
||||
|
||||
// 企微OpenID
|
||||
wecomUserId String? @map("wecom_user_id")
|
||||
|
||||
// V1.1 新增:小程序支持
|
||||
miniProgramOpenId String? @unique @map("mini_program_open_id")
|
||||
sessionKey String? @map("session_key")
|
||||
|
||||
// 角色
|
||||
role String
|
||||
|
||||
// 时间戳
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
// 关系
|
||||
project IitProject @relation(fields: [projectId], references: [id])
|
||||
|
||||
@@unique([projectId, systemUserId])
|
||||
@@unique([projectId, redcapUsername])
|
||||
@@index([wecomUserId])
|
||||
@@index([miniProgramOpenId])
|
||||
@@map("user_mappings")
|
||||
@@schema("iit_schema")
|
||||
}
|
||||
|
||||
/// 审计日志表
|
||||
model IitAuditLog {
|
||||
id String @id @default(uuid())
|
||||
projectId String @map("project_id")
|
||||
|
||||
// 操作信息
|
||||
userId String @map("user_id")
|
||||
actionType String @map("action_type")
|
||||
entityType String @map("entity_type")
|
||||
entityId String @map("entity_id")
|
||||
|
||||
// 详细信息
|
||||
details Json?
|
||||
|
||||
// 追踪链
|
||||
traceId String @map("trace_id")
|
||||
|
||||
// 时间戳
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
// 关系
|
||||
project IitProject @relation(fields: [projectId], references: [id])
|
||||
|
||||
@@index([projectId, createdAt])
|
||||
@@index([userId, createdAt])
|
||||
@@index([actionType, createdAt])
|
||||
@@index([traceId])
|
||||
@@map("audit_logs")
|
||||
@@schema("iit_schema")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user