LingxinMeng 1 anno fa
parent
commit
a931c29f62
1 ha cambiato i file con 101 aggiunte e 85 eliminazioni
  1. 101 85
      amd64/web_server/handler/h_exam.go

+ 101 - 85
amd64/web_server/handler/h_exam.go

@@ -6,7 +6,6 @@ import (
 	"cicv-data-closedloop/common/config/c_log"
 	commonEntity "cicv-data-closedloop/common/entity"
 	"cicv-data-closedloop/common/util"
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/signintech/gopdf"
 	"io"
@@ -341,25 +340,20 @@ func Report(c *gin.Context) {
 
 		leftMargin := 70.0
 		topMargin := 100.0
-		lineHeight := 30.0
-		tableWidth := 400.0
+		lineHeight := 25.0
+		tableWidth := 450.0
+		paragraphSpacing := 10.0
 		pdf.SetLeftMargin(leftMargin) // 设置左边距
+		//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}
 
 		// ------- 封面页 -------
 		pdf.AddPage()
 		{
 			err = pdf.SetFont("simfang", "", 36)
-			if err != nil {
-				fmt.Print(err.Error())
-			}
 			err = pdf.Image("D:\\code\\cicv-data-closedloop\\amd64\\web_server\\background.png", 0, 0, nil) // 背景图片
-			if err != nil {
-				fmt.Print(err.Error())
-			}
 			err = pdf.Image("D:\\code\\cicv-data-closedloop\\amd64\\web_server\\logo.png", 20, 20, &gopdf.Rect{W: 320, H: 100})
-			if err != nil {
-				fmt.Print(err.Error())
-			}
 			{
 				pdf.SetXY(100, 250)
 				_ = pdf.Text("车路云一体化算法挑战赛")
@@ -390,22 +384,26 @@ func Report(c *gin.Context) {
 				_ = pdf.Cell(nil, "国汽(北京)智能网联汽车研究院有限公司")
 			}
 		}
-		// ------- 目录页 -------
-		{
-			pdf.AddPage()
-			currentLine := 0.0
-			{
-				pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
-				currentLine++
-				err = pdf.Text("目录")
-			}
-			{
-				pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
-				currentLine++
-				err = pdf.Text("1. 总体情况\t22")
-			}
-		}
-		// ------- 详情页 -------
+		// todo 先不要目录页
+		//// ------- 目录页 -------
+		//{
+		//	pdf.AddPage()
+		//	currentLine := 0.0
+		//	{
+		//		err = pdf.SetFont("simfang", "", 18)
+		//		pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+		//		_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "目录", alignOptionText2)
+		//		currentLine++
+		//		currentLine++
+		//	}
+		//	{
+		//		err = pdf.SetFont("simfang", "", 14)
+		//		pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+		//		currentLine++
+		//		_ = pdf.CellWithOption(&gopdf.Rect{W: tableWidth, H: lineHeight}, "1. 总体情况 ............................... 1", alignOptionText)
+		//	}
+		//}
+		// ------- 详情页 ------- todo 详情页暂时不分页,因为内容可能很长
 		{
 			pdf.AddPage()
 			currentLine := 0.0
@@ -419,17 +417,22 @@ func Report(c *gin.Context) {
 				{
 					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
 					currentLine++
-					err = pdf.Text("整体得分:")
+					_ = pdf.Text("整体得分:")
+				}
+				{
+					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					currentLine++
+					_ = pdf.Text("线上得分:")
 				}
 				{
 					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
 					currentLine++
-					err = pdf.Text("线下得分:")
+					_ = pdf.Text("线下得分:")
 				}
 				{
 					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
 					currentLine++
-					err = pdf.Text("整体耗时:")
+					_ = pdf.Text("整体耗时:")
 				}
 			}
 			// 2. 分数详情
@@ -437,106 +440,119 @@ func Report(c *gin.Context) {
 				columnNumber := 4.0                         // 列数
 				tableCellWidth := tableWidth / columnNumber // 单元格宽度
 				{
-					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+					pdf.SetXY(leftMargin, paragraphSpacing+topMargin+currentLine*lineHeight)
 					currentLine++
-					err = pdf.Cell(nil, "2. 分数详情")
+					_ = pdf.Cell(nil, "2. 分数详情")
 				}
 				// 分数详情表格
 				{
 					{
 						pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
-						err = pdf.Cell(nil, "序号")
+						_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "序号", alignOptionTable)
 					}
 					{
 						pdf.SetXY(leftMargin+1.0*tableCellWidth, topMargin+currentLine*lineHeight)
-						err = pdf.Cell(nil, "场景名称")
+						_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "场景名称", alignOptionTable)
 					}
 					{
 						pdf.SetXY(leftMargin+2.0*tableCellWidth, topMargin+currentLine*lineHeight)
-						err = pdf.Cell(nil, "线上得分")
+						_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "线上得分", alignOptionTable)
 					}
 					{
 						pdf.SetXY(leftMargin+3.0*tableCellWidth, topMargin+currentLine*lineHeight)
-						err = pdf.Cell(nil, "线下得分")
+						_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "线下得分", alignOptionTable)
 					}
 					currentLine++
 				}
-				{
-					{
-						pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
-						err = pdf.Cell(nil, "1")
-					}
-					{
-						pdf.SetXY(leftMargin+1.0*tableCellWidth, topMargin+currentLine*lineHeight)
-						err = pdf.Cell(nil, "xxx")
-					}
-					{
-						pdf.SetXY(leftMargin+2.0*tableCellWidth, topMargin+currentLine*lineHeight)
-						err = pdf.Cell(nil, "xxx")
-					}
-					{
-						pdf.SetXY(leftMargin+3.0*tableCellWidth, topMargin+currentLine*lineHeight)
-						err = pdf.Cell(nil, "xxx")
-					}
-					currentLine++
-				}
-			}
-			// 3. 线上扣分详情
-			{
-				columnNumber := 3.0                         // 列数
-				tableCellWidth := tableWidth / columnNumber // 单元格宽度
-				{
-					pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
-					currentLine++
-					err = pdf.Cell(nil, "3. 线上扣分详情")
-				}
-				// 场景1
-				{
-					{
-						pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
-						currentLine++
-						err = pdf.Cell(nil, "(1)xxxx场景")
-					}
-					// 场景1 表格
+				for i := 0; i < 10; i++ {
 					{
 						{
 							pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
-							err = pdf.Cell(nil, "序号")
+							_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, util.ToString(i+1), alignOptionTable)
 						}
 						{
 							pdf.SetXY(leftMargin+1.0*tableCellWidth, topMargin+currentLine*lineHeight)
-							err = pdf.Cell(nil, "扣分点")
+							_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "xxx", alignOptionTable)
 						}
 						{
 							pdf.SetXY(leftMargin+2.0*tableCellWidth, topMargin+currentLine*lineHeight)
-							err = pdf.Cell(nil, "扣分说明")
+							_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "xxx", alignOptionTable)
+						}
+						{
+							pdf.SetXY(leftMargin+3.0*tableCellWidth, topMargin+currentLine*lineHeight)
+							_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "xxx", alignOptionTable)
 						}
 						currentLine++
 					}
