f
This commit is contained in:
@@ -31,6 +31,15 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
// 获取全局logger
|
// 获取全局logger
|
||||||
zapLogger := logger.GetGlobalLogger()
|
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(如果存在)
|
// 从context获取config(如果存在)
|
||||||
var cacheTTL time.Duration = 24 * time.Hour
|
var cacheTTL time.Duration = 24 * time.Hour
|
||||||
var cacheDir string
|
var cacheDir string
|
||||||
@@ -46,6 +55,18 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
var maxSize int64
|
var maxSize int64
|
||||||
if cfg, ok := ctx.Value("config").(*config.Config); ok && cfg != nil {
|
if cfg, ok := ctx.Value("config").(*config.Config); ok && cfg != nil {
|
||||||
maxSize = cfg.PDFGen.Cache.MaxSize
|
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缓存管理器
|
// 创建PDF缓存管理器
|
||||||
@@ -107,6 +128,11 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
// 格式化数据为PDF生成服务需要的格式(为缺失的数据提供默认值)
|
// 格式化数据为PDF生成服务需要的格式(为缺失的数据提供默认值)
|
||||||
formattedData := formatDataForPDF(apiData, paramsDto, zapLogger)
|
formattedData := formatDataForPDF(apiData, paramsDto, zapLogger)
|
||||||
|
|
||||||
|
zapLogger.Debug("PDFG01GZ数据准备完成",
|
||||||
|
zap.Int("api_data_count", len(apiData)),
|
||||||
|
zap.Int("formatted_items", len(formattedData)),
|
||||||
|
)
|
||||||
|
|
||||||
// 从APPLICANT_BASIC_INFO中提取报告编号(如果存在)
|
// 从APPLICANT_BASIC_INFO中提取报告编号(如果存在)
|
||||||
var reportNumber string
|
var reportNumber string
|
||||||
if len(formattedData) > 0 {
|
if len(formattedData) > 0 {
|
||||||
@@ -130,6 +156,11 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
|
|
||||||
// 调用PDF生成服务
|
// 调用PDF生成服务
|
||||||
// 即使部分子处理器失败,只要有APPLICANT_BASIC_INFO就可以生成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)
|
pdfResp, err := pdfGenService.GenerateGuangzhouPDF(ctx, pdfReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zapLogger.Error("生成PDF失败",
|
zapLogger.Error("生成PDF失败",
|
||||||
|
|||||||
@@ -93,6 +93,12 @@ func (s *PDFGenService) GenerateGuangzhouPDF(ctx context.Context, req *GenerateP
|
|||||||
return nil, fmt.Errorf("序列化请求失败: %w", err)
|
return nil, fmt.Errorf("序列化请求失败: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debug:打印请求体预览(最多1024字节),防止日志过大
|
||||||
|
bodyPreview := reqBody
|
||||||
|
if len(bodyPreview) > 1024 {
|
||||||
|
bodyPreview = bodyPreview[:1024]
|
||||||
|
}
|
||||||
|
|
||||||
// 构建请求URL
|
// 构建请求URL
|
||||||
url := fmt.Sprintf("%s%s", s.baseURL, s.apiPath)
|
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")
|
httpReq.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
// 发送请求
|
// 发送请求
|
||||||
s.logger.Info("开始调用PDF生成服务",
|
s.logger.Info("开始调用PDF生成服务",
|
||||||
zap.String("url", url),
|
zap.String("url", url),
|
||||||
zap.Int("data_count", len(req.Data)),
|
zap.Int("data_count", len(req.Data)),
|
||||||
|
zap.ByteString("body_preview", bodyPreview),
|
||||||
)
|
)
|
||||||
|
|
||||||
resp, err := s.client.Do(httpReq)
|
resp, err := s.client.Do(httpReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("调用PDF生成服务失败",
|
s.logger.Error("调用PDF生成服务失败",
|
||||||
zap.String("url", url),
|
zap.String("url", url),
|
||||||
|
zap.Duration("duration", time.Since(start)),
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
)
|
)
|
||||||
return nil, fmt.Errorf("调用PDF生成服务失败: %w", 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)
|
errorBody, _ := io.ReadAll(resp.Body)
|
||||||
s.logger.Error("PDF生成服务返回错误",
|
s.logger.Error("PDF生成服务返回错误",
|
||||||
|
zap.String("url", url),
|
||||||
zap.Int("status_code", resp.StatusCode),
|
zap.Int("status_code", resp.StatusCode),
|
||||||
|
zap.Duration("duration", time.Since(start)),
|
||||||
zap.String("error_body", string(errorBody)),
|
zap.String("error_body", string(errorBody)),
|
||||||
)
|
)
|
||||||
return nil, fmt.Errorf("PDF生成失败,状态码: %d, 错误: %s", resp.StatusCode, 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生成成功",
|
s.logger.Info("PDF生成成功",
|
||||||
|
zap.String("url", url),
|
||||||
zap.String("file_name", fileName),
|
zap.String("file_name", fileName),
|
||||||
zap.Int("file_size", len(pdfBytes)),
|
zap.Int("file_size", len(pdfBytes)),
|
||||||
|
zap.Duration("duration", time.Since(start)),
|
||||||
)
|
)
|
||||||
|
|
||||||
return &GeneratePDFResponse{
|
return &GeneratePDFResponse{
|
||||||
|
|||||||
Reference in New Issue
Block a user