Browse Source

增加运营分析接口

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.9.2^2
zouap 3 years ago
parent
commit
65afb3bb73
3 changed files with 117 additions and 5 deletions
  1. +9
    -5
      models/user_invitation.go
  2. +10
    -0
      routers/api/v1/api.go
  3. +98
    -0
      routers/repo/user_invitation.go

+ 9
- 5
models/user_invitation.go View File

@@ -32,18 +32,22 @@ func QueryInvitaionByPhone(phone string) []*Invitation {
} }
} }


func QueryInvitaion(start int64, end int64) ([]*Invitation, int) {
func QueryInvitaionPage(startTime int64, endTime int64, start int, pageSize int) ([]*Invitation, int64) {
statictisSess := xStatistic.NewSession() statictisSess := xStatistic.NewSession()
defer statictisSess.Close() defer statictisSess.Close()
cond := "created_unix >=" + fmt.Sprint(start) + " and created_unix <=" + fmt.Sprint(end)
cond := "created_unix >=" + fmt.Sprint(startTime) + " and created_unix <=" + fmt.Sprint(endTime)


allCount, err := statictisSess.Where(cond).Count(new(Invitation))
if err != nil {
log.Info("query error." + err.Error())
return nil, 0
}
invitationList := make([]*Invitation, 0) invitationList := make([]*Invitation, 0)

if err := statictisSess.Table(new(Invitation)).Where(cond).OrderBy("created_unix desc").
if err := statictisSess.Table(new(Invitation)).Where(cond).OrderBy("created_unix desc").Limit(pageSize, start).
Find(&invitationList); err != nil { Find(&invitationList); err != nil {
return nil, 0 return nil, 0
} }
return invitationList, len(invitationList)
return invitationList, allCount
} }


func InsertInvitaion(invitationUser *Invitation) error { func InsertInvitaion(invitationUser *Invitation) error {


+ 10
- 0
routers/api/v1/api.go View File

@@ -572,6 +572,16 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/query_user_all", operationReq, repo_ext.QueryUserStaticAll) m.Get("/query_user_all", operationReq, repo_ext.QueryUserStaticAll)
m.Get("/query_user_activity", operationReq, repo_ext.QueryUserActivity) m.Get("/query_user_activity", operationReq, repo_ext.QueryUserActivity)
m.Get("/query_user_login", operationReq, repo_ext.QueryUserLoginInfo) m.Get("/query_user_login", operationReq, repo_ext.QueryUserLoginInfo)

m.Get("/query_invitation_current_month", operationReq, repo_ext.QueryInvitationCurrentMonth)
m.Get("/query_invitation_current_week", operationReq, repo_ext.QueryInvitationCurrentWeek)
m.Get("/query_invitation_last_week", operationReq, repo_ext.QueryInvitationLastWeek)
m.Get("/query_invitation_current_year", operationReq, repo_ext.QueryInvitationCurrentYear)
m.Get("/query_invitation_last30_day", operationReq, repo_ext.QueryInvitationLast30Day)
m.Get("/query_invitation_last_month", operationReq, repo_ext.QueryInvitationLastMonth)
m.Get("/query_invitation_yesterday", operationReq, repo_ext.QueryInvitationYesterday)
m.Get("/query_invitation_all", operationReq, repo_ext.QueryInvitationAll)

//cloudbrain board //cloudbrain board
m.Group("/cloudbrainboard", func() { m.Group("/cloudbrainboard", func() {
m.Get("/downloadAll", repo.DownloadCloudBrainBoard) m.Get("/downloadAll", repo.DownloadCloudBrainBoard)


+ 98
- 0
routers/repo/user_invitation.go View File

@@ -0,0 +1,98 @@
package repo

import (
"net/http"
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
)

func QueryInvitationCurrentMonth(ctx *context.Context) {

currentTimeNow := time.Now()
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location())
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location())

queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix())
}

func QueryInvitationCurrentWeek(ctx *context.Context) {
currentTimeNow := time.Now()
offset := int(time.Monday - currentTimeNow.Weekday())
if offset > 0 {
offset = -6
}
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location())
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix())
}

func QueryInvitationLastWeek(ctx *context.Context) {
currentTimeNow := time.Now()
offset := int(time.Monday - currentTimeNow.Weekday())
if offset > 0 {
offset = -6
}
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
pageStartTime := pageEndTime.AddDate(0, 0, -7)
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix())
}

func QueryInvitationCurrentYear(ctx *context.Context) {
currentTimeNow := time.Now()
pageStartTime := time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location())
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location())
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix())
}

func QueryInvitationLast30Day(ctx *context.Context) {
currentTimeNow := time.Now()
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30)
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location())
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix())
}

func QueryInvitationLastMonth(ctx *context.Context) {
currentTimeNow := time.Now()
thisMonth := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location())
pageStartTime := thisMonth.AddDate(0, -1, 0)
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1)
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix())
}

func QueryInvitationYesterday(ctx *context.Context) {
currentTimeNow := time.Now().AddDate(0, 0, -1)
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local)
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location())
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix())
}

func QueryInvitationAll(ctx *context.Context) {
currentTimeNow := time.Now()
pageStartTime := time.Date(2022, 8, 5, 0, 0, 0, 0, currentTimeNow.Location())
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location())
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix())
}

func queryData(ctx *context.Context, startTime int64, endTime int64) {
page, pageSize := getPageInfo(ctx)
result, count := models.QueryInvitaionPage(startTime, endTime, (page-1)*pageSize, pageSize)
mapInterface := make(map[string]interface{})
mapInterface["data"] = result
mapInterface["count"] = count
ctx.JSON(http.StatusOK, mapInterface)
}

func getPageInfo(ctx *context.Context) (int, int) {
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
pageSize := ctx.QueryInt("pageSize")
if pageSize <= 0 {
pageSize = setting.UI.IssuePagingNum
}
return page, pageSize
}

Loading…
Cancel
Save