ソースを参照

主动查询一次模拟器状态。

tom 3 ヶ月 前
コミット
cf9be02dd1

+ 6 - 1
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommConst.java

@@ -56,9 +56,13 @@ public interface CommConst {
      */
     Long SLEEP_LONG = 200L;
     /**
+     * 请求间隔睡眠时间-mid
+     */
+    Long SLEEP_MID = 100L;
+    /**
      * 请求间隔睡眠时间-short
      */
-    Long SLEEP_SHORT = 50L;
+    Long SLEEP_SHORT = 64L;
 
     int SOCKET_TIME_OUT = 200;
 
@@ -76,6 +80,7 @@ public interface CommConst {
     int RETRY_COUNT_CLEAR_ONE_FAULT = 2;
     int RETRY_COUNT_WRITE_ONE_FAULT = 2;
     int RETRY_COUNT_READ_ONE_RESISTANCE = 4;
+    int RETRY_COUNT_QUERY_SN_IMPORTANT = 1;
     int RETRY_COUNT_0 = 0;
 
     int OFFLINE_LIMIT = 6;

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

@@ -5,6 +5,7 @@ import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.sim.config.SimConfig;
 import com.ruoyi.sim.config.SimDebugConfig;
 import com.ruoyi.sim.domain.*;
+import com.ruoyi.sim.domain.vo.SelectSysDeptVo;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -247,7 +248,10 @@ public class CommSendService {
         }
     }
 
-    public void checkOneSimState(final Sim s) {
+    /**
+     * @param s
+     */
+    public void checkOneSimState(final Sim s, final boolean important) {
         // check
         if (s == null) {
             return;
@@ -262,7 +266,12 @@ public class CommSendService {
         }
         //
         SimMsg smS = commBuildService.buildSendMsgReadSimType(s.getSimNum());
-        SimMsg smR = send(smS, s, RETRY_COUNT_0, SLEEP_SHORT);
+        int retryCount = RETRY_COUNT_0;
+        long sleep = SLEEP_SHORT;
+        if (important) {
+            retryCount = RETRY_COUNT_QUERY_SN_IMPORTANT;
+        }
+        SimMsg smR = send(smS, s, retryCount, sleep);
         if (StringUtils.isNotBlank(smR.getReceiveMsg())) {
             l.info("isNotBlank");
             commFailCountClearOne(s.getSimId());
@@ -279,7 +288,9 @@ public class CommSendService {
         if (ecF != null) {
             List<Sim> list = simService.listAllEnableBySimType(ecF.getSimType());
             l.info("checkAllSimState list.size() = {}", list.size());
-            list.forEach(this::checkOneSimState);
+            list.forEach(s -> {
+                checkOneSimState(s, false);
+            });
         }
     }
 
@@ -493,6 +504,14 @@ public class CommSendService {
                 return ar1;
             }
         }
+        // 主动查询一次模拟器状态
+        {
+            checkOneSimState(s, true);
+            // 如果模拟器离线
+            if (s == null || !Sim.State.ONLINE.equals(s.getSimState())) {
+                return AjaxResult.error("未连接模拟器,请检查连接!");
+            }
+        }
         // Step 2
         // msg判断,是否含有"故障部位"字符串
         {

+ 18 - 10
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/RealExamService.java

@@ -298,7 +298,7 @@ public class RealExamService {
             // re.setSimId(getFakeSimId(re));
             // l.info("fake re = {}", re);
         }
-        // check part.
+        // check id data.
         {
             AjaxResult arE1 = checkExamId(examId);
             if (arE1.isError()) {
@@ -306,28 +306,36 @@ public class RealExamService {
             }
         }
         RealExam re = selectRealExamByExamId(examId);
-        // Step 1 读取对应一台模拟器 所有故障部位值。检查模拟器所有的 真实的 故障部位 是否异常 或者 空值。
+        Sim s = simService.selectSimBySimId(re.getSimId());
+        // Step 1 主动查询一次模拟器状态
+        {
+            commSendService.checkOneSimState(s, true);
+            // 如果模拟器离线
+            if (s == null || !Sim.State.ONLINE.equals(s.getSimState())) {
+                return AjaxResult.error("未连接模拟器,请检查连接!");
+            }
+        }
+        // Step 2 读取对应一台模拟器 所有故障部位值。检查模拟器所有的 真实的 故障部位 是否异常 或者 空值。
         if (SimDebugConfig.CHECK_REPLACE_EMPTY) {
-            Sim sim = simService.selectSimBySimId(re.getSimId());
-            AjaxResult arE2 = commSendService.readOneSimAllFaultCheck(sim);
+            AjaxResult arE2 = commSendService.readOneSimAllFaultCheck(s);
             if (arE2.isError()) {
                 return arE2;
             }
         }
-        // Step 2 清除对应一台模拟器 所有故障部位故障。
+        // Step 3 清除对应一台模拟器 所有故障部位故障。
         {
             commSendService.clearOneSimAllFaultByExam(re);
         }
-        // Step 3 下发对应一台模拟器 出题选中的 故障位置故障。
+        // Step 4 下发对应一台模拟器 出题选中的 故障位置故障。
         {
             commSendService.writeOneSimAllSelectFaultByExam(re);
         }
-        // Step 4 读取对应一台模拟器 所有的 真实的 故障部位 电阻值 作为出题值。
+        // Step 5 读取对应一台模拟器 所有的 真实的 故障部位 电阻值 作为出题值。
         // 修改关联状态
         {
             commSendService.readOneSimAllFaultFirstTimeByExam(re);
         }
-        // Step 5 修改Exam状态
+        // Step 6 修改Exam状态
         if (realExamFaultService.isType2ExamPrepareStartOk(re.getExamId())) {
             updateOneState(re.getExamId(), RealExam.State.SIM_PREPARE_OK);
             updateOneState(re.getExamId(), RealExam.State.ANSWERING);
@@ -429,11 +437,11 @@ public class RealExamService {
                 return arE1;
             }
         }
-        // 最后检查一下模拟器状态。
+        // 检查一下模拟器状态。
         Sim s = simService.selectSimBySimId(re.getSimId());
         // 如果模拟器离线
         if (s == null || !Sim.State.ONLINE.equals(s.getSimState())) {
-            return AjaxResult.error("未连接维修模拟器,请检查连接!");
+            return AjaxResult.error("未连接模拟器,请检查连接!");
         }
         // 最后读取一下模拟器电阻值。
         commSendService.readOneExamAtLast(re);