From 62f724b0183e8f60bcc47fdce88ae0664dd3b405 Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 6 Apr 2022 10:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 23 +++++++++++++++++++++++ routers/api/v1/api.go | 2 ++ routers/repo/user_data_analysis.go | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index edfe73939..65ce642d5 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -207,6 +207,29 @@ func getLastCountDate() int64 { return pageStartTime.Unix() } +func QueryMetrics(start int64, end int64) ([]*UserMetrics, int64) { + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + userMetricsList := make([]*UserMetrics, 0) + if err := statictisSess.Table(new(UserMetrics)).Where("count_date >" + fmt.Sprint(start) + " and count_date<" + fmt.Sprint(end)).OrderBy("count_date desc"). + Find(&userMetricsList); err != nil { + return nil, 0 + } + return userMetricsList, int64(len(userMetricsList)) +} + +func QueryRankList(key string, tableName string, limit int) ([]*UserBusinessAnalysisAll, int64) { + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + + userBusinessAnalysisAllList := make([]*UserBusinessAnalysisAll, 0) + if err := statictisSess.Table(tableName).OrderBy(key+" desc,id desc").Limit(limit, 0). + Find(&userBusinessAnalysisAllList); err != nil { + return nil, 0 + } + return userBusinessAnalysisAllList, int64(len(userBusinessAnalysisAllList)) +} + func QueryUserStaticDataByTableName(start int, pageSize int, tableName string, queryObj interface{}, userName string) ([]*UserBusinessAnalysisAll, int64) { statictisSess := xStatistic.NewSession() defer statictisSess.Close() diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 1868edcb5..9de65662f 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -547,6 +547,8 @@ func RegisterRoutes(m *macaron.Macaron) { }) }, operationReq) + m.Get("/query_user_metrics", operationReq, repo_ext.QueryMetrics) + m.Get("/query_user_rank_list", operationReq, repo_ext.QueryRankingList) m.Get("/query_user_static_page", operationReq, repo_ext.QueryUserStaticDataPage) m.Get("/query_user_current_month", operationReq, repo_ext.QueryUserStaticCurrentMonth) m.Get("/query_user_current_week", operationReq, repo_ext.QueryUserStaticCurrentWeek) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 96503e5c9..9d906270f 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -126,6 +126,30 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac } } +func QueryMetrics(ctx *context.Context) { + startDate := ctx.Query("startDate") + endDate := ctx.Query("endDate") + startTime, _ := time.ParseInLocation("2006-01-02", startDate, time.Local) + endTime, _ := time.ParseInLocation("2006-01-02", endDate, time.Local) + result, count := models.QueryMetrics(startTime.Unix(), endTime.Unix()) + mapInterface := make(map[string]interface{}) + mapInterface["data"] = result + mapInterface["count"] = count + ctx.JSON(http.StatusOK, mapInterface) +} + +func QueryRankingList(ctx *context.Context) { + key := ctx.Query("key") + tableName := ctx.Query("tableName") + limit := ctx.QueryInt("limit") + + result, count := models.QueryRankList(key, tableName, limit) + mapInterface := make(map[string]interface{}) + mapInterface["data"] = result + mapInterface["count"] = count + ctx.JSON(http.StatusOK, mapInterface) +} + func QueryUserStaticCurrentMonth(ctx *context.Context) { queryUserDataPage(ctx, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth)) }