362 lines
13 KiB
Plaintext
362 lines
13 KiB
Plaintext
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// =============================================================================
|
|
// 管理员模块
|
|
// =============================================================================
|
|
|
|
model AdminUser {
|
|
id String @id @default(uuid())
|
|
username String @unique
|
|
password String // bcrypt hashed
|
|
name String
|
|
role String // SUPER_ADMIN, ADMIN, OPERATOR
|
|
status String @default("ACTIVE") // ACTIVE, DISABLED
|
|
lastLoginAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
auditLogs AuditLog[]
|
|
|
|
@@map("admin_users")
|
|
}
|
|
|
|
// =============================================================================
|
|
// 系统配置
|
|
// =============================================================================
|
|
|
|
model SystemConfig {
|
|
id String @id @default(uuid())
|
|
category String // MINING, TRADING, CONTRIBUTION, SYSTEM
|
|
key String
|
|
value String
|
|
description String?
|
|
isPublic Boolean @default(false)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@unique([category, key])
|
|
@@map("system_configs")
|
|
}
|
|
|
|
// =============================================================================
|
|
// 系统账户(运营/省/市)
|
|
// =============================================================================
|
|
|
|
model SystemAccount {
|
|
id String @id @default(uuid())
|
|
accountType String @unique // OPERATION, PROVINCE, CITY, HEADQUARTERS
|
|
name String
|
|
description String?
|
|
totalContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("system_accounts")
|
|
}
|
|
|
|
// =============================================================================
|
|
// 初始化记录
|
|
// =============================================================================
|
|
|
|
model InitializationRecord {
|
|
id String @id @default(uuid())
|
|
type String // MINING_CONFIG, BLACK_HOLE, SYSTEM_ACCOUNTS, ACTIVATE_MINING
|
|
status String // PENDING, COMPLETED, FAILED
|
|
config Json
|
|
executedBy String
|
|
executedAt DateTime?
|
|
errorMessage String?
|
|
createdAt DateTime @default(now())
|
|
|
|
@@map("initialization_records")
|
|
}
|
|
|
|
// =============================================================================
|
|
// 审计日志
|
|
// =============================================================================
|
|
|
|
model AuditLog {
|
|
id String @id @default(uuid())
|
|
adminId String
|
|
action String // CREATE, UPDATE, DELETE, LOGIN, LOGOUT, INIT
|
|
resource String // CONFIG, USER, SYSTEM_ACCOUNT, MINING
|
|
resourceId String?
|
|
oldValue Json?
|
|
newValue Json?
|
|
ipAddress String?
|
|
userAgent String?
|
|
createdAt DateTime @default(now())
|
|
|
|
admin AdminUser @relation(fields: [adminId], references: [id])
|
|
|
|
@@index([adminId])
|
|
@@index([action])
|
|
@@index([resource])
|
|
@@index([createdAt(sort: Desc)])
|
|
@@map("audit_logs")
|
|
}
|
|
|
|
// =============================================================================
|
|
// 报表快照
|
|
// =============================================================================
|
|
|
|
model DailyReport {
|
|
id String @id @default(uuid())
|
|
reportDate DateTime @unique @db.Date
|
|
|
|
// 用户统计
|
|
totalUsers Int @default(0)
|
|
newUsers Int @default(0)
|
|
activeUsers Int @default(0)
|
|
|
|
// 认种统计
|
|
totalAdoptions Int @default(0)
|
|
newAdoptions Int @default(0)
|
|
totalTrees Int @default(0)
|
|
|
|
// 算力统计
|
|
totalContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
contributionGrowth Decimal @db.Decimal(30, 8) @default(0)
|
|
|
|
// 挖矿统计
|
|
totalDistributed Decimal @db.Decimal(30, 8) @default(0)
|
|
totalBurned Decimal @db.Decimal(30, 8) @default(0)
|
|
|
|
// 交易统计
|
|
tradingVolume Decimal @db.Decimal(30, 8) @default(0)
|
|
tradingAmount Decimal @db.Decimal(30, 8) @default(0)
|
|
tradeCount Int @default(0)
|
|
|
|
// 价格
|
|
openPrice Decimal @db.Decimal(30, 18) @default(1)
|
|
closePrice Decimal @db.Decimal(30, 18) @default(1)
|
|
highPrice Decimal @db.Decimal(30, 18) @default(1)
|
|
lowPrice Decimal @db.Decimal(30, 18) @default(1)
|
|
|
|
createdAt DateTime @default(now())
|
|
|
|
@@map("daily_reports")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 用户数据 (from auth-service)
|
|
// =============================================================================
|
|
|
|
model SyncedUser {
|
|
id String @id @default(uuid())
|
|
originalUserId String @unique // auth-service 中的原始 ID
|
|
accountSequence String @unique // 账户序列号
|
|
phone String
|
|
status String // ACTIVE, DISABLED, DELETED
|
|
kycStatus String // PENDING, SUBMITTED, VERIFIED, REJECTED
|
|
realName String?
|
|
isLegacyUser Boolean @default(false) // 是否为 1.0 迁移用户
|
|
createdAt DateTime
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// 关联同步表
|
|
contributionAccount SyncedContributionAccount?
|
|
miningAccount SyncedMiningAccount?
|
|
tradingAccount SyncedTradingAccount?
|
|
|
|
@@index([phone])
|
|
@@index([status])
|
|
@@index([kycStatus])
|
|
@@index([createdAt(sort: Desc)])
|
|
@@map("synced_users")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 算力账户 (from contribution-service)
|
|
// =============================================================================
|
|
|
|
model SyncedContributionAccount {
|
|
id String @id @default(uuid())
|
|
accountSequence String @unique
|
|
personalContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
teamLevelContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
teamBonusContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
totalContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
effectiveContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
hasAdopted Boolean @default(false)
|
|
directReferralCount Int @default(0)
|
|
unlockedLevelDepth Int @default(0)
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
user SyncedUser @relation(fields: [accountSequence], references: [accountSequence])
|
|
|
|
@@map("synced_contribution_accounts")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 挖矿账户 (from mining-service)
|
|
// =============================================================================
|
|
|
|
model SyncedMiningAccount {
|
|
id String @id @default(uuid())
|
|
accountSequence String @unique
|
|
totalMined Decimal @db.Decimal(30, 8) @default(0)
|
|
availableBalance Decimal @db.Decimal(30, 8) @default(0)
|
|
frozenBalance Decimal @db.Decimal(30, 8) @default(0)
|
|
totalContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
user SyncedUser @relation(fields: [accountSequence], references: [accountSequence])
|
|
|
|
@@map("synced_mining_accounts")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 交易账户 (from trading-service)
|
|
// =============================================================================
|
|
|
|
model SyncedTradingAccount {
|
|
id String @id @default(uuid())
|
|
accountSequence String @unique
|
|
shareBalance Decimal @db.Decimal(30, 8) @default(0)
|
|
cashBalance Decimal @db.Decimal(30, 8) @default(0)
|
|
frozenShares Decimal @db.Decimal(30, 8) @default(0)
|
|
frozenCash Decimal @db.Decimal(30, 8) @default(0)
|
|
totalBought Decimal @db.Decimal(30, 8) @default(0)
|
|
totalSold Decimal @db.Decimal(30, 8) @default(0)
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
user SyncedUser @relation(fields: [accountSequence], references: [accountSequence])
|
|
|
|
@@map("synced_trading_accounts")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 挖矿配置 (from mining-service)
|
|
// =============================================================================
|
|
|
|
model SyncedMiningConfig {
|
|
id String @id @default(uuid())
|
|
totalShares Decimal @db.Decimal(30, 8)
|
|
distributionPool Decimal @db.Decimal(30, 8)
|
|
remainingDistribution Decimal @db.Decimal(30, 8)
|
|
halvingPeriodYears Int
|
|
currentEra Int @default(1)
|
|
minuteDistribution Decimal @db.Decimal(30, 8)
|
|
isActive Boolean @default(false)
|
|
activatedAt DateTime?
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("synced_mining_configs")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 每日挖矿统计 (from mining-service)
|
|
// =============================================================================
|
|
|
|
model SyncedDailyMiningStat {
|
|
id String @id @default(uuid())
|
|
statDate DateTime @unique @db.Date
|
|
totalContribution Decimal @db.Decimal(30, 8) @default(0)
|
|
totalDistributed Decimal @db.Decimal(30, 8) @default(0)
|
|
totalBurned Decimal @db.Decimal(30, 8) @default(0)
|
|
participantCount Int @default(0)
|
|
avgContributionRate Decimal @db.Decimal(30, 18) @default(0)
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("synced_daily_mining_stats")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 日K线 (from trading-service)
|
|
// =============================================================================
|
|
|
|
model SyncedDayKLine {
|
|
id String @id @default(uuid())
|
|
klineDate DateTime @unique @db.Date
|
|
open Decimal @db.Decimal(30, 18)
|
|
high Decimal @db.Decimal(30, 18)
|
|
low Decimal @db.Decimal(30, 18)
|
|
close Decimal @db.Decimal(30, 18)
|
|
volume Decimal @db.Decimal(30, 8) @default(0)
|
|
amount Decimal @db.Decimal(30, 8) @default(0)
|
|
tradeCount Int @default(0)
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("synced_day_klines")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 流通池 (from trading-service)
|
|
// =============================================================================
|
|
|
|
model SyncedCirculationPool {
|
|
id String @id @default(uuid())
|
|
totalShares Decimal @db.Decimal(30, 8) @default(0)
|
|
totalCash Decimal @db.Decimal(30, 8) @default(0)
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("synced_circulation_pools")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步表 - 系统账户算力 (from contribution-service)
|
|
// =============================================================================
|
|
|
|
model SyncedSystemContribution {
|
|
id String @id @default(uuid())
|
|
accountType String @unique // OPERATION, PROVINCE, CITY, HEADQUARTERS
|
|
name String
|
|
contributionBalance Decimal @db.Decimal(30, 8) @default(0)
|
|
contributionNeverExpires Boolean @default(false)
|
|
syncedAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("synced_system_contributions")
|
|
}
|
|
|
|
// =============================================================================
|
|
// CDC 同步进度跟踪
|
|
// =============================================================================
|
|
|
|
model CdcSyncProgress {
|
|
id String @id @default(uuid())
|
|
sourceTopic String @unique
|
|
sourceService String // auth, contribution, mining, trading
|
|
lastOffset String? // Kafka offset
|
|
lastSequenceNum BigInt @default(0)
|
|
lastSyncedAt DateTime @default(now())
|
|
errorCount Int @default(0)
|
|
lastError String?
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([sourceService])
|
|
@@map("cdc_sync_progress")
|
|
}
|
|
|
|
// =============================================================================
|
|
// 已处理事件(幂等性)
|
|
// =============================================================================
|
|
|
|
model ProcessedEvent {
|
|
id String @id @default(uuid())
|
|
eventId String @unique
|
|
eventType String
|
|
sourceService String
|
|
processedAt DateTime @default(now())
|
|
|
|
@@index([sourceService])
|
|
@@index([processedAt])
|
|
@@map("processed_events")
|
|
}
|