1
0

2 Коммиты a42d9f13d2 ... 6224c338e4

Автор SHA1 Сообщение Дата
  tom 6224c338e4 studentRefreshSimState 2 месяцев назад
  tom 604af6493d 优化请求间隔。 2 месяцев назад

+ 3 - 3
ruoyi-sim/src/main/java/com/ruoyi/sim/constant/CommConst.java

@@ -76,7 +76,7 @@ public interface CommConst {
      * 请求间隔睡眠时间-long
      * default:200L
      */
-    Long SLEEP_LONG = 1000L;
+    Long SLEEP_LONG = 300L;
     /**
      * 请求间隔睡眠时间-mid
      * default:100L
@@ -86,11 +86,11 @@ public interface CommConst {
      * 请求间隔睡眠时间-short
      * default:64L
      */
-    Long SLEEP_SHORT = 1000L;
+    Long SLEEP_SHORT = 200L;
 
     int SOCKET_TIME_OUT = 50;
 
-    int PING_TIME_OUT = 1000;
+    int PING_TIME_OUT = 500;
 
     String[] TYPE_1_BIND_MSG = new String[]{"01", "02", "03", "04", "05",
             "06", "07", "08", "09", "0A"};

+ 7 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/RealExamController.java

@@ -90,6 +90,13 @@ public class RealExamController extends BaseController {
         return realExamService.studentStartRealExam(examId, ip, RealExamCollection.Type.SELF_EXERCISE);
     }
 
+    @GetMapping("/student/refresh-sim-state")
+    @ApiOperation("刷新模拟器状态")
+    public AjaxResult studentRefreshSimState(@RequestParam final String ip) {
+        l.info("刷新模拟器状态");
+        return realExamService.studentRefreshSimState(ip);
+    }
+
     @GetMapping("/student/exam/answering/{examId}")
     @ApiOperation("[轮询][学生]正在考试界面")
     public AjaxResult studentLoopAnsweringRealExam(@PathVariable("examId") Long examId) {

+ 15 - 7
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommCheckService.java

@@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.text.MessageFormat;
 import java.util.List;
 import java.util.Objects;
 
@@ -127,7 +128,6 @@ public class CommCheckService {
         }
         //
         socketService.tryOpenAll();
-        //
         int retryTotalCount;
         if (important) {
             retryTotalCount = CommConst.RETRY_COUNT_WHICH_SIM_IMPORTANT;
@@ -149,13 +149,18 @@ public class CommCheckService {
             seatService.updateSimIdBySeatNum(seat.getSeatNum(), sim.getSimId());
             // 更新Sim状态
             simService.updateSimStateBySimId(sim.getSimId(), Sim.State.ONLINE);
-            return AjaxResult.success("成功,检查一个座次[" + seat.getSeatNum() + "]OK!模拟器[" + sim.getSimNum() + "]在线。");
+
+            String msgTemp = "座号[{0}]-模拟器[{1}]型[{2}]在线";
+            String msg = MessageFormat.format(msgTemp, seat.getSeatNum(), Sim.TYPE_NAME_MAP.get(sim.getSimType()), sim.getSimNum());
+            return AjaxResult.success(msg);
         } else if (Objects.equals(result, SimMsg.Result.RECEIVE_CHECK_FAIL)) {
             return AjaxResult.error("失败,报文回复异常。");
         } else if (Objects.equals(result, SimMsg.Result.SOCKET_EXCEPTION)) {
             // 更新SimId
             seatService.updateSimIdBySeatNum(seat.getSeatNum(), Sim.ID_0);
-            return AjaxResult.success("成功,检查一个座次[" + seat.getSeatNum() + "]OK!未连接模拟器。");
+            String msgTemp = "座号[{0}]-没有连接任何接模拟器,检查线缆连接和线缆开关";
+            String msg = MessageFormat.format(msgTemp, seat.getSeatNum());
+            return AjaxResult.success(msg);
         }
         return AjaxResult.error("失败");
     }
@@ -168,6 +173,9 @@ public class CommCheckService {
      * @return
      */
     public AjaxResult checkOneSimOnlineState(final Long simId) {
+        if (simId == null || simId <= 0) {
+            return AjaxResult.error("没有连接任何接模拟器,<br>检查线缆连接和线缆开关!");
+        }
         Sim sim = simService.selectSimBySimId(simId);
         if (sim != null) {
             switch (sim.getSimState()) {
@@ -206,7 +214,7 @@ public class CommCheckService {
             return AjaxResult.error("模拟器ID[" + seat.getCurrentSimId() + "]不存在!");
         }
         //
-        final String msgError = "连接模拟器类型或序列号不正确!应该连接型号:";
+        final String msgErrorTemp = "连接模拟器类型或序列号不正确!<br>应该连接模拟器型号:<br>";
         final String msgOk = "连接模拟器类型或序列号正确!";
         int retryTotalCount;
         if (important) {
@@ -224,21 +232,21 @@ public class CommCheckService {
                     if (content.startsWith(CommConst.TYPE_0001_SN_PREFIX) && content.endsWith(sim.getSimNum())) {
                         return AjaxResult.success(msgOk);
                     } else {
-                        return AjaxResult.error(msgError + Sim.TYPE_NAME_MAP.get(targetSimType));
+                        return AjaxResult.error(msgErrorTemp + Sim.TYPE_NAME_MAP.get(targetSimType));
                     }
                 }
                 case Sim.TYPE_0002 -> {
                     if (content.startsWith(CommConst.TYPE_0002_SN_PREFIX) && content.endsWith(sim.getSimNum())) {
                         return AjaxResult.success(msgOk);
                     } else {
-                        return AjaxResult.error(msgError + Sim.TYPE_NAME_MAP.get(targetSimType));
+                        return AjaxResult.error(msgErrorTemp + Sim.TYPE_NAME_MAP.get(targetSimType));
                     }
                 }
                 case Sim.TYPE_0003 -> {
                     if (content.startsWith(CommConst.TYPE_0003_SN_PREFIX) && content.endsWith(sim.getSimNum())) {
                         return AjaxResult.success(msgOk);
                     } else {
-                        return AjaxResult.error(msgError + Sim.TYPE_NAME_MAP.get(targetSimType));
+                        return AjaxResult.error(msgErrorTemp + Sim.TYPE_NAME_MAP.get(targetSimType));
                     }
                 }
                 default -> throw new IllegalStateException("Unexpected value: " + targetSimType);

+ 8 - 8
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommSendService.java

@@ -3,6 +3,7 @@ package com.ruoyi.sim.service.impl;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.sim.config.SimConfig;
+import com.ruoyi.sim.config.SimDebugConfig;
 import com.ruoyi.sim.constant.CommConst;
 import com.ruoyi.sim.domain.*;
 import com.ruoyi.sim.domain.vo.SimSocketVo;
@@ -223,7 +224,7 @@ public class CommSendService {
      */
     public void scheduledConnect() {
         l.info("scheduled####Connect  连接情况 的 定时任务");
-//        if (!SimDebugConfig.SCHEDULED_CONNECT) {
+        // if (!SimDebugConfig.SCHEDULED_CONNECT) {
         if (true) {
             l.info("连接情况 的 定时任务被禁用!");
             return;
@@ -237,8 +238,8 @@ public class CommSendService {
 
         //
         {
-            AjaxResult ar01 = commCheckService.checkRouterState(config.getRouterIp());
-            if (ar01.isError()) {
+            AjaxResult ar = commCheckService.checkRouterState(config.getRouterIp());
+            if (ar.isError()) {
                 return;
             }
         }
@@ -248,8 +249,7 @@ public class CommSendService {
                 commCheckService.checkPingRs485State(rs485Ip);
             });
         }
-        // SocketOldService实现
-        // socketOldService.openSocket();
+
 
         // SocketOldService实现
 //        if (socketOldService.isCachedSocketOk()) {
@@ -591,7 +591,7 @@ public class CommSendService {
             Seat seat = seatService.selectSeatBySeatId(re.getSeatId());
             Sim sim = simService.selectSimBySimId(re.getSimId());
             Fault f = faultService.selectFaultByFaultId(ref.getFaultId());
-            // 选中的才下发。
+            // 选中的故障才下发。
             writeOneSimOneFault(seat, sim, ref, f);
         }
     }
@@ -636,9 +636,9 @@ public class CommSendService {
         }
         StringBuilder sbNG = new StringBuilder();
         for (Fault f : listNG) {
-            sbNG.append("[" + f.getReplaceName() + "]件异常;<br>");
+            sbNG.append("[" + f.getReplaceName() + "]可换件异常;<br>");
         }
-        sbNG.append("请检查后重新开始考试!");
+        sbNG.append("请正确安装可换件,检查后重新开始考试!");
         return AjaxResult.error(sbNG.toString());
     }
 

+ 18 - 13
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/RealExamCollectionService.java

@@ -288,18 +288,23 @@ public class RealExamCollectionService extends Ele6RYBaseService {
      */
     @Transactional
     public AjaxResult open(final Long examCollectionId, final String examCollectionType) {
+        l.debug("open examCollectionId= {}", examCollectionId);
         // check 1:检查id有效。
-        RealExamCollection ref = selectRealExamCollectionByExamCollectionId(examCollectionId);
-        if (ref == null) {
+        RealExamCollection rec = selectRealExamCollectionByExamCollectionId(examCollectionId);
+        if (rec == null) {
             return AjaxResult.error("考试集合不存在!");
         }
+        l.debug("rec = {}", rec);
         // check 2:检查考试集合类型对应。
-        {
-            final String dbType = ref.getExamCollectionType();
-            if (!StringUtils.equals(dbType, examCollectionType)) {
-                return AjaxResult.error("考试集合类型不对应!");
-            }
-        }
+
+//        {
+//            final String dbType = rec.getExamCollectionType();
+//            if (!StringUtils.equals(dbType, examCollectionType)) {
+//                return AjaxResult.error("考试集合类型不对应!");
+//            }
+//        }
+
+
         // check 3:唯一open检查。
 //        if (existOpened()) {
 //            return AjaxResult.error("已经有打开的考试或者练习!");
@@ -310,15 +315,15 @@ public class RealExamCollectionService extends Ele6RYBaseService {
 
         // Step 1:强制停掉所有的自主练习
         {
-            closeAllType(RealExamCollection.Type.SELF_EXERCISE);
+            // closeAllType(RealExamCollection.Type.SELF_EXERCISE);
         }
         // Step 2:强制停掉所有的练习
         {
-            closeAllType(RealExamCollection.Type.EXERCISE);
+            // closeAllType(RealExamCollection.Type.EXERCISE);
         }
         // Step 3:强制停掉 除本考试外的 所有考试
         {
-            closeAllExamExcludeId(ref.getExamCollectionId());
+            // closeAllExamExcludeId(rec.getExamCollectionId());
         }
         // Step 4:尝试打开所有Socket,提前准备,允许有打开失败的
         // SocketOldService实现。
@@ -335,8 +340,8 @@ public class RealExamCollectionService extends Ele6RYBaseService {
 
         // Step :修改考试集合状态。
         {
-            ref.setExamCollectionState(RealExamCollection.State.OPENED);
-            updateRealExamCollection(ref);
+            rec.setExamCollectionState(RealExamCollection.State.OPENED);
+            updateRealExamCollection(rec);
         }
         return AjaxResult.success("开启成功!");
     }

+ 20 - 6
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/RealExamService.java

@@ -294,11 +294,10 @@ public class RealExamService {
      *
      * @param examId
      * @param studentBindIp
-     * @param type
      * @return
      */
     @Transactional
-    public AjaxResult studentStartRealExam(final Long examId, final String studentBindIp, final String type) {
+    public AjaxResult studentStartRealExam(final Long examId, final String studentBindIp, final String examCollectionType) {
         l.info("studentStartRealExam = {}", examId);
         // todo: 暂时没有解决方案 检查 考试的sim和seat,是否正确对应。
         {
@@ -314,6 +313,7 @@ public class RealExamService {
                 return ar01;
             }
         }
+        // todo:examCollectionType 类型对应
         if (StringUtils.isBlank(studentBindIp)) {
             return AjaxResult.error("ip地址无效。");
         }
@@ -333,10 +333,10 @@ public class RealExamService {
         }
         // Step :ping通 学员端电脑。
         {
-            AjaxResult ar = commCheckService.checkPingStudentPcState(studentBindIp);
-            if (ar.isError()) {
-                return ar;
-            }
+//            AjaxResult ar = commCheckService.checkPingStudentPcState(studentBindIp);
+//            if (ar.isError()) {
+//                return ar;
+//            }
         }
         // Step :ping通 RS485。
         {
@@ -433,6 +433,20 @@ public class RealExamService {
         }
     }
 
+
+    public AjaxResult studentRefreshSimState(final String studentBindIp) {
+        Seat seat = seatService.uniqueByBindIp(studentBindIp);
+        {
+            if (seat == null) {
+                throw new IllegalArgumentException("XXX");
+            }
+        }
+        AjaxResult ar = commCheckService.checkOneSeatState(seat, true);
+        return ar;
+//                return AjaxResult.success("QWERT-nihao");
+    }
+
+
     public AjaxResult checkExamId(final Long examId) {
         // check
         // 检查 examId 是否正确存在