deason 3 жил өмнө
parent
commit
4145b0b3d6

+ 0 - 30
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_exam_student_score/ExportAllQuestionScoreDetail.java

@@ -1,30 +0,0 @@
-package cn.com.qmth.dp.examcloud.oe.modules.export_exam_student_score;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.stereotype.Component;
-
-/**
- * 导出 - 考生考试中所有题的得分明细
- */
-@Component
-public class ExportAllQuestionScoreDetail {
-
-    private static Logger log = LoggerFactory.getLogger(ExportAllQuestionScoreDetail.class);
-
-    private static final Long MARKING_TYPE_KEY = 24L;// 阅卷方式KEY
-
-    @Autowired
-    private JdbcTemplate jdbcTemplate;
-
-    @Autowired
-    private MongoTemplate mongoTemplate;
-
-    public void start() {
-
-    }
-
-}

+ 66 - 61
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_exam_student_score/ExportExamStudentScore.java

@@ -6,9 +6,10 @@ import cn.com.qmth.dp.examcloud.oe.modules.export_exam_student_score.vo.ExamStud
 import cn.com.qmth.dp.examcloud.oe.modules.export_exam_student_score.vo.ScoreVO;
 import cn.com.qmth.dp.examcloud.oe.modules.export_exam_student_score.vo.ScoreVO;
 import cn.com.qmth.examcloud.commons.helpers.poi.ExcelWriter;
 import cn.com.qmth.examcloud.commons.helpers.poi.ExcelWriter;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.jsoup.Jsoup;
