From 760d54333735defac5c2c1a4730aae93715c0692 Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Thu, 5 Dec 2024 09:43:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=B9=B3=E5=9D=87=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TheoryTestServiceImpl.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sztzjy/money_management/service/impl/TheoryTestServiceImpl.java b/src/main/java/com/sztzjy/money_management/service/impl/TheoryTestServiceImpl.java index 0e13706..f0fd0d0 100644 --- a/src/main/java/com/sztzjy/money_management/service/impl/TheoryTestServiceImpl.java +++ b/src/main/java/com/sztzjy/money_management/service/impl/TheoryTestServiceImpl.java @@ -170,11 +170,15 @@ public class TheoryTestServiceImpl implements TheoryTestService { if (record.getAverageScore() == null) { record.setAverageScore(score); } else { - Integer examCount = record.getExamCount(); - BigDecimal averageScore = record.getAverageScore(); - BigDecimal multiply = averageScore.multiply(BigDecimal.valueOf(examCount)); - BigDecimal newAvg = multiply.add(score).divide(BigDecimal.valueOf(examCount), 2, RoundingMode.HALF_UP); - record.setAverageScore(newAvg); + StuTheoryExamExample example = new StuTheoryExamExample(); + example.createCriteria().andUserIdEqualTo(userId).andAnsweredEqualTo(true); + List stuTheoryExamWithBLOBs = theoryExamMapper.selectByExampleWithBLOBs(example); + BigDecimal totalScore = stuTheoryExamWithBLOBs.stream() + .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); @@ -525,13 +529,14 @@ public class TheoryTestServiceImpl implements TheoryTestService { } public static void main(String[] args) { - String singleStuAnswer = ", , , ,"+" ,"; + String singleStuAnswer = ", , , ," + " ,"; System.out.println(singleStuAnswer); String[] split = singleStuAnswer.split(", "); for (String s : split) { System.out.println(s); } } + @Override public List getTheoryTestDetail(String theoryExamId, Integer index, Integer size) throws IOException { ArrayList idsList = new ArrayList<>();