Procházet zdrojové kódy

完善交卷接口。

tom před 2 měsíci
rodič
revize
4750538a70

+ 2 - 2
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/RealExamCollectionController.java

@@ -105,14 +105,14 @@ public class RealExamCollectionController extends BaseController {
     }
 
     @PutMapping(value = "/teacher/exercise/open/{examCollectionId}")
-    @ApiOperation("[教师][正式使用]打开训练集合;")
+    @ApiOperation("[教师][正式使用]打开训练集合")
     public AjaxResult openExercise(@PathVariable("examCollectionId") Long examCollectionId) {
         l.info("[教师][正式使用]打开训练集合;examCollectionId = {}", examCollectionId);
         return service.open(examCollectionId, RealExamCollection.Type.EXERCISE);
     }
 
     @PutMapping(value = "/teacher/exam/close/{examCollectionId}")
-    @ApiOperation("[教师][正式使用]关闭考试集合;")
+    @ApiOperation("[教师][正式使用]关闭考试集合")
     public AjaxResult closeExam(@PathVariable("examCollectionId") Long examCollectionId) {
         l.info("[教师][正式使用]关闭考试集合;examCollectionId = {}", examCollectionId);
         return service.close(examCollectionId, RealExamCollection.Type.EXAM);

+ 11 - 19
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/RealExamController.java

@@ -103,33 +103,25 @@ public class RealExamController extends BaseController {
         return realExamService.studentLoopAnsweringRealExam(examId);
     }
 
-    // todo:交卷验证交卷ip
-//    @GetMapping("/student/exam/submit/{examId}")
-//    @ApiOperation("[学生][正式使用]交卷考试")
-//    public AjaxResult studentSubmitRealExam(@PathVariable("examId") Long examId, @RequestParam final String ip) {
-//        l.info("[学生][正式使用]交卷考试");
-//        return realExamService.studentSubmitRealExam(examId, ip, RealExamCollection.Type.EXAM);
-//    }
-
     @GetMapping("/student/exam/submit/{examId}")
     @ApiOperation("[学生][正式使用]交卷考试")
-    public AjaxResult studentSubmitRealExam(@PathVariable("examId") Long examId) {
-        l.info("[学生][正式使用]交卷考试");
-        return realExamService.studentSubmitRealExam(examId, null, RealExamCollection.Type.EXAM);
+    public AjaxResult studentSubmitRealExam(@PathVariable("examId") Long examId, @RequestParam final String ip) {
+        l.info("[学生][正式使用]交卷考试;examId = {};ip = {}", examId, ip);
+        return realExamService.studentSubmitRealExam(examId, ip, RealExamCollection.Type.EXAM);
     }
 
     @GetMapping("/student/exercise/submit/{examId}")
-    @ApiOperation("[学生][正式使用]交卷练")
-    public AjaxResult studentSubmitRealExercise(@PathVariable("examId") Long examId) {
-        l.info("[学生][正式使用]交卷练习");
-        return realExamService.studentSubmitRealExam(examId, null, RealExamCollection.Type.EXERCISE);
+    @ApiOperation("[学生][正式使用]交卷练")
+    public AjaxResult studentSubmitRealExercise(@PathVariable("examId") Long examId, @RequestParam final String ip) {
+        l.info("[学生][正式使用]交卷训练;examId = {};ip = {}", examId, ip);
+        return realExamService.studentSubmitRealExam(examId, ip, RealExamCollection.Type.EXERCISE);
     }
 
     @GetMapping("/student/self-exercise/submit/{examId}")
-    @ApiOperation("[学生][正式使用]交卷自主练习")
-    public AjaxResult studentSubmitRealSelfExercise(@PathVariable("examId") Long examId) {
-        l.info("[学生][正式使用]交卷自主练习");
-        return realExamService.studentSubmitRealExam(examId, null, RealExamCollection.Type.SELF_EXERCISE);
+    @ApiOperation("[学生][正式使用]交卷练习")
+    public AjaxResult studentSubmitRealSelfExercise(@PathVariable("examId") Long examId, @RequestParam final String ip) {
+        l.info("[学生][正式使用]交卷练习;examId = {};ip = {}", examId, ip);
+        return realExamService.studentSubmitRealExam(examId, ip, RealExamCollection.Type.SELF_EXERCISE);
     }
 
     @GetMapping("/student/exam/report/{examId}")

+ 0 - 5
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/TestIotController.java

@@ -78,11 +78,6 @@ public class TestIotController extends BaseController {
                 //
             }
             break;
-            case 22: {
-                realExamService.studentStartRealExam(examId, null, null);
-                //
-            }
-            break;
             case 23: {
                 realExamService.studentLoopAnsweringRealExam(examId);
                 //

+ 81 - 19
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/RealExamService.java

@@ -381,6 +381,12 @@ public class RealExamService {
                 return ar;
             }
         }
+        // 针对练习(自主练习),进行特殊检查。
+        if (StringUtils.equals(RealExamCollection.Type.SELF_EXERCISE, examCollectionType)) {
+            // 已经open的考试。
+
+            // 已经open的训练。
+        }
         // Step:可换件检查,读取对应一台模拟器 所有故障部位值。
         //      检查模拟器所有的 真实的 故障部位 是否异常 或者 空值。特殊的故障部位要单独判断。
         if (SimDebugConfig.CHECK_REPLACE_EMPTY) {
@@ -389,6 +395,7 @@ public class RealExamService {
                 return ar;
             }
         }
+        // Step:正式开始考试。
         // Step:清除对应一台模拟器 所有 真实的 故障部位故障。
         {
             commSendService.clearOneSimAllFaultByExam(re);
@@ -464,34 +471,89 @@ public class RealExamService {
      */
     @Transactional
     public AjaxResult studentSubmitRealExam(final Long examId, final String studentBindIp, final String examCollectionType) {
+        // Check:检查参数examId有效性
+        {
+            AjaxResult ar = checkExamId(examId);
+            if (ar.isError()) {
+                return ar;
+            }
+        }
         RealExam re = selectRealExamByExamId(examId);
-        // Step :检查参数examId有效性
-        // Step :检查参数studentBindIp有效性
-        // Step :检查参数examCollectionType有效性
-        // check part.
+        RealExamCollection rec = realExamCollectionService.selectRealExamCollectionByExamCollectionId(re.getExamCollectionId());
+        // Check:检查参数studentBindIp有效性
+        if (StringUtils.isBlank(studentBindIp)) {
+            return AjaxResult.error("IP地址无效");
+        }
+        // 现在交卷的座次
+        Seat seatNow = seatService.uniqueByBindIp(studentBindIp);
+        // 开始考试的座次
+        Seat seatStart = seatService.selectSeatBySeatId(re.getSeatId());
+        if (seatNow == null || seatStart == null) {
+            return AjaxResult.error("没有IP对应座次数据!");
+        }
+        // Check:防止换座位交卷。
+        if (!Objects.equals(seatStart.getSeatId(), seatNow.getSeatId())) {
+            return AjaxResult.error("没有在原始座次上交卷,请回到原座次[" + seatStart.getSeatNum() + "]上进行交卷!");
+        }
+
+        // Check:检查参数examCollectionType有效性
+        if (!StringUtils.equals(examCollectionType, rec.getExamCollectionType())) {
+            return AjaxResult.error("考试集合类型不对应!");
+        }
+        // Check:ping通 RS485。
+        {
+            AjaxResult ar = commCheckService.checkPingRs485State(seatStart.getSeatRs485Ip());
+            if (ar.isError()) {
+                // todo:重复
+                // 更新SimId
+                seatService.updateSimIdBySeatNum(seatStart.getSeatNum(), Seat.ID_0);
+                // 更新SocketState
+                seatService.updateSocketStateBySeatNum(seatStart.getSeatNum(), Seat.SocketState.OFFLINE);
+                return ar;
+            } else {
+                // Ping通不代表在线,Socket连接建立表示在线。
+            }
+        }
+        // Check:如果有缓存Socket并且可用,使用缓存Socket,检查并建立Socket连接;否则返回对应错误。
         {
-            AjaxResult arE1 = checkExamId(examId);
-            if (arE1.isError()) {
-                return arE1;
+            AjaxResult ar = socketService.openOne(seatStart.toSimSocketParamVo(), true);
+            if (ar.isError()) {
+                return ar;
             }
         }
-        // 检查一下模拟器状态。
-        Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
+        // Check:发送通用询问指令,询问是连接的哪种型号的哪一台模拟器;否则返回对应错误。
+        {
+            AjaxResult ar = commCheckService.checkOneSeatState(seatStart, true);
+            if (ar.isError()) {
+                return ar;
+            }
+        }
+        // Step:查询模拟器在线状态,纯DB查询。
+        {
+            AjaxResult ar = commCheckService.checkOneSimOnlineState(seatStart.getCurrentSimId());
+            if (ar.isError()) {
+                return ar;
+            }
+        }
+        // Check:检查是否是出题值使用的模拟器。防止换机器交卷。
+        re = selectRealExamByExamId(examId);
+        if (!Objects.equals(re.getSimId(), seatNow.getCurrentSimId())) {
+            return AjaxResult.error("没有使用原始模拟器交卷,请使用模拟器[" +
+                    simService.selectSimBySimId(re.getSimId()).getSimNum() +
+                    "]进行交卷!");
+        }
+
+        // todo:检查一下模拟器状态。
 
-        // 检查换学生端交卷的情况。
+
+        // Check:检查换学生端交卷的情况。
 
         //
 
-        // 如果模拟器离线
-        {
-            // AjaxResult arE3 = commSendService.checkOneSimStateActive(seat);
-            AjaxResult arE3 = commCheckService.checkOneSeatState(seat, true);
-            if (arE3.isError()) {
-                return arE3;
-            }
-        }
-        // 最后读取一下模拟器电阻值。
+
+        // Step:最后读取一下模拟器电阻值。
         commSendService.readOneExamAtLast(re);
+        // Step:
         if (realExamFaultService.isType2ExamPrepareSubmitOk(re.getExamId())) {
             re.setExamStatus(RealExam.State.SUBMITTED);
             // 修改真实考试结束时间。