f
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tyapi-server/internal/domains/api/entities"
|
||||
"tyapi-server/internal/domains/api/repositories"
|
||||
"tyapi-server/internal/shared/database"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const (
|
||||
ReportsTable = "reports"
|
||||
)
|
||||
|
||||
// GormReportRepository 报告记录 GORM 仓储实现
|
||||
type GormReportRepository struct {
|
||||
*database.BaseRepositoryImpl
|
||||
}
|
||||
|
||||
var _ repositories.ReportRepository = (*GormReportRepository)(nil)
|
||||
|
||||
// NewGormReportRepository 创建报告记录仓储实现
|
||||
func NewGormReportRepository(db *gorm.DB, logger *zap.Logger) repositories.ReportRepository {
|
||||
return &GormReportRepository{
|
||||
BaseRepositoryImpl: database.NewBaseRepositoryImpl(db, logger),
|
||||
}
|
||||
}
|
||||
|
||||
// Create 创建报告记录
|
||||
func (r *GormReportRepository) Create(ctx context.Context, report *entities.Report) error {
|
||||
return r.CreateEntity(ctx, report)
|
||||
}
|
||||
|
||||
// FindByReportID 根据报告编号查询记录
|
||||
func (r *GormReportRepository) FindByReportID(ctx context.Context, reportID string) (*entities.Report, error) {
|
||||
var report entities.Report
|
||||
if err := r.FindOneByField(ctx, &report, "report_id", reportID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &report, nil
|
||||
}
|
||||
|
||||
137
internal/infrastructure/http/handlers/qygl_report_handler.go
Normal file
137
internal/infrastructure/http/handlers/qygl_report_handler.go
Normal file
@@ -0,0 +1,137 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"tyapi-server/internal/application/api/commands"
|
||||
"tyapi-server/internal/domains/api/dto"
|
||||
api_repositories "tyapi-server/internal/domains/api/repositories"
|
||||
api_services "tyapi-server/internal/domains/api/services"
|
||||
"tyapi-server/internal/domains/api/services/processors"
|
||||
"tyapi-server/internal/domains/api/services/processors/qygl"
|
||||
)
|
||||
|
||||
// QYGLReportHandler 企业全景报告页面渲染处理器
|
||||
// 使用 QYGLJ1U9 聚合接口生成企业报告数据,并通过模板引擎渲染 qiye.html
|
||||
type QYGLReportHandler struct {
|
||||
apiRequestService *api_services.ApiRequestService
|
||||
logger *zap.Logger
|
||||
|
||||
reportRepo api_repositories.ReportRepository
|
||||
}
|
||||
|
||||
// NewQYGLReportHandler 创建企业报告页面处理器
|
||||
func NewQYGLReportHandler(
|
||||
apiRequestService *api_services.ApiRequestService,
|
||||
logger *zap.Logger,
|
||||
reportRepo api_repositories.ReportRepository,
|
||||
) *QYGLReportHandler {
|
||||
return &QYGLReportHandler{
|
||||
apiRequestService: apiRequestService,
|
||||
logger: logger,
|
||||
reportRepo: reportRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// GetQYGLReportPage 企业全景报告页面
|
||||
// GET /reports/qygl?ent_code=xxx&ent_name=yyy&ent_reg_no=zzz
|
||||
func (h *QYGLReportHandler) GetQYGLReportPage(c *gin.Context) {
|
||||
// 读取查询参数
|
||||
entCode := c.Query("ent_code")
|
||||
entName := c.Query("ent_name")
|
||||
entRegNo := c.Query("ent_reg_no")
|
||||
|
||||
// 组装 QYGLUY3S 入参
|
||||
req := dto.QYGLUY3SReq{
|
||||
EntName: entName,
|
||||
EntRegno: entRegNo,
|
||||
EntCode: entCode,
|
||||
}
|
||||
|
||||
params, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
h.logger.Error("序列化企业全景报告入参失败", zap.Error(err))
|
||||
c.String(http.StatusInternalServerError, "生成企业报告失败,请稍后重试")
|
||||
return
|
||||
}
|
||||
|
||||
// 通过 ApiRequestService 调用 QYGLJ1U9 聚合处理器
|
||||
options := &commands.ApiCallOptions{}
|
||||
callCtx := &processors.CallContext{}
|
||||
|
||||
ctx := c.Request.Context()
|
||||
respBytes, err := h.apiRequestService.PreprocessRequestApi(ctx, "QYGLJ1U9", params, options, callCtx)
|
||||
if err != nil {
|
||||
h.logger.Error("调用企业全景报告处理器失败", zap.Error(err))
|
||||
c.String(http.StatusInternalServerError, "生成企业报告失败,请稍后重试")
|
||||
return
|
||||
}
|
||||
|
||||
var report map[string]interface{}
|
||||
if err := json.Unmarshal(respBytes, &report); err != nil {
|
||||
h.logger.Error("解析企业全景报告结果失败", zap.Error(err))
|
||||
c.String(http.StatusInternalServerError, "生成企业报告失败,请稍后重试")
|
||||
return
|
||||
}
|
||||
|
||||
reportJSONBytes, err := json.Marshal(report)
|
||||
if err != nil {
|
||||
h.logger.Error("序列化企业全景报告结果失败", zap.Error(err))
|
||||
c.String(http.StatusInternalServerError, "生成企业报告失败,请稍后重试")
|
||||
return
|
||||
}
|
||||
|
||||
// 使用 template.JS 避免在脚本中被转义,直接作为 JS 对象字面量注入
|
||||
reportJSON := template.JS(reportJSONBytes)
|
||||
|
||||
c.HTML(http.StatusOK, "qiye.html", gin.H{
|
||||
"ReportJSON": reportJSON,
|
||||
})
|
||||
}
|
||||
|
||||
// GetQYGLReportPageByID 通过编号查看企业全景报告页面
|
||||
// GET /reports/qygl/:id
|
||||
func (h *QYGLReportHandler) GetQYGLReportPageByID(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
c.String(http.StatusBadRequest, "报告编号不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
// 优先从数据库中查询报告记录
|
||||
if h.reportRepo != nil {
|
||||
if entity, err := h.reportRepo.FindByReportID(c.Request.Context(), id); err == nil && entity != nil {
|
||||
reportJSON := template.JS(entity.ReportData)
|
||||
c.HTML(http.StatusOK, "qiye.html", gin.H{
|
||||
"ReportJSON": reportJSON,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 回退到进程内存缓存(兼容老的访问方式)
|
||||
report, ok := qygl.GetQYGLReport(id)
|
||||
if !ok {
|
||||
c.String(http.StatusNotFound, "报告不存在或已过期")
|
||||
return
|
||||
}
|
||||
|
||||
reportJSONBytes, err := json.Marshal(report)
|
||||
if err != nil {
|
||||
h.logger.Error("序列化企业全景报告结果失败", zap.Error(err))
|
||||
c.String(http.StatusInternalServerError, "生成企业报告失败,请稍后再试")
|
||||
return
|
||||
}
|
||||
|
||||
reportJSON := template.JS(reportJSONBytes)
|
||||
|
||||
c.HTML(http.StatusOK, "qiye.html", gin.H{
|
||||
"ReportJSON": reportJSON,
|
||||
})
|
||||
}
|
||||
|
||||
32
internal/infrastructure/http/routes/qygl_report_routes.go
Normal file
32
internal/infrastructure/http/routes/qygl_report_routes.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"tyapi-server/internal/infrastructure/http/handlers"
|
||||
sharedhttp "tyapi-server/internal/shared/http"
|
||||
)
|
||||
|
||||
// QYGLReportRoutes 企业报告页面路由注册器
|
||||
type QYGLReportRoutes struct {
|
||||
handler *handlers.QYGLReportHandler
|
||||
}
|
||||
|
||||
// NewQYGLReportRoutes 创建企业报告页面路由注册器
|
||||
func NewQYGLReportRoutes(
|
||||
handler *handlers.QYGLReportHandler,
|
||||
) *QYGLReportRoutes {
|
||||
return &QYGLReportRoutes{
|
||||
handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
// Register 注册企业报告页面路由
|
||||
func (r *QYGLReportRoutes) Register(router *sharedhttp.GinRouter) {
|
||||
engine := router.GetEngine()
|
||||
|
||||
// 企业全景报告页面(实时生成)
|
||||
engine.GET("/reports/qygl", r.handler.GetQYGLReportPage)
|
||||
|
||||
// 企业全景报告页面(通过编号查看)
|
||||
engine.GET("/reports/qygl/:id", r.handler.GetQYGLReportPageByID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user