Parcourir la source

修复套题小题分的bug

宋悦 il y a 7 ans
Parent
commit
61fe429c60

+ 7 - 0
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/CommonUtils.java

@@ -3,6 +3,8 @@ package com.qmth.cqb.utils;
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -268,6 +270,11 @@ public final class CommonUtils {
 		}
 		return idValues;
     }
+
+    public static double formatDouble(double number){
+        BigDecimal formatNumber = new BigDecimal(number);
+        return formatNumber.setScale(2, RoundingMode.HALF_UP).doubleValue();
+    }
     
 
     public static void main(String[] args) {

+ 1 - 2
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/service/GenPaperService.java

@@ -395,8 +395,7 @@ public class GenPaperService {
                         if(subQuestions != null && subQuestions.size() > 0){
                             for(Question subQuestion:subQuestions){
                                 double score = paperDetailUnit.getScore()/ subQuestions.size();
-                                BigDecimal formatScore = new BigDecimal(score);
-                                subScoreList.add(formatScore.setScale(2, RoundingMode.HALF_UP).doubleValue());
+                                subScoreList.add(CommonUtils.formatDouble(score));
                             }
                             paperDetailUnit.setSubScoreListNew(subScoreList);
                         }

+ 2 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailUnit.java

@@ -201,7 +201,7 @@ public class PaperDetailUnit implements Serializable, Comparable<PaperDetailUnit
                 }
                 totalScore += score;
             }
-            this.score = totalScore;
+            this.score = CommonUtils.formatDouble(totalScore);
         }
     }
 
@@ -262,6 +262,6 @@ public class PaperDetailUnit implements Serializable, Comparable<PaperDetailUnit
                 totalScore += score;
             }
         }
-        return totalScore;
+        return CommonUtils.formatDouble(totalScore);
     }
 }