f
This commit is contained in:
@@ -1509,18 +1509,18 @@ func (h *StatisticsHandler) AdminGetTodayCertifiedEnterprises(c *gin.Context) {
|
|||||||
|
|
||||||
// GetPublicApiPopularityRanking 获取API受欢迎程度排行榜(公开接口)
|
// GetPublicApiPopularityRanking 获取API受欢迎程度排行榜(公开接口)
|
||||||
// @Summary 获取API受欢迎程度排行榜
|
// @Summary 获取API受欢迎程度排行榜
|
||||||
// @Description 获取API受欢迎程度排行榜,仅返回产品名称和编码,默认统计日度数据
|
// @Description 获取API受欢迎程度排行榜,返回原始数据
|
||||||
// @Tags 统计公开接口
|
// @Tags 统计公开接口
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param period query string false "时间周期" Enums(today,month,total) default(today)
|
// @Param period query string false "时间周期" Enums(today,month,total) default(month)
|
||||||
// @Param limit query int false "返回数量" default(10)
|
// @Param limit query int false "返回数量" default(10)
|
||||||
// @Success 200 {object} interfaces.APIResponse{data=[]ApiPopularityRankingItem} "获取成功"
|
// @Success 200 {object} interfaces.APIResponse "获取成功"
|
||||||
// @Failure 400 {object} interfaces.APIResponse "请求参数错误"
|
// @Failure 400 {object} interfaces.APIResponse "请求参数错误"
|
||||||
// @Failure 500 {object} interfaces.APIResponse "服务器内部错误"
|
// @Failure 500 {object} interfaces.APIResponse "服务器内部错误"
|
||||||
// @Router /api/v1/statistics/api-popularity-ranking [get]
|
// @Router /api/v1/statistics/api-popularity-ranking [get]
|
||||||
func (h *StatisticsHandler) GetPublicApiPopularityRanking(c *gin.Context) {
|
func (h *StatisticsHandler) GetPublicApiPopularityRanking(c *gin.Context) {
|
||||||
period := c.DefaultQuery("period", "today") // 默认日度
|
period := c.DefaultQuery("period", "month") // 默认月度
|
||||||
limit := h.getIntQuery(c, "limit", 10) // 默认10条
|
limit := h.getIntQuery(c, "limit", 10) // 默认10条
|
||||||
|
|
||||||
// 调用应用服务获取API受欢迎程度排行榜
|
// 调用应用服务获取API受欢迎程度排行榜
|
||||||
@@ -1531,23 +1531,48 @@ func (h *StatisticsHandler) GetPublicApiPopularityRanking(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换数据,只保留产品名称和编码
|
processedData := removeCallCountWhenDescriptionEqualsName(result.Data)
|
||||||
if rankings, ok := result.Data.([]interface{}); ok {
|
h.responseBuilder.Success(c, processedData, "获取API受欢迎程度排行榜成功")
|
||||||
var publicRankings []ApiPopularityRankingItem
|
}
|
||||||
for _, ranking := range rankings {
|
|
||||||
if rankingMap, ok := ranking.(map[string]interface{}); ok {
|
// removeCallCountWhenDescriptionEqualsName 在公开排行榜数据中移除 product_id 和 call_count 字段
|
||||||
if product, productOk := rankingMap["product"].(map[string]interface{}); productOk {
|
func removeCallCountWhenDescriptionEqualsName(data interface{}) interface{} {
|
||||||
item := ApiPopularityRankingItem{
|
dataMap, ok := data.(map[string]interface{})
|
||||||
Name: product["name"].(string),
|
if !ok {
|
||||||
Code: product["code"].(string),
|
return data
|
||||||
}
|
|
||||||
publicRankings = append(publicRankings, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h.responseBuilder.Success(c, publicRankings, "获取API受欢迎程度排行榜成功")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h.responseBuilder.Success(c, []ApiPopularityRankingItem{}, "获取API受欢迎程度排行榜成功")
|
rankingsRaw, ok := dataMap["rankings"]
|
||||||
|
if !ok {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
switch rankings := rankingsRaw.(type) {
|
||||||
|
case []map[string]interface{}:
|
||||||
|
for _, item := range rankings {
|
||||||
|
delete(item, "product_id")
|
||||||
|
delete(item, "call_count")
|
||||||
|
}
|
||||||
|
|
||||||
|
case []interface{}:
|
||||||
|
for _, ranking := range rankings {
|
||||||
|
item, ok := ranking.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
delete(item, "product_id")
|
||||||
|
delete(item, "call_count")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataMap
|
||||||
|
}
|
||||||
|
|
||||||
|
// getMapKeys 获取map的所有键(用于调试)
|
||||||
|
func getMapKeys(m map[string]interface{}) []string {
|
||||||
|
keys := make([]string, 0, len(m))
|
||||||
|
for k := range m {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
return keys
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user