|
@@ -124,7 +124,7 @@ public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentE
|
|
|
throw new BizException("考试结果不存在");
|
|
|
}
|
|
|
if(Objects.isNull(oldStudentExamResult.getAvgScore())){
|
|
|
- throw new BizException("考试结果暂不可编辑");
|
|
|
+ throw new BizException("考试未结束");
|
|
|
}
|
|
|
ExaminationBasic examinationBasic = examinationBasicDao.get(oldStudentExamResult.getExaminationBasicId().longValue());
|
|
|
if(Objects.isNull(examinationBasic)){
|
|
@@ -170,25 +170,24 @@ public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentE
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void calculateStudentExamAvgScore(Long examRoomId) {
|
|
|
- List<ExamReview> examReviews = examReviewDao.getWithExamRoom(examRoomId);
|
|
|
- if(CollectionUtils.isEmpty(examReviews)){
|
|
|
+ List<StudentExamResult> studentExamResults = studentExamResultDao.getWithExamRoom(examRoomId);
|
|
|
+ if(CollectionUtils.isEmpty(studentExamResults)){
|
|
|
return;
|
|
|
}
|
|
|
+ List<ExamReview> examReviews = examReviewDao.getWithExamRoom(examRoomId);
|
|
|
Map<Long, List<ExamReview>> registReviewMap = examReviews.stream().collect(Collectors.groupingBy(ExamReview::getExamRegistrationId));
|
|
|
- List<StudentExamResult> needUpdateStudentExamResult = new ArrayList<>();
|
|
|
- for (Map.Entry<Long, List<ExamReview>> registReviewEntry : registReviewMap.entrySet()) {
|
|
|
- List<ExamReview> reviews = registReviewEntry.getValue().stream().filter(e->Objects.nonNull(e.getEvaluationResult())).collect(Collectors.toList());
|
|
|
+ for (StudentExamResult studentExamResult : studentExamResults) {
|
|
|
+ List<ExamReview> reviews = registReviewMap.get(studentExamResult.getExamRegistrationId());
|
|
|
if(CollectionUtils.isEmpty(reviews)){
|
|
|
+ studentExamResult.setAvgScore((float) 0);
|
|
|
continue;
|
|
|
}
|
|
|
- StudentExamResult studentExamResult=new StudentExamResult();
|
|
|
- studentExamResult.setExamRegistrationId(registReviewEntry.getKey());
|
|
|
+ reviews = reviews.stream().filter(e->Objects.nonNull(e.getEvaluationResult())).collect(Collectors.toList());
|
|
|
long totalScore = reviews.stream().mapToLong(ExamReview::getEvaluationResult).sum();
|
|
|
BigDecimal avgScore = new BigDecimal(totalScore).divide(new BigDecimal(reviews.size()), 2, BigDecimal.ROUND_CEILING);
|
|
|
studentExamResult.setAvgScore(avgScore.floatValue());
|
|
|
- needUpdateStudentExamResult.add(studentExamResult);
|
|
|
}
|
|
|
- studentExamResultDao.updateRegistAvgScore(needUpdateStudentExamResult);
|
|
|
+ studentExamResultDao.updateRegistAvgScore(studentExamResults);
|
|
|
}
|
|
|
|
|
|
@Override
|