Parcourir la source

预测成绩 平均成绩

小么熊🐻 il y a 3 ans
Parent
commit
3107ce35c0

+ 32 - 0
jkt-admin/src/main/java/com/miaxis/app/controller/score/ScoreInfoController.java

@@ -19,7 +19,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 【模拟考成绩】Controller
@@ -100,4 +102,34 @@ public class ScoreInfoController extends BaseController{
     ){
         return toResponse(scoreInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
     }
+
+
+    /**
+     * 获取预测成功
+     */
+    @GetMapping(value = "/forecastScore")
+    @ApiOperation("获取预测成绩")
+    public Response<Integer> getInfo(){
+        ScoreInfo scoreInfo = new ScoreInfo();
+        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
+        int forecastScore = scoreInfoService.getForecastScore(scoreInfo);
+//        Map<String,Object> map = new HashMap<String,Object>();
+//        map.put("forecastScore",forecastScore);
+        return Response.success(forecastScore);
+    }
+
+
+    /**
+     * 获取预测成功
+     */
+    @GetMapping(value = "/avgScore")
+    @ApiOperation("获取平均成绩")
+    public Response<Integer> getAvgScore(){
+        ScoreInfo scoreInfo = new ScoreInfo();
+        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
+        int aveScore = scoreInfoService.getAveScore(scoreInfo);
+//        Map<String,Object> map = new HashMap<String,Object>();
+//        map.put("forecastScore",forecastScore);
+        return Response.success(aveScore);
+    }
 }

+ 12 - 1
jkt-admin/src/test/java/com/miaxis/test/NormalTest.java

@@ -1,8 +1,12 @@
 package com.miaxis.test;
 
 import com.miaxis.JktApplication;
+import com.miaxis.score.domain.ScoreInfo;
+import com.miaxis.score.dto.ScoreInfoDTO;
+import com.miaxis.score.service.IScoreInfoService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
@@ -11,10 +15,17 @@ import org.springframework.test.context.junit4.SpringRunner;
 @RunWith(SpringRunner.class)
 public class NormalTest {
 
-
+    @Autowired
+    private IScoreInfoService iScoreInfoService;
     @Test
     public void test1() throws Exception {
 
+        ScoreInfo scoreInfo = new ScoreInfo();
+        scoreInfo.setUserId(4240l);
+
+//        int result = iScoreInfoService.getAveScore(scoreInfo);
+        iScoreInfoService.getForecastScore(scoreInfo);
+
     }
 
 

+ 15 - 0
jkt-service/src/main/java/com/miaxis/score/mapper/ScoreInfoMapper.java

@@ -19,4 +19,19 @@ public interface ScoreInfoMapper extends BaseMapper<ScoreInfo> {
      */
     public List<ScoreInfo> selectScoreInfoList(ScoreInfo scoreInfo);
 
+
+    /**
+     * 返回
+     * @param scoreInfo
+     * @return
+     */
+    public int getAvgScore(ScoreInfo scoreInfo);
+
+
+    /**
+     * 返回
+     * @param scoreInfo
+     * @return
+     */
+    public List getLast10Score(ScoreInfo scoreInfo);
 }

+ 14 - 0
jkt-service/src/main/java/com/miaxis/score/service/IScoreInfoService.java

@@ -18,4 +18,18 @@ public interface IScoreInfoService extends IService<ScoreInfo>{
      * @return 模拟考成绩集合
      */
     public List<ScoreInfo> selectScoreInfoList(ScoreInfo scoreInfo);
+
+    /**
+     * 查询模拟考试平均成绩
+     * @param scoreInfo
+     * @return
+     */
+    public int getAveScore(ScoreInfo scoreInfo);
+
+    /**
+     * 查询模拟考试预测成绩
+     * @param scoreInfo
+     * @return
+     */
+    public int getForecastScore(ScoreInfo scoreInfo);
 }

+ 23 - 0
jkt-service/src/main/java/com/miaxis/score/service/impl/ScoreInfoServiceImpl.java

@@ -33,4 +33,27 @@ public class ScoreInfoServiceImpl extends ServiceImpl<ScoreInfoMapper, ScoreInfo
     public List<ScoreInfo> selectScoreInfoList(ScoreInfo scoreInfo){
         return scoreInfoMapper.selectScoreInfoList(scoreInfo);
     }
+
+    @Override
+    public int getAveScore(ScoreInfo scoreInfo) {
+        int avgScore= scoreInfoMapper.getAvgScore(scoreInfo);
+        return avgScore;
+    }
+
+    @Override
+    public int getForecastScore(ScoreInfo scoreInfo) {
+        List<Integer> list = scoreInfoMapper.getLast10Score(scoreInfo);
+        if(list!=null && list.size()>=3) {
+            list.remove(0);
+            list.remove(list.size() - 1);
+        }
+        int total = 0;
+        for (int a: list) {
+            total +=a;
+        }
+        int forecastScore= total/list.size();
+        return forecastScore;
+    }
+
+
 }

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

@@ -28,4 +28,42 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
 
+
+    <select id="getLast10Score" parameterType="ScoreInfo" resultType="int">
+        select score from
+        (select score from score_info s
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+        </where>
+        order by id desc limit 0,10) x order by score
+    </select>
+
+    <select id="getAvgScore" parameterType="ScoreInfo" resultType="int">
+        select ROUND(avg(score),0) from score_info s
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+        </where>
+    </select>
+
+
+
+    <select id="getMinScore" parameterType="ScoreInfo" resultType="int">
+        select min(score) from score_info s
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+            <if test="type != null  and type != ''"> and type = #{type}</if>
+            <if test="kskm != null  and kskm != ''"> and kskm = #{kskm}</if>
+        </where>
+    </select>
+
+    <select id="getMaxScore" parameterType="ScoreInfo" resultType="int">
+        select max(score) from score_info s
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+            <if test="type != null  and type != ''"> and type = #{type}</if>
+            <if test="kskm != null  and kskm != ''"> and kskm = #{kskm}</if>
+        </where>
+    </select>
+
+
 </mapper>