This commit is contained in:
2026-01-27 19:00:09 +08:00
parent 43e4daa45b
commit 847d48d276
2 changed files with 45 additions and 0 deletions

View File

@@ -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失败",

View File

@@ -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{