Compare commits

...

2 Commits

Author SHA1 Message Date
6a801acee1 Merge branch 'main' of http://1.117.67.95:3000/team/tyapi-server 2026-03-21 19:23:23 +08:00
6120020a7c f 2026-03-21 19:23:08 +08:00
2 changed files with 39 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package handlers
import (
"context"
"encoding/json"
"fmt"
"html/template"
@@ -116,6 +117,7 @@ func (h *QYGLReportHandler) GetQYGLReportPageByID(c *gin.Context) {
// 优先从数据库中查询报告记录
if h.reportRepo != nil {
if entity, err := h.reportRepo.FindByReportID(c.Request.Context(), id); err == nil && entity != nil {
h.maybeScheduleQYGLPDFPregen(c.Request.Context(), id)
reportJSON := template.JS(entity.ReportData)
c.HTML(http.StatusOK, "qiye.html", gin.H{
"ReportJSON": reportJSON,
@@ -140,11 +142,36 @@ func (h *QYGLReportHandler) GetQYGLReportPageByID(c *gin.Context) {
reportJSON := template.JS(reportJSONBytes)
h.maybeScheduleQYGLPDFPregen(c.Request.Context(), id)
c.HTML(http.StatusOK, "qiye.html", gin.H{
"ReportJSON": reportJSON,
})
}
// qyglReportExists 报告是否仍在库或本进程内存中(用于决定是否补开预生成)
func (h *QYGLReportHandler) qyglReportExists(ctx context.Context, id string) bool {
if h.reportRepo != nil {
if e, err := h.reportRepo.FindByReportID(ctx, id); err == nil && e != nil {
return true
}
}
_, ok := qygl.GetQYGLReport(id)
return ok
}
// maybeScheduleQYGLPDFPregen 在已配置公网基址时异步预生成 PDFSchedule 内部会去重。
// 解决:服务重启 / 多实例后内存队列为空,用户打开报告页或轮询状态时仍应能启动预生成。
func (h *QYGLReportHandler) maybeScheduleQYGLPDFPregen(ctx context.Context, id string) {
if id == "" || h.qyglPDFPregen == nil || !h.qyglPDFPregen.Enabled() {
return
}
if !h.qyglReportExists(ctx, id) {
return
}
h.qyglPDFPregen.ScheduleQYGLReportPDF(context.Background(), id)
}
// GetQYGLReportPDFStatusByID 查询企业报告 PDF 预生成状态(供前端轮询)
// GET /reports/qygl/:id/pdf/status
func (h *QYGLReportHandler) GetQYGLReportPDFStatusByID(c *gin.Context) {
@@ -164,6 +191,10 @@ func (h *QYGLReportHandler) GetQYGLReportPDFStatusByID(c *gin.Context) {
return
}
st, msg := h.qyglPDFPregen.Status(id)
if st == pdf.QYGLReportPDFStatusNone && h.qyglReportExists(c.Request.Context(), id) {
h.qyglPDFPregen.ScheduleQYGLReportPDF(context.Background(), id)
st, msg = h.qyglPDFPregen.Status(id)
}
c.JSON(http.StatusOK, gin.H{"status": string(st), "message": userFacingPDFStatusMessage(st, msg)})
}

View File

@@ -3434,6 +3434,14 @@
break;
}
}
if (
!reportId &&
reportData &&
reportData.reportId &&
typeof reportData.reportId === "string"
) {
reportId = reportData.reportId;
}
if (!reportId) {
console.error(
"无法从当前 URL 解析报告编号,路径为",