add hotapi
This commit is contained in:
@@ -11,6 +11,12 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// ApiPopularityRankingItem API受欢迎榜单项
|
||||
type ApiPopularityRankingItem struct {
|
||||
Name string `json:"name" comment:"产品名称"`
|
||||
Code string `json:"code" comment:"产品编码"`
|
||||
}
|
||||
|
||||
// StatisticsHandler 统计处理器
|
||||
type StatisticsHandler struct {
|
||||
statisticsAppService statistics.StatisticsApplicationService
|
||||
@@ -1499,4 +1505,49 @@ func (h *StatisticsHandler) AdminGetTodayCertifiedEnterprises(c *gin.Context) {
|
||||
}
|
||||
|
||||
h.responseBuilder.Success(c, result.Data, "获取今日认证企业列表成功")
|
||||
}
|
||||
|
||||
// GetPublicApiPopularityRanking 获取API受欢迎程度排行榜(公开接口)
|
||||
// @Summary 获取API受欢迎程度排行榜
|
||||
// @Description 获取API受欢迎程度排行榜,仅返回产品名称和编码,默认统计日度数据
|
||||
// @Tags 统计公开接口
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param period query string false "时间周期" Enums(today,month,total) default(today)
|
||||
// @Param limit query int false "返回数量" default(10)
|
||||
// @Success 200 {object} interfaces.APIResponse{data=[]ApiPopularityRankingItem} "获取成功"
|
||||
// @Failure 400 {object} interfaces.APIResponse "请求参数错误"
|
||||
// @Failure 500 {object} interfaces.APIResponse "服务器内部错误"
|
||||
// @Router /api/v1/statistics/api-popularity-ranking [get]
|
||||
func (h *StatisticsHandler) GetPublicApiPopularityRanking(c *gin.Context) {
|
||||
period := c.DefaultQuery("period", "today") // 默认日度
|
||||
limit := h.getIntQuery(c, "limit", 10) // 默认10条
|
||||
|
||||
// 调用应用服务获取API受欢迎程度排行榜
|
||||
result, err := h.statisticsAppService.AdminGetApiPopularityRanking(c.Request.Context(), period, limit)
|
||||
if err != nil {
|
||||
h.logger.Error("获取API受欢迎程度排行榜失败", zap.Error(err))
|
||||
h.responseBuilder.InternalError(c, "获取API受欢迎程度排行榜失败")
|
||||
return
|
||||
}
|
||||
|
||||
// 转换数据,只保留产品名称和编码
|
||||
if rankings, ok := result.Data.([]interface{}); ok {
|
||||
var publicRankings []ApiPopularityRankingItem
|
||||
for _, ranking := range rankings {
|
||||
if rankingMap, ok := ranking.(map[string]interface{}); ok {
|
||||
if product, productOk := rankingMap["product"].(map[string]interface{}); productOk {
|
||||
item := ApiPopularityRankingItem{
|
||||
Name: product["name"].(string),
|
||||
Code: product["code"].(string),
|
||||
}
|
||||
publicRankings = append(publicRankings, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
h.responseBuilder.Success(c, publicRankings, "获取API受欢迎程度排行榜成功")
|
||||
return
|
||||
}
|
||||
|
||||
h.responseBuilder.Success(c, []ApiPopularityRankingItem{}, "获取API受欢迎程度排行榜成功")
|
||||
}
|
||||
Reference in New Issue
Block a user