Files
in-server/app/main/api/internal/logic/report/downloadreportpdflogic.go
2026-03-19 16:55:24 +08:00

49 lines
1.1 KiB
Go

package report
import (
"context"
"fmt"
"in-server/app/main/api/internal/svc"
"in-server/app/main/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DownloadReportPdfLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDownloadReportPdfLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DownloadReportPdfLogic {
return &DownloadReportPdfLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DownloadReportPdfLogic) DownloadReportPdf(req *types.DownloadReportPdfReq) (resp *types.DownloadReportPdfResp, err error) {
pdfBytes, err := l.svcCtx.ReportPDFService.GenerateReportPDF(l.ctx, req.OrderId, req.OrderNo)
if err != nil {
logx.Errorf("生成报告 PDF 失败, orderId=%s, orderNo=%s, err=%v", req.OrderId, req.OrderNo, err)
return nil, fmt.Errorf("生成报告 PDF 失败: %w", err)
}
fileKey := req.OrderNo
if fileKey == "" {
fileKey = req.OrderId
}
if fileKey == "" {
fileKey = "unknown"
}
resp = &types.DownloadReportPdfResp{
FileName: fmt.Sprintf("report_%s.pdf", fileKey),
Content: pdfBytes,
}
return resp, nil
}