You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
5.8 KiB

syntax = "proto3";
option go_package = ".;pb";
import "enum.proto";
// =============================================================================
// 平台统计数据模型
//
// 设计要点:
// 1. 数据库层只保留「日」粒度。周/月/年报表由后台按 stat_day 区间 SUM 聚合查询
// 得到,不再单独维护月表/年表,避免重复统计。
// 2. 每行维度为 [应用 app_id × 产品 product_id × 渠道商 channel_id × 区域 region × 日 stat_day]。
// channel_id 是设备生产时定下的渠道商归属(授权码上的短码),用户绑定该设备后其数据即挂到
// 该渠道商名下;无渠道归属(历史数据/未挂设备的应用级指标)为空串。
// 写入方是「某应用在某区域的部署」,它只写 (app_id=自己, region=自己) 的行。
// app_id 与 region 同在主键里,因此:同区域的不同应用各写各的行(app_id 不同),
// 不同区域的同一应用也各写各的行(region 不同)——任意两个写入方都不会撞行,
// 在多区域延迟同步下不会发生并发写覆盖、不丢累加。
// 3. 取某天某应用/产品的总量(跨区域)时按 stat_day 区间求和:
// SELECT SUM(...) FROM stats_global_day
// WHERE app_id=? AND product_id=? AND stat_day BETWEEN ? AND ?
// idx_app_product_day 复合索引即为该查询服务;
// 按区域下钻则直接走主键前缀 (app_id, product_id, region)。
// =============================================================================
// StatsGlobalDay 每日全局统计(每 应用×产品×渠道商×区域×日 一行)
message StatsGlobalDay {
// ---- 维度 / 复合主键 ----
string app_id = 1; //@go_tags(`gorm:"column:app_id;size:64;primaryKey;index:idx_app_product_day,priority:1" json:"app_id"`) 应用标识(应用名称)
uint32 product_id = 2; //@go_tags(`gorm:"column:product_id;primaryKey;index:idx_app_product_day,priority:2" json:"product_id"`) 产品ID(无产品填0)
string region = 3; //@go_tags(`gorm:"column:region;size:16;primaryKey" json:"region"`) 区域代码(cn/us/...)
uint32 stat_day = 4; //@go_tags(`gorm:"column:stat_day;primaryKey;index:idx_app_product_day,priority:3" json:"stat_day"`) 统计日 YYYYMMDD
string channel_id = 5; //@go_tags(`gorm:"column:channel_id;size:16;primaryKey;index:idx_channel_day,priority:1" json:"channel_id"`) 渠道商id(短码,空=未分配渠道)
// ---- 用户 ----
int64 login_user_count = 10; //@go_tags(`gorm:"column:login_user_count" json:"login_user_count"`) 登录用户数(当日去重)
int64 login_count = 11; //@go_tags(`gorm:"column:login_count" json:"login_count"`) 登录次数
int64 new_user_count = 12; //@go_tags(`gorm:"column:new_user_count" json:"new_user_count"`) 新增注册用户数
int64 active_user_count = 13; //@go_tags(`gorm:"column:active_user_count" json:"active_user_count"`) 活跃用户数(当日去重)
// ---- 设备 ----
int64 active_device_count = 20; //@go_tags(`gorm:"column:active_device_count" json:"active_device_count"`) 激活设备数
int64 bind_device_count = 21; //@go_tags(`gorm:"column:bind_device_count" json:"bind_device_count"`) 绑定账号设备数
// ---- 二维码(公码) ----
int64 qr_active_count = 22; //@go_tags(`gorm:"column:qr_active_count" json:"qr_active_count"`) 二维码(公码)激活次数(只到应用×区域,product_id=0)
// ---- 订单 / 支付 ----
int64 order_create_count = 30; //@go_tags(`gorm:"column:order_create_count" json:"order_create_count"`) 创建订单数
int64 order_paid_count = 31; //@go_tags(`gorm:"column:order_paid_count" json:"order_paid_count"`) 完成订单数
int64 order_failed_count = 32; //@go_tags(`gorm:"column:order_failed_count" json:"order_failed_count"`) 失败订单数
int64 order_create_amount = 33; //@go_tags(`gorm:"column:order_create_amount" json:"order_create_amount"`) 预计累计订单金额(所有创建订单,分)
int64 order_paid_amount = 34; //@go_tags(`gorm:"column:order_paid_amount" json:"order_paid_amount"`) 实际累计订单金额(已支付,分)
int64 pay_user_count = 35; //@go_tags(`gorm:"column:pay_user_count" json:"pay_user_count"`) 付费用户数(当日去重)
// ---- 资源发放 ----
int64 grant_vip_day = 40; //@go_tags(`gorm:"column:grant_vip_day" json:"grant_vip_day"`) 发放VIP天数
int64 grant_ai_integral = 41; //@go_tags(`gorm:"column:grant_ai_integral" json:"grant_ai_integral"`) 发放AI积分
int64 grant_trade_second = 42; //@go_tags(`gorm:"column:grant_trade_second" json:"grant_trade_second"`) 发放翻译时长(秒)
int64 grant_meet_second = 43; //@go_tags(`gorm:"column:grant_meet_second" json:"grant_meet_second"`) 发放会议时长(秒)
// ---- 功能消耗 ----
int64 ai_chat_count = 50; //@go_tags(`gorm:"column:ai_chat_count" json:"ai_chat_count"`) AI聊天次数
int64 ai_up_token = 51; //@go_tags(`gorm:"column:ai_up_token" json:"ai_up_token"`) AI上行token
int64 ai_down_token = 52; //@go_tags(`gorm:"column:ai_down_token" json:"ai_down_token"`) AI下行token
int64 trade_count = 53; //@go_tags(`gorm:"column:trade_count" json:"trade_count"`) 翻译次数
int64 trade_second = 54; //@go_tags(`gorm:"column:trade_second" json:"trade_second"`) 累计翻译使用时长(秒)
int64 trade_words = 55; //@go_tags(`gorm:"column:trade_words" json:"trade_words"`) 翻译字数
int64 meet_count = 56; //@go_tags(`gorm:"column:meet_count" json:"meet_count"`) 会议次数
int64 meet_second = 57; //@go_tags(`gorm:"column:meet_second" json:"meet_second"`) 累计会议使用时长(秒)
// ---- 元信息 ----
int64 update_time = 99; //@go_tags(`gorm:"column:update_time" json:"update_time"`) 最后更新时间(unix秒)
}