LingxinMeng 1 год назад
Родитель
Сommit
119c9dd6c9
1 измененных файлов с 30 добавлено и 19 удалено
  1. 30 19
      amd64/score_server/handler/h_exam.go

+ 30 - 19
amd64/score_server/handler/h_exam.go

@@ -107,32 +107,41 @@ func Tick(c *gin.Context) {
 		// 车辆不是在起点启动的自动驾驶模式
 		result := mapper.SelectLatestByTeamName(teamName)
 		if len(result) == 1 {
-			c_log.GlobalLogger.Info("上一条数据记录为:", result[0])
-			// 添加队伍名到缓存中
-			cacheTeamName.Store(teamName, time.Now())
-			//cacheTeamName[teamName] = time.Now()
-		} else {
+			if time.Since(result[0].EndTime).Minutes() <= 5 { // 5分钟之内重启就还算上一条数据
+				c_log.GlobalLogger.Info("上一条数据记录为:", result[0])
+				// 添加队伍名到缓存中
+				cacheTeamName.Store(teamName, time.Now())
+				//cacheTeamName[teamName] = time.Now()
+				// 更新记录结束时间为默认时间
+				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)
+					c.JSON(http.StatusOK, commonEntity.Response{
+						Code: 500,
+						Msg:  "插入数据报错。",
+					})
+					return
+				}
+				c_log.GlobalLogger.Infof("队伍 %v 的考试在中途中断后重新开始。", teamName)
+				c.JSON(http.StatusOK, commonEntity.Response{
+					Code: 200,
+					Msg:  "队伍 " + teamName + " 的考试在中途中断后重新开始。",
+				})
+				return
+			}
+		}
+		{
 			c_log.GlobalLogger.Errorf("队伍 %v 的考试车辆未在起点开启自动驾驶模式,且今日无考试记录,错误启动自动驾驶模式。", param.TeamName)
 			c.JSON(http.StatusOK, commonEntity.Response{
 				Code: 400,
 				Msg:  "车辆未在起点开启自动驾驶模式,且今日无考试记录,错误启动自动驾驶模式。",
 			})
-		}
-
-		// 更新记录结束时间为默认时间
-		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: 200,
-			Msg:  "队伍 " + teamName + " 的考试在中途中断后重新开始。",
-		})
+
 	} else if util.ContainsKey(&cacheTeamName, teamName) { // 进行中
 		cacheTeamName.Store(teamName, time.Now())
 		//cacheTeamName[teamName] = time.Now()
@@ -141,12 +150,14 @@ func Tick(c *gin.Context) {
 			Code: 200,
 			Msg:  "队伍 " + teamName + " 的考试进行中,心跳接收成功。",
 		})
+		return
 	} else {
 		c_log.GlobalLogger.Errorf("接收到心跳信息但考试并未开始,队伍名字为 %s,x坐标为  %.f,y坐标为 %.f ", teamName, positionX, positionY)
 		c.JSON(http.StatusOK, commonEntity.Response{
 			Code: 200,
 			Msg:  "队伍 " + teamName + " 的考试未开始。",
 		})
+		return
 	}
 }