41 lines
1.0 KiB
Go
41 lines
1.0 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)
|
|
}
|
|
|
|
resp = &types.DownloadReportPdfResp{
|
|
FileName: fmt.Sprintf("report_%s.pdf", req.OrderNo),
|
|
Content: pdfBytes,
|
|
}
|
|
return resp, nil
|
|
}
|
|
|