|
|
@@ -15,6 +15,10 @@ import ( |
|
|
"github.com/360EntSecGroup-Skylar/excelize/v2" |
|
|
"github.com/360EntSecGroup-Skylar/excelize/v2" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
PAGE_SIZE = 2000 |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
func queryUserDataPage(ctx *context.Context, tableName string, queryObj interface{}) { |
|
|
func queryUserDataPage(ctx *context.Context, tableName string, queryObj interface{}) { |
|
|
page := ctx.QueryInt("page") |
|
|
page := ctx.QueryInt("page") |
|
|
if page <= 0 { |
|
|
if page <= 0 { |
|
|
@@ -24,11 +28,89 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac |
|
|
if pageSize <= 0 { |
|
|
if pageSize <= 0 { |
|
|
pageSize = setting.UI.IssuePagingNum |
|
|
pageSize = setting.UI.IssuePagingNum |
|
|
} |
|
|
} |
|
|
re, count := models.QueryUserStaticDataByTableName(page, pageSize, tableName, queryObj) |
|
|
|
|
|
mapInterface := make(map[string]interface{}) |
|
|
|
|
|
mapInterface["data"] = re |
|
|
|
|
|
mapInterface["count"] = count |
|
|
|
|
|
ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
|
|
|
|
|
userName := ctx.Query("userName") |
|
|
|
|
|
IsReturnFile := ctx.QueryBool("IsReturnFile") |
|
|
|
|
|
|
|
|
|
|
|
if IsReturnFile { |
|
|
|
|
|
//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) |
|
|
|
|
|
} |
|
|
|
|
|
_, count := models.QueryUserStaticDataByTableName(1, 1, tableName, queryObj, userName) |
|
|
|
|
|
var indexTotal int64 |
|
|
|
|
|
indexTotal = 0 |
|
|
|
|
|
for { |
|
|
|
|
|
re, _ := models.QueryUserStaticDataByTableName(int(indexTotal), PAGE_SIZE, tableName, queryObj, "") |
|
|
|
|
|
log.Info("return count=" + fmt.Sprint(count)) |
|
|
|
|
|
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 = userRecord.DataDate |
|
|
|
|
|
xlsx.SetCellValue(sheetName, "Q"+rows, formatTime+" 00:01") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//设置默认打开的表单 |
|
|
|
|
|
xlsx.SetActiveSheet(index) |
|
|
|
|
|
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()) |
|
|
|
|
|
} |
|
|
|
|
|
indexTotal += PAGE_SIZE |
|
|
|
|
|
if indexTotal >= count { |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
re, count := models.QueryUserStaticDataByTableName((page-1)*pageSize, pageSize, tableName, queryObj, userName) |
|
|
|
|
|
mapInterface := make(map[string]interface{}) |
|
|
|
|
|
mapInterface["data"] = re |
|
|
|
|
|
mapInterface["count"] = count |
|
|
|
|
|
ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func QueryUserStaticCurrentMonth(ctx *context.Context) { |
|
|
func QueryUserStaticCurrentMonth(ctx *context.Context) { |
|
|
|