LingxinMeng 1 年間 前
コミット
89195f5560
2 ファイル変更21 行追加16 行削除
  1. 5 2
      amd64/web_server/entity/e_exam.go
  2. 16 14
      amd64/web_server/handler/h_exam.go

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

@@ -43,6 +43,9 @@ type ExamPagePao struct {
 	Topic       string `json:"topic"`    // 赛题
 }
 type ExamReportPao struct {
-	Id       int    `json:"id"`
-	TeamName string `json:"teamName"`
+	Id         int    `json:"id"`
+	TeamName   string `json:"teamName"`
+	ScoreFinal int    `json:"scoreFinal"`
+	BeginTime  string `json:"beginTime"`
+	EndTime    string `json:"endTime"`
 }

+ 16 - 14
amd64/web_server/handler/h_exam.go

@@ -317,13 +317,16 @@ func Report(c *gin.Context) {
 	param := new(webServerEntity.ExamReportPao)
 	// 映射到结构体
 	if err := c.ShouldBindJSON(&param); err != nil {
-		c_log.GlobalLogger.Error("项目启动接收请求参数报错:", err)
+		c_log.GlobalLogger.Error("接收请求参数报错:", err)
 		c.JSON(http.StatusBadRequest, commonEntity.Response{
 			Code: 500,
 			Msg:  "请求体解析失败。",
 		})
 		return
 	}
+	layout := "2006-01-02 15:04:05"
+	beginTime, _ := time.Parse(layout, param.BeginTime)
+	endTime, _ := time.Parse(layout, param.EndTime)
 	// 1 根据ID查询数据
 	// 2 根据数据生成pdf
 	// 3 创建pdf文件
@@ -342,9 +345,8 @@ func Report(c *gin.Context) {
 		topMargin := 100.0
 		lineHeight := 25.0
 		tableWidth := 450.0
-		paragraphSpacing := 10.0
 		pdf.SetLeftMargin(leftMargin) // 设置左边距
-		//alignOptionText := gopdf.CellOption{Align: gopdf.Left | gopdf.Middle}
+		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}
@@ -444,28 +446,28 @@ func Report(c *gin.Context) {
 			{
 				{
 					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "1. 总体分数情况", alignOptionText)
 					currentLine++
-					err = pdf.Text("1. 总体分数情况")
 				}
 				{
 					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "整体得分:"+util.ToString(param.ScoreFinal), alignOptionText)
 					currentLine++
-					_ = pdf.Text("整体得分:")
 				}
 				{
 					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "线上得分:"+util.ToString(param.ScoreFinal), alignOptionText)
 					currentLine++
-					_ = pdf.Text("线上得分:")
 				}
 				{
 					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "线下得分:", alignOptionText)
 					currentLine++
-					_ = pdf.Text("线下得分:")
 				}
 				{
 					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "整体耗时:"+endTime.Sub(beginTime).String(), alignOptionText)
 					currentLine++
-					_ = pdf.Text("整体耗时:")
 				}
 			}
 			// 2. 分数详情
@@ -473,9 +475,9 @@ func Report(c *gin.Context) {
 				columnNumber := 4.0                         // 列数
 				tableCellWidth := tableWidth / columnNumber // 单元格宽度
 				{
-					pdf.SetXY(leftMargin, paragraphSpacing+topMargin+currentLine*lineHeight)
+					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "2. 分数详情", alignOptionText)
 					currentLine++
-					_ = pdf.Cell(nil, "2. 分数详情")
 				}
 				// 分数详情表格
 				{
@@ -525,17 +527,17 @@ func Report(c *gin.Context) {
 				columnNumber := 3.0                         // 列数
 				tableCellWidth := tableWidth / columnNumber // 单元格宽度
 				{
-					pdf.SetXY(leftMargin, paragraphSpacing+topMargin+currentLine*lineHeight)
+					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "3. 线上扣分详情", alignOptionText)
 					currentLine++
-					err = pdf.Cell(nil, "3. 线上扣分详情")
 				}
 				for i := 0; i < 10; i++ {
 					// 场景1
 					{
 						{
 							pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+							_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "("+util.ToString(i+1)+")xxxx场景", alignOptionText)
 							currentLine++
-							err = pdf.Cell(nil, "("+util.ToString(i+1)+")xxxx场景")
 						}
 						// 场景1 表格
 						{
@@ -575,7 +577,7 @@ func Report(c *gin.Context) {
 			}
 			// 4 作品优化建议
 			{
-				pdf.SetXY(leftMargin, paragraphSpacing+topMargin+currentLine*lineHeight)
+				pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
 				currentLine++
 				err = pdf.Cell(nil, "4. 作品优化建议")
 			}