|
@@ -43,6 +43,25 @@ func getInvitationExcelHeader(ctx *context.Context) map[string]string { |
|
|
return excelHeaderMap |
|
|
return excelHeaderMap |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getInvitationDetailExcelHeader(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.srcUserId")) |
|
|
|
|
|
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) { |
|
|
func writeInvitationExcel(row int, xlsx *excelize.File, sheetName string, userRecord *models.UserBusinessAnalysisAll) { |
|
|
rows := fmt.Sprint(row) |
|
|
rows := fmt.Sprint(row) |
|
|
var tmp byte |
|
|
var tmp byte |
|
@@ -63,8 +82,61 @@ func writeInvitationExcel(row int, xlsx *excelize.File, sheetName string, userRe |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func writeInvitationDetailExcel(row int, xlsx *excelize.File, sheetName string, userRecord *models.Invitation) { |
|
|
|
|
|
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.SrcUserID) |
|
|
|
|
|
tmp = tmp + 1 |
|
|
|
|
|
|
|
|
|
|
|
xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.Phone) |
|
|
|
|
|
tmp = tmp + 1 |
|
|
|
|
|
|
|
|
|
|
|
formatTime := userRecord.CreatedUnix.Format("2006-01-02 15:04:05") |
|
|
|
|
|
xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, formatTime[0:len(formatTime)-3]) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func DownloadInvitationDetail(ctx *context.Context) { |
|
|
func DownloadInvitationDetail(ctx *context.Context) { |
|
|
|
|
|
xlsx := excelize.NewFile() |
|
|
|
|
|
sheetName := ctx.Tr("user.static.invitationdetailsheetname") |
|
|
|
|
|
index := xlsx.NewSheet(sheetName) |
|
|
|
|
|
xlsx.DeleteSheet("Sheet1") |
|
|
|
|
|
excelHeader := getInvitationDetailExcelHeader(ctx) |
|
|
|
|
|
for k, v := range excelHeader { |
|
|
|
|
|
//设置单元格的值 |
|
|
|
|
|
xlsx.SetCellValue(sheetName, k, v) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_, count := models.QueryInvitaionPage(1, 1) |
|
|
|
|
|
var indexTotal int64 |
|
|
|
|
|
indexTotal = 0 |
|
|
|
|
|
row := 1 |
|
|
|
|
|
for { |
|
|
|
|
|
re, _ := models.QueryInvitaionPage(int(indexTotal), PAGE_SIZE) |
|
|
|
|
|
log.Info("return count=" + fmt.Sprint(count)) |
|
|
|
|
|
for _, userRecord := range re { |
|
|
|
|
|
row++ |
|
|
|
|
|
writeInvitationDetailExcel(row, xlsx, sheetName, userRecord) |
|
|
|
|
|
} |
|
|
|
|
|
indexTotal += PAGE_SIZE |
|
|
|
|
|
if indexTotal >= count { |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//设置默认打开的表单 |
|
|
|
|
|
xlsx.SetActiveSheet(index) |
|
|
|
|
|
filename := sheetName + ".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 queryDataFromStaticTable(ctx *context.Context, tableName string, queryObj interface{}) { |
|
|
func queryDataFromStaticTable(ctx *context.Context, tableName string, queryObj interface{}) { |
|
@@ -198,14 +270,14 @@ func QueryInvitationAll(ctx *context.Context) { |
|
|
queryDataFromStaticTable(ctx, "public.user_business_analysis_all", new(models.UserBusinessAnalysisAll)) |
|
|
queryDataFromStaticTable(ctx, "public.user_business_analysis_all", new(models.UserBusinessAnalysisAll)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func queryData(ctx *context.Context, startTime int64, endTime int64) { |
|
|
|
|
|
page, pageSize := getPageInfo(ctx) |
|
|
|
|
|
result, count := models.QueryInvitaionPage(startTime, endTime, (page-1)*pageSize, pageSize) |
|
|
|
|
|
mapInterface := make(map[string]interface{}) |
|
|
|
|
|
mapInterface["data"] = result |
|
|
|
|
|
mapInterface["count"] = count |
|
|
|
|
|
ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// func queryData(ctx *context.Context, startTime int64, endTime int64) { |
|
|
|
|
|
// page, pageSize := getPageInfo(ctx) |
|
|
|
|
|
// result, count := models.QueryInvitaionPage(startTime, endTime, (page-1)*pageSize, pageSize) |
|
|
|
|
|
// mapInterface := make(map[string]interface{}) |
|
|
|
|
|
// mapInterface["data"] = result |
|
|
|
|
|
// mapInterface["count"] = count |
|
|
|
|
|
// ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
func getPageInfo(ctx *context.Context) (int, int) { |
|
|
func getPageInfo(ctx *context.Context) (int, int) { |
|
|
page := ctx.QueryInt("page") |
|
|
page := ctx.QueryInt("page") |
|
|