+				}
+
+			}
+			// 3. 线上扣分详情
+			{
+				columnNumber := 3.0                         // 列数
+				tableCellWidth := tableWidth / columnNumber // 单元格宽度
+				{
+					pdf.SetXY(leftMargin, paragraphSpacing+topMargin+currentLine*lineHeight)
+					currentLine++
+					err = pdf.Cell(nil, "3. 线上扣分详情")
+				}
+				for i := 0; i < 10; i++ {
+					// 场景1
 					{
 						{
 							pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
-							err = pdf.Cell(nil, "1")
+							currentLine++
+							err = pdf.Cell(nil, "("+util.ToString(i+1)+")xxxx场景")
 						}
+						// 场景1 表格
 						{
-							pdf.SetXY(leftMargin+1.0*tableCellWidth, topMargin+currentLine*lineHeight)
-							err = pdf.Cell(nil, "xxx")
+							{
+								pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+								_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "序号", alignOptionTable)
+							}
+							{
+								pdf.SetXY(leftMargin+1.0*tableCellWidth, topMargin+currentLine*lineHeight)
+								_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "扣分点", alignOptionTable)
+							}
+							{
+								pdf.SetXY(leftMargin+2.0*tableCellWidth, topMargin+currentLine*lineHeight)
+								_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "扣分说明", alignOptionTable)
+							}
+							currentLine++
 						}
-						{
-							pdf.SetXY(leftMargin+2.0*tableCellWidth, topMargin+currentLine*lineHeight)
-							err = pdf.Cell(nil, "xxx")
+						for j := 0; j < 4; j++ {
+							{
+								{
+									pdf.SetXY(leftMargin, topMargin+currentLine*lineHeight)
+									_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, util.ToString(j+1), alignOptionTable)
+								}
+								{
+									pdf.SetXY(leftMargin+1.0*tableCellWidth, topMargin+currentLine*lineHeight)
+									_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "xxx", alignOptionTable)
+								}
+								{
+									pdf.SetXY(leftMargin+2.0*tableCellWidth, topMargin+currentLine*lineHeight)
+									_ = pdf.CellWithOption(&gopdf.Rect{W: tableCellWidth, H: lineHeight}, "xxx", alignOptionTable)
+								}
+								currentLine++
+							}
 						}
-						currentLine++
 					}
 				}
 			}
+			// 4 作品优化建议
+			{
+				pdf.SetXY(leftMargin, paragraphSpacing+topMargin+currentLine*lineHeight)
+				currentLine++
+				err = pdf.Cell(nil, "4. 作品优化建议")
+			}
 		}
 		// ------- 附录页 -------
 		pdf.AddPage()
 		{
 			pdf.SetXY(leftMargin, topMargin)
 			_ = pdf.Text("附件:评分规则")
-			pdf.AddExternalLink("http://www.baidu.com/", 27.5, 28, 125, 15)
+			pdf.AddExternalLink("https://www.baidu.com/", leftMargin, topMargin-lineHeight, 6*14, lineHeight)
 		}
 		// 写入本地
 		pdf.WritePdf("D:\\hello.pdf")