|
|
|
@@ -1,11 +1,15 @@ |
|
|
|
package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"github.com/360EntSecGroup-Skylar/excelize/v2" |
|
|
|
) |
|
|
|
|
|
|
|
func QueryInvitationCurrentMonth(ctx *context.Context) { |
|
|
|
@@ -14,30 +18,113 @@ func QueryInvitationCurrentMonth(ctx *context.Context) { |
|
|
|
// pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
// pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
|
|
|
|
// queryUserDataPage(ctx, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth)) |
|
|
|
//queryUserDataPage(ctx, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth)) |
|
|
|
//_, count := models.QueryUserStaticDataByTableName(1, 1, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth), userName, 1) |
|
|
|
|
|
|
|
queryDataFromStaticTable(ctx, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth)) |
|
|
|
} |
|
|
|
|
|
|
|
func getInvitationExcelHeader(ctx *context.Context) map[string]string { |
|
|
|
excelHeader := make([]string, 0) |
|
|
|
excelHeader = append(excelHeader, ctx.Tr("user.static.id")) |
|
|
|
excelHeader = append(excelHeader, ctx.Tr("user.static.name")) |
|
|
|
excelHeader = append(excelHeader, ctx.Tr("user.static.invitationNum")) |
|
|
|
excelHeader = append(excelHeader, ctx.Tr("user.static.phone")) |
|
|
|
excelHeader = append(excelHeader, ctx.Tr("user.static.registdate")) |
|
|
|
|
|
|
|
excelHeaderMap := make(map[string]string, 0) |
|
|
|
var i byte |
|
|
|
i = 0 |
|
|
|
for _, value := range excelHeader { |
|
|
|
excelColumn := getColumn(i) + fmt.Sprint(1) |
|
|
|
excelHeaderMap[excelColumn] = value |
|
|
|
i++ |
|
|
|
} |
|
|
|
return excelHeaderMap |
|
|
|
} |
|
|
|
|
|
|
|
func writeInvitationExcel(row int, xlsx *excelize.File, sheetName string, userRecord *models.UserBusinessAnalysisAll) { |
|
|
|
rows := fmt.Sprint(row) |
|
|
|
var tmp byte |
|
|
|
tmp = 0 |
|
|
|
xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.ID) |
|
|
|
tmp = tmp + 1 |
|
|
|
xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.Name) |
|
|
|
tmp = tmp + 1 |
|
|
|
|
|
|
|
xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.InvitationUserNum) |
|
|
|
tmp = tmp + 1 |
|
|
|
|
|
|
|
xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.Phone) |
|
|
|
tmp = tmp + 1 |
|
|
|
|
|
|
|
formatTime := userRecord.RegistDate.Format("2006-01-02 15:04:05") |
|
|
|
xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, formatTime[0:len(formatTime)-3]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func DownloadInvitationDetail(ctx *context.Context) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func queryDataFromStaticTable(ctx *context.Context, tableName string, queryObj interface{}) { |
|
|
|
page, pageSize := getPageInfo(ctx) |
|
|
|
userName := ctx.Query("userName") |
|
|
|
resultRecord, count := models.QueryUserInvitationDataByTableName((page-1)*pageSize, pageSize, tableName, queryObj, userName, 1) |
|
|
|
result := make([]models.Invitation, 0) |
|
|
|
for _, record := range resultRecord { |
|
|
|
invi := models.Invitation{ |
|
|
|
SrcUserID: record.ID, |
|
|
|
Name: record.Name, |
|
|
|
InvitationUserNum: record.InvitationUserNum, |
|
|
|
Phone: record.Phone, |
|
|
|
IsReturnFile := ctx.QueryBool("IsReturnFile") |
|
|
|
|
|
|
|
if IsReturnFile { |
|
|
|
//writer exec file. |
|
|
|
xlsx := excelize.NewFile() |
|
|
|
sheetName := ctx.Tr("user.static.invitationsheetname") |
|
|
|
index := xlsx.NewSheet(sheetName) |
|
|
|
xlsx.DeleteSheet("Sheet1") |
|
|
|
excelHeader := getInvitationExcelHeader(ctx) |
|
|
|
for k, v := range excelHeader { |
|
|
|
//设置单元格的值 |
|
|
|
xlsx.SetCellValue(sheetName, k, v) |
|
|
|
} |
|
|
|
_, count := models.QueryUserInvitationDataByTableName(1, 1, tableName, queryObj, "", 1) |
|
|
|
var indexTotal int64 |
|
|
|
indexTotal = 0 |
|
|
|
row := 1 |
|
|
|
for { |
|
|
|
re, _ := models.QueryUserInvitationDataByTableName(int(indexTotal), PAGE_SIZE, tableName, queryObj, "", 1) |
|
|
|
log.Info("return count=" + fmt.Sprint(count)) |
|
|
|
for _, userRecord := range re { |
|
|
|
row++ |
|
|
|
writeInvitationExcel(row, xlsx, sheetName, userRecord) |
|
|
|
} |
|
|
|
indexTotal += PAGE_SIZE |
|
|
|
if indexTotal >= count { |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
//设置默认打开的表单 |
|
|
|
xlsx.SetActiveSheet(index) |
|
|
|
filename := sheetName + "_" + ctx.Tr("user.static."+tableName) + ".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()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
resultRecord, count := models.QueryUserInvitationDataByTableName((page-1)*pageSize, pageSize, tableName, queryObj, userName, 1) |
|
|
|
result := make([]models.Invitation, 0) |
|
|
|
for _, record := range resultRecord { |
|
|
|
invi := models.Invitation{ |
|
|
|
SrcUserID: record.ID, |
|
|
|
Name: record.Name, |
|
|
|
InvitationUserNum: record.InvitationUserNum, |
|
|
|
Phone: record.Phone, |
|
|
|
CreatedUnix: record.RegistDate, |
|
|
|
} |
|
|
|
result = append(result, invi) |
|
|
|
} |
|
|
|
result = append(result, invi) |
|
|
|
mapInterface := make(map[string]interface{}) |
|
|
|
mapInterface["data"] = result |
|
|
|
mapInterface["count"] = count |
|
|
|
ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
} |
|
|
|
mapInterface := make(map[string]interface{}) |
|
|
|
mapInterface["data"] = result |
|
|
|
mapInterface["count"] = count |
|
|
|
ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryInvitationCurrentWeek(ctx *context.Context) { |
|
|
|
|