Browse Source

增加下载接口。

Signed-off-by: zouap <zouap@pcl.ac.cn>
pull/2977/head
zouap 2 years ago
parent
commit
0bb98eb80d
3 changed files with 86 additions and 10 deletions
  1. +3
    -1
      options/locale/locale_en-US.ini
  2. +3
    -1
      options/locale/locale_zh-CN.ini
  3. +80
    -8
      routers/repo/user_invitation.go

+ 3
- 1
options/locale/locale_en-US.ini View File

@@ -536,8 +536,10 @@ form.name_reserved = The username '%s' is reserved.
form.name_pattern_not_allowed = The pattern '%s' is not allowed in a username. form.name_pattern_not_allowed = The pattern '%s' is not allowed in a username.
form.name_chars_not_allowed = User name '%s' contains invalid characters. form.name_chars_not_allowed = User name '%s' contains invalid characters.


user.static.invitationNum=User Invitation Count
static.invitationdetailsheetname=User Invitation Detail
static.invitationNum=User Invitation Count
static.invitationsheetname=User Invitation static.invitationsheetname=User Invitation
static.srcUserId=Recommended User ID
static.sheetname=User Analysis static.sheetname=User Analysis
static.id=ID static.id=ID
static.name=User Name static.name=User Name


+ 3
- 1
options/locale/locale_zh-CN.ini View File

@@ -541,8 +541,10 @@ form.name_reserved='%s' 用户名被保留。
form.name_pattern_not_allowed=用户名中不允许使用 "%s"。 form.name_pattern_not_allowed=用户名中不允许使用 "%s"。
form.name_chars_not_allowed=用户名 '%s' 包含无效字符。 form.name_chars_not_allowed=用户名 '%s' 包含无效字符。


user.static.invitationNum=邀请用户数
static.invitationdetailsheetname=用户邀请详细数据
static.invitationNum=邀请用户数
static.sheetname=用户分析 static.sheetname=用户分析
static.srcUserId=推荐用户ID
static.invitationsheetname=用户邀请分析 static.invitationsheetname=用户邀请分析
static.id=ID static.id=ID
static.name=用户名 static.name=用户名


+ 80
- 8
routers/repo/user_invitation.go View File

@@ -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")


Loading…
Cancel
Save