Browse Source

修改填空题,有对的就给一半分数

chenminghua 1 year ago
parent
commit
c4d95b4e3b

+ 23 - 6
exam-06173-api/src/main/java/com/gyee/exam/modules/paper/service/impl/PaperServiceImpl.java

@@ -25,6 +25,7 @@ import com.gyee.exam.modules.paper.dto.ext.PaperGroupExtDTO;
 import com.gyee.exam.modules.paper.dto.ext.PaperQuAnswerExtDTO;
 import com.gyee.exam.modules.paper.dto.ext.PaperQuDetailDTO;
 import com.gyee.exam.modules.paper.dto.request.PaperListReqDTO;
+import com.gyee.exam.modules.paper.dto.request.PaperQuQueryDTO;
 import com.gyee.exam.modules.paper.dto.response.ExamDetailRespDTO;
 import com.gyee.exam.modules.paper.dto.response.ExamResultRespDTO;
 import com.gyee.exam.modules.paper.dto.response.PaperListRespDTO;
@@ -61,6 +62,7 @@ import org.springframework.util.CollectionUtils;
 import java.math.BigDecimal;
 import java.text.MessageFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -635,7 +637,7 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
         // 循环标准答案
         for (PaperQuAnswerExtDTO an : answers) {
             if (!StringUtils.isBlank(an.getAnswer())) {
-                userList.add(an.getAnswer());
+                userList.add(an.getAnswer().trim());
                 qu.setAnswered(true);
             }
         }
@@ -651,10 +653,25 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
         List<PaperQuAnswer> list = BeanMapper.mapList(answers, PaperQuAnswer.class);
         paperQuAnswerService.updateBatchById(list);
 
-        boolean right = ListUtils.compareList(rightList, userList);
-
+        //boolean right = ListUtils.compareList(rightList, userList);
+        BigDecimal score = BigDecimal.valueOf(0);
+        boolean right = false;
+        List<String> reduce = rightList.stream().filter(item -> !userList.contains(item)).collect(Collectors.toList());
+        if (userList.size() == 0){
+            //没有答案
+            right = false;
+            score = pathScore;
+        } else if (reduce.size() == 0 && userList.size() == rightList.size()){
+            //答案全部正确
+            right = true;
+            score = qu.getScore();
+        } else if (reduce.size() > 0 && reduce.size() != rightList.size()){
+            //答案部分正确
+            right = true;
+            score = new BigDecimal(qu.getScore().doubleValue() / 2).setScale(1, BigDecimal.ROUND_CEILING);
+        }
         qu.setIsRight(right);
-        qu.setActualScore(right ? qu.getScore() : pathScore);
+        qu.setActualScore(score);
 
         // 回写内部使用
         reqDTO.setIsRight(right);
@@ -675,11 +692,11 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements
 
         for (PaperQuAnswerExtDTO item : fullList) {
             if (fill) {
-                rightMap.add(item.getContent());
+                rightMap.add(item.getContent().trim());
                 continue;
             }
             if (item.getIsRight()) {
-                rightMap.add(item.getAnswerId());
+                rightMap.add(item.getAnswerId().trim());
             }
         }
         return rightMap;

+ 19 - 27
exam-06173-api/src/main/java/com/gyee/exam/utils/ListUtils.java

@@ -2,10 +2,8 @@ package com.gyee.exam.utils;
 
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
@@ -71,33 +69,27 @@ public class ListUtils {
 
     public static void main(String[] args) {
 
-        // 集合1
-        List<List<String>> list1 = new ArrayList();
+        List<String> list1 = new ArrayList<>();
+        list1.add("1111");
+        list1.add("2222");
+        list1.add("3333");
 
-        List<String> list11 = new ArrayList<>();
-        list11.add("10010");
-        list11.add("10088");
-        list1.add(list11);
+        List<String> list2 = new ArrayList<>();
+        list2.add("3333");
+        list2.add("2222");
 
-        List<String> list12 = new ArrayList<>();
-        list12.add("18800");
-        list12.add("19900");
-        list1.add(list12);
+        Set<String> list1Set = new HashSet<>(list1);
 
+        Set<String> list2Set = new HashSet<>(list2);
 
-        // 集合2
-        List<List<String>> list2 = new ArrayList();
+        // 交集
+        List<String> intersection = list1.stream().filter(list2Set::contains).collect(Collectors.toList());
+        System.out.println("---得到交集 intersection---");
+        intersection.parallelStream().forEach(System.out::println);
 
-        List<String> list21 = new ArrayList<>();
-        list21.add("19900");
-        list21.add("18800");
-        list2.add(list21);
-
-        List<String> list22 = new ArrayList<>();
-        list22.add("10088");
-        list22.add("10010");
-        list2.add(list22);
-
-        System.out.println("比较结果:"+equals(list1, list2));
+        // 差集 (list1 - list2)
+        List<String> reduce1 = list1.stream().filter(item -> !list2Set.contains(item)).collect(Collectors.toList());
+        System.out.println("---得到差集 reduce1 (list1 - list2)---");
+        reduce1.parallelStream().forEach(System.out::println);
     }
 }