Browse Source

故障主键修改成常量。T0001.F09 故障临时强制写入。

tom 1 month ago
parent
commit
8a3eddf68c

+ 7 - 6
ruoyi-sim/src/main/java/com/ruoyi/sim/constant/FaultConst.java

@@ -26,11 +26,12 @@ public class FaultConst {
             // FAULT_SET_CHECK_PASS.add("0001GZBW0006");
             // 1型不存在
             // 2型
-            FAULT_SET_CHECK_PASS.add("0002GZBW0001");
-            FAULT_SET_CHECK_PASS.add("0002GZBW0003");
-            FAULT_SET_CHECK_PASS.add("0002GZBW0005");
+            FAULT_SET_CHECK_PASS.add(FaultIdConst.T0002.F01);
+            FAULT_SET_CHECK_PASS.add(FaultIdConst.T0002.F03);
+            FAULT_SET_CHECK_PASS.add(FaultIdConst.T0002.F05);
             // 3型
-            FAULT_SET_CHECK_PASS.add("0003GZBW0006");
+            FAULT_SET_CHECK_PASS.add(FaultIdConst.T0003.F06);
+            FAULT_SET_CHECK_PASS.add(FaultIdConst.T0003.F08);
         }
         {
             // 1型
@@ -48,9 +49,9 @@ public class FaultConst {
         }
         {
             // 2型
-            FAULT_SET_WHG.add("0002GZBW0009");
+            FAULT_SET_WHG.add(FaultIdConst.T0002.F09);
             // 3型
-            FAULT_SET_WHG.add("0003GZBW0007");
+            FAULT_SET_WHG.add(FaultIdConst.T0003.F07);
         }
     }
 }

+ 26 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/constant/FaultContentConst.java

@@ -0,0 +1,26 @@
+package com.ruoyi.sim.constant;
+
+public interface FaultContentConst {
+
+    /**
+     * 1型
+     */
+    interface T0001 {
+        String F09_OPENED = "00000001";
+        String F09_CLOSED = "00000002";
+    }
+
+    /**
+     * 2型
+     */
+    interface T0002 {
+
+    }
+
+    /**
+     * 3型
+     */
+    interface T0003 {
+
+    }
+}

+ 61 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/constant/FaultIdConst.java

@@ -0,0 +1,61 @@
+package com.ruoyi.sim.constant;
+
+/**
+ *
+ */
+public interface FaultIdConst {
+
+    /**
+     * 1型
+     */
+    interface T0001 {
+        String F01 = "0001GZBW0001";
+        String F02 = "0001GZBW0002";
+        String F03 = "0001GZBW0003";
+        String F04 = "0001GZBW0004";
+        String F05 = "0001GZBW0005";
+        String F06 = "0001GZBW0006";
+        String F07 = "0001GZBW0007";
+        String F08 = "0001GZBW0008";
+        String F09 = "0001GZBW0009";
+    }
+
+    /**
+     * 2型
+     */
+    interface T0002 {
+        String F01 = "0002GZBW0001";
+        String F02 = "0002GZBW0002";
+        String F03 = "0002GZBW0003";
+        String F04 = "0002GZBW0004";
+        String F05 = "0002GZBW0005";
+        String F06 = "0002GZBW0006";
+        String F07 = "0002GZBW0007";
+        String F08 = "0002GZBW0008";
+        String F09 = "0002GZBW0009";
+        String F0A = "0002GZBW000A";
+        String F0B = "0002GZBW000B";
+        String F0C = "0002GZBW000C";
+    }
+
+    /**
+     * 3型
+     */
+    interface T0003 {
+        String F01 = "0003GZBW0001";
+        String F02 = "0003GZBW0002";
+        String F03 = "0003GZBW0003";
+        String F04 = "0003GZBW0004";
+        String F05 = "0003GZBW0005";
+        String F06 = "0003GZBW0006";
+        String F07 = "0003GZBW0007";
+        String F08 = "0003GZBW0008";
+        String F09 = "0003GZBW0009";
+        String F0A = "0003GZBW000A";
+        String F0B = "0003GZBW000B";
+        String F0C = "0003GZBW000C";
+        String F0D = "0003GZBW000D";
+        String F0E = "0003GZBW000E";
+        String F0F = "0003GZBW000F";
+    }
+}

+ 7 - 2
ruoyi-sim/src/main/java/com/ruoyi/sim/domain/SimMsg.java

