package report

import (
	"github.com/gin-gonic/gin"
	"hongze/hongze_yb/controller/response"
	"hongze/hongze_yb/models/request"
	"hongze/hongze_yb/models/tables/yb_pdf"
	"hongze/hongze_yb/utils"
)

// PdfDetail 报告PDF详情
func PdfDetail(c *gin.Context) {
	var req request.ReportPdfDetailReq
	if err := c.Bind(&req); err != nil {
		response.Fail("参数有误", c)
		return
	}
	if req.PdfId <= 0 {
		response.Fail("参数有误", c)
		return
	}

	pdfOB := new(yb_pdf.YbPdf)
	item, e := pdfOB.Fetch(req.PdfId)
	if e != nil {
		if e == utils.ErrNoRow {
			response.Fail("PDF已被删除", c)
			return
		}
		response.FailMsg("获取失败", "获取PDF详情失败, Err: "+e.Error(), c)
		return
	}
	if item.PdfID <= 0 {
		response.Fail("PDF已被删除", c)
		return
	}
	response.OkData("查询成功", item, c)
}
