计算平均分

master
xiaoCJ 4 months ago
parent b7051dc993
commit 760d543337

@ -170,11 +170,15 @@ public class TheoryTestServiceImpl implements TheoryTestService {
if (record.getAverageScore() == null) { if (record.getAverageScore() == null) {
record.setAverageScore(score); record.setAverageScore(score);
} else { } else {
Integer examCount = record.getExamCount(); StuTheoryExamExample example = new StuTheoryExamExample();
BigDecimal averageScore = record.getAverageScore(); example.createCriteria().andUserIdEqualTo(userId).andAnsweredEqualTo(true);
BigDecimal multiply = averageScore.multiply(BigDecimal.valueOf(examCount)); List<StuTheoryExamWithBLOBs> stuTheoryExamWithBLOBs = theoryExamMapper.selectByExampleWithBLOBs(example);
BigDecimal newAvg = multiply.add(score).divide(BigDecimal.valueOf(examCount), 2, RoundingMode.HALF_UP); BigDecimal totalScore = stuTheoryExamWithBLOBs.stream()
record.setAverageScore(newAvg); .map(StuTheoryExamWithBLOBs::getScore)
.reduce(BigDecimal.ZERO, BigDecimal::add)
.add(score);
BigDecimal avgScore = totalScore.divide(BigDecimal.valueOf(stuTheoryExamWithBLOBs.size()+1), 2, RoundingMode.HALF_UP);
record.setAverageScore(avgScore);
} }
} }
theoryRecordMapper.updateByPrimaryKey(record); theoryRecordMapper.updateByPrimaryKey(record);
@ -532,6 +536,7 @@ public class TheoryTestServiceImpl implements TheoryTestService {
System.out.println(s); System.out.println(s);
} }
} }
@Override @Override
public List<StuTheoryExamDetailDto> getTheoryTestDetail(String theoryExamId, Integer index, Integer size) throws IOException { public List<StuTheoryExamDetailDto> getTheoryTestDetail(String theoryExamId, Integer index, Integer size) throws IOException {
ArrayList<String> idsList = new ArrayList<>(); ArrayList<String> idsList = new ArrayList<>();

Loading…
Cancel
Save