f
This commit is contained in:
@@ -33,22 +33,20 @@ func NewPDFGHandler(
|
||||
}
|
||||
|
||||
// DownloadPDF 下载PDF文件
|
||||
// GET /api/v1/pdfg/download?name=xxx&id_card=xxx
|
||||
// GET /api/v1/pdfg/download?id=报告ID
|
||||
func (h *PDFGHandler) DownloadPDF(c *gin.Context) {
|
||||
name := c.Query("name")
|
||||
idCard := c.Query("id_card")
|
||||
reportID := c.Query("id")
|
||||
|
||||
if name == "" || idCard == "" {
|
||||
h.responseBuilder.BadRequest(c, "姓名和身份证号不能为空")
|
||||
if reportID == "" {
|
||||
h.responseBuilder.BadRequest(c, "报告ID不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
// 从缓存获取PDF
|
||||
pdfBytes, hit, createdAt, err := h.cacheManager.Get(name, idCard)
|
||||
pdfBytes, hit, createdAt, err := h.cacheManager.GetByCacheKey(reportID)
|
||||
if err != nil {
|
||||
h.logger.Error("获取PDF缓存失败",
|
||||
zap.String("name", name),
|
||||
zap.String("id_card", idCard),
|
||||
zap.String("report_id", reportID),
|
||||
zap.Error(err),
|
||||
)
|
||||
h.responseBuilder.InternalError(c, "获取PDF文件失败")
|
||||
@@ -57,8 +55,7 @@ func (h *PDFGHandler) DownloadPDF(c *gin.Context) {
|
||||
|
||||
if !hit {
|
||||
h.logger.Warn("PDF文件不存在或已过期",
|
||||
zap.String("name", name),
|
||||
zap.String("id_card", idCard),
|
||||
zap.String("report_id", reportID),
|
||||
)
|
||||
h.responseBuilder.NotFound(c, "PDF文件不存在或已过期,请重新生成")
|
||||
return
|
||||
@@ -68,8 +65,7 @@ func (h *PDFGHandler) DownloadPDF(c *gin.Context) {
|
||||
expiresAt := createdAt.Add(24 * time.Hour)
|
||||
if time.Now().After(expiresAt) {
|
||||
h.logger.Warn("PDF文件已过期",
|
||||
zap.String("name", name),
|
||||
zap.String("id_card", idCard),
|
||||
zap.String("report_id", reportID),
|
||||
zap.Time("expires_at", expiresAt),
|
||||
)
|
||||
h.responseBuilder.NotFound(c, "PDF文件已过期,请重新生成")
|
||||
@@ -85,8 +81,7 @@ func (h *PDFGHandler) DownloadPDF(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "application/pdf", pdfBytes)
|
||||
|
||||
h.logger.Info("PDF文件下载成功",
|
||||
zap.String("name", name),
|
||||
zap.String("id_card", idCard),
|
||||
zap.String("report_id", reportID),
|
||||
zap.Int("file_size", len(pdfBytes)),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user