add hotapi
This commit is contained in:
@@ -51,7 +51,7 @@ var (
|
|||||||
ErrSuccess = &JiguangError{Code: 0, Message: "请求成功"}
|
ErrSuccess = &JiguangError{Code: 0, Message: "请求成功"}
|
||||||
|
|
||||||
// 参数错误
|
// 参数错误
|
||||||
ErrParamInvalid = &JiguangError{Code: 400, Message: "请求参数不正确"}
|
ErrParamInvalid = &JiguangError{Code: 400, Message: "请求参数不正确,QCXGGB2Q查询为空"}
|
||||||
ErrMethodInvalid = &JiguangError{Code: 405, Message: "请求方法不正确"}
|
ErrMethodInvalid = &JiguangError{Code: 405, Message: "请求方法不正确"}
|
||||||
ErrParamFormInvalid = &JiguangError{Code: 906, Message: "请求参数形式不正确"}
|
ErrParamFormInvalid = &JiguangError{Code: 906, Message: "请求参数形式不正确"}
|
||||||
ErrBodyIncomplete = &JiguangError{Code: 914, Message: "Body 请求参数不完整"}
|
ErrBodyIncomplete = &JiguangError{Code: 914, Message: "Body 请求参数不完整"}
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ApiPopularityRankingItem API受欢迎榜单项
|
||||||
|
type ApiPopularityRankingItem struct {
|
||||||
|
Name string `json:"name" comment:"产品名称"`
|
||||||
|
Code string `json:"code" comment:"产品编码"`
|
||||||
|
}
|
||||||
|
|
||||||
// StatisticsHandler 统计处理器
|
// StatisticsHandler 统计处理器
|
||||||
type StatisticsHandler struct {
|
type StatisticsHandler struct {
|
||||||
statisticsAppService statistics.StatisticsApplicationService
|
statisticsAppService statistics.StatisticsApplicationService
|
||||||
@@ -1500,3 +1506,48 @@ func (h *StatisticsHandler) AdminGetTodayCertifiedEnterprises(c *gin.Context) {
|
|||||||
|
|
||||||
h.responseBuilder.Success(c, result.Data, "获取今日认证企业列表成功")
|
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受欢迎程度排行榜成功")
|
||||||
|
}
|
||||||
@@ -45,6 +45,9 @@ func (r *StatisticsRoutes) Register(router *sharedhttp.GinRouter) {
|
|||||||
{
|
{
|
||||||
// 获取公开统计信息
|
// 获取公开统计信息
|
||||||
statistics.GET("/public", r.statisticsHandler.GetPublicStatistics)
|
statistics.GET("/public", r.statisticsHandler.GetPublicStatistics)
|
||||||
|
|
||||||
|
// 获取API受欢迎榜单(公开接口)
|
||||||
|
statistics.GET("/api-popularity-ranking", r.statisticsHandler.GetPublicApiPopularityRanking)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户统计接口 - 需要认证
|
// 用户统计接口 - 需要认证
|
||||||
|
|||||||
Reference in New Issue
Block a user