Browse Source

最后一次和模拟器成功连接并通信的时间。添加测试日志。

tom 1 month ago
parent
commit
857da0d0f0

+ 1 - 1
ruoyi-sim/src/main/java/com/ruoyi/sim/controller/ConfigController.java

@@ -14,7 +14,7 @@ public class ConfigController {
 
     /**
      * http://192.168.1.151:8080/sim/config/set?key=CHECK_REPLACE_EMPTY&value=false
-     * http://192.168.1.60:8080/sim/config/set?key=CHECK_REPLACE_EMPTY&value=false
+     * http://192.168.1.110:8080/sim/config/set?key=CHECK_REPLACE_EMPTY&value=false
      * http://192.168.1.60:8080/sim/config/set?key=SCHEDULED_CONNECT&value=false
      *
      * @param key

+ 18 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/domain/Seat.java

@@ -1,11 +1,14 @@
 package com.ruoyi.sim.domain;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ruoyi.sim.domain.vo.SimSocketParamVo;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
 
+import java.util.Date;
+
 /**
  * 座对象 sim_seat
  *
@@ -63,6 +66,12 @@ public class Seat extends BaseEntity {
     @Excel(name = "模拟器的ID:[0]没有连接任何模拟器,[xx]:具体某台模拟器")
     private Long currentSimId;
 
+    /**
+     * 最后一次和模拟器成功连接并通信的时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date lastConnectedTime;
+
     public void setSeatId(Long seatId) {
         this.seatId = seatId;
     }
@@ -127,6 +136,14 @@ public class Seat extends BaseEntity {
         return currentSimId;
     }
 
+    public void setLastConnectedTime(Date lastConnectedTime) {
+        this.lastConnectedTime = lastConnectedTime;
+    }
+
+    public Date getLastConnectedTime() {
+        return lastConnectedTime;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
@@ -138,6 +155,7 @@ public class Seat extends BaseEntity {
                 .append("seatRs485SocketState", getSeatRs485SocketState())
                 .append("currentUserId", getCurrentUserId())
                 .append("currentSimId", getCurrentSimId())
+                .append("lastConnectedTime", getLastConnectedTime())
                 .append("createBy", getCreateBy())
                 .append("createTime", getCreateTime())
                 .append("updateBy", getUpdateBy())

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

@@ -1,9 +1,6 @@
 package com.ruoyi.sim.service.impl;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
@@ -14,6 +11,7 @@ import com.ruoyi.sim.domain.vo.RealExamVo;
 import com.ruoyi.sim.domain.vo.StudentRealExamIngVo;
 import com.ruoyi.sim.domain.vo.StudentRealExamPostVo;
 import com.ruoyi.sim.domain.vo.StudentRealExamPreVo;
+import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -299,16 +297,22 @@ public class RealExamService {
             if (realExamCollectionService.existOpenedByType(RealExamCollection.Type.EXAM)) {
                 return AjaxResult.error("存在打开的考试,无法开启训练!<br/>请向教员说明情况。");
             }
+        } else {
+            l.info("type EXERCISE,没有打开的考试,校验正确");
         }
         // Check:针对练习(自主练习),进行特殊检查。
         if (StringUtils.equals(RealExamCollection.Type.SELF_EXERCISE, examCollectionType)) {
             // 已经open的考试。
             if (realExamCollectionService.existOpenedByType(RealExamCollection.Type.EXAM)) {
                 return AjaxResult.error("存在打开的考试,无法开启练习!<br/>请向教员说明情况。");
+            } else {
+                l.info("type SELF_EXERCISE,没有打开的考试,校验正确");
             }
             // 已经open的训练。
             if (realExamCollectionService.existOpenedByType(RealExamCollection.Type.EXERCISE)) {
                 return AjaxResult.error("存在打开的训练,无法开启练习!<br/>请向教员说明情况。");
+            } else {
+                l.info("type SELF_EXERCISE,没有打开的训练,校验正确");
             }
         }
         // Check:检查参数examId有效性
@@ -324,32 +328,46 @@ public class RealExamService {
                 StringUtils.equals(re.getExamStatus(), RealExam.State.CALCULATING_SCORE) ||
                 StringUtils.equals(re.getExamStatus(), RealExam.State.GOT_REPORT)) {
             return AjaxResult.error("已经交卷,禁止重复开始考试!");
+        } else {
+            l.info("没有重复交卷校验正确");
         }
         RealExamCollection rec = realExamCollectionService.selectRealExamCollectionByExamCollectionId(re.getExamCollectionId());
         // Check:考试集合数据有效性。
         if (rec == null) {
             return AjaxResult.error("考试集合数据异常!");
+        } else {
+            l.info("考试集合数据校验正确");
         }
         if (!StringUtils.equals(rec.getExamCollectionState(), RealExamCollection.State.OPENED)) {
             return AjaxResult.error("教师端对应考试/训练尚未打开!<br/>请向教员说明情况。");
+        } else {
+            l.info("考试集合开启校验正确");
         }
         // Check:检查参数examCollectionType有效性
         if (!StringUtils.equals(examCollectionType, rec.getExamCollectionType())) {
             return AjaxResult.error("考试集合类型不对应!");
+        } else {
+            l.info("考试集合类型校验正确");
         }
         // Check:检查参数studentBindIp有效性
         if (StringUtils.isBlank(studentBindIp)) {
             return AjaxResult.error("IP地址无效");
+        } else {
+            l.info("IP地址检验正确");
         }
         Seat seat = seatService.uniqueByBindIp(studentBindIp);
         if (seat == null) {
             return AjaxResult.error("没有IP对应座次数据!");
+        } else {
+            l.info("座次数据检验正确");
         }
         // Check:ping通 路由器。
         {
             AjaxResult ar = commCheckService.checkRouterState(simConfig.getRouterIp());
             if (ar.isError()) {
                 return ar;
+            } else {
+                l.info("局域网通信校验正确");
             }
         }
         // Check:ping通 学员端电脑。
@@ -371,6 +389,7 @@ public class RealExamService {
                 return ar;
             } else {
                 // Ping通不代表在线,Socket连接建立表示在线。
+                l.info("RS485通信校验正确");
             }
         }
         // Check:如果有缓存Socket并且可用,使用缓存Socket,检查并建立Socket连接;否则返回对应错误。
@@ -378,6 +397,8 @@ public class RealExamService {
             AjaxResult ar = socketService.openOne(seat.toSimSocketParamVo());
             if (ar.isError()) {
                 return ar;
+            } else {
+                l.info("Socket校验正确");
             }
         }
         // Check:发送通用询问指令,询问是连接的哪种型号的哪一台模拟器;否则返回对应错误。
@@ -388,6 +409,8 @@ public class RealExamService {
             if (ar.get(AjaxResult.DATA_TAG) == null ||
                     !StringUtils.equals(((Sim) ar.get(AjaxResult.DATA_TAG)).getSimState(), Sim.State.ONLINE)) {
                 return AjaxResult.error((String) ar.get(AjaxResult.MSG_TAG));
+            } else {
+                l.info("Who模拟器校验正确");
             }
             // 其他的异常情况。
             if (ar.isError()) {
@@ -422,6 +445,8 @@ public class RealExamService {
             AjaxResult ar = commCheckService.checkOneSimOnlineState(seat.getCurrentSimId());
             if (ar.isError()) {
                 return ar;
+            } else {
+                l.info("模拟器在线校验正确");
             }
         }
         Sim sim = simService.selectSimBySimId(re.getSimId());
@@ -431,6 +456,8 @@ public class RealExamService {
             AjaxResult ar = commCheckService.checkOneSimType(seat, true, targetSimType);
             if (ar.isError()) {
                 return ar;
+            } else {
+                l.info("模拟器类型校验正确");
             }
         }
         // Step:可换件检查,读取对应一台模拟器 所有故障部位值。
@@ -439,19 +466,31 @@ public class RealExamService {
             AjaxResult ar = commSendService.readOneSimAllFaultCheck(seat, sim);
             if (ar.isError()) {
                 return ar;
+            } else {
+                l.info("模拟器可换件校验正确");
             }
         }
+        // 虚假的练习清单日志。
+        {
+//            if (rec != null) {
+//                l.info("start exam,exam id = {},sim type = {},使用练习清单task id = {}.",
+//                        re.getExamId(), re.getSimType(), RandomUtils.nextInt(100, 300));
+//            }
+        }
         // Step:清除对应一台模拟器 所有 真实的 故障部位故障。
         {
             commSendService.clearOneSimAllFaultByExam(re);
+            l.info("清除对应一台模拟器 所有 真实的 故障部位故障");
         }
         // Step:下发对应一台模拟器 出题选中的 故障位置故障。
         {
             commSendService.writeOneSimAllSelectFaultByExam(re);
+            l.info("下发对应一台模拟器 出题选中的 故障位置故障");
         }
         // Step:读取对应一台模拟器 所有的 真实的 故障部位 电阻值代表值 作为出题值。
         {
             commSendService.readOneSimAllFaultFirstTimeByExam(re);
+            l.info("读取对应一台模拟器 所有的 真实的 故障部位 电阻值代表值 作为出题值");
         }
         // Step:修改当前exam_id的考试状态。
         // 修改关联状态
@@ -461,6 +500,7 @@ public class RealExamService {
             // 修改真实考试开始时间。
             re.setStartTime(DateUtils.getNowDate());
             updateRealExam(re);
+            l.info("开始考试成功");
             return AjaxResult.success("开始考试成功!");
         } else {
             return AjaxResult.error("开始考试失败,<br/>请重新尝试开始考试!");
@@ -663,8 +703,6 @@ public class RealExamService {
 
         // Check:检查换学生端交卷的情况。
 
-        //
-
         // Step:最后读取一下模拟器电阻值。
         commSendService.readOneExamAtLast(re);
         // Step: