|
@@ -51,54 +51,71 @@ func Tick(c *gin.Context) {
|
|
|
numStr := param.PositionY
|
|
|
_, _ = fmt.Sscanf(numStr, "%e", &positionY)
|
|
|
if !util.ContainsKey(&cacheTeamName, teamName) && math.Abs(positionX-InitialPositionX) < 5.00 && math.Abs(positionY-InitialPositionY) < 5.00 { // (在起点开始)
|
|
|
- sqlTemplate, _ := util.ReadFile(c_db.SqlFilesMap["exam-insert-begin_time-and-topic-and-equipment_no-by-team_name.sql"])
|
|
|
|
|
|
- stage := ""
|
|
|
- if time.Now().Before(trialBegin) {
|
|
|
- stage = "表演赛"
|
|
|
- } else if time.Now().After(trialBegin) && time.Now().Before(trialEnd) {
|
|
|
- stage = "预赛"
|
|
|
- } else {
|
|
|
- stage = "决赛"
|
|
|
- }
|
|
|
- competitionBegin := time.Now()
|
|
|
- //cacheTeamName[teamName] = competitionBegin
|
|
|
- cacheTeamName.Store(teamName, competitionBegin)
|
|
|
- c_log.GlobalLogger.Infof("当前比赛阶段为 %v ,队伍 %v 在起始点范围内第一次启动,保存新一条比赛记录的开始时间 %v", stage, teamName, competitionBegin)
|
|
|
- if err := c_db.DoTx(sqlTemplate, []any{param.TeamName, stage, competitionBegin, param.EquipmentNo}); 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: "队伍 " + teamName + " 的考试开始。",
|
|
|
- })
|
|
|
- } else if !util.ContainsKey(&cacheTeamName, teamName) && (math.Abs(positionX-InitialPositionX) > 5.00 || math.Abs(positionY-InitialPositionY) > 5.00) { // 不在起点(开始)
|
|
|
- // 车辆不是在起点启动的自动驾驶模式
|
|
|
- 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)
|
|
|
- return
|
|
|
- }
|
|
|
- if err = c_db.MysqlDb.Select(&result, selectSql, teamName); err != nil {
|
|
|
- c_log.GlobalLogger.Error("数据库查询报错:", err)
|
|
|
- return
|
|
|
- }
|
|
|
- if len(result) == 1 {
|
|
|
- c_log.GlobalLogger.Info("上一条数据记录为:", result[0])
|
|
|
+ result := mapper.SelectLatestByTeamName(teamName)
|
|
|
+ if len(result) == 1 {
|
|
|
+ c_log.GlobalLogger.Info("上一条数据记录为:", result[0])
|
|
|
+ // 判断上一条记录的开始时间和当前时间是否小于2分钟
|
|
|
+ if time.Since(result[0].BeginTime).Minutes() < 2 {
|
|
|
// 添加队伍名到缓存中
|
|
|
cacheTeamName.Store(teamName, time.Now())
|
|
|
- //cacheTeamName[teamName] = time.Now()
|
|
|
- } else {
|
|
|
- c_log.GlobalLogger.Errorf("队伍 %v 的考试车辆未在起点开启自动驾驶模式,且今日无考试记录,错误启动自动驾驶模式。", param.TeamName)
|
|
|
+ // 更新记录结束时间为默认时间
|
|
|
+ sqlTemplate, _ := util.ReadFile(c_db.SqlFilesMap["exam-update-end_time-by-id.sql"])
|
|
|
+ if err := c_db.DoTx(sqlTemplate, []any{
|
|
|
+ defaultTime,
|
|
|
+ result[0].Id,
|
|
|
+ }); err != nil {
|
|
|
+ c_log.GlobalLogger.Error("插入数据报错:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c_log.GlobalLogger.Infof("队伍 %v 的考试在起点重复启动后重新开始。", teamName)
|
|
|
c.JSON(http.StatusOK, commonEntity.Response{
|
|
|
- Code: 400,
|
|
|
- Msg: "车辆未在起点开启自动驾驶模式,且今日无考试记录,错误启动自动驾驶模式。",
|
|
|
+ Code: 200,
|
|
|
+ Msg: "队伍 " + teamName + " 的考试在起点重复启动后重新开始。",
|
|
|
})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sqlTemplate, _ := util.ReadFile(c_db.SqlFilesMap["exam-insert-begin_time-and-topic-and-equipment_no-by-team_name.sql"])
|
|
|
+
|
|
|
+ stage := ""
|
|
|
+ if time.Now().Before(trialBegin) {
|
|
|
+ stage = "表演赛"
|
|
|
+ } else if time.Now().After(trialBegin) && time.Now().Before(trialEnd) {
|
|
|
+ stage = "预赛"
|
|
|
+ } else {
|
|
|
+ stage = "决赛"
|
|
|
+ }
|
|
|
+ competitionBegin := time.Now()
|
|
|
+ // 添加队伍名到缓存中
|
|
|
+ cacheTeamName.Store(teamName, competitionBegin)
|
|
|
+ c_log.GlobalLogger.Infof("当前比赛阶段为 %v ,队伍 %v 在起始点范围内第一次启动,保存新一条比赛记录的开始时间 %v", stage, teamName, competitionBegin)
|
|
|
+ if err := c_db.DoTx(sqlTemplate, []any{param.TeamName, stage, competitionBegin, param.EquipmentNo}); 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: "队伍 " + teamName + " 的考试开始。",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if !util.ContainsKey(&cacheTeamName, teamName) && (math.Abs(positionX-InitialPositionX) > 5.00 || math.Abs(positionY-InitialPositionY) > 5.00) { // 不在起点(开始)
|
|
|
+ // 车辆不是在起点启动的自动驾驶模式
|
|
|
+ result := mapper.SelectLatestByTeamName(teamName)
|
|
|
+ if len(result) == 1 {
|
|
|
+ c_log.GlobalLogger.Info("上一条数据记录为:", result[0])
|
|
|
+ // 添加队伍名到缓存中
|
|
|
+ cacheTeamName.Store(teamName, time.Now())
|
|
|
+ //cacheTeamName[teamName] = time.Now()
|
|
|
+ } else {
|
|
|
+ c_log.GlobalLogger.Errorf("队伍 %v 的考试车辆未在起点开启自动驾驶模式,且今日无考试记录,错误启动自动驾驶模式。", param.TeamName)
|
|
|
+ c.JSON(http.StatusOK, commonEntity.Response{
|
|
|
+ Code: 400,
|
|
|
+ Msg: "车辆未在起点开启自动驾驶模式,且今日无考试记录,错误启动自动驾驶模式。",
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// 更新记录结束时间为默认时间
|