Compare commits
2 Commits
da0990e015
...
6a801acee1
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a801acee1 | |||
| 6120020a7c |
@@ -1,6 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
@@ -116,6 +117,7 @@ func (h *QYGLReportHandler) GetQYGLReportPageByID(c *gin.Context) {
|
|||||||
// 优先从数据库中查询报告记录
|
// 优先从数据库中查询报告记录
|
||||||
if h.reportRepo != nil {
|
if h.reportRepo != nil {
|
||||||
if entity, err := h.reportRepo.FindByReportID(c.Request.Context(), id); err == nil && entity != 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)
|
reportJSON := template.JS(entity.ReportData)
|
||||||
c.HTML(http.StatusOK, "qiye.html", gin.H{
|
c.HTML(http.StatusOK, "qiye.html", gin.H{
|
||||||
"ReportJSON": reportJSON,
|
"ReportJSON": reportJSON,
|
||||||
@@ -140,11 +142,36 @@ func (h *QYGLReportHandler) GetQYGLReportPageByID(c *gin.Context) {
|
|||||||
|
|
||||||
reportJSON := template.JS(reportJSONBytes)
|
reportJSON := template.JS(reportJSONBytes)
|
||||||
|
|
||||||
|
h.maybeScheduleQYGLPDFPregen(c.Request.Context(), id)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "qiye.html", gin.H{
|
c.HTML(http.StatusOK, "qiye.html", gin.H{
|
||||||
"ReportJSON": reportJSON,
|
"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 在已配置公网基址时异步预生成 PDF;Schedule 内部会去重。
|
||||||
|
// 解决:服务重启 / 多实例后内存队列为空,用户打开报告页或轮询状态时仍应能启动预生成。
|
||||||
|
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 预生成状态(供前端轮询)
|
// GetQYGLReportPDFStatusByID 查询企业报告 PDF 预生成状态(供前端轮询)
|
||||||
// GET /reports/qygl/:id/pdf/status
|
// GET /reports/qygl/:id/pdf/status
|
||||||
func (h *QYGLReportHandler) GetQYGLReportPDFStatusByID(c *gin.Context) {
|
func (h *QYGLReportHandler) GetQYGLReportPDFStatusByID(c *gin.Context) {
|
||||||
@@ -164,6 +191,10 @@ func (h *QYGLReportHandler) GetQYGLReportPDFStatusByID(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
st, msg := h.qyglPDFPregen.Status(id)
|
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)})
|
c.JSON(http.StatusOK, gin.H{"status": string(st), "message": userFacingPDFStatusMessage(st, msg)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3434,6 +3434,14 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
!reportId &&
|
||||||
|
reportData &&
|
||||||
|
reportData.reportId &&
|
||||||
|
typeof reportData.reportId === "string"
|
||||||
|
) {
|
||||||
|
reportId = reportData.reportId;
|
||||||
|
}
|
||||||
if (!reportId) {
|
if (!reportId) {
|
||||||
console.error(
|
console.error(
|
||||||
"无法从当前 URL 解析报告编号,路径为",
|
"无法从当前 URL 解析报告编号,路径为",
|
||||||
|
|||||||
Reference in New Issue
Block a user