Browse Source

计算减分 + 判断对错。

tom 3 months ago
parent
commit
0c524734c5

+ 3 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/constant/CommConst.java

@@ -43,6 +43,9 @@ public interface CommConst {
 
     String ANSWER_RIGHT = "00000000";
     String ANSWER_WRONG = "00000001";
+
+    String ANSWER_LAST_RIGHT_MSG = "00";
+    String ANSWER_LAST_WRONG_MSG = "01";
     String WHG_MSG_EXIT_NO = "00";
     String WHG_MSG_EXIST_YES = "01";
 

+ 1 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommSendService.java

@@ -140,6 +140,7 @@ public class CommSendService {
     }
 
     /**
+     *
      * 计算减分(不包括超时)。汇总到deduction_total_score字段。
      *
      * @param realExamId

+ 55 - 39
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/RealExamFaultService.java

@@ -4,7 +4,10 @@ import java.util.ArrayList;
 import java.util.List;
 
 import com.github.jsonzou.jmockdata.JMockData;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.sim.constant.CommConst;
+import com.ruoyi.sim.constant.FaultConst;
 import com.ruoyi.sim.domain.vo.RealExamFaultReportPart1Vo;
 import com.ruoyi.sim.domain.vo.RealExamFaultReportPart2Vo;
 import com.ruoyi.sim.domain.vo.RealExamFaultReportPart3Vo;
@@ -150,18 +153,16 @@ public class RealExamFaultService {
      */
     @Transactional
     public void resetAllType2(final Long examId) {
-        listAllType2(examId)
-                .stream()
-                .forEach(ref -> {
-                    ref.setRefState(RealExamFault.State.INIT);
-                    ref.setAnswerRight(RealExamFault.AnswerRight.UNKNOWN);
-                    ref.setChoiceQuestionValue("");
-                    ref.setChoiceAnswerValue("");
-                    ref.setSimFaultQuestionValue("");
-                    ref.setSimFaultAnswerValue("");
-                    ref.setMinus(0L);
-                    updateRealExamFault(ref);
-                });
+        listAllType2(examId).stream().forEach(ref -> {
+            ref.setRefState(RealExamFault.State.INIT);
+            ref.setAnswerRight(RealExamFault.AnswerRight.UNKNOWN);
+            ref.setChoiceQuestionValue("");
+            ref.setChoiceAnswerValue("");
+            ref.setSimFaultQuestionValue("");
+            ref.setSimFaultAnswerValue("");
+            ref.setMinus(0L);
+            updateRealExamFault(ref);
+        });
     }
 
     public void reset(final Long examId) {
@@ -276,54 +277,69 @@ public class RealExamFaultService {
     }
 
     /**
-     * 计算减分。
+     * 计算减分 + 判断对错
      *
      * @param refId
+     * @return 每条关联计算结果。
      */
     @Transactional
-    public void calculateMinus(Long refId) {
-        l.info("calculate refId : {}", refId);
-        RealExamFault f = selectRealExamFaultByRefId(refId);
-        if (f == null) {
+    public AjaxResult calculateMinus(Long refId) {
+        l.info("calculateMinus refId : {}", refId);
+        RealExamFault ref = selectRealExamFaultByRefId(refId);
+        // check
+        if (ref == null) {
             throw new RuntimeException("calculateMinus");
         }
-        if (!RealExamFault.Flag.YES.equals(f.getFlag())) {
+        if (!RealExamFault.Flag.YES.equals(ref.getFlag())) {
             // throw new RuntimeException("calculateMinus");
             l.warn("not yes");
-            return;
+            return AjaxResult.error("not yes");
         }
+        // default minus 0
         int minus = 0;
         String answerRight = RealExamFault.AnswerRight.UNKNOWN;
-        l.info("f = {}", f);
+        l.info("f = {}", ref);
+        String refType = ref.getRefType();
+        final String qV = ref.getSimFaultQuestionValue();
+        final String aV = ref.getSimFaultAnswerValue();
 
-        if (RealExamFault.Type.TYPE_1.equals(f.getRefType())) {
+        if (RealExamFault.Type.TYPE_1.equals(refType)) {
             // todo:选择题的算减分
-            final String q = f.getChoiceQuestionValue();
-            final String a = f.getChoiceAnswerValue();
-        } else if (RealExamFault.Type.TYPE_2.equals(f.getRefType())) {
-            final String q = f.getSimFaultQuestionValue();
-            final String a = f.getSimFaultAnswerValue();
-            // 模拟器故障的算减分
-            if (StringUtils.isAllBlank(q, a)) {
-                // todo:不应该出现的情况
-                minus = 25;
-                answerRight = RealExamFault.AnswerRight.NO;
-            } else {
-                if (!StringUtils.equals(q, a)) {
-                    // 扣0分
+            // todo:细化实现
+        }
+        if (RealExamFault.Type.TYPE_2.equals(refType)) {
+            // check
+            if (StringUtils.isAnyBlank(qV, aV)) {
+                // todo:一般不应该出现的情况
+                return AjaxResult.error("数据报文异常!");
+            }
+            // 模拟器故障 的 计算减分 + 判断对错
+            if (FaultConst.FAULT_SET_JUDGE_RIGHT_FROM_WRONG_SP2.contains(ref.getFaultId())) {
+                String aVLast = aV.substring(6, 8);
+                if (CommConst.ANSWER_LAST_RIGHT_MSG.equals(aVLast)) {
                     minus = 0;
                     answerRight = RealExamFault.AnswerRight.YES;
-                } else {
-                    // 扣25分 故障未排除
+                } else if (CommConst.ANSWER_LAST_WRONG_MSG.equals(aVLast)) {
                     minus = 25;
                     answerRight = RealExamFault.AnswerRight.NO;
+                } else {
+                    return AjaxResult.error("数据报文异常!");
                 }
+            } else if (!StringUtils.equals(qV, aV)) {
+                // 扣0分
+                minus = 0;
+                answerRight = RealExamFault.AnswerRight.YES;
+            } else {
+                // 扣25分 故障未排除
+                minus = 25;
+                answerRight = RealExamFault.AnswerRight.NO;
             }
         }
-        f.setMinus((long) minus);
-        f.setAnswerRight(answerRight);
+        ref.setMinus((long) minus);
+        ref.setAnswerRight(answerRight);
         // 更新减分数据。
-        updateRealExamFault(f);
+        updateRealExamFault(ref);
+        return AjaxResult.success();
     }
 
     public List<RealExamFaultReportPart1Vo> getReportListPart1(final Long examId) {