LingxinMeng 1 gadu atpakaļ
vecāks
revīzija
6ff19c89e3
2 mainītis faili ar 53 papildinājumiem un 19 dzēšanām
  1. 2 1
      amd64/web_server/entity/e_exam.go
  2. 51 18
      amd64/web_server/handler/h_exam.go

+ 2 - 1
amd64/web_server/entity/e_exam.go

@@ -43,5 +43,6 @@ type ExamPagePao struct {
 	Topic       string `json:"topic"`    // 赛题
 }
 type ExamReportPao struct {
-	Id int `json:"id"`
+	Id       int    `json:"id"`
+	TeamName string `json:"teamName"`
 }

+ 51 - 18
amd64/web_server/handler/h_exam.go

@@ -314,16 +314,16 @@ func Page(c *gin.Context) {
 
 // 评分报告pdf下载
 func Report(c *gin.Context) {
-	//param := new(webServerEntity.ExamReportPao)
-	//// 映射到结构体
-	//if err := c.ShouldBindJSON(&param); err != nil {
-	//	c_log.GlobalLogger.Error("项目启动接收请求参数报错:", err)
-	//	c.JSON(http.StatusBadRequest, commonEntity.Response{
-	//		Code: 500,
-	//		Msg:  "请求体解析失败。",
-	//	})
-	//	return
-	//}
+	param := new(webServerEntity.ExamReportPao)
+	// 映射到结构体
+	if err := c.ShouldBindJSON(&param); err != nil {
+		c_log.GlobalLogger.Error("项目启动接收请求参数报错:", err)
+		c.JSON(http.StatusBadRequest, commonEntity.Response{
+			Code: 500,
+			Msg:  "请求体解析失败。",
+		})
+		return
+	}
 	// 1 根据ID查询数据
 	// 2 根据数据生成pdf
 	// 3 创建pdf文件
@@ -347,6 +347,7 @@ func Report(c *gin.Context) {
 		//alignOptionText := gopdf.CellOption{Align: gopdf.Left | gopdf.Middle}
 		//alignOptionText2 := gopdf.CellOption{Align: gopdf.Center | gopdf.Middle}
 		alignOptionTable := gopdf.CellOption{Align: gopdf.Center | gopdf.Middle, Border: gopdf.Left | gopdf.Right | gopdf.Bottom | gopdf.Top}
+		alignOptionTable2 := gopdf.CellOption{Align: gopdf.Left | gopdf.Middle}
 
 		// ------- 封面页 -------
 		pdf.AddPage()
@@ -363,21 +364,53 @@ func Report(c *gin.Context) {
 				_ = pdf.Text("评分报告")
 			}
 			_ = pdf.SetFont("simfang", "", 14)
+			currentLine := 0.0
+			tableCellWidth := 100.0
+			tableLeftMartin := 190.0
+			tableTopMartin := 500.0
 			{
-				pdf.SetXY(200, 525)
-				_ = pdf.Text("赛队编号:01")
+				{
+					pdf.SetXY(tableLeftMartin, tableTopMartin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: 100, H: lineHeight}, "赛队编号:", alignOptionTable2)
+				}
+				{
+					pdf.SetXY(tableLeftMartin+1.0*tableCellWidth, tableTopMartin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: 100, H: lineHeight}, param.TeamName, alignOptionTable2)
+				}
+				currentLine++
 			}
 			{
-				pdf.SetXY(200, 545)
-				_ = pdf.Cell(nil, "评测车型:多功能车平台")
+				{
+					pdf.SetXY(tableLeftMartin, tableTopMartin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: 100, H: lineHeight}, "评测车型:", alignOptionTable2)
+				}
+				{
+					pdf.SetXY(tableLeftMartin+1.0*tableCellWidth, tableTopMartin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: 100, H: lineHeight}, "多功能车平台", alignOptionTable2)
+				}
+				currentLine++
 			}
 			{
-				pdf.SetXY(200, 565)
-				_ = pdf.Cell(nil, "评测地点:天津生态城")
+				{
+					pdf.SetXY(tableLeftMartin, tableTopMartin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: 100, H: lineHeight}, "评测地点:", alignOptionTable2)
+				}
+				{
+					pdf.SetXY(tableLeftMartin+1.0*tableCellWidth, tableTopMartin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: 100, H: lineHeight}, "天津生态城", alignOptionTable2)
+				}
+				currentLine++
 			}
 			{
-				pdf.SetXY(200, 585)
-				_ = pdf.Cell(nil, "报告时间:2023年10月12日")
+				{
+					pdf.SetXY(tableLeftMartin, tableTopMartin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: 100, H: lineHeight}, "报告时间:", alignOptionTable2)
+				}
+				{
+					pdf.SetXY(tableLeftMartin+1.0*tableCellWidth, tableTopMartin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: 100, H: lineHeight}, time.Now().Format("2006年01月02日"), alignOptionTable2)
+				}
+				currentLine++
 			}
 			{
 				pdf.SetXY(165, 775)