fix:调整错误提示语,格式化代码
This commit is contained in:
parent
d9f8e69a11
commit
bbc18f56af
@ -114,7 +114,7 @@ func CreateCompetitiveReportCore(ctx *gin.Context, req *cast.CreateCompetitiveRe
|
||||
// 验证:必须传入 json_data(使用模板方式生成PDF)
|
||||
hasReportData := reportData.OverallSummary != "" || reportData.HighlightAnalysis.Summary != ""
|
||||
if !hasReportData {
|
||||
return nil, errors.New("请传入json_data参数")
|
||||
return nil, errors.New("参数错误")
|
||||
}
|
||||
|
||||
if req.ImageUrl != "" {
|
||||
@ -128,6 +128,7 @@ func CreateCompetitiveReportCore(ctx *gin.Context, req *cast.CreateCompetitiveRe
|
||||
|
||||
// 使用模板方式生成PDF
|
||||
zap.L().Info("reportData内容", zap.Any("reportData", reportData))
|
||||
fmt.Println(reportData)
|
||||
|
||||
// 直接使用传入的结构体数据
|
||||
competitorReportData := reportData
|
||||
@ -139,35 +140,35 @@ func CreateCompetitiveReportCore(ctx *gin.Context, req *cast.CreateCompetitiveRe
|
||||
|
||||
zap.L().Info("解析成功", zap.Any("competitorReportData", competitorReportData))
|
||||
|
||||
today := time.Now().Format("20060102")
|
||||
timestamp := time.Now().UnixMicro()
|
||||
pdfFileName := fmt.Sprintf("%s%s老师的竞品报告%d.pdf", today, req.ArtistName, timestamp)
|
||||
pdfFilePath := "./runtime/report_pdf/" + pdfFileName
|
||||
today := time.Now().Format("20060102")
|
||||
timestamp := time.Now().UnixMicro()
|
||||
pdfFileName := fmt.Sprintf("%s%s老师的竞品报告%d.pdf", today, req.ArtistName, timestamp)
|
||||
pdfFilePath := "./runtime/report_pdf/" + pdfFileName
|
||||
|
||||
_, err = utils.CheckDirPath("./runtime/report_pdf/", true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("创建PDF目录失败: %v", err)
|
||||
}
|
||||
_, err = utils.CheckDirPath("./runtime/report_pdf/", true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("创建PDF目录失败: %v", err)
|
||||
}
|
||||
|
||||
// 模板路径
|
||||
templatePath := "./data/竞品报告pdf模板.pdf"
|
||||
// 模板路径
|
||||
templatePath := "./data/竞品报告pdf模板.pdf"
|
||||
|
||||
// 调用 GenerateCompetitorReportPDF
|
||||
err = utils.GenerateCompetitorReportPDF(templatePath, pdfFilePath, competitorReportData)
|
||||
if err != nil {
|
||||
zap.L().Error("生成PDF失败", zap.Error(err))
|
||||
return nil, errors.New("生成PDF失败")
|
||||
}
|
||||
// 调用 GenerateCompetitorReportPDF
|
||||
err = utils.GenerateCompetitorReportPDF(templatePath, pdfFilePath, competitorReportData)
|
||||
if err != nil {
|
||||
zap.L().Error("生成PDF失败", zap.Error(err))
|
||||
return nil, errors.New("生成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))
|
||||
}
|
||||
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))
|
||||
}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
|
||||
pdfUrl, uploadErr := upload.PutBos(pdfFilePath, upload.PdfType, true)
|
||||
if uploadErr != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user