@@ -271,9 +271,9 @@ public class SimMsg extends BaseEntity {
         } else if (Objects.equals(this.result, Result.READ_TIMEOUT_EXCEPTION)) {
             return AjaxResult.error("模拟器通信超时!");
         } else if (Objects.equals(this.result, Result.RECEIVE_CHECK_FAIL)) {
-            return AjaxResult.error("回复报文格式错误!");
+            return AjaxResult.error("回复报文格式错误!<br/>系统自动尝试重新连接,请3秒后重新尝试开始考试!");
         } else if (Objects.equals(this.result, Result.RECEIVE_NOT_MATCH)) {
-            return AjaxResult.error("回复报文不匹配!");
+            return AjaxResult.error("回复报文不匹配!<br/>系统自动尝试重新连接,请3秒后重新尝试开始考试!");
         } else {
             // throw new IllegalArgumentException("参数错误!");
         }
@@ -306,6 +306,11 @@ public class SimMsg extends BaseEntity {
          */
         Integer RECEIVE_NOT_MATCH = 530;
         /**
+         * 报文校验码错误。
+         * todo:没有启用。
+         */
+        Integer VERIFY_ERROR = 540;
+        /**
          * 重要报文在运行,低优先级的跳过
          */
         Integer SKIP = 600;

+ 28 - 18
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommReceiveService.java

@@ -3,6 +3,8 @@ 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.constant.FaultContentConst;
+import com.ruoyi.sim.constant.FaultIdConst;
 import com.ruoyi.sim.domain.*;
 import com.ruoyi.sim.domain.vo.FaultCheckVo;
 import com.ruoyi.sim.util.CRC16Modbus;
@@ -65,6 +67,10 @@ public class CommReceiveService {
         }
         l.info("faultQuestionValue = {}", faultQuestionValue);
         if (reF != null) {
+            // todo:临时强制写入
+            if (f != null && StringUtils.equals(f.getFaultId(), FaultIdConst.T0001.F09)) {
+                faultQuestionValue = FaultContentConst.T0001.F09_OPENED;
+            }
             // 修改关联状态。
             reF.setSimFaultQuestionValue(faultQuestionValue);
             realExamFaultService.updateRealExamFault(reF);
@@ -124,6 +130,10 @@ public class CommReceiveService {
                 l.info("nothing change.");
                 return;
             }
+            // todo:临时强制写入
+            if (f != null && StringUtils.equals(f.getFaultId(), FaultIdConst.T0001.F09)) {
+                faultAnswerValue = FaultContentConst.T0001.F09_CLOSED;
+            }
             reF.setSimFaultAnswerValue(faultAnswerValue);
             realExamFaultService.updateRealExamFault(reF);
         } else {
@@ -179,24 +189,24 @@ public class CommReceiveService {
         }
         // 是否在 故障部位 跳过检查 白名单中。
         if (FaultConst.FAULT_SET_CHECK_PASS.contains(f.getFaultId())) {
-            // 跳过检查,直接成功。
             vo.setErrorMsg("");
             vo.setCheckOk(true);
+            // 跳过检查,直接返回成功。
             return AjaxResult.success(vo);
         }
-        // 是否是 2型的 检测干燥管 或 3型的 检测干燥管
+        // 是否是
+        // 2型的 检测干燥管 或
+        // 3型的 检测干燥管
         if (FaultConst.FAULT_SET_WHG.contains(f.getFaultId())) {
             // 判断必须存在
             String WHG_EXIST_MSG = checkValue.substring(4, 6);
-            if (WHG_MSG_EXIST_YES.equals(WHG_EXIST_MSG)) {
-                vo.setCheckOk(true);
-                return AjaxResult.success(vo);
-            } else {
-                String eMsg = "[" + f.getReplaceName() + "]可换件异常;<br>";
+            if (!WHG_MSG_EXIST_YES.equals(WHG_EXIST_MSG)) {
+                String eMsg = "[" + f.getReplaceName() + "]可换件异常;<br>" +
+                        "请正确安装[" + f.getReplaceName() + "]后再次开始考试。<br>";
                 l.info(eMsg);
                 vo.setErrorMsg(eMsg);
                 vo.setCheckOk(false);
-                return AjaxResult.success(vo);
+                return AjaxResult.error(eMsg, vo);
             }
         }
         // 非空判断
@@ -205,7 +215,7 @@ public class CommReceiveService {
             l.info(eMsg);
             vo.setErrorMsg(eMsg);
             vo.setCheckOk(false);
-            return AjaxResult.success(vo);
+            return AjaxResult.error(eMsg, vo);
         }
         // final ok.
         vo.setErrorMsg("");
@@ -232,38 +242,38 @@ public class CommReceiveService {
     /**
      * 有返回报文的情况下,检查Receive的报文格式。
      *
-     * @param receiveMsg
+     * @param rMsg
      * @return
      */
-    public AjaxResult checkReceiveMsgFormat(final String receiveMsg) {
-        l.info("####checkReceiveMsg#### = [{}]", receiveMsg);
+    public AjaxResult checkReceiveMsgFormat(final String rMsg) {
+        l.info("####checkReceiveMsg#### = [{}]", rMsg);
         String msgErr = "ReceiveMsg ";
         // check:不能是empty
-        if (StringUtils.isBlank(receiveMsg)) {
+        if (StringUtils.isBlank(rMsg)) {
             return AjaxResult.error(msgErr + "isBlank");
         }
         // check:长度
-        if (receiveMsg.length() != LENGTH_24) {
+        if (rMsg.length() != LENGTH_24) {
             return AjaxResult.error(msgErr + "length error.length not 24.");
         }
         // check:数据方向
-        final String orn = StringUtils.substring(receiveMsg, 4, 6);
+        final String orn = StringUtils.substring(rMsg, 4, 6);
         if (!ORN_RECEIVE.equals(orn)) {
             return AjaxResult.error(msgErr + "orn error.");
         }
         // check:前缀
-        if (!StringUtils.startsWith(receiveMsg, PREFIX)) {
+        if (!StringUtils.startsWith(rMsg, PREFIX)) {
             return AjaxResult.error(msgErr + "not start with AA.");
         }
         // check:后缀
-        if (!StringUtils.endsWith(receiveMsg, SUFFIX)) {
+        if (!StringUtils.endsWith(rMsg, SUFFIX)) {
             return AjaxResult.error(msgErr + "not end with 55.");
         }
         // 计算CRC16
         // todo:
         // todo: receive报文检验错误。
         if (false) {
-            String crcContent = receiveMsg.substring(0, 18);
+            String crcContent = rMsg.substring(0, 18);
             l.debug("crcContent: {}", crcContent.toUpperCase());
             byte[] receiveByteContent = CommSendService.hexStrToByteArrs(crcContent);
             byte[] receiveByteCrc = CRC16Modbus.calculateCRC(receiveByteContent);

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

@@ -115,8 +115,7 @@ public class CommSendService {
                 if (refQ == null || refQ.getExamId() == 0L) {
                     continue;
                 }
-                if (!RealExamFault.State.WRITTEN.equals(ref.getRefState()) &&
-                        !RealExamFault.State.LOOP_READ.equals(ref.getRefState())) {
+                if (!RealExamFault.State.WRITTEN.equals(ref.getRefState()) && !RealExamFault.State.LOOP_READ.equals(ref.getRefState())) {
                     continue;
                 }
             }
@@ -559,8 +558,7 @@ public class CommSendService {
      * @return
      * @throws IOException
      */
-    public SimMsg debugWriteOneFault(final Long seatId,
-                                     final String bindHardwareMsg) {
+    public SimMsg debugWriteOneFault(final Long seatId, final String bindHardwareMsg) {
         Seat seat = seatService.selectSeatBySeatId(seatId);
         Sim sim = getSimBySeatIdNewVer(seatId);
         SimMsg sm = commBuildService.buildSendMsgWriteFault(sim.getSimNum(), bindHardwareMsg);
@@ -773,16 +771,20 @@ public class CommSendService {
                 voOne.setSim(sim);
                 voOne.setFault(oneF);
                 AjaxResult ar = readOneSimOneFaultCheck(voOne);
+                // getDefaultErrorAR voReturn 可能为空
                 FaultCheckVo voReturn = (FaultCheckVo) ar.get(AjaxResult.DATA_TAG);
-                if (!voReturn.isCheckOk()) {
-                    l.info("log 故障部位[" + oneF.getBindHardwareMsg() + "][" + oneF.getReplaceName() + "]未正确安装;");
-                    listNGVo.add(voReturn);
-                    // add map.
-                    // mapVo.put(buildKey(voReturn.getSim().getSimType(), voReturn.getFault().getBindHardwareMsg()), voReturn);
-                    setNG.add(oneF.getFaultId());
-                } else {
-                    l.info("log 故障部位[" + oneF.getBindHardwareMsg() + "][" + oneF.getReplaceName() + "]安装ok;");
+                if (voReturn != null) {
+                    if (voReturn.isCheckOk()) {
+                        l.info("log 故障部位[" + oneF.getBindHardwareMsg() + "][" + oneF.getReplaceName() + "]安装ok;");
+                    } else {
+                        l.info("log 故障部位[" + oneF.getBindHardwareMsg() + "][" + oneF.getReplaceName() + "]未正确安装;");
+                        listNGVo.add(voReturn);
+                        // add map.
+                        // mapVo.put(buildKey(voReturn.getSim().getSimType(), voReturn.getFault().getBindHardwareMsg()), voReturn);
+                        setNG.add(oneF.getFaultId());
+                    }
                 }
+                // readOneSimOneFaultCheck 得出ar有问题直接返回
                 if (ar.isError()) {
                     return ar;
                 }
@@ -830,12 +832,7 @@ public class CommSendService {
 //
 //                }
 //            }
-            if (setNG != null &&
-                    setNG.contains("0003GZBW0003") &&
-                    setNG.contains("0003GZBW0004") &&
-                    setNG.contains("0003GZBW000B") &&
-                    setNG.contains("0003GZBW000E")
-            ) {
+            if (setNG != null && setNG.contains("0003GZBW0003") && setNG.contains("0003GZBW0004") && setNG.contains("0003GZBW000B") && setNG.contains("0003GZBW000E")) {
                 return AjaxResult.error("请检查 显控报警板与主板连接线 连接情况!");
             }
         }
@@ -853,6 +850,14 @@ public class CommSendService {
         SimMsg smS = commBuildService.buildSendMsgReadFaultResistance(vo.getSim().getSimNum(), vo.getFault().getBindHardwareMsg());
         SimMsg smR = send(smS, vo.getSeat(), vo.getSim(), RETRY_COUNT_CHECK_ONE_FAULT, commStrategy.getSleepLong());
         if (smR.isResultNotOk()) {
+            if (Objects.equals(smR.getResult(), SimMsg.Result.RECEIVE_CHECK_FAIL) ||
+                    (Objects.equals(smR.getResult(), SimMsg.Result.RECEIVE_NOT_MATCH))) {
+                l.info("reset connection!");
+                String ip = vo.getSeat().getSeatRs485Ip();
+                Integer port = vo.getSeat().getSeatRs485Port();
+                SimSocketParamVo sspv = new SimSocketParamVo(ip, port);
+                socketService.closeOne(sspv, true);
+            }
             return smR.getDefaultErrorAR();
         }
         // set send and receive msg.
@@ -915,8 +920,7 @@ public class CommSendService {
      * @param bindHardwareMsg
      * @return
      */
-    public SimMsg debugReadOneFaultResistance(final Long seatId,
-                                              final String bindHardwareMsg) {
+    public SimMsg debugReadOneFaultResistance(final Long seatId, final String bindHardwareMsg) {
         Seat seat = seatService.selectSeatBySeatId(seatId);
         Sim sim = getSimBySeatIdNewVer(seatId);
         SimMsg sm = commBuildService.buildSendMsgReadFaultResistance(sim.getSimNum(), bindHardwareMsg);
@@ -951,14 +955,11 @@ public class CommSendService {
         SimMsg sm2 = null;
         if (reF != null && refState != null) {
             if (RealExamFault.State.FINISH.equals(refState)) { // 是否最后一次读取。
-                sm2 = send(sm1, seat, sim,
-                        RETRY_COUNT_READ_ONE_RESISTANCE_FINAL, commStrategy.getSleepShort());
+                sm2 = send(sm1, seat, sim, RETRY_COUNT_READ_ONE_RESISTANCE_FINAL, commStrategy.getSleepShort());
             } else if (RealExamFault.State.LOOP_READ.equals(refState)) { // 是否是中间读取
-                sm2 = send(sm1, seat, sim,
-                        RETRY_COUNT_READ_ONE_RESISTANCE_MIDDLE, commStrategy.getSleepShort(), false);
+                sm2 = send(sm1, seat, sim, RETRY_COUNT_READ_ONE_RESISTANCE_MIDDLE, commStrategy.getSleepShort(), false);
             } else {
-                sm2 = send(sm1, seat, sim,
-                        RETRY_COUNT_0, commStrategy.getSleepShort());
+                sm2 = send(sm1, seat, sim, RETRY_COUNT_0, commStrategy.getSleepShort());
             }
         } else {
             sm2 = send(sm1, seat, sim, RETRY_COUNT_READ_ONE_RESISTANCE_FINAL, commStrategy.getSleepShort());
@@ -966,8 +967,7 @@ public class CommSendService {
         simReceiveService.setFaultAnswerValue(sm2, sim, reF, f, refState);
     }
 
-    public SimMsg send(final SimMsg sm, final Seat seat, final Sim sim,
-                       final int retryTotalCount, final long sleep) {
+    public SimMsg send(final SimMsg sm, final Seat seat, final Sim sim, final int retryTotalCount, final long sleep) {
         return send(sm, seat, sim, retryTotalCount, sleep, true);
     }
 
@@ -985,8 +985,7 @@ public class CommSendService {
      * @param importantTask
      * @return
      */
-    public SimMsg send(final SimMsg sm, final Seat seat, final Sim sim,
-                       final int retryTotalCount, final long sleep, final boolean importantTask) {
+    public SimMsg send(final SimMsg sm, final Seat seat, final Sim sim, final int retryTotalCount, final long sleep, final boolean importantTask) {
         if (!config.isCommGlobal()) {
             l.warn("isCommGlobal == false [模拟器通信被禁用!]");
             return sm;