Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
pull/1036/head
zouap 3 years ago
parent
commit
c5e3e7ab67
2 changed files with 121 additions and 2 deletions
  1. +42
    -0
      models/user_business_analysis.go
  2. +79
    -2
      routers/repo/user_data_analysis.go

+ 42
- 0
models/user_business_analysis.go View File

@@ -333,6 +333,48 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus
return userBusinessAnalysisReturnList, count
}

func RefreshUserStaticAllTabel() {

statictisSess := xStatistic.NewSession()
defer statictisSess.Close()

statictisSess.Exec("delete from user_business_analysis_all")

currentTimeNow := time.Now()
pageStartTime := getLastCountDate()
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()).Unix()

var cond = builder.NewCond()
cond = cond.And(
builder.Gte{"count_date": pageStartTime},
)
cond = cond.And(
builder.Lte{"count_date": pageEndTime},
)
userBusinessAnalysisList := make([]*UserBusinessAnalysis, 0)
if err := statictisSess.Table("user_business_analysis").Where(cond).OrderBy("id desc").
Find(&userBusinessAnalysisList); err != nil {
return
}
for _, userRecord := range userBusinessAnalysisList {
log.Info("insert to UserBusinessAnalysisAll table,user id=" + fmt.Sprint(userRecord.ID))
allData := getAllData(userRecord.ID, statictisSess)
allData.ID = userRecord.ID
allData.CountDate = 0
allData.DataDate = userRecord.DataDate
allData.Email = userRecord.Email
allData.OpenIIndex = userRecord.OpenIIndex
allData.GiteaAgeMonth = userRecord.GiteaAgeMonth
allData.Name = userRecord.Name
allData.RegistDate = userRecord.RegistDate

_, err := statictisSess.Insert(&allData)
if err != nil {
log.Info("insert all data failed." + err.Error())
}
}
}

func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, endTime time.Time, isReCount bool) error {

log.Info("start to count other user info data")


+ 79
- 2
routers/repo/user_data_analysis.go View File

@@ -16,6 +16,77 @@ import (
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func DownloadAllUserData(ctx *context.Context) {
re, count := models.QueryUserStaticDataAll(pageOpts)
log.Info("return count=" + fmt.Sprint(count))
//writer exec file.
xlsx := excelize.NewFile()
sheetName := ctx.Tr("user.static.sheetname")
index := xlsx.NewSheet(sheetName)
xlsx.DeleteSheet("Sheet1")
dataHeader := map[string]string{
"A1": ctx.Tr("user.static.id"),
"B1": ctx.Tr("user.static.name"),
"C1": ctx.Tr("user.static.codemergecount"),
"D1": ctx.Tr("user.static.commitcount"),
"E1": ctx.Tr("user.static.issuecount"),
"F1": ctx.Tr("user.static.commentcount"),
"G1": ctx.Tr("user.static.focusrepocount"),
"H1": ctx.Tr("user.static.starrepocount"),
"I1": ctx.Tr("user.static.logincount"),
"J1": ctx.Tr("user.static.watchedcount"),
"K1": ctx.Tr("user.static.commitcodesize"),
"L1": ctx.Tr("user.static.solveissuecount"),
"M1": ctx.Tr("user.static.encyclopediascount"),
"N1": ctx.Tr("user.static.createrepocount"),
"O1": ctx.Tr("user.static.openiindex"),
"P1": ctx.Tr("user.static.registdate"),
"Q1": ctx.Tr("user.static.countdate"),
}
for k, v := range dataHeader {
//设置单元格的值
xlsx.SetCellValue(sheetName, k, v)
}

for i, userRecord := range re {
rows := fmt.Sprint(i + 2)

xlsx.SetCellValue(sheetName, "A"+rows, userRecord.ID)
xlsx.SetCellValue(sheetName, "B"+rows, userRecord.Name)
xlsx.SetCellValue(sheetName, "C"+rows, userRecord.CodeMergeCount)
xlsx.SetCellValue(sheetName, "D"+rows, userRecord.CommitCount)
xlsx.SetCellValue(sheetName, "E"+rows, userRecord.IssueCount)
xlsx.SetCellValue(sheetName, "F"+rows, userRecord.CommentCount)
xlsx.SetCellValue(sheetName, "G"+rows, userRecord.FocusRepoCount)
xlsx.SetCellValue(sheetName, "H"+rows, userRecord.StarRepoCount)
xlsx.SetCellValue(sheetName, "I"+rows, userRecord.LoginCount)
xlsx.SetCellValue(sheetName, "J"+rows, userRecord.WatchedCount)
xlsx.SetCellValue(sheetName, "K"+rows, userRecord.CommitCodeSize)
xlsx.SetCellValue(sheetName, "L"+rows, userRecord.SolveIssueCount)
xlsx.SetCellValue(sheetName, "M"+rows, userRecord.EncyclopediasCount)
xlsx.SetCellValue(sheetName, "N"+rows, userRecord.CreateRepoCount)
xlsx.SetCellValue(sheetName, "O"+rows, fmt.Sprintf("%.2f", userRecord.OpenIIndex))

formatTime := userRecord.RegistDate.Format("2006-01-02 15:04:05")
xlsx.SetCellValue(sheetName, "P"+rows, formatTime[0:len(formatTime)-3])

formatTime = time.Unix(userRecord.CountDate, 0).Format("2006-01-02 15:04:05")
xlsx.SetCellValue(sheetName, "Q"+rows, formatTime[0:len(formatTime)-3])
}

//设置默认打开的表单
xlsx.SetActiveSheet(index)
var filename string

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")
if _, err := xlsx.WriteTo(ctx.Resp); err != nil {
log.Info("writer exel error." + err.Error())
}
}

func QueryUserStaticDataPage(ctx *context.Context) {
startDate := ctx.Query("startDate")
endDate := ctx.Query("endDate")
@@ -120,8 +191,8 @@ func QueryUserStaticDataPage(ctx *context.Context) {
formatTime := userRecord.RegistDate.Format("2006-01-02 15:04:05")
xlsx.SetCellValue(sheetName, "P"+rows, formatTime[0:len(formatTime)-3])

formatTime = time.Unix(userRecord.CountDate, 0).Format("2006-01-02 15:04:05")
xlsx.SetCellValue(sheetName, "Q"+rows, formatTime[0:len(formatTime)-3])
formatTime = userRecord.DataDate
xlsx.SetCellValue(sheetName, "Q"+rows, formatTime+" 00:01")
}

//设置默认打开的表单
@@ -160,6 +231,12 @@ func QueryUserStaticDataPage(ctx *context.Context) {
}

func TimingCountDataByDateAndReCount(date string, isReCount bool) {

if date == "refreshAll" {
models.RefreshUserStaticAllTabel()
return
}

t, _ := time.Parse("2006-01-02", date)
startTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())



Loading…
Cancel
Save