Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
pull/1036/head
zouap 3 years ago
parent
commit
be4a352947
2 changed files with 21 additions and 19 deletions
  1. +20
    -2
      models/user_business_analysis.go
  2. +1
    -17
      routers/repo/user_data_analysis.go

+ 20
- 2
models/user_business_analysis.go View File

@@ -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()


+ 1
- 17
routers/repo/user_data_analysis.go View File

@@ -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")


Loading…
Cancel
Save