Преглед изворни кода

处理报文前端加00的情况,最多可能加5组00。调试模式下,两个清除按钮,都删除DebugFault表所有数据。

tom пре 2 месеци
родитељ
комит
23182ec2e4

+ 6 - 3
ruoyi-admin/src/main/resources/application.yml

@@ -87,6 +87,7 @@ spring:
     # database: 2
     # server-其他
     database: 0
+    # database: 2
     # 密码
     # server-阿里云47
     # password: Z*eQ8xXK7ryYynFv
@@ -151,11 +152,13 @@ xss:
 # com.ruoyi.sim.config.SimConfig
 sim-module-config:
   # 123.112.16.165
-  routerIp: 192.168.1.199
+  # routerIp: 221.218.212.74
+  routerIp: 192.168.1.1
   # 123.112.16.165
-  rs485Ip: 192.168.1.199
+  # rs485Ip: 221.218.212.74
+  rs485Ip: 192.168.1.202
   #
-  rs485Port: 8899
+  rs485Port: 11008
   #
   commGlobal: true
   #

+ 27 - 20
ruoyi-sim/src/main/java/com/ruoyi/sim/domain/SimMsg.java

@@ -82,6 +82,8 @@ public class SimMsg extends BaseEntity {
     @Excel(name = "接收报文")
     private String receiveMsg;
 
+    private String receiveOriginalMsg;
+
     /**
      * 接收时间
      */
@@ -185,6 +187,14 @@ public class SimMsg extends BaseEntity {
         return receiveMsg;
     }
 
+    public String getReceiveOriginalMsg() {
+        return receiveOriginalMsg;
+    }
+
+    public void setReceiveOriginalMsg(String receiveOriginalMsg) {
+        this.receiveOriginalMsg = receiveOriginalMsg;
+    }
+
     public void setReceiveTime(Date receiveTime) {
         this.receiveTime = receiveTime;
     }
@@ -220,28 +230,25 @@ public class SimMsg extends BaseEntity {
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
-                .append("simMsgId", getSimMsgId())
-                .append("simId", getSimId())
-                .append("examFaultRefId", getExamFaultRefId())
-                .append("examCollectionType", getExamCollectionType())
-                .append("sendMsgState", getSendMsgState())
-                .append("priority", getPriority())
-                .append("sendMsgType", getSendMsgType())
-                .append("sendMsg", getSendMsg())
-                .append("sendTime", getSendTime())
-                .append("receiveMsg", getReceiveMsg())
-                .append("receiveTime", getReceiveTime())
-                .append("retryCount", getRetryCount())
-                .append("ok", getOk())
-                .append("errorMsg", getErrorMsg())
-                .append("createBy", getCreateBy())
-                .append("createTime", getCreateTime())
-                .append("updateBy", getUpdateBy())
-                .append("updateTime", getUpdateTime())
-                .append("remark", getRemark())
+                .append("simMsgId", simMsgId)
+                .append("simId", simId)
+                .append("examFaultRefId", examFaultRefId)
+                .append("examCollectionType", examCollectionType)
+                .append("sendMsgState", sendMsgState)
+                .append("priority", priority)
+                .append("sendMsgType", sendMsgType)
+                .append("sendMsg", sendMsg)
+                .append("sendTime", sendTime)
+                .append("receiveMsg", receiveMsg)
+                .append("receiveOriginalMsg", receiveOriginalMsg)
+                .append("receiveTime", receiveTime)
+                .append("retryCount", retryCount)
+                .append("ok", ok)
+                .append("errorMsg", errorMsg)
                 .toString();
     }
-    // -------------------------------- tom add  --------------------------------
+
+// -------------------------------- tom add  --------------------------------
 
     public SimMsg() {
     }

+ 22 - 16
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommReceiveService.java

@@ -256,43 +256,49 @@ public class CommReceiveService {
     }
 
     /**
+     * 处理报文前端加00的情况,最多可能加5组00
+     * @param receiveMsg
+     * @return
+     */
+    public String removeRrefix0(String receiveMsg) {
+        int count = 0;
+        while (StringUtils.startsWith(receiveMsg, CommConst.PREFIX_ERROR_0)) {
+            receiveMsg = StringUtils.removeStartIgnoreCase(receiveMsg, CommConst.PREFIX_ERROR_0);
+            count = count + 1;
+        }
+        l.info("####remove count#### = [{}]", count);
+        return receiveMsg;
+    }
+
+    /**
      * check receiveMsg
      *
      * @param receiveMsg
      * @return
      */
-    public AjaxResult checkReceiveMsg(String receiveMsg) {
+    public AjaxResult checkReceiveMsg(final String receiveMsg) {
         l.info("####checkReceiveMsg#### = [{}]", receiveMsg);
-        String start = "ReceiveMsg ";
+        String msgErr = "ReceiveMsg ";
         // check:不能是empty
         if (StringUtils.isBlank(receiveMsg)) {
-            return AjaxResult.error(start + "isBlank");
-        }
-        // check:处理报文前端加00的情况,最多可能加5组00
-        {
-            int count = 0;
-            while (StringUtils.startsWith(receiveMsg, CommConst.PREFIX_ERROR_0)) {
-                receiveMsg = StringUtils.removeStartIgnoreCase(receiveMsg, CommConst.PREFIX_ERROR_0);
-                count = count + 1;
-            }
-            l.info("####remove count#### = [{}]", count);
+            return AjaxResult.error(msgErr + "isBlank");
         }
         // check:长度
         if (receiveMsg.length() != LENGTH_24) {
-            return AjaxResult.error(start + "length error.length not 24.");
+            return AjaxResult.error(msgErr + "length error.length not 24.");
         }
         // check:数据方向
         final String orn = StringUtils.substring(receiveMsg, 4, 6);
         if (!ORN_RECEIVE.equals(orn)) {
-            return AjaxResult.error(start + "orn error.");
+            return AjaxResult.error(msgErr + "orn error.");
         }
         // check:前缀
         if (!StringUtils.startsWith(receiveMsg, PREFIX)) {
-            return AjaxResult.error(start + "not start with AA.");
+            return AjaxResult.error(msgErr + "not start with AA.");
         }
         // check:后缀
         if (!StringUtils.endsWith(receiveMsg, SUFFIX)) {
-            return AjaxResult.error(start + "not end with 55.");
+            return AjaxResult.error(msgErr + "not end with 55.");
         }
         // 计算CRC16
         // todo:

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

@@ -11,6 +11,7 @@ import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -432,6 +433,7 @@ public class CommSendService {
         simService.listAllOnline().forEach(s -> {
             AjaxResult ar = debugClearAllFaultBySimNum(s.getSimNum());
         });
+        debugFaultService.deleteAll();
         return AjaxResult.success("清除成功,清除所有在线模拟器所有故障!");
     }
 
@@ -441,29 +443,31 @@ public class CommSendService {
      * @param simNum
      * @return
      */
+    @Transactional
     public AjaxResult debugClearAllFaultBySimNum(final String simNum) {
-        Sim s1 = simService.uniqueBySimNum(simNum);
+        Sim s = simService.uniqueBySimNum(simNum);
         {
-            AjaxResult arE3 = checkOneSimStateActive(s1);
+            AjaxResult arE3 = checkOneSimStateActive(s);
             if (arE3.isError()) {
                 return arE3;
             }
         }
-        s1 = simService.uniqueBySimNum(simNum);
-        if (s1 == null) {
+        s = simService.uniqueBySimNum(simNum);
+        if (s == null) {
             return AjaxResult.error("清除失败,对应simNum模拟器不存在!");
         }
-        if (!Sim.State.ONLINE.equals(s1.getSimState())) {
+        if (!Sim.State.ONLINE.equals(s.getSimState())) {
             return AjaxResult.error("清除失败,模拟器尚未在线!");
         }
         List<SimMsg> list = new ArrayList<>();
-        for (String b : getGZBWBySimType(s1.getSimType())) {
+        for (String b : getGZBWBySimType(s.getSimType())) {
             SimMsg sm = debugClearOneFault(simNum, b);
             list.add(sm);
             if (sm != null && !sm.getOk()) {
 
             }
         }
+        debugFaultService.deleteAll();
         return AjaxResult.success("清除成功,清除当前模拟器所有故障!");
     }
 
@@ -540,6 +544,7 @@ public class CommSendService {
      * @param checkReplace 是否进行可换件检查
      * @return
      */
+    @Transactional
     public AjaxResult debugWriteSelectedFaultBySimNum(final String simNum,
                                                       final String[] faultIds,
                                                       final Boolean checkReplace) {
@@ -842,14 +847,16 @@ public class CommSendService {
             for (int i = 0; i < length; i++) {
                 sbHex.append(String.format("%02X", buffer[i]));
             }
-            sm.setReceiveMsg(sbHex.toString());
+            String receiveWith0 = sbHex.toString();
+            sm.setReceiveOriginalMsg(receiveWith0);
+            sm.setReceiveMsg(commReceiveService.removeRrefix0(receiveWith0));
             sm.setReceiveTime(DateUtils.getNowDate());
             // log.
             {
                 l.info("####ReceiveMsg#### = [{}]", sm);
             }
             {
-                AjaxResult ar =    commReceiveService.checkReceiveMsg(sm.getReceiveMsg());
+                AjaxResult ar = commReceiveService.checkReceiveMsg(sm.getReceiveMsg());
                 if (ar.isError()) {
                     // todo:
                     l.warn("####Fail#### = {}", sm);

+ 0 - 2
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/DebugFaultService.java

@@ -103,11 +103,9 @@ public class DebugFaultService {
         return null;
     }
 
-    @Transactional
     public int deleteAll() {
         DebugFault q = new DebugFault();
         List<DebugFault> list = selectDebugFaultList(q);
-        Long[] refIds = new Long[list.size()];
         for (int i = 0; i < list.size(); i++) {
             deleteDebugFaultByRefId(list.get(i).getRefId());
         }

+ 4 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/SeatService.java

@@ -96,4 +96,8 @@ public class SeatService {
         }
         return true;
     }
+
+    public List<Seat> all() {
+        return seatMapper.selectSeatList(new Seat());
+    }
 }