LingxinMeng преди 1 година
родител
ревизия
df8a5a3e3d

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

@@ -1,15 +1,34 @@
 package entity
 
-import "time"
+import (
+	commonEntity "cicv-data-closedloop/common/entity"
+	"time"
+)
 
-type ExamPAO struct {
+type ExamPao struct {
 	TeamName string `json:"teamName"` // 队伍名字
 }
 
-type ExamPO struct {
+type ExamPo struct {
 	Id              int       `db:"id"` // 自增id
+	TeamName        string    `db:"team_name"`
+	Topic           string    `db:"topic"`
 	BeginTime       time.Time `db:"begin_time"`
 	EndTime         time.Time `db:"end_time"`
-	ScoreReportPath time.Time `db:"score_report_path"`
-	TeamName        time.Time `db:"team_name"`
+	ScoreOnline     float64   `db:"score_online"`
+	ScoreOffline    float64   `db:"score_offline"`
+	ScoreFinal      float64   `db:"score_final"`
+	Details         string    `db:"details"`
+	ScoreReportPath string    `db:"score_report_path"`
+}
+
+type ExamPagePao struct {
+	Page     commonEntity.PagePao
+	TeamName string `json:"teamName"` // 队伍名字
+	Topic    string `json:"topic"`
+}
+
+type ExamPageVo struct {
+	Exam ExamPo
+	Page commonEntity.PagePao
 }

+ 0 - 10
amd64/web_server/entity/e_report.go

@@ -1,10 +0,0 @@
-package entity
-
-type Record struct {
-	Team         string  `json:"team"`
-	Topic        string  `json:"topic"`
-	ScoreOnline  float64 `json:"scoreOnline"`
-	ScoreOffline float64 `json:"scoreOffline"`
-	ScoreFinal   float64 `json:"scoreFinal"`
-	Details      string  `json:"details"`
-}

+ 24 - 4
amd64/web_server/handler/h_exam.go

@@ -1,7 +1,7 @@
 package handler
 
 import (
-	"cicv-data-closedloop/amd64/web_server/entity"
+	webServerEntity "cicv-data-closedloop/amd64/web_server/entity"
 	"cicv-data-closedloop/common/config/c_db"
 	"cicv-data-closedloop/common/config/c_log"
 	commonEntity "cicv-data-closedloop/common/entity"
@@ -13,7 +13,7 @@ import (
 
 // 考试开始时间
 func Begin(c *gin.Context) {
-	param := new(entity.ExamPAO)
+	param := new(webServerEntity.ExamPao)
 	// 映射到结构体
 	if err := c.ShouldBindJSON(&param); err != nil {
 		c_log.GlobalLogger.Error("项目启动接收请求参数报错:", err)
@@ -44,7 +44,7 @@ func Begin(c *gin.Context) {
 
 // 考试结束时间
 func End(c *gin.Context) {
-	param := new(entity.ExamPAO)
+	param := new(webServerEntity.ExamPao)
 	// 映射到结构体
 	if err := c.ShouldBindJSON(&param); err != nil {
 		c_log.GlobalLogger.Error("项目启动接收请求参数报错:", err)
@@ -55,7 +55,7 @@ func End(c *gin.Context) {
 		return
 	}
 	// 1 查询指定队伍的开始时间最新的考试是否有结束时间,如果有则不在处理,如果没有则更新
-	var result entity.ExamPO
+	var result webServerEntity.ExamPo
 	selectSql, err := util.ReadFile(c_db.SqlFilesMap["exam-select-latest-by-team_name.sql"])
 	if err != nil {
 		c_log.GlobalLogger.Error("读取sql文件报错:", err)
@@ -101,3 +101,23 @@ func End(c *gin.Context) {
 		Msg:  "插入数据成功。",
 	})
 }
+
+// Page 分页查询
+func Page(c *gin.Context) {
+	param := new(webServerEntity.ExamPagePao)
+	_ = c.ShouldBindJSON(&param)
+	c_log.GlobalLogger.Info("参数为:", param)
+	var result []webServerEntity.ExamPo
+	if param.TeamName == "" {
+		if param.Topic == "" {
+			selectSql, _ := util.ReadFile(c_db.SqlFilesMap["exam-select-page.sql"])
+			_ = c_db.MysqlDb.Select(&result, selectSql, param.Page.CurrentPage*param.Page.Size, param.Page.Size)
+		}
+	}
+
+	c.JSON(http.StatusOK, commonEntity.Response{
+		Code: 200,
+		Msg:  "分页查询成功。",
+		Data: result,
+	})
+}

+ 0 - 50
amd64/web_server/handler/h_report.go

@@ -1,50 +0,0 @@
-package handler
-
-import (
-	"cicv-data-closedloop/amd64/web_server/entity"
-	"cicv-data-closedloop/common/config/c_log"
-	commonEntity "cicv-data-closedloop/common/entity"
-	"cicv-data-closedloop/common/util"
-	"github.com/gin-gonic/gin"
-	"net/http"
-)
-
-type ReportRequest struct {
-	Page  commonEntity.PageRequest
-	Team  string `json:"team"`
-	Topic string `json:"topic"`
-}
-
-// Page 分页查询
-func Page(c *gin.Context) {
-	param := new(commonEntity.PageRequest)
-	// 映射到结构体
-	if err := c.ShouldBindJSON(&param); err != nil {
-		c_log.GlobalLogger.Error("项目启动接收请求参数报错:", err)
-		c.JSON(http.StatusBadRequest, commonEntity.Response{
-			Code: 500,
-			Msg:  "请求体解析失败。",
-		})
-		return
-	}
-	var result []entity.Record
-
-	// todo 查询数据库
-
-	for i := 0; i < param.PageSize; i++ {
-		result = append(result, entity.Record{
-			Team:         "team" + util.NewShortUUID(),
-			Topic:        "topic" + util.NewShortUUID(),
-			ScoreOnline:  100.0,
-			ScoreOffline: 100.0,
-			ScoreFinal:   100.0,
-			Details:      "sdlkfjsaljfldsakjfkls",
-		})
-	}
-
-	c.JSON(http.StatusOK, commonEntity.Response{
-		Code: 200,
-		Msg:  "分页查询成功。",
-		Data: result,
-	})
-}

+ 2 - 3
amd64/web_server/main.go

@@ -71,9 +71,8 @@ func main() {
 	examPrefix := projectPrefix.Group("/exam")
 	examPrefix.POST("/begin", handler.Begin) // 考试开始
 	examPrefix.POST("/end", handler.End)     // 考试结束
-	reportPrefix := projectPrefix.Group("/report")
-	reportPrefix.POST("/page", handler.Page) // 分页查询
-	//reportPrefix.POST("/pdf", handler.Hello)  // pdf下载
+	examPrefix.POST("/page", handler.Page)   // 分页查询
+	//examPrefix.POST("/pdf", handler.Hello)  // pdf下载
 	monitorPrefix := projectPrefix.Group("/monitor")
 	monitorPrefix.POST("/insert", handler.SaveDeviceMonitor)
 	// 端口

+ 0 - 0
amd64/web_server/sql/exam-select-by-team_name.sql


+ 0 - 0
amd64/web_server/sql/exam-select-by-topic.sql


+ 11 - 0
amd64/web_server/sql/exam-select-page.sql

@@ -0,0 +1,11 @@
+select id,
+       begin_time,
+       end_time,
+       team_name,
+       score_online,
+       score_offline,
+       score_final,
+       details,
+       score_report_path
+from exam
+limit ?,?

+ 3 - 2
common/entity/e_page.go

@@ -1,6 +1,7 @@
 package entity
 
-type PageRequest struct {
+type PagePao struct {
 	CurrentPage int `json:"currentPage"`
-	PageSize    int `json:"pageSize"`
+	Size        int `json:"pageSize"`
+	TotalPages  int `json:"totalPages"`
 }