From 847d48d276ea70fa367bcc8267ea59962834b1df Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Tue, 27 Jan 2026 19:00:09 +0800 Subject: [PATCH] f --- .../processors/pdfg/pdfg01gz_processor.go | 31 +++++++++++++++++++ .../external/pdfgen/pdfgen_service.go | 14 +++++++++ 2 files changed, 45 insertions(+) diff --git a/internal/domains/api/services/processors/pdfg/pdfg01gz_processor.go b/internal/domains/api/services/processors/pdfg/pdfg01gz_processor.go index c2b0b58..3adbbdf 100644 --- a/internal/domains/api/services/processors/pdfg/pdfg01gz_processor.go +++ b/internal/domains/api/services/processors/pdfg/pdfg01gz_processor.go @@ -31,6 +31,15 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors // 获取全局logger zapLogger := logger.GetGlobalLogger() + // Debug:记录入口参数 + zapLogger.Debug("PDFG01GZ请求开始", + zap.String("name", paramsDto.Name), + zap.String("id_card", paramsDto.IDCard), + zap.String("mobile_no", paramsDto.MobileNo), + zap.String("authorized", paramsDto.Authorized), + zap.String("auth_authorize_file_code", paramsDto.AuthAuthorizeFileCode), + ) + // 从context获取config(如果存在) var cacheTTL time.Duration = 24 * time.Hour var cacheDir string @@ -46,6 +55,18 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors var maxSize int64 if cfg, ok := ctx.Value("config").(*config.Config); ok && cfg != nil { maxSize = cfg.PDFGen.Cache.MaxSize + + // Debug:记录PDF生成服务配置 + zapLogger.Debug("PDFG01GZ加载配置", + zap.String("env", cfg.App.Env), + zap.String("pdfgen_production_url", cfg.PDFGen.ProductionURL), + zap.String("pdfgen_development_url", cfg.PDFGen.DevelopmentURL), + zap.String("pdfgen_api_path", cfg.PDFGen.APIPath), + zap.Duration("pdfgen_timeout", cfg.PDFGen.Timeout), + zap.String("cache_dir", cacheDir), + zap.Duration("cache_ttl", cacheTTL), + zap.Int64("cache_max_size", maxSize), + ) } // 创建PDF缓存管理器 @@ -107,6 +128,11 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors // 格式化数据为PDF生成服务需要的格式(为缺失的数据提供默认值) formattedData := formatDataForPDF(apiData, paramsDto, zapLogger) + zapLogger.Debug("PDFG01GZ数据准备完成", + zap.Int("api_data_count", len(apiData)), + zap.Int("formatted_items", len(formattedData)), + ) + // 从APPLICANT_BASIC_INFO中提取报告编号(如果存在) var reportNumber string if len(formattedData) > 0 { @@ -130,6 +156,11 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors // 调用PDF生成服务 // 即使部分子处理器失败,只要有APPLICANT_BASIC_INFO就可以生成PDF + zapLogger.Debug("PDFG01GZ开始调用PDF生成服务", + zap.String("report_number", reportNumber), + zap.Int("data_items", len(formattedData)), + ) + pdfResp, err := pdfGenService.GenerateGuangzhouPDF(ctx, pdfReq) if err != nil { zapLogger.Error("生成PDF失败", diff --git a/internal/infrastructure/external/pdfgen/pdfgen_service.go b/internal/infrastructure/external/pdfgen/pdfgen_service.go index f676d13..ba21aac 100644 --- a/internal/infrastructure/external/pdfgen/pdfgen_service.go +++ b/internal/infrastructure/external/pdfgen/pdfgen_service.go @@ -93,6 +93,12 @@ func (s *PDFGenService) GenerateGuangzhouPDF(ctx context.Context, req *GenerateP return nil, fmt.Errorf("序列化请求失败: %w", err) } + // Debug:打印请求体预览(最多1024字节),防止日志过大 + bodyPreview := reqBody + if len(bodyPreview) > 1024 { + bodyPreview = bodyPreview[:1024] + } + // 构建请求URL url := fmt.Sprintf("%s%s", s.baseURL, s.apiPath) @@ -105,16 +111,20 @@ func (s *PDFGenService) GenerateGuangzhouPDF(ctx context.Context, req *GenerateP // 设置请求头 httpReq.Header.Set("Content-Type", "application/json") + start := time.Now() + // 发送请求 s.logger.Info("开始调用PDF生成服务", zap.String("url", url), zap.Int("data_count", len(req.Data)), + zap.ByteString("body_preview", bodyPreview), ) resp, err := s.client.Do(httpReq) if err != nil { s.logger.Error("调用PDF生成服务失败", zap.String("url", url), + zap.Duration("duration", time.Since(start)), zap.Error(err), ) return nil, fmt.Errorf("调用PDF生成服务失败: %w", err) @@ -126,7 +136,9 @@ func (s *PDFGenService) GenerateGuangzhouPDF(ctx context.Context, req *GenerateP // 尝试读取错误信息 errorBody, _ := io.ReadAll(resp.Body) s.logger.Error("PDF生成服务返回错误", + zap.String("url", url), zap.Int("status_code", resp.StatusCode), + zap.Duration("duration", time.Since(start)), zap.String("error_body", string(errorBody)), ) return nil, fmt.Errorf("PDF生成失败,状态码: %d, 错误: %s", resp.StatusCode, string(errorBody)) @@ -145,8 +157,10 @@ func (s *PDFGenService) GenerateGuangzhouPDF(ctx context.Context, req *GenerateP } s.logger.Info("PDF生成成功", + zap.String("url", url), zap.String("file_name", fileName), zap.Int("file_size", len(pdfBytes)), + zap.Duration("duration", time.Since(start)), ) return &GeneratePDFResponse{