|
@@ -11,6 +11,7 @@ import org.assertj.core.util.Lists;
|
|
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;
|
|
|
|
+import org.springframework.dao.EmptyResultDataAccessException;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
@@ -19,7 +20,10 @@ 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
|
|
@@ -36,36 +40,60 @@ public class ExportExamStudentScore {
|
|
private MongoTemplate mongoTemplate;
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
public void start() {
|
|
public void start() {
|
|
- Set<Long> examIds = new HashSet<>();
|
|
|
|
- // examIds.add(808L);
|
|
|
|
- // examIds.add(815L);
|
|
|
|
- // examIds.add(816L);
|
|
|
|
- // examIds.add(817L);
|
|
|
|
- // examIds.add(818L);
|
|
|
|
- // examIds.add(821L);
|
|
|
|
- // examIds.add(822L);
|
|
|
|
- // examIds.add(823L);
|
|
|
|
- examIds.add(47L);
|
|
|
|
|
|
+ /*
|
|
|
|
+ 待导出的“考试 <课程...课程>”列表
|
|
|
|
+ Map : <examId, <courseId...courseId>
|
|
|
|
+ 示例1:<1L, 不指定任何课程时,则默认导所有课程>
|
|
|
|
+ 示例2:<1L, 指定某些课程时,则只导指定的课程>
|
|
|
|
+ */
|
|
|
|
+ HashMap<Long, List<Long>> examMaps = new HashMap<>();
|
|
|
|
+ // examMaps.put(1L, Lists.list(1L, 2L, 3L));
|
|
|
|
+ examMaps.put(10L, Lists.list());
|
|
|
|
+
|
|
|
|
+ // examMaps.put(808L, Lists.list());
|
|
|
|
+ // examMaps.put(815L, Lists.list());
|
|
|
|
+ // examMaps.put(816L, Lists.list());
|
|
|
|
+ // examMaps.put(817L, Lists.list());
|
|
|
|
+ // examMaps.put(818L, Lists.list());
|
|
|
|
+ // examMaps.put(821L, Lists.list());
|
|
|
|
+ // examMaps.put(822L, Lists.list());
|
|
|
|
+ // examMaps.put(823L, Lists.list());
|
|
|
|
+
|
|
|
|
+ this.export(examMaps);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ private void export(HashMap<Long, List<Long>> examMaps) {
|
|
Map<Long, String> orgNameMaps = new HashMap<>(), courseNameMaps = new HashMap<>();
|
|
Map<Long, String> orgNameMaps = new HashMap<>(), courseNameMaps = new HashMap<>();
|
|
- for (Long examId : examIds) {
|
|
|
|
- log.info("===> export starting, examId = " + examId);
|
|
|
|
|
|
|
|
- List<Long> examCourseIds = this.queryExamCourseIds(examId);
|
|
|
|
|
|
+ for (Map.Entry<Long, List<Long>> entry : examMaps.entrySet()) {
|
|
|
|
+ log.info("===> 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());
|
|
log.info("---> examCourseIds size is " + examCourseIds.size());
|
|
|
|
|
|
|
|
+ // 获取考试的阅卷方式
|
|
|
|
+ String markingType = this.queryExamMarkingType(entry.getKey(), MARKING_TYPE_KEY);
|
|
|
|
+ log.info("---> markingType is " + markingType);
|
|
|
|
+
|
|
for (Long courseId : examCourseIds) {
|
|
for (Long courseId : examCourseIds) {
|
|
// 按考试的每个课程依次导出
|
|
// 按考试的每个课程依次导出
|
|
- this.export(examId, courseId, orgNameMaps, courseNameMaps);
|
|
|
|
|
|
+ this.export(entry.getKey(), courseId, markingType, orgNameMaps, courseNameMaps);
|
|
}
|
|
}
|
|
|
|
|
|
- log.info("---> orgMap size is " + orgNameMaps.size());
|
|
|
|
- log.info("---> courseMap size is " + courseNameMaps.size());
|
|
|
|
- log.info("===> export finished, examId = " + examId);
|
|
|
|
|
|
+ log.info("===> export finished, examId = " + entry.getKey());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void export(Long examId, Long courseId, Map<Long, String> orgNameMaps, Map<Long, String> courseNameMaps) {
|
|
|
|
|
|
+ private void export(Long examId, 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(String.format("---> examId = %s, courseId = %s, examStudentSize = %s", examId, courseId, examStudents.size()));
|
|
|
|
|
|
@@ -125,10 +153,6 @@ public class ExportExamStudentScore {
|
|
scores.add(score);
|
|
scores.add(score);
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取考试的阅卷方式
|
|
|
|
- String markingType = this.queryExamMarkingType(examId, MARKING_TYPE_KEY);
|
|
|
|
- log.info("---> markingType is " + markingType);
|
|
|
|
-
|
|
|
|
ScoreVO okScore;
|
|
ScoreVO okScore;
|
|
if (markingType.equals("ALL") || markingType.equals("OBJECT_SCORE_MAX")) {
|
|
if (markingType.equals("ALL") || markingType.equals("OBJECT_SCORE_MAX")) {
|
|
// 全部评阅规则 或 客观分最高规则:取总分最高
|
|
// 全部评阅规则 或 客观分最高规则:取总分最高
|
|
@@ -151,8 +175,7 @@ public class ExportExamStudentScore {
|
|
}
|
|
}
|
|
|
|
|
|
// 获取试题作答记录
|
|
// 获取试题作答记录
|
|
- // ExamRecordQuestionVO questions = this.queryExamRecordQuestions(okExamRecordDataId);
|
|
|
|
- ExamRecordQuestionVO questions = this.queryExamRecordQuestions(11346965L);
|
|
|
|
|
|
+ ExamRecordQuestionVO questions = this.queryExamRecordQuestions(okExamRecordDataId);
|
|
if (questions == null || CollectionUtils.isEmpty(questions.getExamQuestionEntities())) {
|
|
if (questions == null || CollectionUtils.isEmpty(questions.getExamQuestionEntities())) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -163,17 +186,15 @@ public class ExportExamStudentScore {
|
|
for (ExamQuestionVO question : examQuestionEntities) {
|
|
for (ExamQuestionVO question : examQuestionEntities) {
|
|
String questionType = this.convertQuestionType(question.getQuestionType());
|
|
String questionType = this.convertQuestionType(question.getQuestionType());
|
|
if ("SINGLE_CHOICE".equals(question.getQuestionType()) || "MULTIPLE_CHOICE".equals(question.getQuestionType()) || "TRUE_OR_FALSE".equals(question.getQuestionType())) {
|
|
if ("SINGLE_CHOICE".equals(question.getQuestionType()) || "MULTIPLE_CHOICE".equals(question.getQuestionType()) || "TRUE_OR_FALSE".equals(question.getQuestionType())) {
|
|
- String titleX = questionType + question.getMainNumber() + "-" + question.getOrder() + " 作答";
|
|
|
|
- String titleY = questionType + question.getMainNumber() + "-" + question.getOrder() + " 得分";
|
|
|
|
- dynamicExcelHeaders.add(titleX);
|
|
|
|
- dynamicExcelHeaders.add(titleY);
|
|
|
|
|
|
+ dynamicExcelHeaders.add(String.format("%s%s-%s作答", questionType, question.getMainNumber(), question.getOrder()));
|
|
dynamicDefaultValues.add("");
|
|
dynamicDefaultValues.add("");
|
|
|
|
+
|
|
|
|
+ dynamicExcelHeaders.add(String.format("%s%s-%s得分", questionType, question.getMainNumber(), question.getOrder()));
|
|
dynamicDefaultValues.add("0");
|
|
dynamicDefaultValues.add("0");
|
|
} else {
|
|
} else {
|
|
// 主观题不设置“作答”列
|
|
// 主观题不设置“作答”列
|
|
- String title = questionType + question.getMainNumber() + "-" + question.getOrder() + " 得分";
|
|
|
|
- dynamicExcelHeaders.add(title);
|
|
|
|
- dynamicDefaultValues.add("");
|
|
|
|
|
|
+ dynamicExcelHeaders.add(String.format("%s%s-%s得分", questionType, question.getMainNumber(), question.getOrder()));
|
|
|
|
+ dynamicDefaultValues.add("0");
|
|
}
|
|
}
|
|
hasDynamicExcelHeaderSetting = true;
|
|
hasDynamicExcelHeaderSetting = true;
|
|
}
|
|
}
|
|
@@ -236,12 +257,20 @@ public class ExportExamStudentScore {
|
|
|
|
|
|
private String queryOrgName(Long orgId) {
|
|
private String queryOrgName(Long orgId) {
|
|
final String querySql = String.format("select name from ec_b_org where id = %s", orgId);
|
|
final String querySql = String.format("select name from ec_b_org where id = %s", orgId);
|
|
- return jdbcTemplate.queryForObject(querySql, String.class);
|
|
|
|
|
|
+ try {
|
|
|
|
+ return jdbcTemplate.queryForObject(querySql, String.class);
|
|
|
|
+ } catch (EmptyResultDataAccessException e) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private String queryCourseName(Long courseId) {
|
|
private String queryCourseName(Long courseId) {
|
|
final String querySql = String.format("select name from ec_b_course where id = %s", courseId);
|
|
final String querySql = String.format("select name from ec_b_course where id = %s", courseId);
|
|
- return jdbcTemplate.queryForObject(querySql, String.class);
|
|
|
|
|
|
+ try {
|
|
|
|
+ return jdbcTemplate.queryForObject(querySql, String.class);
|
|
|
|
+ } catch (EmptyResultDataAccessException e) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private List<Long> queryExamCourseIds(Long examId) {
|
|
private List<Long> queryExamCourseIds(Long examId) {
|
|
@@ -257,11 +286,12 @@ public class ExportExamStudentScore {
|
|
|
|
|
|
private String queryExamMarkingType(Long examId, Long markingTypeKey) {
|
|
private String queryExamMarkingType(Long examId, Long markingTypeKey) {
|
|
final String querySql = String.format("select value from ec_e_exam_prop where exam_id = %s and key_id = %s", examId, markingTypeKey);
|
|
final String querySql = String.format("select value from ec_e_exam_prop where exam_id = %s and key_id = %s", examId, markingTypeKey);
|
|
- String value = jdbcTemplate.queryForObject(querySql, String.class);
|
|
|
|
- if (StringUtils.isBlank(value)) {
|
|
|
|
|
|
+ try {
|
|
|
|
+ String result = jdbcTemplate.queryForObject(querySql, String.class);
|
|
|
|
+ return StringUtils.isNoneBlank(result) ? result.trim() : "ALL";
|
|
|
|
+ } catch (EmptyResultDataAccessException e) {
|
|
return "ALL";// 默认值
|
|
return "ALL";// 默认值
|
|
}
|
|
}
|
|
- return value;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private List<Map<String, Object>> queryExamRecordDataList(Long examId, Long courseId, Long examStudentId) {
|
|
private List<Map<String, Object>> queryExamRecordDataList(Long examId, Long courseId, Long examStudentId) {
|