events.prisma 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. model AdClickEvents {
  2. id String @id @map("_id") @default(auto()) @db.ObjectId
  3. uid String // 设备码(from JWT / device)
  4. adsId String? @db.ObjectId // 广告 ID mongo objectId
  5. adId Int? @db.Int // 广告 ID 自增数字唯一 ID
  6. adType String? // 广告类型 (BANNER/STARTUP/...)
  7. clickedAt BigInt // 点击时间 (epoch)
  8. ip String // 点击 IP
  9. channelId String // 用户自带渠道 Id (required)
  10. machine String? // 客户端提供 : 设备的信息,品牌及系统版本什么的 (required)
  11. createAt BigInt // 记录创建时间
  12. updateAt BigInt // 记录更新时间
  13. // Query helpers
  14. // 1. 查某广告的点击列表
  15. @@index([adId, clickedAt])
  16. // 2. 查某设备的点击轨迹
  17. @@index([uid, clickedAt])
  18. // 3. 按渠道+设备分析(报表)
  19. @@index([channelId, uid, clickedAt])
  20. // 4. 按广告类型/时间分析
  21. @@index([adType, clickedAt])
  22. // 5. 全局按时间片
  23. @@index([clickedAt])
  24. @@map("adClickEvents")
  25. }
  26. model ProcessedMessage {
  27. id String @id @map("_id") @default(auto()) @db.ObjectId
  28. messageId String @unique // 去重用的唯一消息 ID
  29. eventType String // 事件类型(如 stats.ad.click)
  30. processedAt BigInt // 处理时间 (epoch seconds)
  31. createdAt BigInt // 创建时间 (epoch seconds)
  32. @@map("processedMessages")
  33. }
  34. model AdsGlobalStats {
  35. id String @id @map("_id") @default(auto()) @db.ObjectId
  36. adsId String @unique @db.ObjectId // ✅ required + unique
  37. // adId Int? @db.Int // 广告 ID 自增数字唯一 ID
  38. impressions BigInt @default(0) // 曝光总数
  39. clicks BigInt @default(0) // 点击总数
  40. firstSeenAt BigInt // 首次出现时间 (epoch)
  41. lastSeenAt BigInt // 最后活跃时间 (epoch)
  42. computedCtr Float @default(0) // 计算的点击率 (clicks/impressions)
  43. computedPopularity Float @default(0) // 计算的热度得分
  44. computedRecency Float @default(0) // 计算的时效性得分
  45. computedScore Float @default(0) // 综合得分
  46. createAt BigInt // 创建时间 (epoch)
  47. updateAt BigInt // 更新时间 (epoch)
  48. @@index([computedScore])
  49. @@index([computedRecency, computedScore])
  50. @@index([computedCtr])
  51. @@index([lastSeenAt])
  52. @@map("adsGlobalStats")
  53. }