fix pdf
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"tyapi-server/internal/domains/product/entities"
|
||||
|
||||
@@ -55,50 +54,20 @@ func NewPDFGeneratorRefactored(logger *zap.Logger) *PDFGeneratorRefactored {
|
||||
return gen
|
||||
}
|
||||
|
||||
// findLogo 查找logo文件
|
||||
// findLogo 查找logo文件(仅从resources/pdf加载)
|
||||
func (g *PDFGeneratorRefactored) findLogo() {
|
||||
// 获取当前文件所在目录
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
baseDir := filepath.Dir(filename)
|
||||
// 获取resources/pdf目录(使用统一的资源路径查找函数)
|
||||
resourcesPDFDir := GetResourcesPDFDir()
|
||||
logoPath := filepath.Join(resourcesPDFDir, "logo.png")
|
||||
|
||||
// 优先使用 baseDir(最可靠,基于当前文件位置)
|
||||
logoPaths := []string{
|
||||
filepath.Join(baseDir, "天远数据.png"), // 相对当前文件(最优先)
|
||||
}
|
||||
|
||||
// 尝试相对于工作目录的路径
|
||||
if workDir, err := os.Getwd(); err == nil {
|
||||
logoPaths = append(logoPaths,
|
||||
filepath.Join(workDir, "internal", "shared", "pdf", "天远数据.png"),
|
||||
filepath.Join(workDir, "tyapi-server", "internal", "shared", "pdf", "天远数据.png"),
|
||||
)
|
||||
}
|
||||
|
||||
// 尝试服务器绝对路径(Linux环境,优先查找 /www/tyapi-server)
|
||||
if runtime.GOOS == "linux" {
|
||||
serverPaths := []string{
|
||||
"/www/tyapi-server/internal/shared/pdf/天远数据.png",
|
||||
"/app/internal/shared/pdf/天远数据.png",
|
||||
}
|
||||
logoPaths = append(logoPaths, serverPaths...)
|
||||
}
|
||||
|
||||
// 尝试相对路径(作为最后的后备方案)
|
||||
logoPaths = append(logoPaths,
|
||||
"internal/shared/pdf/天远数据.png",
|
||||
"./internal/shared/pdf/天远数据.png",
|
||||
)
|
||||
|
||||
// 尝试所有路径
|
||||
for _, logoPath := range logoPaths {
|
||||
if _, err := os.Stat(logoPath); err == nil {
|
||||
g.logoPath = logoPath
|
||||
return
|
||||
}
|
||||
// 检查文件是否存在
|
||||
if _, err := os.Stat(logoPath); err == nil {
|
||||
g.logoPath = logoPath
|
||||
return
|
||||
}
|
||||
|
||||
// 只记录关键错误
|
||||
g.logger.Warn("未找到logo文件")
|
||||
g.logger.Warn("未找到logo文件", zap.String("path", logoPath))
|
||||
}
|
||||
|
||||
// GenerateProductPDF 为产品生成PDF文档(接受响应类型,内部转换)
|
||||
|
||||
Reference in New Issue
Block a user