Pārlūkot izejas kodu

添加模拟器序列号检查。

tom 3 mēneši atpakaļ
vecāks
revīzija
ffaf58cbae

+ 4 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/domain/Sim.java

@@ -165,6 +165,10 @@ public class Sim extends BaseEntity {
      */
     public static final String TYPE_0003 = "0003";
 
+    public static final String TYPE_0001_SN = "01";
+    public static final String TYPE_0002_SN = "02";
+    public static final String TYPE_0003_SN = "03";
+
     public static final Set<String> TYPE_SET = new HashSet<>(Arrays.asList(TYPE_0001, TYPE_0002, TYPE_0003));
 
     public static final String TYPE_0001_NAME = "FZD04B";

+ 40 - 9
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommReceiveService.java

@@ -1,7 +1,6 @@
 package com.ruoyi.sim.service.impl;
 
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.sim.constant.CommConst;
 import com.ruoyi.sim.constant.FaultConst;
 import com.ruoyi.sim.domain.*;
 import org.apache.commons.lang3.StringUtils;
@@ -36,15 +35,47 @@ public class CommReceiveService {
      *
      * @param sm
      * @param s
+     * @return
      */
-    public void checkOneSimState(SimMsg sm, Sim s) {
+    public AjaxResult checkOneSimState(SimMsg sm, Sim s) {
         if (s == null) {
             l.warn("s is null");
-            return;
+            return AjaxResult.error("sim is null");
         }
         if (StringUtils.isNotBlank(sm.getReceiveMsg())) {
             simService.updateSimStateBySimId(s.getSimId(), Sim.State.ONLINE);
         }
+        return AjaxResult.success();
+    }
+
+    public AjaxResult checkOneSimSn(SimMsg sm, Sim s) {
+        final String simType = s.getSimType();
+        final String r = sm.getReceiveMsg();
+        final String msgError = "连接模拟器类型不正确!";
+        switch (simType) {
+            case Sim.TYPE_0001 -> {
+                if (r.startsWith(Sim.TYPE_0001_SN) && r.endsWith(s.getSimNum())) {
+                    return AjaxResult.success();
+                } else {
+                    return AjaxResult.error(msgError);
+                }
+            }
+            case Sim.TYPE_0002 -> {
+                if (r.startsWith(Sim.TYPE_0002_SN) && r.endsWith(s.getSimNum())) {
+                    return AjaxResult.success();
+                } else {
+                    return AjaxResult.error(msgError);
+                }
+            }
+            case Sim.TYPE_0003 -> {
+                if (r.startsWith(Sim.TYPE_0003_SN) && r.endsWith(s.getSimNum())) {
+                    return AjaxResult.success();
+                } else {
+                    return AjaxResult.error(msgError);
+                }
+            }
+            default -> throw new IllegalStateException("Unexpected value: " + simType);
+        }
     }
 
     public void clearOneFault(SimMsg sm, Sim s, RealExamFault reF, Fault f) {
@@ -70,7 +101,7 @@ public class CommReceiveService {
         // check
 
         //
-        String faultQuestionValue = parseGetData(sm.getReceiveMsg());
+        String faultQuestionValue = subContentData(sm.getReceiveMsg());
         // todo:
         if (StringUtils.isBlank(faultQuestionValue)) {
             l.warn("faultQuestionValue is empty!");
@@ -137,7 +168,7 @@ public class CommReceiveService {
     public void setFaultAnswerValue(SimMsg sm, Sim s, RealExamFault reF, Fault f, String refState) {
         // check
         //
-        String faultAnswerValue = parseGetData(sm.getReceiveMsg());
+        String faultAnswerValue = subContentData(sm.getReceiveMsg());
         // todo:
         if (StringUtils.isBlank(faultAnswerValue)) {
             l.warn("faultAnswerValue is empty!");
@@ -171,7 +202,7 @@ public class CommReceiveService {
      * @param receiveMsg
      * @return
      */
-    public String parseGetData(String receiveMsg) {
+    public String subContentData(String receiveMsg) {
         if (StringUtils.isEmpty(receiveMsg)) {
             return "";
         }
@@ -187,7 +218,7 @@ public class CommReceiveService {
      * @return
      */
     public AjaxResult getOneFaultCheck(SimMsg sm, Sim s, Fault f) {
-        String checkValue = parseGetData(sm.getReceiveMsg());
+        String checkValue = subContentData(sm.getReceiveMsg());
         if (s == null) {
             return AjaxResult.error("没有对应模拟器!");
         }
@@ -200,13 +231,13 @@ public class CommReceiveService {
         if (FaultConst.FAULT_SET_WHG.contains(f.getFaultId())) {
             // 判断必须存在
             String WHG_EXIST_MSG = checkValue.substring(4, 6);
-            if (CommConst.WHG_MSG_EXIST_YES.equals(WHG_EXIST_MSG)) {
+            if (WHG_MSG_EXIST_YES.equals(WHG_EXIST_MSG)) {
                 return AjaxResult.success(f);
             } else {
                 return AjaxResult.error("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;", f);
             }
         }
-        if (CommConst.BLANK_CONTENT.equals(checkValue)) {
+        if (BLANK_CONTENT.equals(checkValue)) {
             l.info("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;");
             return AjaxResult.error("故障部位[" + f.getBindHardwareMsg() + "][" + f.getReplaceName() + "]未正确安装;", f);
         } else {

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

@@ -256,10 +256,15 @@ public class CommSendService {
      * @return
      */
     public AjaxResult checkOneSimStateActive(Sim s) {
-        long simId = s.getSimId();
-        // 这句可能会调整模拟器状态
-        checkOneSimState(s, true);
-        //
+        final long simId = s.getSimId();
+        // 这句可能会调整模拟器状态,后面需要重新查询。
+        {
+            AjaxResult ar1 = checkOneSimState(s, true);
+            if (ar1.isError()) {
+                return ar1;
+            }
+        }
+        // 重新最新模拟器。
         s = simService.selectSimBySimId(simId);
         // 如果模拟器离线
         if (s != null && Sim.State.ONLINE.equals(s.getSimState())) {
@@ -271,19 +276,22 @@ public class CommSendService {
 
     /**
      * @param s
+     * @param important true 重试次数不同,也会进行序列号检查。
+     * @return
      */
-    public void checkOneSimState(final Sim s, final boolean important) {
+    public AjaxResult checkOneSimState(final Sim s, final boolean important) {
         // check
         if (s == null) {
-            return;
+            return AjaxResult.error("sim is null");
         }
         if (Sim.State.DISABLE.equals(s.getSimState())) {
             l.warn("sim DISABLE,模拟器被禁用,sim = {}", s);
-            return;
+            return AjaxResult.error("模拟器被禁用");
         }
         if (StringUtils.isBlank(s.getSimType()) || StringUtils.isBlank(s.getSimNum())) {
             l.warn("sim error data {}", s);
-            return;
+            return AjaxResult.error("模拟器数据错误。");
+            ;
         }
         //
         SimMsg smS = commBuildService.buildSendMsgReadSimType(s.getSimNum());
@@ -298,6 +306,15 @@ public class CommSendService {
             commFailCountClearOne(s.getSimId());
         }
         simReceiveService.checkOneSimState(smR, s);
+        {
+            if (important) {
+                AjaxResult ar1 = simReceiveService.checkOneSimSn(smR, s);
+                if (ar1.isError()) {
+                    return ar1;
+                }
+            }
+        }
+        return AjaxResult.success();
     }
 
     /**