@@ -37,18 +37,19 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
zap . String ( "id_card" , paramsDto . IDCard ) ,
zap . String ( "id_card" , paramsDto . IDCard ) ,
zap . String ( "mobile_no" , paramsDto . MobileNo ) ,
zap . String ( "mobile_no" , paramsDto . MobileNo ) ,
zap . String ( "authorized" , paramsDto . Authorized ) ,
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
var apiDomain string
if cfg , ok := ctx . Value ( "config" ) . ( * config . Config ) ; ok && cfg != nil {
if cfg , ok := ctx . Value ( "config" ) . ( * config . Config ) ; ok && cfg != nil {
cacheTTL = cfg . PDFGen . Cache . TTL
cacheTTL = cfg . PDFGen . Cache . TTL
if cacheTTL == 0 {
if cacheTTL == 0 {
cacheTTL = 24 * time . Hour
cacheTTL = 24 * time . Hour
}
}
cacheDir = cfg . PDFGen . Cache . CacheDir
cacheDir = cfg . PDFGen . Cache . CacheDir
apiDomain = cfg . API . Domain
}
}
// 获取最大缓存大小
// 获取最大缓存大小
@@ -112,12 +113,15 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
time . Sleep ( 2 * time . Second )
time . Sleep ( 2 * time . Second )
// 生成下载链接( 基于报告ID)
// 生成下载链接( 基于报告ID)
downloadURL := generateDownloadURL ( reportID )
downloadURL := generateDownloadURL ( apiDomain , reportID)
expiresAt := createdAt . Add ( cacheTTL )
return json . Marshal ( map [ string ] interface { } {
return json . Marshal ( map [ string ] interface { } {
"download_url" : downloadURL ,
"download_url" : downloadURL ,
"report_id" : reportID ,
"report_id" : reportID ,
"cached" : true ,
"cached" : true ,
"created_at" : createdAt . Format ( time . RFC3339 ) ,
"created_at" : createdAt . Format ( time . RFC3339 ) ,
"expires_at" : expiresAt . Format ( time . RFC3339 ) ,
"ttl_seconds" : int ( cacheTTL . Seconds ( ) ) ,
} )
} )
}
}
@@ -187,7 +191,8 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
}
}
// 生成下载链接( 基于报告ID)
// 生成下载链接( 基于报告ID)
downloadURL := generateDownloadURL ( reportID )
downloadURL := generateDownloadURL ( apiDomain , reportID)
expiresAt := time . Now ( ) . Add ( cacheTTL )
zapLogger . Info ( "PDF生成成功" ,
zapLogger . Info ( "PDF生成成功" ,
zap . String ( "name" , paramsDto . Name ) ,
zap . String ( "name" , paramsDto . Name ) ,
@@ -202,6 +207,8 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
"report_id" : reportID ,
"report_id" : reportID ,
"report_number" : reportNumber ,
"report_number" : reportNumber ,
"cached" : false ,
"cached" : false ,
"expires_at" : expiresAt . Format ( time . RFC3339 ) ,
"ttl_seconds" : int ( cacheTTL . Seconds ( ) ) ,
} )
} )
}
}
@@ -219,35 +226,29 @@ func collectAPIData(ctx context.Context, params dto.PDFG01GZReq, deps *processor
results := make ( chan processorResult , 5 )
results := make ( chan processorResult , 5 )
// 调用IVYZ5A9O - 需要: name, id_card, auth_authorize_file_code
// 调用JRZQ0L85 - 需要: name, id_card, mobile_no
go func ( ) {
go func ( ) {
defer func ( ) {
defer func ( ) {
if r := recover ( ) ; r != nil {
if r := recover ( ) ; r != nil {
logger . Error ( "调用IVYZ5A9O 处理器时发生panic" ,
logger . Error ( "调用JRZQ0L85 处理器时发生panic" ,
zap . Any ( "panic" , r ) ,
zap . Any ( "panic" , r ) ,
)
)
results <- processorResult { "IVYZ5A9O " , nil , fmt . Errorf ( "处理器panic: %v" , r ) }
results <- processorResult { "JRZQ0L85 " , nil , fmt . Errorf ( "处理器panic: %v" , r ) }
}
}
} ( )
} ( )
// 检查必需字段
jrzq0l85Params := map [ string ] interface { } {
if params . AuthAuthorizeFileCode == "" {
logger . Warn ( "IVYZ5A9O缺少auth_authorize_file_code字段, 跳过调用" )
results <- processorResult { "IVYZ5A9O" , nil , fmt . Errorf ( "缺少必需字段: auth_authorize_file_code" ) }
return
}
ivyzParams := map [ string ] interface { } {
"name" : params . Name ,
"name" : params . Name ,
"id_card" : params . IDCard ,
"id_card" : params . IDCard ,
"auth_authorize_file_code" : params . AuthAuthorizeFileCode ,
"mobileNo" : params . MobileNo ,
}
}
paramsBytes , err := json . Marshal ( ivyz Params)
paramsBytes , err := json . Marshal ( jrzq0l85 Params)
if err != nil {
if err != nil {
logger . Warn ( "序列化IVYZ5A9O 参数失败" , zap . Error ( err ) )
logger . Warn ( "序列化JRZQ0L85 参数失败" , zap . Error ( err ) )
results <- processorResult { "IVYZ5A9O " , nil , err }
results <- processorResult { "JRZQ0L85 " , nil , err }
return
return
}
}
data , err := callProcessor ( ctx , "IVYZ5A9O " , paramsBytes , deps )
data , err := callProcessor ( ctx , "JRZQ0L85 " , paramsBytes , deps )
results <- processorResult { "IVYZ5A9O " , data , err }
results <- processorResult { "JRZQ0L85 " , data , err }
} ( )
} ( )
// 调用JRZQ8A2D - 需要: name, id_card, mobile_no, authorized
// 调用JRZQ8A2D - 需要: name, id_card, mobile_no, authorized
@@ -501,9 +502,13 @@ func generateReportNumber() string {
}
}
// generateDownloadURL 生成下载链接( 基于报告ID/缓存键)
// generateDownloadURL 生成下载链接( 基于报告ID/缓存键)
func generateDownloadURL ( reportID string ) string {
// apiDomain: 外部可访问的API域名, 如 api.tianyuanapi.com
// 这里应该生成实际的下载URL
func generateDownloadURL ( apiDomain , reportID string ) string {
// 暂时返回一个占位符,实际应该根据服务器配置生成
if apiDomain == "" {
// 兜底:保留相对路径,方便本地/测试环境使用
return fmt . Sprintf ( "/api/v1/pdfg/download?id=%s" , reportID )
return fmt . Sprintf ( "/api/v1/pdfg/download?id=%s" , reportID )
}
}
// 生成完整链接, 例如: https://api.tianyuanapi.com/api/v1/pdfg/download?id=xxx
return fmt . Sprintf ( "https://%s/api/v1/pdfg/download?id=%s" , apiDomain , reportID )
}