GetChannelStatistics 获取按渠道统计的数据
(c *gin.Context)
| 12 | |
| 13 | // GetChannelStatistics 获取按渠道统计的数据 |
| 14 | func GetChannelStatistics(c *gin.Context) { |
| 15 | startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64) |
| 16 | endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64) |
| 17 | username := c.Query("username") |
| 18 | tokenName := c.Query("token_name") |
| 19 | modelName := c.Query("model_name") |
| 20 | channel, _ := strconv.Atoi(c.Query("channel")) |
| 21 | group := c.Query("group") |
| 22 | defaultTime := c.Query("default_time") |
| 23 | |
| 24 | // 设置默认时间范围为最近7天 |
| 25 | if startTimestamp == 0 && endTimestamp == 0 { |
| 26 | endTimestamp = time.Now().Unix() |
| 27 | startTimestamp = endTimestamp - 7*24*3600 |
| 28 | } |
| 29 | |
| 30 | // 设置默认时间粒度 |
| 31 | if defaultTime == "" { |
| 32 | defaultTime = "day" |
| 33 | } |
| 34 | |
| 35 | statistics, err := model.GetChannelStatistics(int(startTimestamp), int(endTimestamp), username, tokenName, modelName, channel, group, defaultTime) |
| 36 | if err != nil { |
| 37 | common.ApiError(c, err) |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | c.JSON(http.StatusOK, gin.H{ |
| 42 | "success": true, |
| 43 | "message": "", |
| 44 | "data": statistics, |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | // GetTokenStatistics 获取按令牌统计的数据 |
| 49 | func GetTokenStatistics(c *gin.Context) { |
nothing calls this directly
no test coverage detected