+import org.jsoup.safety.Safelist;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,11 +22,14 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
 import java.io.File;
 import java.io.File;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 /**
 /**
- * 导出 - 小题分
+ * 导出 - 考生的考试记录中小题的作答内容和得明细
  */
  */
 @Component
 @Component
 public class ExportExamStudentScore {
 public class ExportExamStudentScore {
@@ -34,71 +38,46 @@ public class ExportExamStudentScore {
 
 
     private static final Long MARKING_TYPE_KEY = 24L;// 阅卷方式KEY
     private static final Long MARKING_TYPE_KEY = 24L;// 阅卷方式KEY
 
 
+    private static final boolean needSubjective = false;// 是否包含主观题
+
     @Autowired
     @Autowired
     private JdbcTemplate jdbcTemplate;
     private JdbcTemplate jdbcTemplate;
 
 
     @Autowired
     @Autowired
     private MongoTemplate mongoTemplate;
     private MongoTemplate mongoTemplate;
 
 
-    public void start() {
-        /*
-            待导出的“考试 <课程...课程>”列表
-            Map : <examId, <courseId...courseId>
-            示例1:<1L, 不指定任何课程时,则默认导所有课程>
-            示例2:<1L, 指定某些课程时,则只导指定的课程>
-         */
-        HashMap<Long, List<Long>> examMaps = new HashMap<>();
-        // examMaps.put(2989L, Lists.newArrayList());
-
-        Set<Long> skipCourseIds = Sets.newHashSet();
-
-        this.export(examMaps, skipCourseIds);
+    public void start(Long... examIds) {
+        for (Long examId : examIds) {
+            this.export(examId);
+        }
     }
     }
 
 
-    private void export(HashMap<Long, List<Long>> examMaps, Set<Long> skipCourseIds) {
-        Map<Long, String> orgNameMaps = new HashMap<>(), courseNameMaps = new HashMap<>();
-
-        log.info("Total size is " + examMaps.size());
-
-        int count = 1;
-        for (Map.Entry<Long, List<Long>> entry : examMaps.entrySet()) {
-            log.info((count++) + "===> export starting, examId = " + entry.getKey());
-
-            // 获取考试下待导的课程
-            List<Long> examCourseIds;
-            if (CollectionUtils.isEmpty(entry.getValue())) {
-                // 导考试下全部课程
-                examCourseIds = this.queryExamCourseIds(entry.getKey());
-            } else {
-                // 导考试下指定课程
-                examCourseIds = entry.getValue();
-            }
-
-            log.info("---> examCourseIds size is " + examCourseIds.size());
+    private void export(Long examId) {
+        log.info("===> export starting, examId = " + examId);
 
 
-            // 获取考试的阅卷方式
-            String markingType = this.queryExamMarkingType(entry.getKey(), MARKING_TYPE_KEY);
-            log.info("---> markingType is " + markingType);
+        // 获取考试下待导的课程
+        List<Long> examCourseIds = this.queryExamCourseIds(examId);
+        log.info("---> examCourseIds size is " + examCourseIds.size());
 
 
-            String examName = this.queryExamName(entry.getKey());
+        // 获取考试的阅卷方式
+        String markingType = this.queryExamMarkingType(examId, MARKING_TYPE_KEY);
+        log.info("---> markingType is " + markingType);
 
 
-            for (Long courseId : examCourseIds) {
-                if (skipCourseIds.contains(courseId)) {
-                    log.info("skip courseId " + courseId);
-                    continue;
-                }
+        String examName = this.queryExamName(examId);
 
 
-                // 按考试的每个课程依次导出
-                this.export(entry.getKey(), examName, courseId, markingType, orgNameMaps, courseNameMaps);
-            }
+        Map<Long, String> orgNameMaps = new HashMap<>(), courseNameMaps = new HashMap<>();
 
 
-            log.info("===> export finished, examId = " + entry.getKey() + "\n");
+        for (Long courseId : examCourseIds) {
+            // 按考试的每个课程依次导出
+            this.export(examId, examName, courseId, markingType, orgNameMaps, courseNameMaps);
         }
         }
+
+        log.info("===> export finished, examId = " + examId + "\n");
     }
     }
 
 
     private void export(Long examId, String examName, Long courseId, String markingType, Map<Long, String> orgNameMaps, Map<Long, String> courseNameMaps) {
     private void export(Long examId, String examName, Long courseId, String markingType, Map<Long, String> orgNameMaps, Map<Long, String> courseNameMaps) {
         List<ExamStudentVO> examStudents = this.queryExamStudents(examId, courseId);
         List<ExamStudentVO> examStudents = this.queryExamStudents(examId, courseId);
-        log.info(String.format("---> examId = %s, courseId = %s, examStudentSize = %s", examId, courseId, examStudents.size()));
+        log.info("---> examId = {}, courseId = {}, examStudentSize = {}", examId, courseId, examStudents.size());
 
 
         boolean hasDynamicExcelHeaderSetting = false;
         boolean hasDynamicExcelHeaderSetting = false;
         List<String> dynamicExcelHeaders = new ArrayList<>();// Excel动态列
         List<String> dynamicExcelHeaders = new ArrayList<>();// Excel动态列
@@ -203,9 +182,14 @@ public class ExportExamStudentScore {
                         dynamicExcelHeaders.add(String.format("%s%s-%s得分", questionType, question.getMainNumber(), question.getOrder()));
                         dynamicExcelHeaders.add(String.format("%s%s-%s得分", questionType, question.getMainNumber(), question.getOrder()));
                         defaultDynamicColumnValues.add("0");
                         defaultDynamicColumnValues.add("0");
                     } else {
                     } else {
-                        // 主观题不设置“作答”列
-                        dynamicExcelHeaders.add(String.format("%s%s-%s得分", questionType, question.getMainNumber(), question.getOrder()));
-                        defaultDynamicColumnValues.add("0");
+                        // 主观题默认不设置“作答”列
+                        if (needSubjective) {
+                            dynamicExcelHeaders.add(String.format("%s%s-%s作答", questionType, question.getMainNumber(), question.getOrder()));
+                            defaultDynamicColumnValues.add("");
+
+                            dynamicExcelHeaders.add(String.format("%s%s-%s得分", questionType, question.getMainNumber(), question.getOrder()));
+                            defaultDynamicColumnValues.add("0");
+                        }
                     }
                     }
 
 
                     hasDynamicExcelHeaderSetting = true;
                     hasDynamicExcelHeaderSetting = true;
@@ -233,7 +217,12 @@ public class ExportExamStudentScore {
                         curDynamicColumnValues.add("0");
                         curDynamicColumnValues.add("0");
                     }
                     }
                 } else {
                 } else {
-                    curDynamicColumnValues.add(question.getStudentScore() != null ? question.getStudentScore().toString() : "0");
+                    // 主观题默认不设置“作答”列
+                    if (needSubjective) {
+                        curDynamicColumnValues.add(Jsoup.clean(question.getStudentAnswer() != null ? question.getStudentAnswer() : "", Safelist.relaxed()));
+
+                        curDynamicColumnValues.add(question.getStudentScore() != null ? question.getStudentScore().toString() : "0");
+                    }
                 }
                 }
 
 
                 curPaperStructKey += (question.getOrder() + question.getQuestionType());
                 curPaperStructKey += (question.getOrder() + question.getQuestionType());
@@ -257,7 +246,10 @@ public class ExportExamStudentScore {
             examStudent.setDetails(defaultDynamicColumnValues);
             examStudent.setDetails(defaultDynamicColumnValues);
         }
         }
 
 
