deason 2 年之前
父节点
当前提交
1ea229ba97

+ 46 - 3
src/main/java/cn/com/qmth/examcloud/tool/service/export_student_answer_and_score_detail/ExportStudentAnswerAndScoreDetailTask.java

@@ -13,6 +13,8 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.google.common.collect.Lists;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.jsoup.Jsoup;
+import org.jsoup.safety.Safelist;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -127,6 +129,20 @@ public class ExportStudentAnswerAndScoreDetailTask {
                 }
             }
 
+            boolean existSubjectiveQuestion = false;
+            for (ExamQuestionVO question : examQuestions) {
+                if (!isObjectiveQuestion(question.getQuestionType())) {
+                    existSubjectiveQuestion = true;
+                    break;
+                }
+            }
+
+            Map<String, Double> subjectiveQuestionScores = null;
+            if (existSubjectiveQuestion && needSubjective) {
+                // 获取阅卷端考生考试记录中主观题的得分明细
+                subjectiveQuestionScores = this.getSubjectiveQuestionScores(user.getKey(), user.getToken(), vo.getExamRecordDataId());
+            }
+
             // Excel动态列值
             List<String> dynamicColumnValues = new ArrayList<>();
             for (ExamQuestionVO question : examQuestions) {
@@ -149,9 +165,13 @@ public class ExportStudentAnswerAndScoreDetailTask {
                     }
                 } else {
                     if (needSubjective) {
-                        dynamicColumnValues.add("-");
-                        dynamicColumnValues.add("-");
-                        dynamicColumnValues.add("0");
+                        // String correctAnswer = question.getCorrectAnswer() != null ? question.getCorrectAnswer() : "";
+                        // dynamicColumnValues.add(Jsoup.clean(correctAnswer, Safelist.simpleText()));
+                        String studentAnswer = question.getStudentAnswer() != null ? question.getStudentAnswer() : "";
+                        dynamicColumnValues.add(Jsoup.clean(studentAnswer, Safelist.simpleText()));
+
+                        Double studentScore = subjectiveQuestionScores.get(question.getMainNumber() + "-" + question.getOrder());
+                        dynamicColumnValues.add(studentScore != null ? String.valueOf(studentScore) : "0");
                     }
                 }
             }
@@ -180,6 +200,29 @@ public class ExportStudentAnswerAndScoreDetailTask {
         return QuestionType.SINGLE_CHOICE == type || QuestionType.MULTIPLE_CHOICE == type || QuestionType.TRUE_OR_FALSE == type;
     }
 
+    /**
+     * 获取阅卷端考生考试记录中主观题的得分明细
+     */
+    private Map<String, Double> getSubjectiveQuestionScores(String key, String token, Long examRecordDataId) {
+        Map<String, String> headers = new HashMap<>();
+        headers.put("key", key);
+        headers.put("token", token);
+
+        String url = sysProperty.getServerUrl() + "/api/ecs_marking/student/paper/getSubjectiveQuestionScores/" + examRecordDataId;
+        String json = HttpHelper.post(url, headers, null);
+
+        JsonMapper jsonMapper = new JsonMapper();
+        List<SubjectiveQuestionScoreVO> scores = jsonMapper.toList(json, SubjectiveQuestionScoreVO.class);
+
+        Map<String, Double> subjectiveQuestionScores = new HashMap<>();
+        if (CollectionUtils.isNotEmpty(scores)) {
+            for (SubjectiveQuestionScoreVO vo : scores) {
+                subjectiveQuestionScores.put(vo.getMainNumber() + "-" + vo.getOrders(), vo.getScore());
+            }
+        }
+        return subjectiveQuestionScores;
+    }
+
     /**
      * 获取考试试题作答记录
      */

+ 16 - 0
src/main/java/cn/com/qmth/examcloud/tool/service/export_student_answer_and_score_detail/vo/SubjectiveQuestionScoreVO.java

@@ -0,0 +1,16 @@
+package cn.com.qmth.examcloud.tool.service.export_student_answer_and_score_detail.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class SubjectiveQuestionScoreVO {
+
+    private Integer mainNumber;
+
+    private Integer orders;
+
+    private Double score;
+
+}