|
|
|
@@ -3,6 +3,7 @@ package repo |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
@@ -10,6 +11,7 @@ import ( |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"github.com/xuri/excelize/v2" |
|
|
|
) |
|
|
|
|
|
|
|
func QueryUserStaticData(ctx *context.Context) { |
|
|
|
@@ -35,6 +37,7 @@ func QueryUserStaticDataPage(ctx *context.Context) { |
|
|
|
pageSize = setting.UI.IssuePagingNum |
|
|
|
} |
|
|
|
userName := ctx.Query("userName") |
|
|
|
IsReturnFile := ctx.QueryBool("IsReturnFile") |
|
|
|
|
|
|
|
log.Info("startDate=" + startDate + " endDate=" + endDate + " userName=" + userName + " page=" + fmt.Sprint(page)) |
|
|
|
startTime, _ := time.Parse("2006-01-02", startDate) |
|
|
|
@@ -55,7 +58,71 @@ func QueryUserStaticDataPage(ctx *context.Context) { |
|
|
|
re, count := models.QueryUserStaticDataPage(pageOpts) |
|
|
|
mapInterface["data"] = re |
|
|
|
mapInterface["count"] = count |
|
|
|
ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
if IsReturnFile { |
|
|
|
//writer exec file. |
|
|
|
xlsx := excelize.NewFile() |
|
|
|
sheetName := ctx.Tr("static.sheetname") |
|
|
|
index := xlsx.NewSheet(sheetName) |
|
|
|
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.issuecount"), |
|
|
|
"E1": ctx.Tr("user.static.commentcount"), |
|
|
|
"F1": ctx.Tr("user.static.focusrepocount"), |
|
|
|
"G1": ctx.Tr("user.static.starrepocount"), |
|
|
|
"H1": ctx.Tr("user.static.logincount"), |
|
|
|
"I1": ctx.Tr("user.static.watchedcount"), |
|
|
|
"J1": ctx.Tr("user.static.commitcodesize"), |
|
|
|
"K1": ctx.Tr("user.static.solveissuecount"), |
|
|
|
"L1": ctx.Tr("user.static.encyclopediascount"), |
|
|
|
"M1": ctx.Tr("user.static.createrepocount"), |
|
|
|
"N1": ctx.Tr("user.static.openiindex"), |
|
|
|
"O1": ctx.Tr("user.static.registdate"), |
|
|
|
"P1": 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.IssueCount) |
|
|
|
xlsx.SetCellValue(sheetName, "E"+rows, userRecord.CommentCount) |
|
|
|
xlsx.SetCellValue(sheetName, "F"+rows, userRecord.FocusRepoCount) |
|
|
|
xlsx.SetCellValue(sheetName, "G"+rows, userRecord.StarRepoCount) |
|
|
|
xlsx.SetCellValue(sheetName, "H"+rows, userRecord.LoginCount) |
|
|
|
xlsx.SetCellValue(sheetName, "I"+rows, userRecord.WatchedCount) |
|
|
|
xlsx.SetCellValue(sheetName, "J"+rows, userRecord.CommitCodeSize) |
|
|
|
xlsx.SetCellValue(sheetName, "K"+rows, userRecord.SolveIssueCount) |
|
|
|
xlsx.SetCellValue(sheetName, "L"+rows, userRecord.EncyclopediasCount) |
|
|
|
xlsx.SetCellValue(sheetName, "M"+rows, userRecord.CreateRepoCount) |
|
|
|
xlsx.SetCellValue(sheetName, "N"+rows, userRecord.OpenIIndex) |
|
|
|
xlsx.SetCellValue(sheetName, "O"+rows, userRecord.RegistDate.Format("2006-01-02")) |
|
|
|
xlsx.SetCellValue(sheetName, "P"+rows, time.Unix(userRecord.CountDate, 0).Format("2006-01-02")) |
|
|
|
} |
|
|
|
|
|
|
|
//设置默认打开的表单 |
|
|
|
xlsx.SetActiveSheet(index) |
|
|
|
filename := sheetName + "_" + strings.ReplaceAll(startDate, "-", "") + "_" + strings.ReplaceAll(endDate, "-", "") + ".xlsx" |
|
|
|
if len(userName) > 0 { |
|
|
|
filename = sheetName + "_" + userName + "_" + strings.ReplaceAll(startDate, "-", "") + "_" + strings.ReplaceAll(endDate, "-", "") + ".xlsx" |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+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()) |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TimingCountDataByDateAndReCount(date string, isReCount bool) { |
|
|
|
|