-        List<String> fixedExcelHeaders = Lists.newArrayList("学习中心", "课程代码", "课程名称", "层次", "是否缺考", "身份证号", "学号", "姓名", "年级", "专业", "客观总分", "主观总分", "总分");
+        List<String> fixedExcelHeaders = Lists.newArrayList(
+                // "学习中心", "课程代码", "课程名称", "课程层次", "是否缺考", "身份证号", "学号", "姓名", "年级", "专业", "客观总分", "主观总分", "总分"
+                "学习中心", "课程代码", "课程名称", "课程层次", "是否缺考", "身份证号", "学号", "姓名", "客观总分", "主观总分", "总分"
+        );
         fixedExcelHeaders.addAll(dynamicExcelHeaders);
         fixedExcelHeaders.addAll(dynamicExcelHeaders);
 
 
         this.toExcel(examId, examName, courseId, examStudents, fixedExcelHeaders);
         this.toExcel(examId, examName, courseId, examStudents, fixedExcelHeaders);
@@ -271,10 +263,19 @@ public class ExportExamStudentScore {
 
 
         if (CollectionUtils.isNotEmpty(examStudents)) {
         if (CollectionUtils.isNotEmpty(examStudents)) {
             for (ExamStudentVO vo : examStudents) {
             for (ExamStudentVO vo : examStudents) {
-                List<Object> rowValues = Lists.newArrayList(vo.getOrgName(), vo.getCourseCode(), vo.getCourseName(),
-                        vo.getCourseLevel(), vo.getFinished() ? "否" : "是", vo.getIdentityNumber(),
-                        vo.getStudentCode(), vo.getStudentName(), vo.getGrade(), vo.getSpecialtyName(),
-                        vo.getObjectiveScore().toString(), vo.getSubjectiveScore().toString(),
+                List<Object> rowValues = Lists.newArrayList(
+                        vo.getOrgName(),
+                        vo.getCourseCode(),
+                        vo.getCourseName(),
+                        vo.getCourseLevel(),
+                        vo.getFinished() ? "否" : "是",
+                        vo.getIdentityNumber(),
+                        vo.getStudentCode(),
+                        vo.getStudentName(),
+                        // vo.getGrade(),
+                        // vo.getSpecialtyName(),
+                        vo.getObjectiveScore().toString(),
+                        vo.getSubjectiveScore().toString(),
                         vo.getTotalScore().toString());
                         vo.getTotalScore().toString());
 
 
                 if (CollectionUtils.isNotEmpty(vo.getDetails())) {
                 if (CollectionUtils.isNotEmpty(vo.getDetails())) {
@@ -395,7 +396,7 @@ public class ExportExamStudentScore {
         query.addCriteria(Criteria.where("examRecordDataId").is(examRecordDataId));
         query.addCriteria(Criteria.where("examRecordDataId").is(examRecordDataId));
         List<ExamRecordQuestionVO> result = mongoTemplate.find(query, ExamRecordQuestionVO.class, "examRecordQuestions");
         List<ExamRecordQuestionVO> result = mongoTemplate.find(query, ExamRecordQuestionVO.class, "examRecordQuestions");
         if (CollectionUtils.isNotEmpty(result)) {
         if (CollectionUtils.isNotEmpty(result)) {
-            return result.get(0);
+            return result.get(result.size() - 1);
         }
         }
         return null;
         return null;
     }
     }
@@ -434,7 +435,11 @@ public class ExportExamStudentScore {
     }
     }
 
 
     private String convertTrueFalse(String value) {
     private String convertTrueFalse(String value) {
-        if ("1".equals(value)) {
+        if ("true".equals(value)) {
+            return "对";
+        } else if ("false".equals(value)) {
+            return "错";
+        } else if ("1".equals(value)) {
             return "对";
             return "对";
         } else if ("0".equals(value)) {
         } else if ("0".equals(value)) {
             return "错";
             return "错";

+ 1 - 1
src/test/java/cn/com/qmth/dp/examcloud/oe/test/ExportTest.java

@@ -43,7 +43,7 @@ public class ExportTest {
         // fixCorrectAnswerAndResetScoreService.start();
         // fixCorrectAnswerAndResetScoreService.start();
 
 
         // 导出 - 成绩明细 带小题分
         // 导出 - 成绩明细 带小题分
-        // exportExamStudentScore.start();
+        // exportExamStudentScore.start(520L);
 
 
         // 导出 - 考生作答结果(带手机号)
         // 导出 - 考生作答结果(带手机号)
         // studentOneAnswerService.start(1213L, 1, "01");
         // studentOneAnswerService.start(1213L, 1, "01");