From 24d816417017c1f80cd8a2020432f8dd7d652dde Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 17 May 2022 15:55:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/user_data_analysis.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 07b2ad775..80045a5ad 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -290,7 +290,7 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e xlsx.SetActiveSheet(index) filename := sheetName + "_" + ctx.Tr("user.static."+tableName) + ".xlsx" if tableName == "" { - filename = sheetName + "_" + startTime.Add(8*60*60*1000).Format("20060102") + "_" + endTime.Add(8*60*60*1000).Format("20060102") + ".xlsx" + filename = sheetName + "_" + getTimeFileName(startTime) + "_" + getTimeFileName(endTime) + ".xlsx" } ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(filename)) ctx.Resp.Header().Set("Content-Type", "application/octet-stream") @@ -312,7 +312,17 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e } ctx.JSON(http.StatusOK, mapInterface) } - +} +func getTimeFileName(t time.Time) string { + month := fmt.Sprint(t.Month()) + if t.Month() < 10 { + month = "0" + month + } + day := fmt.Sprint(t.Day()) + if t.Day() < 10 { + day = "0" + day + } + return fmt.Sprint(t.Year()) + month + day } func QueryRankingList(ctx *context.Context) {