events.prisma 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. model AdClickEvents {
  2. id String @id @map("_id") @default(auto()) @db.ObjectId
  3. uid String // 设备码(from JWT / device)
  4. adId String @db.ObjectId // 广告 ID
  5. adsModuleId String @db.ObjectId // 广告模块 ID
  6. channelId String @db.ObjectId // 渠道 ID
  7. scene String // 业务场景(页面/流)
  8. slot String // 广告位
  9. adType String // 广告类型 (BANNER/STARTUP/...)
  10. clickedAt BigInt // 点击时间 (epoch)
  11. ip String // 点击 IP
  12. userAgent String // UA
  13. appVersion String // 客户端版本
  14. os String // iOS / Android / Web
  15. countryCode String? // 国家码 (optional)
  16. city String? // 城市 (optional)
  17. createAt BigInt // 记录创建时间
  18. updateAt BigInt // 记录更新时间
  19. // Query helpers
  20. // 1. 查某广告的点击列表
  21. @@index([adId, clickedAt])
  22. // 2. 查某设备的点击轨迹
  23. @@index([uid, clickedAt])
  24. // 3. 按渠道/模块聚合
  25. @@index([channelId, clickedAt])
  26. @@index([adsModuleId, clickedAt])
  27. // 4. 按广告类型/时间分析
  28. @@index([adType, clickedAt])
  29. // 5. 全局按时间片
  30. @@index([clickedAt])
  31. @@map("adClickEvents")
  32. }
  33. model VideoClickEvents {
  34. id String @id @map("_id") @default(auto()) @db.ObjectId
  35. uid String // 设备码
  36. videoId String @db.ObjectId // 视频 ID
  37. channelId String @db.ObjectId // 渠道 ID
  38. categoryId String? @db.ObjectId // 分类 ID (optional)
  39. scene String // 业务场景
  40. clickedAt BigInt // 点击时间 (epoch)
  41. ip String // 点击 IP
  42. userAgent String // UA
  43. appVersion String // 客户端版本
  44. os String // iOS / Android / Web
  45. countryCode String? // 国家码 (optional)
  46. city String? // 城市 (optional)
  47. createAt BigInt // 记录创建时间
  48. updateAt BigInt // 记录更新时间
  49. // Query helpers
  50. // 1. 查某视频的点击
  51. @@index([videoId, clickedAt])
  52. // 2. 查设备点击
  53. @@index([uid, clickedAt])
  54. // 3. 按渠道/分类
  55. @@index([channelId, clickedAt])
  56. @@index([categoryId, clickedAt])
  57. // 4. 全局时间窗口
  58. @@index([clickedAt])
  59. @@map("videoClickEvents")
  60. }
  61. model AdImpressionEvents {
  62. id String @id @map("_id") @default(auto()) @db.ObjectId
  63. uid String // 设备码
  64. adId String @db.ObjectId // 广告 ID
  65. adsModuleId String @db.ObjectId // 广告模块 ID
  66. channelId String @db.ObjectId // 渠道 ID
  67. scene String // 业务场景(页面/流)
  68. slot String // 广告位
  69. adType String // 广告类型 (BANNER/STARTUP/...)
  70. impressionAt BigInt // 曝光时间 (epoch)
  71. visibleDurationMs BigInt? // 可见时长(毫秒,optional)
  72. ip String // IP
  73. userAgent String // UA
  74. appVersion String // 客户端版本
  75. os String // iOS / Android / Web
  76. countryCode String? // 国家码 (optional)
  77. city String? // 城市 (optional)
  78. createAt BigInt // 记录创建时间
  79. updateAt BigInt // 记录更新时间
  80. // Query helpers
  81. // 1. 按广告查看曝光
  82. @@index([adId, impressionAt])
  83. // 2. 设备曝光轨迹
  84. @@index([uid, impressionAt])
  85. // 3. 渠道/模块/广告位
  86. @@index([channelId, impressionAt])
  87. @@index([adsModuleId, impressionAt])
  88. @@index([slot, impressionAt])
  89. // 4. 按广告类型
  90. @@index([adType, impressionAt])
  91. // 5. 时间片
  92. @@index([impressionAt])
  93. @@map("adImpressionEvents")
  94. }
  95. model ProcessedMessage {
  96. id String @id @map("_id") @default(auto()) @db.ObjectId
  97. messageId String @unique // 去重用的唯一消息 ID
  98. eventType String // 事件类型(如 stats.ad.click)
  99. processedAt BigInt // 处理时间(epoch ms)
  100. createdAt BigInt // 创建时间(epoch ms)
  101. @@map("processedMessages")
  102. }
  103. model VideoGlobalStats {
  104. id String @id @map("_id") @default(auto()) @db.ObjectId
  105. videoId String @unique @db.ObjectId // 视频 ID(唯一)
  106. impressions BigInt @default(0) // 曝光总数
  107. clicks BigInt @default(0) // 点击总数
  108. firstSeenAt BigInt // 首次出现时间 (epoch)
  109. lastSeenAt BigInt // 最后活跃时间 (epoch)
  110. computedCtr Float @default(0) // 计算的点击率 (clicks/impressions)
  111. computedPopularity Float @default(0) // 计算的热度得分
  112. computedRecency Float @default(0) // 计算的时效性得分
  113. computedScore Float @default(0) // 综合得分
  114. createAt BigInt // 创建时间 (epoch)
  115. updateAt BigInt // 更新时间 (epoch)
  116. // Query helpers
  117. // 1. videoId has unique index via @unique
  118. // 2. 按综合得分排序(热门视频推荐)
  119. @@index([computedScore])
  120. // 3. 按时效性排序(最新热点)
  121. @@index([computedRecency, computedScore])
  122. // 4. 按点击率排序(高转化内容)
  123. @@index([computedCtr])
  124. // 5. 按最后活跃时间排序
  125. @@index([lastSeenAt])
  126. @@map("videoGlobalStats")
  127. }
  128. model AdsGlobalStats {
  129. id String @id @map("_id") @default(auto()) @db.ObjectId
  130. adId String @unique @db.ObjectId // 广告 ID(唯一)
  131. impressions BigInt @default(0) // 曝光总数
  132. clicks BigInt @default(0) // 点击总数
  133. firstSeenAt BigInt // 首次出现时间 (epoch)
  134. lastSeenAt BigInt // 最后活跃时间 (epoch)
  135. computedCtr Float @default(0) // 计算的点击率 (clicks/impressions)
  136. computedPopularity Float @default(0) // 计算的热度得分
  137. computedRecency Float @default(0) // 计算的时效性得分
  138. computedScore Float @default(0) // 综合得分
  139. createAt BigInt // 创建时间 (epoch)
  140. updateAt BigInt // 更新时间 (epoch)
  141. // Query helpers
  142. // 1. adId has unique index via @unique
  143. // 2. 按综合得分排序(热门广告推荐)
  144. @@index([computedScore])
  145. // 3. 按时效性排序(最新热点)
  146. @@index([computedRecency, computedScore])
  147. // 4. 按点击率排序(高转化广告)
  148. @@index([computedCtr])
  149. // 5. 按最后活跃时间排序
  150. @@index([lastSeenAt])
  151. @@map("adsGlobalStats")
  152. }