package handler import ( "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" "cicv-data-closedloop/common/util" "github.com/gin-gonic/gin" "net/http" "time" ) // 考试开始时间 func Begin(c *gin.Context) { param := new(entity.ExamPAO) // 映射到结构体 if err := c.ShouldBindJSON(¶m); err != nil { c_log.GlobalLogger.Error("项目启动接收请求参数报错:", err) c.JSON(http.StatusBadRequest, commonEntity.Response{ Code: 500, Msg: "请求体解析失败。", }) return } // 插入到数据库 sqlTemplate, _ := util.ReadFile(c_db.SqlFilesMap["insert_exam.sql"]) if err := c_db.DoTx(sqlTemplate, []any{ param.TeamName, time.Now(), }); err != nil { c_log.GlobalLogger.Error("插入数据报错:", err) c.JSON(http.StatusBadRequest, commonEntity.Response{ Code: 500, Msg: "插入数据报错。", }) return } c.JSON(http.StatusOK, commonEntity.Response{ Code: 200, Msg: "插入数据成功。", }) } // 考试结束时间 func End(c *gin.Context) { param := new(entity.ExamPAO) // 映射到结构体 if err := c.ShouldBindJSON(¶m); err != nil { c_log.GlobalLogger.Error("项目启动接收请求参数报错:", err) c.JSON(http.StatusBadRequest, commonEntity.Response{ Code: 500, Msg: "请求体解析失败。", }) return } // 1 查询指定队伍的开始时间最新的考试是否有结束时间,如果有则不在处理,如果没有则更新 // 插入到数据库 sqlTemplate, _ := util.ReadFile(c_db.SqlFilesMap["update.sql"]) if err := c_db.DoTx(sqlTemplate, []any{ time.Now(), param.TeamName, }); err != nil { c_log.GlobalLogger.Error("插入数据报错:", err) c.JSON(http.StatusBadRequest, commonEntity.Response{ Code: 500, Msg: "插入数据报错。", }) return } c.JSON(http.StatusOK, commonEntity.Response{ Code: 200, Msg: "插入数据成功。", }) }