LingxinMeng před 1 rokem
rodič
revize
da6389ae69

+ 26 - 18
amd64/web_server/entity/e_exam.go

@@ -1,7 +1,6 @@
 package entity
 
 import (
-	commonEntity "cicv-data-closedloop/common/entity"
 	"time"
 )
 
@@ -10,25 +9,34 @@ type ExamPao 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"`
-	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"`
+	Id              int       `json:"id" db:"id"` // 自增id
+	TeamName        string    `json:"teamName" db:"team_name"`
+	Topic           string    `json:"topic" db:"topic"`
+	BeginTime       time.Time `json:"beginTime" db:"begin_time"`
+	EndTime         time.Time `json:"endTime" db:"end_time"`
+	ScoreOnline     float64   `json:"scoreOnline" db:"score_online"`
+	ScoreOffline    float64   `json:"scoreOffline" db:"score_offline"`
+	ScoreFinal      float64   `json:"scoreFinal" db:"score_final"`
+	Details         string    `json:"details" db:"details"`
+	ScoreReportPath string    `json:"ScoreReportPath" db:"score_report_path"`
 }
 
-type ExamPagePao struct {
-	Page     commonEntity.PagePao
-	TeamName string `json:"teamName"` // 队伍名字
-	Topic    string `json:"topic"`
+type ExamVo struct {
+	Id              int     `json:"id" ` // 自增id
+	TeamName        string  `json:"teamName"`
+	Topic           string  `json:"topic" `
+	BeginTime       string  `json:"beginTime" `
+	EndTime         string  `json:"endTime"`
+	ScoreOnline     float64 `json:"scoreOnline" `
+	ScoreOffline    float64 `json:"scoreOffline" `
+	ScoreFinal      float64 `json:"scoreFinal"`
+	Details         string  `json:"details" `
+	ScoreReportPath string  `json:"ScoreReportPath" `
 }
 
-type ExamPageVo struct {
-	Exam ExamPo
-	Page commonEntity.PagePao
+type ExamPagePao struct {
+	CurrentPage int    `json:"currentPage"`
+	PageSize    int    `json:"pageSize"`
+	TeamName    string `json:"teamName"` // 队伍名字
+	Topic       string `json:"topic"`    // 赛题
 }

+ 37 - 10
amd64/web_server/handler/h_exam.go

@@ -102,22 +102,49 @@ func End(c *gin.Context) {
 	})
 }
 
-// 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)
-		}
+	var resultPos []webServerEntity.ExamPo
+	var selectSql string
+	offset := (param.CurrentPage - 1) * param.PageSize
+	size := param.PageSize
+	if param.TeamName == "" && param.Topic == "" {
+		selectSql, _ = util.ReadFile(c_db.SqlFilesMap["exam-select-page.sql"])
+		_ = c_db.MysqlDb.Select(&resultPos, selectSql, offset, size)
+	}
+	if param.TeamName != "" && param.Topic == "" {
+		selectSql, _ = util.ReadFile(c_db.SqlFilesMap["exam-select-page-by-team_name.sql"])
+		_ = c_db.MysqlDb.Select(&resultPos, selectSql, "%"+param.TeamName+"%", offset, size)
+	}
+	if param.TeamName == "" && param.Topic != "" {
+		selectSql, _ = util.ReadFile(c_db.SqlFilesMap["exam-select-page-by-topic.sql"])
+		_ = c_db.MysqlDb.Select(&resultPos, selectSql, "%"+param.Topic+"%", offset, size)
+	}
+	if param.TeamName != "" && param.Topic != "" {
+		selectSql, _ = util.ReadFile(c_db.SqlFilesMap["exam-select-page-by-team_name-and-topic.sql"])
+		_ = c_db.MysqlDb.Select(&resultPos, selectSql, "%"+param.TeamName+"%", "%"+param.Topic+"%", offset, size)
+	}
+	var resultVos []webServerEntity.ExamVo
+	for _, po := range resultPos {
+		resultVos = append(resultVos, webServerEntity.ExamVo{
+			Id:              po.Id,
+			TeamName:        po.TeamName,
+			Topic:           po.Topic,
+			BeginTime:       util.GetTimeString(po.BeginTime),
+			EndTime:         util.GetTimeString(po.EndTime),
+			ScoreOnline:     po.ScoreOnline,
+			ScoreOffline:    po.ScoreOffline,
+			ScoreFinal:      po.ScoreFinal,
+			Details:         po.Details,
+			ScoreReportPath: po.ScoreReportPath,
+		})
 	}
 
 	c.JSON(http.StatusOK, commonEntity.Response{
 		Code: 200,
-		Msg:  "分页查询成功。",
-		Data: result,
+		Msg:  "分页查询成功",
+		Data: resultVos,
 	})
 }

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


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


+ 13 - 0
amd64/web_server/sql/exam-select-page-by-team_name-and-topic.sql

@@ -0,0 +1,13 @@
+select id,
+       team_name,
+       topic,
+       begin_time,
+       end_time,
+       score_online,
+       score_offline,
+       score_final,
+       details,
+       score_report_path
+from exam
+where team_name like ? and topic like ?
+limit ?,?

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

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

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

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

+ 2 - 1
amd64/web_server/sql/exam-select-page.sql

@@ -1,7 +1,8 @@
 select id,
+       team_name,
+       topic,
        begin_time,
        end_time,
-       team_name,
        score_online,
        score_offline,
        score_final,

+ 0 - 7
common/entity/e_page.go

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

+ 4 - 0
common/util/u_time.go

@@ -56,3 +56,7 @@ func TimeCustom1LessEqualThanTimeCustom2(timeCustom1 string, timeCustom2 string)
 	timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
 	return timeInt1 <= timeInt2
 }
+
+func GetTimeString(sourceTime time.Time) string {
+	return sourceTime.Format("2006-01-02 15:04:05")
+}