f
This commit is contained in:
@@ -94,13 +94,16 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
|
||||
pdfGenService = pdfgen.NewPDFGenService(defaultCfg, zapLogger)
|
||||
}
|
||||
|
||||
// 计算缓存键(内部使用,不直接暴露给用户)
|
||||
cacheKey := cacheManager.GetCacheKey(paramsDto.Name, paramsDto.IDCard)
|
||||
|
||||
// 检查缓存(基于姓名+身份证)
|
||||
_, hit, createdAt, err := cacheManager.Get(paramsDto.Name, paramsDto.IDCard)
|
||||
if err != nil {
|
||||
zapLogger.Warn("检查缓存失败,继续生成PDF", zap.Error(err))
|
||||
} else if hit {
|
||||
// 计算缓存键,作为报告ID(可持久化)
|
||||
reportID := cacheManager.GetCacheKey(paramsDto.Name, paramsDto.IDCard)
|
||||
// 生成对外可见的报告ID(包含随机前缀,防止用户直接推断缓存键)
|
||||
reportID := generateReportID(cacheKey)
|
||||
|
||||
// 缓存命中,模拟生成耗时(约4秒)
|
||||
zapLogger.Info("PDF缓存命中,返回缓存文件",
|
||||
@@ -158,9 +161,6 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
|
||||
reportNumber = generateReportNumber()
|
||||
}
|
||||
|
||||
// 计算报告ID(与缓存键一致,便于通过ID直接下载)
|
||||
reportID := cacheManager.GetCacheKey(paramsDto.Name, paramsDto.IDCard)
|
||||
|
||||
// 构建PDF生成请求
|
||||
pdfReq := &pdfgen.GeneratePDFRequest{
|
||||
Data: formattedData,
|
||||
@@ -189,6 +189,9 @@ func ProcessPDFG01GZRequest(ctx context.Context, params []byte, deps *processors
|
||||
// 不影响返回结果,只记录警告
|
||||
}
|
||||
|
||||
// 生成报告ID(与内部缓存键解耦,对外只暴露带前缀的ID)
|
||||
reportID := generateReportID(cacheKey)
|
||||
|
||||
// 生成下载链接(基于报告ID)
|
||||
downloadURL := generateDownloadURL(apiDomain, reportID)
|
||||
expiresAt := time.Now().Add(cacheTTL)
|
||||
@@ -499,6 +502,13 @@ func generateReportNumber() string {
|
||||
return fmt.Sprintf("RPT%s", time.Now().Format("20060102150405"))
|
||||
}
|
||||
|
||||
// generateReportID 生成对外可见的报告ID
|
||||
// 结构:{report_number}-{cacheKey},前缀变化以避免用户轻易看出是否命中缓存
|
||||
func generateReportID(cacheKey string) string {
|
||||
reportNumber := generateReportNumber()
|
||||
return fmt.Sprintf("%s-%s", reportNumber, cacheKey)
|
||||
}
|
||||
|
||||
// generateDownloadURL 生成下载链接(基于报告ID/缓存键)
|
||||
// apiDomain: 外部可访问的API域名,如 api.tianyuanapi.com
|
||||
func generateDownloadURL(apiDomain, reportID string) string {
|
||||
|
||||
Reference in New Issue
Block a user