Ver código fonte

修改没有成绩报错问题

小么熊🐻 3 anos atrás
pai
commit
8c056268da

+ 6 - 2
jkt-service/src/main/java/com/miaxis/score/service/impl/ScoreInfoServiceImpl.java

@@ -52,8 +52,12 @@ public class ScoreInfoServiceImpl extends ServiceImpl<ScoreInfoMapper, ScoreInfo
         for (int a: list) {
             total +=a;
         }
-        int forecastScore= total/list.size();
-        return forecastScore;
+        if(total==0){
+            return 0;
+        } else {
+            int forecastScore= total/list.size();
+            return forecastScore;
+        }
     }
 
 

+ 2 - 2
jkt-service/src/main/resources/mapper/score/ScoreInfoMapper.xml

@@ -39,7 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="getAvgScore" parameterType="ScoreInfo" resultType="int">
-        select ROUND(avg(score),0) from score_info s
+        select IFNULL(ROUND(avg(score),0),0) from score_info s
         <where>
             <if test="userId != null "> and user_id = #{userId}</if>
         </where>
@@ -48,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 
     <select id="getMaxScore" parameterType="ScoreInfo" resultType="int">
-        select max(score) from score_info s
+        select IFNULL(max(score),0) from score_info s
         <where>
             <if test="userId != null "> and user_id = #{userId}</if>
         </where>