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