|
@@ -11,23 +11,25 @@ import com.qmth.themis.business.bean.admin.OpenRecordAnswerBean;
|
|
|
import com.qmth.themis.business.bean.admin.OpenRecordNeedMarkBean;
|
|
|
import com.qmth.themis.business.cache.RedisKeyHelper;
|
|
|
import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
|
|
|
-import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.dto.response.TEExamStudentDto;
|
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
|
-import com.qmth.themis.business.entity.TEExamCourse;
|
|
|
import com.qmth.themis.business.enums.InvigilateMonitorStatusEnum;
|
|
|
import com.qmth.themis.business.enums.RecordSelectStrategyEnum;
|
|
|
import com.qmth.themis.business.service.*;
|
|
|
import com.qmth.themis.business.util.OssUtil;
|
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
|
-import com.qmth.themis.common.util.FileUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.File;
|
|
|
-import java.util.*;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -66,7 +68,8 @@ public class TEOpenServiceImpl implements TEOpenService {
|
|
|
|
|
|
@Override
|
|
|
public List<OpenExamCourseBean> examCourseQueryPage(Long examId, String courseCode, Boolean hasPaper,
|
|
|
- int pageNumber, int pageSize) {
|
|
|
+ int pageNumber, int pageSize) {
|
|
|
+ checkExam(examId);
|
|
|
Page<OpenExamCourseBean> ipage = new Page<>(pageNumber, pageSize);
|
|
|
ipage.addOrder(OrderItem.desc("t.id"));
|
|
|
IPage<OpenExamCourseBean> ret = examCourseService.examCourseQueryForOpen(ipage, examId, courseCode, hasPaper);
|
|
@@ -74,309 +77,229 @@ public class TEOpenServiceImpl implements TEOpenService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject examPaperDetail(Long paperId, String filter) {
|
|
|
- String tempDir = SystemConstant.TEMP_FILES_DIR;
|
|
|
- String dir = tempDir + "/" + uuid() + "/";
|
|
|
- File dfile = new File(dir);
|
|
|
-
|
|
|
- try {
|
|
|
- ExamPaperCacheBean paper = examPaperService.getExamPaperCacheBean(paperId);
|
|
|
- if (paper == null) {
|
|
|
- throw new BusinessException("未找到试卷信息");
|
|
|
+ public JSONObject examPaperDetail(Long paperId, String filter) throws IOException {
|
|
|
+ ExamPaperCacheBean paper = examPaperService.getExamPaperCacheBean(paperId);
|
|
|
+ if (paper == null) {
|
|
|
+ throw new BusinessException("未找到试卷信息");
|
|
|
+ }
|
|
|
+ checkExam(paper.getExamId());
|
|
|
+ if (StringUtils.isBlank(paper.getAnswerPath())) {
|
|
|
+ throw new BusinessException("该试卷未上传答案");
|
|
|
+ }
|
|
|
+ boolean acceptObjective = filter == null || "objective".equals(filter);
|
|
|
+ boolean acceptSubjective = filter == null || "subjective".equals(filter);
|
|
|
+ //解析答案JSON文件
|
|
|
+ JSONObject answerJson = JSONObject
|
|
|
+ .parseObject(new String(ossUtil.download(false, paper.getAnswerPath()), StandardCharsets.UTF_8));
|
|
|
+ JSONArray answerDetails = answerJson.getJSONArray("details");
|
|
|
+ //解析试卷JSON文件
|
|
|
+ JSONObject paperResult = JSONObject
|
|
|
+ .parseObject(new String(ossUtil.download(false, paper.getPaperViewPath()), StandardCharsets.UTF_8));
|
|
|
+ paperResult.put("id", paper.getId());
|
|
|
+ paperResult.put("code", paper.getCode());
|
|
|
+ paperResult.put("name", paper.getName());
|
|
|
+ JSONArray detailCollection = new JSONArray();
|
|
|
+ JSONArray paperDetails = paperResult.getJSONArray("details");
|
|
|
+ for (int i = 0; i < paperDetails.size(); i++) {
|
|
|
+ //遍历所有大题
|
|
|
+ JSONObject paperDetail = paperDetails.getJSONObject(i);
|
|
|
+ JSONObject answerDetail = findJsonObject(answerDetails, paperDetail.getIntValue("number"));
|
|
|
+ //按条件过滤需要的小题同时合并答案
|
|
|
+ JSONArray questionCollection = filterQuestions(paperDetail.getJSONArray("questions"),
|
|
|
+ answerDetail != null ? answerDetail.getJSONArray("questions") : null, acceptObjective,
|
|
|
+ acceptSubjective);
|
|
|
+ //有小题的情况下,本大题才需要被包含
|
|
|
+ if (questionCollection.size() > 0) {
|
|
|
+ paperDetail.put("questions", questionCollection);
|
|
|
+ detailCollection.add(paperDetail);
|
|
|
}
|
|
|
- checkExam(paper.getExamId());
|
|
|
- dfile.mkdirs();
|
|
|
- String paperPath = paper.getPaperViewPath();
|
|
|
- String anwserPath = paper.getAnswerPath();
|
|
|
- File paperFile = new File(dir + uuid() + ".json");
|
|
|
- File anwserFile = new File(dir + uuid() + ".json");
|
|
|
- FileUtil.saveUrlAsFile(ossUtil.getAliYunOssPrivateDomain().getPrivateUrl() + "/" + paperPath, paperFile);
|
|
|
- FileUtil.saveUrlAsFile(ossUtil.getAliYunOssPrivateDomain().getPrivateUrl() + "/" + anwserPath, anwserFile);
|
|
|
- JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(anwserFile));
|
|
|
- JSONArray answerdetails = answerJson.getJSONArray("details");
|
|
|
- JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
|
- structJson.put("id", paperId);
|
|
|
- structJson.put("code", paper.getCode());
|
|
|
- JSONArray structdetails = structJson.getJSONArray("details");
|
|
|
- for (int i = 0; i < answerdetails.size(); i++) {
|
|
|
- JSONArray answerdetailquestions = answerdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
- JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
- for (int j = 0; j < structdetailquestions.size(); j++) {
|
|
|
- JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
|
|
|
- JSONObject structquestion = structdetailquestions.getJSONObject(j);
|
|
|
- if ("objective".equals(filter)) {
|
|
|
- if (structquestion.getInteger("structType").intValue() == 1
|
|
|
- || structquestion.getInteger("structType").intValue() == 2
|
|
|
- || structquestion.getInteger("structType").intValue() == 3) {
|
|
|
- if (structquestion.getInteger("structType").intValue() == 3) {
|
|
|
- structquestion.put("answer", answerquestion.getBoolean("answer"));
|
|
|
- } else {
|
|
|
- structquestion.put("answer", answerquestion.getJSONArray("answer"));
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (structquestion.getInteger("structType").intValue() == 6) {
|
|
|
- JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
- JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
- for (int k = 0; k < structsubQuestions.size(); k++) {
|
|
|
- JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
|
|
|
- JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
|
- if (structsubquestion.getInteger("structType").intValue() == 1
|
|
|
- || structsubquestion.getInteger("structType").intValue() == 2
|
|
|
- || structsubquestion.getInteger("structType").intValue() == 3) {
|
|
|
- if (structsubquestion.getInteger("structType").intValue() == 3) {
|
|
|
- structsubquestion.put("answer", answersubquestion.getBoolean("answer"));
|
|
|
- } else {
|
|
|
- structsubquestion.put("answer", answersubquestion.getJSONArray("answer"));
|
|
|
- }
|
|
|
- } else {
|
|
|
- structsubQuestions.remove(k);
|
|
|
- k--;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- structdetailquestions.remove(j);
|
|
|
- j--;
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ paperResult.put("details", detailCollection);
|
|
|
+ return paperResult;
|
|
|
+ }
|
|
|
|
|
|
- } else if ("subjective".equals(filter)) {
|
|
|
- if (structquestion.getInteger("structType").intValue() != 1
|
|
|
- && structquestion.getInteger("structType").intValue() != 2
|
|
|
- && structquestion.getInteger("structType").intValue() != 3) {
|
|
|
- structquestion.put("answer", answerquestion.getJSONArray("answer"));
|
|
|
- } else {
|
|
|
- if (structquestion.getInteger("structType").intValue() == 6) {
|
|
|
- JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
- JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
- for (int k = 0; k < structsubQuestions.size(); k++) {
|
|
|
- JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
|
|
|
- JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
|
- if (structsubquestion.getInteger("structType").intValue() != 1
|
|
|
- && structsubquestion.getInteger("structType").intValue() != 2
|
|
|
- && structsubquestion.getInteger("structType").intValue() != 3) {
|
|
|
- structsubquestion.put("answer", answersubquestion.getJSONArray("answer"));
|
|
|
- } else {
|
|
|
- structsubQuestions.remove(k);
|
|
|
- k--;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- structdetailquestions.remove(j);
|
|
|
- j--;
|
|
|
- }
|
|
|
- }
|
|
|
+ private JSONArray filterQuestions(JSONArray questions, JSONArray answers, boolean acceptObjective,
|
|
|
+ boolean acceptSubjective) {
|
|
|
+ JSONArray collection = new JSONArray();
|
|
|
+ for (int i = 0; i < questions.size(); i++) {
|
|
|
+ JSONObject question = questions.getJSONObject(i);
|
|
|
+ //根据题号查找答案
|
|
|
+ JSONObject answer = findJsonObject(answers, question.getIntValue("number"));
|
|
|
+ boolean accept = true;
|
|
|
+ //判断结构类型
|
|
|
+ switch (question.getIntValue("structType")) {
|
|
|
+ case 1:
|
|
|
+ //单选
|
|
|
+ case 2:
|
|
|
+ //多选
|
|
|
+ case 3:
|
|
|
+ //判断
|
|
|
+ accept = acceptObjective;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ //填空
|
|
|
+ case 5:
|
|
|
+ //问答
|
|
|
+ accept = acceptSubjective;
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ //套题
|
|
|
+ //按条件过滤套题下所有子题
|
|
|
+ JSONArray subAnswers = answer != null ? answer.getJSONArray("subQuestions") : null;
|
|
|
+ JSONArray subCollection = filterQuestions(question.getJSONArray("subQuestions"), subAnswers,
|
|
|
+ acceptObjective, acceptSubjective);
|
|
|
+ //没有子题,则本题也被过滤掉
|
|
|
+ if (subCollection.size() > 0) {
|
|
|
+ question.put("subQuestions", subCollection);
|
|
|
} else {
|
|
|
- if (structquestion.getInteger("structType").intValue() != 6) {
|
|
|
- if (structquestion.getInteger("structType").intValue() == 3) {
|
|
|
- structquestion.put("answer", answerquestion.getBoolean("answer"));
|
|
|
- } else {
|
|
|
- structquestion.put("answer", answerquestion.getJSONArray("answer"));
|
|
|
- }
|
|
|
- } else {
|
|
|
- JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
- JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
- for (int k = 0; k < structsubQuestions.size(); k++) {
|
|
|
- JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
|
|
|
- JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
|
- if (structsubquestion.getInteger("structType").intValue() == 3) {
|
|
|
- structsubquestion.put("answer", answersubquestion.getBoolean("answer"));
|
|
|
- } else {
|
|
|
- structsubquestion.put("answer", answersubquestion.getJSONArray("answer"));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ accept = false;
|
|
|
}
|
|
|
-
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ accept = false;
|
|
|
+ }
|
|
|
+ if (accept) {
|
|
|
+ if (answer != null) {
|
|
|
+ question.put("answer", answer.get("answer"));
|
|
|
}
|
|
|
+ collection.add(question);
|
|
|
}
|
|
|
- return structJson;
|
|
|
- } finally {
|
|
|
- FileUtil.deleteFolder(dir);
|
|
|
}
|
|
|
+ return collection;
|
|
|
}
|
|
|
|
|
|
- private String uuid() {
|
|
|
- return UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ private JSONObject findJsonObject(JSONArray array, int number) {
|
|
|
+ if (array != null) {
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ JSONObject item = array.getJSONObject(i);
|
|
|
+ if (item.getIntValue("number") == number) {
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- private void checkExam(Long examId) {
|
|
|
+ private TEExam checkExam(Long examId) {
|
|
|
TEExam exam = examService.getById(examId);
|
|
|
if (exam == null) {
|
|
|
throw new BusinessException("未找到考试信息");
|
|
|
}
|
|
|
- if (exam.getEnable() == null || exam.getEnable().intValue() == 0) {
|
|
|
+ if (exam.getEnable() == null || exam.getEnable() == 0) {
|
|
|
throw new BusinessException("考试批次已禁用");
|
|
|
}
|
|
|
if (!InvigilateMonitorStatusEnum.FINISHED.equals(exam.getMonitorStatus())) {
|
|
|
throw new BusinessException("考试批次监考未结束");
|
|
|
}
|
|
|
- List<TEExamCourse> courses = examCourseService.findByExamId(examId);
|
|
|
- if (courses == null || courses.size() == 0) {
|
|
|
- throw new BusinessException("考试批次下没有课程");
|
|
|
- }
|
|
|
- for (TEExamCourse course : courses) {
|
|
|
- if (course.getHasAnswer() == null || course.getHasAnswer().intValue() == 0) {
|
|
|
- throw new BusinessException("考试批次下标答未齐全");
|
|
|
- }
|
|
|
- }
|
|
|
+ return exam;
|
|
|
+ // List<TEExamCourse> courses = examCourseService.findByExamId(examId);
|
|
|
+ // if (courses == null || courses.size() == 0) {
|
|
|
+ // throw new BusinessException("考试批次下没有课程");
|
|
|
+ // }
|
|
|
+ // for (TEExamCourse course : courses) {
|
|
|
+ // if (course.getHasAnswer() == null || course.getHasAnswer().intValue() == 0) {
|
|
|
+ // throw new BusinessException("考试批次下标答未齐全");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONArray examRecordNeedMark(Long examId, String courseCode, Long idGt, Integer count) {
|
|
|
- checkExam(examId);
|
|
|
- List<OpenRecordNeedMarkBean> list;
|
|
|
- for (; ; ) {
|
|
|
- List<Long> examStudentIds = examStudentService.findExamStudentIdsNeedMark(examId, courseCode, idGt, count);
|
|
|
- if (examStudentIds == null || examStudentIds.size() == 0) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- list = findExamRecordNeedMark(examId, examStudentIds);
|
|
|
- if (list == null || list.size() == 0) {
|
|
|
- idGt = examStudentIds.get(examStudentIds.size() - 1);
|
|
|
- } else {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- List<Long> ids = list.stream().map(dto -> dto.getExamRecordId()).collect(Collectors.toList());
|
|
|
- List<OpenRecordAnswerBean> answers = examAnswerService.findByRecordIds(ids);
|
|
|
- if (answers != null && answers.size() > 0) {
|
|
|
- for (int i = 0; i < answers.size(); i++) {//剔除客观题答案
|
|
|
- OpenRecordAnswerBean answer = answers.get(i);
|
|
|
- Map<String, Integer> struct = examPaperService.getPaperStructCacheBean(answer.getPaperId());
|
|
|
- Integer type = struct.get(RedisKeyHelper
|
|
|
- .examAnswerHashKey(answer.getMainNumber(), answer.getSubNumber(), answer.getSubIndex()));
|
|
|
- if (type == 1 || type == 2 || type == 3) {
|
|
|
- answers.remove(i);
|
|
|
- i--;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (answers != null && answers.size() > 0) {
|
|
|
- Map<Long, Integer> map = new HashMap<>();
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- map.put(list.get(i).getExamRecordId(), i);
|
|
|
- }
|
|
|
- for (OpenRecordAnswerBean anwser : answers) {
|
|
|
- OpenRecordNeedMarkBean mark = list.get(map.get(anwser.getRecordId()));
|
|
|
- List<OpenRecordAnswerBean> ans = mark.getAnswers();
|
|
|
- if (ans == null) {
|
|
|
- ans = new ArrayList<OpenRecordAnswerBean>();
|
|
|
- mark.setAnswers(ans);
|
|
|
- }
|
|
|
- ans.add(anwser);
|
|
|
- }
|
|
|
- }
|
|
|
- JSONArray ja = JSONArray.parseArray(JSONArray.toJSONString(list));
|
|
|
- for (int i = 0; i < ja.size(); i++) {
|
|
|
- JSONObject job = ja.getJSONObject(i);
|
|
|
- JSONArray answersJa = job.getJSONArray("answers");
|
|
|
- if (answersJa != null) {
|
|
|
- for (int j = 0; j < answersJa.size(); j++) {
|
|
|
- JSONObject answersJob = answersJa.getJSONObject(j);
|
|
|
- answersJob.remove("recordId");
|
|
|
- answersJob.remove("paperId");
|
|
|
- String answerStr = answersJob.getString("answer");
|
|
|
- if (StringUtils.isNotBlank(answerStr)) {
|
|
|
- if (answerStr.toLowerCase().startsWith("true") || answerStr.toLowerCase().startsWith("false")) {
|
|
|
- answersJob.put("answer", Boolean.getBoolean(answerStr.replaceAll("\n", "")));
|
|
|
- } else {
|
|
|
- answersJob.put("answer", answersJob.getJSONArray("answer"));
|
|
|
+ JSONArray result = new JSONArray();
|
|
|
+ TEExam exam = checkExam(examId);
|
|
|
+ Map<Long, ExamPaperCacheBean> paperMap = new HashMap<>();
|
|
|
+ final Map<Long, Map<String, Integer>> paperStructMap = new HashMap<>();
|
|
|
+ //查询需要参与评卷的考生
|
|
|
+ List<TEExamStudentDto> examStudents = examStudentService
|
|
|
+ .findExamStudentNeedMark(examId, courseCode, idGt, count);
|
|
|
+ if (examStudents != null) {
|
|
|
+ for (TEExamStudentDto examStudent : examStudents) {
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("id", examStudent.getId());
|
|
|
+ obj.put("identity", examStudent.getIdentity());
|
|
|
+ obj.put("name", examStudent.getName());
|
|
|
+ obj.put("activityCode", examStudent.getActivityCode());
|
|
|
+ obj.put("courseCode", examStudent.getCourseCode());
|
|
|
+ obj.put("courseName", examStudent.getCourseName());
|
|
|
+ //查询需要主观题评卷的考试记录
|
|
|
+ List<OpenRecordNeedMarkBean> recordList = findExamRecordNeedMark(examStudent.getId(), paperMap,
|
|
|
+ exam.getRecordSelectStrategy());
|
|
|
+ for (OpenRecordNeedMarkBean record : recordList) {
|
|
|
+ //查询所有单题作答结果
|
|
|
+ List<OpenRecordAnswerBean> answers = examAnswerService.findByExamRecordId(record.getId());
|
|
|
+ record.setAnswers(answers.stream().filter(answer -> {
|
|
|
+ Map<String, Integer> struct = paperStructMap.get(record.getPaperId());
|
|
|
+ if (struct == null) {
|
|
|
+ struct = examPaperService.getPaperStructCacheBean(record.getPaperId());
|
|
|
+ if (struct != null) {
|
|
|
+ paperStructMap.put(record.getPaperId(), struct);
|
|
|
+ } else {
|
|
|
+ log.error("找不到对应的试卷结构,paperId=" + record.getPaperId());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ Integer type = struct.get(RedisKeyHelper
|
|
|
+ .examAnswerHashKey(answer.getMainNumber(), answer.getSubNumber(),
|
|
|
+ answer.getSubIndex()));
|
|
|
+ //过滤单选、多选、判断题
|
|
|
+ return type != null && type != 1 && type != 2 && type != 3;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
}
|
|
|
+ obj.put("records", recordList);
|
|
|
+ result.add(obj);
|
|
|
}
|
|
|
}
|
|
|
- return ja;
|
|
|
+ paperMap.clear();
|
|
|
+ paperStructMap.clear();
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- private List<OpenRecordNeedMarkBean> findExamRecordNeedMark(Long examId, List<Long> examStudentIds) {
|
|
|
- List<OpenRecordNeedMarkBean> list = examRecordService.findExamRecordNeedMark(examId, examStudentIds);
|
|
|
- if (list == null || list.size() == 0) {
|
|
|
- return null;
|
|
|
+ private List<OpenRecordNeedMarkBean> findExamRecordNeedMark(Long examStudentId,
|
|
|
+ Map<Long, ExamPaperCacheBean> paperMap, RecordSelectStrategyEnum strategy) {
|
|
|
+ List<OpenRecordNeedMarkBean> list = examRecordService.findExamRecordNeedMark(examStudentId);
|
|
|
+ List<OpenRecordNeedMarkBean> result = new ArrayList<>();
|
|
|
+ if (list == null) {
|
|
|
+ return result;
|
|
|
}
|
|
|
- for (int i = 0; i < list.size(); i++) {//剔除没有主观题的试卷考试记录
|
|
|
- ExamPaperCacheBean paper = examPaperService.getExamPaperCacheBean(list.get(i).getPaperId());
|
|
|
- if (paper.getTotalSubjectiveScore() == 0) {
|
|
|
- list.remove(i);
|
|
|
- i--;
|
|
|
- }
|
|
|
- }
|
|
|
- if (list == null || list.size() == 0) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- TEExam exam = examService.getById(examId);
|
|
|
- if (RecordSelectStrategyEnum.HIGHEST_TOTAL_SCORE.equals(exam.getRecordSelectStrategy())) {//全阅
|
|
|
- return list;
|
|
|
- } else if (RecordSelectStrategyEnum.HIGHEST_OBJECTIVE_SCORE
|
|
|
- .equals(exam.getRecordSelectStrategy())) {//客观分最高,相同则都阅
|
|
|
- Map<Long, List<OpenRecordNeedMarkBean>> map = new HashMap<>();
|
|
|
- for (OpenRecordNeedMarkBean bean : list) {
|
|
|
- List<OpenRecordNeedMarkBean> temList = map.get(bean.getExamStudentId());
|
|
|
- if (temList == null) {
|
|
|
- temList = new ArrayList<OpenRecordNeedMarkBean>();
|
|
|
- temList.add(bean);
|
|
|
- map.put(bean.getExamStudentId(), temList);
|
|
|
+ double highestObjectiveScore = 0.0;
|
|
|
+ long maxFinishTime = 0L;
|
|
|
+ for (OpenRecordNeedMarkBean bean : list) {
|
|
|
+ //获取对应的试卷信息
|
|
|
+ ExamPaperCacheBean paper = paperMap.get(bean.getPaperId());
|
|
|
+ if (paper == null) {
|
|
|
+ paper = examPaperService.getExamPaperCacheBean(bean.getPaperId());
|
|
|
+ if (paper == null) {
|
|
|
+ log.error("找不到对应的试卷信息, paperId=" + bean.getPaperId());
|
|
|
+ continue;
|
|
|
} else {
|
|
|
- if (temList.get(0).getObjectiveScore().doubleValue() == bean.getObjectiveScore().doubleValue()) {
|
|
|
- temList.add(bean);
|
|
|
- } else if (temList.get(0).getObjectiveScore() < bean.getObjectiveScore()) {
|
|
|
- temList = new ArrayList<OpenRecordNeedMarkBean>();
|
|
|
- temList.add(bean);
|
|
|
- map.put(bean.getExamStudentId(), temList);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- List<OpenRecordNeedMarkBean> ret = new ArrayList<OpenRecordNeedMarkBean>();
|
|
|
- for (List<OpenRecordNeedMarkBean> tem : map.values()) {
|
|
|
- for (OpenRecordNeedMarkBean bean : tem) {
|
|
|
- ret.add(bean);
|
|
|
+ paperMap.put(bean.getPaperId(), paper);
|
|
|
}
|
|
|
}
|
|
|
- Collections.sort(ret, new Comparator<OpenRecordNeedMarkBean>() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public int compare(OpenRecordNeedMarkBean o1, OpenRecordNeedMarkBean o2) {
|
|
|
- Long c1 = o1.getExamStudentId();
|
|
|
- Long c2 = o2.getExamStudentId();
|
|
|
- if (c1 > c2) {
|
|
|
- return 1;
|
|
|
- } else if (c1 < c2) {
|
|
|
- return -1;
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- return ret;
|
|
|
- } else if (RecordSelectStrategyEnum.LATEST.equals(exam.getRecordSelectStrategy())) {//最后一次提交
|
|
|
- Map<Long, OpenRecordNeedMarkBean> map = new HashMap<>();
|
|
|
- for (OpenRecordNeedMarkBean bean : list) {
|
|
|
- OpenRecordNeedMarkBean old = map.get(bean.getExamStudentId());
|
|
|
- if (old == null || old.getFinishTime() < bean.getFinishTime()) {
|
|
|
- map.put(bean.getExamStudentId(), bean);
|
|
|
- }
|
|
|
+ //根据试卷结构过滤没有主观题的情况
|
|
|
+ if (paper.getTotalSubjectiveScore() == 0) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- List<OpenRecordNeedMarkBean> ret = map.values().stream().collect(Collectors.toList());
|
|
|
- Collections.sort(ret, new Comparator<OpenRecordNeedMarkBean>() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public int compare(OpenRecordNeedMarkBean o1, OpenRecordNeedMarkBean o2) {
|
|
|
- Long c1 = o1.getExamStudentId();
|
|
|
- Long c2 = o2.getExamStudentId();
|
|
|
- if (c1 > c2) {
|
|
|
- return 1;
|
|
|
- } else if (c1 < c2) {
|
|
|
- return -1;
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- return ret;
|
|
|
- } else {
|
|
|
- throw new BusinessException("考试批次阅卷类型未定义");
|
|
|
+ highestObjectiveScore = Math.max(highestObjectiveScore, bean.getObjectiveScore());
|
|
|
+ maxFinishTime = Math.max(maxFinishTime, bean.getFinishTime());
|
|
|
+ result.add(bean);
|
|
|
+ }
|
|
|
+ if (result.isEmpty()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ switch (strategy) {
|
|
|
+ case HIGHEST_OBJECTIVE_SCORE:
|
|
|
+ //客观分最高,客观分相同则全部提交阅卷
|
|
|
+ final double score = highestObjectiveScore;
|
|
|
+ return result.stream().filter(bean -> bean.getObjectiveScore() == score).collect(Collectors.toList());
|
|
|
+ case LATEST:
|
|
|
+ //最后一次提交
|
|
|
+ final long time = maxFinishTime;
|
|
|
+ return result.stream().filter(bean -> bean.getFinishTime() == time).collect(Collectors.toList());
|
|
|
+ default:
|
|
|
+ //总分最高,全部提交阅卷
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|