Quellcode durchsuchen

班级成绩查看导出

dzx vor 10 Monaten
Ursprung
Commit
57e0c2492f

+ 10 - 7
src/main/java/com/xjrsoft/module/xycxedu/service/impl/ExamSubjectScoreServiceImpl.java

@@ -221,15 +221,18 @@ public class ExamSubjectScoreServiceImpl extends MPJBaseServiceImpl<ExamSubjectS
                 sortCode ++;
                 continue;
             }
-            double totalSocre = scoreList.stream().filter(x -> StrUtil.isNotEmpty(x.getScore())).mapToDouble(x -> Float.parseFloat(x.getScore())).sum();
-            if(totalSocre != 0){
-                BigDecimal bd = new BigDecimal(totalSocre);
-                bd = bd.stripTrailingZeros();
-                if (bd.scale() <= 0) { // 如果是整数
-                    rowData.add(bd.toBigInteger().toString());
+            BigDecimal reduce = scoreList.stream().filter(x -> StrUtil.isNotEmpty(x.getScore())).map(x -> new BigDecimal(x.getScore())).reduce(BigDecimal.ZERO, BigDecimal::add);
+            BigDecimal totalSocre = reduce
+                    .setScale(2, BigDecimal.ROUND_HALF_UP);
+            if(!totalSocre.equals(BigDecimal.ZERO)){
+                totalSocre = totalSocre.stripTrailingZeros();
+                if (totalSocre.scale() <= 0) { // 如果是整数
+                    rowData.add(totalSocre.toBigInteger().toString());
                 } else {
-                    rowData.add(bd.toPlainString());
+                    rowData.add(totalSocre.toPlainString());
                 }
+            }else{
+                rowData.add("");
             }
 
             Map<String, String> scoreMap = scoreList.stream().filter(x -> StrUtil.isNotEmpty(x.getScore())).collect(Collectors.toMap(ClassStudentScoreTitleVo::getCourseId, ClassStudentScoreTitleVo::getScore));