|
@@ -357,66 +357,69 @@ public class ExamRecordDataServiceImpl implements ExamRecordDataService {
|
|
|
*/
|
|
|
@Override
|
|
|
public CalcExamScoreResp calcExamScore(CalcExamScoreReq req) {
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
- ExamRecordQuestions examRecordQuestions = examRecordQuestionsService.getExamRecordQuestions(req.getExamRecordDataId());
|
|
|
-
|
|
|
- // todo NPE
|
|
|
-
|
|
|
- // 考生作答记录明细
|
|
|
- List<ExamQuestion> examQuestions = examRecordQuestions.getExamQuestions();
|
|
|
-
|
|
|
- for (ExamQuestion examQuestion : examQuestions) {
|
|
|
- if (QuestionTypeUtil.isObjectiveQuestion(examQuestion.getQuestionType())) {
|
|
|
- // 如果客观题的标准答案为空,则更新标准答案
|
|
|
- if (StringUtils.isEmpty(examQuestion.getCorrectAnswer())) {
|
|
|
- this.updateCorrectAnswer(req.getExamRecordDataId(), examQuestions, examQuestion);
|
|
|
+ try {
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ ExamRecordQuestions examRecordQuestions = examRecordQuestionsService.getExamRecordQuestions(req.getExamRecordDataId());
|
|
|
+
|
|
|
+ // 考生作答记录明细
|
|
|
+ List<ExamQuestion> examQuestions = examRecordQuestions.getExamQuestions();
|
|
|
+
|
|
|
+ for (ExamQuestion examQuestion : examQuestions) {
|
|
|
+ if (QuestionTypeUtil.isObjectiveQuestion(examQuestion.getQuestionType())) {
|
|
|
+ // 如果客观题的标准答案为空,则更新标准答案
|
|
|
+ if (StringUtils.isEmpty(examQuestion.getCorrectAnswer())) {
|
|
|
+ this.updateCorrectAnswer(req.getExamRecordDataId(), examQuestions, examQuestion);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- double objectiveScore = 0d;//客观题总分
|
|
|
- int totalObjective = 0;//客观题总数
|
|
|
- int totalRightObjective = 0;//答题正确数
|
|
|
+ double objectiveScore = 0d;//客观题总分
|
|
|
+ int totalObjective = 0;//客观题总数
|
|
|
+ int totalRightObjective = 0;//答题正确数
|
|
|
|
|
|
- for (int i = 0; i < examQuestions.size(); i++) {
|
|
|
- ExamQuestion examQuestion = examQuestions.get(i);
|
|
|
- if (!QuestionTypeUtil.isObjectiveQuestion(examQuestion.getQuestionType())) {
|
|
|
- // 跳过主观题
|
|
|
- continue;
|
|
|
- }
|
|
|
+ for (int i = 0; i < examQuestions.size(); i++) {
|
|
|
+ ExamQuestion examQuestion = examQuestions.get(i);
|
|
|
+ if (!QuestionTypeUtil.isObjectiveQuestion(examQuestion.getQuestionType())) {
|
|
|
+ // 跳过主观题
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- totalObjective++;
|
|
|
+ totalObjective++;
|
|
|
|
|
|
- // 如果学生作答正确,则客观分累加,答题数累加
|
|
|
- if (examQuestion.getStudentAnswer() != null && examQuestion.getCorrectAnswer() != null
|
|
|
- // && QuestionOptionHelper.isEqualAnswer(examQuestion.getCorrectAnswer(), examQuestion.getStudentAnswer())) {
|
|
|
- && examQuestion.getStudentAnswer().equals(examQuestion.getCorrectAnswer())) {
|
|
|
+ // 如果学生作答正确,则客观分累加,答题数累加
|
|
|
+ if (examQuestion.getStudentAnswer() != null && examQuestion.getCorrectAnswer() != null
|
|
|
+ // && QuestionOptionHelper.isEqualAnswer(examQuestion.getCorrectAnswer(), examQuestion.getStudentAnswer())) {
|
|
|
+ && examQuestion.getStudentAnswer().equals(examQuestion.getCorrectAnswer())) {
|
|
|
|
|
|
- double questionScore = examQuestion.getQuestionScore();
|
|
|
- BigDecimal bigObjectiveScore = new BigDecimal(Double.toString(objectiveScore));
|
|
|
- BigDecimal bigQuestionScore = new BigDecimal(Double.toString(questionScore));
|
|
|
+ double questionScore = examQuestion.getQuestionScore();
|
|
|
+ BigDecimal bigObjectiveScore = new BigDecimal(Double.toString(objectiveScore));
|
|
|
+ BigDecimal bigQuestionScore = new BigDecimal(Double.toString(questionScore));
|
|
|
|
|
|
- objectiveScore = bigQuestionScore.add(bigObjectiveScore).doubleValue();
|
|
|
- totalRightObjective++;
|
|
|
+ objectiveScore = bigQuestionScore.add(bigObjectiveScore).doubleValue();
|
|
|
+ totalRightObjective++;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 计算客观题答题正确率
|
|
|
- double objectiveAccuracy = 0;
|
|
|
- if (totalRightObjective > 0 && totalObjective > 0) {
|
|
|
- objectiveAccuracy = Double.parseDouble(new DecimalFormat("#.00").format(totalRightObjective * 100D / totalObjective));
|
|
|
- }
|
|
|
-
|
|
|
- CalcExamScoreResp resp = new CalcExamScoreResp();
|
|
|
- resp.setObjectiveScore(objectiveScore);
|
|
|
- resp.setObjectiveAccuracy(objectiveAccuracy);
|
|
|
- //交卷时,总分=客观分得分
|
|
|
- resp.setTotalScore(objectiveScore);
|
|
|
+ // 计算客观题答题正确率
|
|
|
+ double objectiveAccuracy = 0;
|
|
|
+ if (totalRightObjective > 0 && totalObjective > 0) {
|
|
|
+ objectiveAccuracy = Double.parseDouble(new DecimalFormat("#.00").format(totalRightObjective * 100D / totalObjective));
|
|
|
+ }
|
|
|
|
|
|
- long cost = System.currentTimeMillis() - startTime;
|
|
|
- log.warn("calcExamScore examRecordDataId:{}, totalQuestion:{}, totalObjective:{}, cost:{}ms",
|
|
|
- req.getExamRecordDataId(), examQuestions.size(), totalObjective, cost);
|
|
|
- return resp;
|
|
|
+ CalcExamScoreResp resp = new CalcExamScoreResp();
|
|
|
+ resp.setObjectiveScore(objectiveScore);
|
|
|
+ resp.setObjectiveAccuracy(objectiveAccuracy);
|
|
|
+ //交卷时,总分=客观分得分
|
|
|
+ resp.setTotalScore(objectiveScore);
|
|
|
+
|
|
|
+ long cost = System.currentTimeMillis() - startTime;
|
|
|
+ log.warn("calcExamScore examRecordDataId:{}, totalQuestion:{}, totalObjective:{}, cost:{}ms",
|
|
|
+ req.getExamRecordDataId(), examQuestions.size(), totalObjective, cost);
|
|
|
+ return resp;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ throw new StatusException("计算考试分数异常!examRecordDataId=" + req.getExamRecordDataId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|