From bdf3fa61442febe7930569430e5ec82954719373 Mon Sep 17 00:00:00 2001 From: cjy Date: Wed, 14 Jan 2026 17:08:55 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Apdf=E4=B8=8A=E4=BC=A0=E5=AE=8C?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E5=B0=B1=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/cast/report.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/service/cast/report.go b/pkg/service/cast/report.go index c2bee2b..5154d9c 100644 --- a/pkg/service/cast/report.go +++ b/pkg/service/cast/report.go @@ -15,6 +15,7 @@ import ( "fonchain-fiee/pkg/service" "fonchain-fiee/pkg/service/upload" "fonchain-fiee/pkg/utils" + "os" "path/filepath" "strconv" "time" @@ -101,6 +102,18 @@ func CreateCompetitiveReport(ctx *gin.Context) { } fmt.Println("生成PDF成功", pdfFilePath) + // 确保在上传后(无论成功或失败)删除临时PDF文件 + defer func() { + // 检查文件是否存在,存在才删除 + if _, err := os.Stat(pdfFilePath); err == nil { + if err := os.Remove(pdfFilePath); err != nil { + zap.L().Warn("删除临时PDF文件失败", zap.String("path", pdfFilePath), zap.Error(err)) + } else { + zap.L().Info("删除临时PDF文件成功", zap.String("path", pdfFilePath)) + } + } + }() + // 上传PDF到OSS pdfUrl, uploadErr := upload.PutBos(pdfFilePath, upload.PdfType, true) if uploadErr != nil {