From be4a352947c33cfdf5783f347c59ae18bdc95a32 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 25 Nov 2021 10:06:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 22 ++++++++++++++++++++-- routers/repo/user_data_analysis.go | 18 +----------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index f81683242..15f67e858 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -89,7 +89,7 @@ type UserBusinessAnalysis struct { //action :ActionCommitRepo // 5 CommitCount int `xorm:"NOT NULL DEFAULT 0"` - //action :ActionCreateIssue // 10 + //action :ActionCreateIssue // 6 IssueCount int `xorm:"NOT NULL DEFAULT 0"` //comment table current date @@ -406,7 +406,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, DataDate := startTime.Format("2006-01-02") CodeMergeCountMap := queryPullRequest(start_unix, end_unix) - CommitCountMap := queryAction(start_unix, end_unix, 5) + CommitCountMap := queryCommitAction(start_unix, end_unix, 5) IssueCountMap := queryAction(start_unix, end_unix, 6) CommentCountMap := queryComment(start_unix, end_unix) @@ -674,6 +674,24 @@ func queryPullRequest(start_unix int64, end_unix int64) map[int64]int { return resultMap } +func queryCommitAction(start_unix int64, end_unix int64, actionType int64) map[int64]int { + sess := x.NewSession() + defer sess.Close() + sess.Select("id,user_id,op_type,act_user_id").Table("action").Where("user_id=act_user_id and op_type=" + fmt.Sprint(actionType) + " and created_unix>=" + fmt.Sprint(start_unix) + " and created_unix<=" + fmt.Sprint(end_unix)) + actionList := make([]*Action, 0) + sess.Find(&actionList) + resultMap := make(map[int64]int) + log.Info("query action size=" + fmt.Sprint(len(actionList))) + for _, actionRecord := range actionList { + if _, ok := resultMap[actionRecord.UserID]; !ok { + resultMap[actionRecord.UserID] = 1 + } else { + resultMap[actionRecord.UserID] += 1 + } + } + return resultMap +} + func queryAction(start_unix int64, end_unix int64, actionType int64) map[int64]int { sess := x.NewSession() defer sess.Close() diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index c893594bc..2f37dc15e 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -4,7 +4,6 @@ import ( "fmt" "net/http" "net/url" - "strings" "time" "code.gitea.io/gitea/models" @@ -129,23 +128,8 @@ func QueryUserStaticDataPage(ctx *context.Context) { //设置默认打开的表单 xlsx.SetActiveSheet(index) - var filename string - nowTime := time.Now() - nowZeroTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, nowTime.Location()) - if endTime.Unix() >= nowZeroTime.Unix() { - endDate = nowZeroTime.AddDate(0, 0, -1).Format("2006-01-02") - } - - if isAll { - filename = sheetName + "_" + ctx.Tr("user.static.all") + ".xlsx" - } else { - filename = sheetName + "_" + strings.ReplaceAll(startDate, "-", "") + "_" + strings.ReplaceAll(endDate, "-", "") + ".xlsx" - } - - if len(userName) > 0 { - filename = sheetName + "_" + userName + "_" + strings.ReplaceAll(startDate, "-", "") + "_" + strings.ReplaceAll(endDate, "-", "") + ".xlsx" - } + filename := sheetName + "_" + ctx.Tr("user.static.all") + ".xlsx" ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(filename)) ctx.Resp.Header().Set("Content-Type", "application/octet-stream")