| @@ -207,6 +207,29 @@ func getLastCountDate() int64 { | |||||
| return pageStartTime.Unix() | 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) { | func QueryUserStaticDataByTableName(start int, pageSize int, tableName string, queryObj interface{}, userName string) ([]*UserBusinessAnalysisAll, int64) { | ||||
| statictisSess := xStatistic.NewSession() | statictisSess := xStatistic.NewSession() | ||||
| defer statictisSess.Close() | defer statictisSess.Close() | ||||
| @@ -547,6 +547,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| }) | }) | ||||
| }, operationReq) | }, 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_static_page", operationReq, repo_ext.QueryUserStaticDataPage) | ||||
| m.Get("/query_user_current_month", operationReq, repo_ext.QueryUserStaticCurrentMonth) | m.Get("/query_user_current_month", operationReq, repo_ext.QueryUserStaticCurrentMonth) | ||||
| m.Get("/query_user_current_week", operationReq, repo_ext.QueryUserStaticCurrentWeek) | m.Get("/query_user_current_week", operationReq, repo_ext.QueryUserStaticCurrentWeek) | ||||
| @@ -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) { | func QueryUserStaticCurrentMonth(ctx *context.Context) { | ||||
| queryUserDataPage(ctx, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth)) | queryUserDataPage(ctx, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth)) | ||||
| } | } | ||||