From da26806f0fbc78b501d58976092cc681f786c35b Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期一, 22 七月 2024 14:42:05 +0800
Subject: [PATCH] 添加学习配置 优化

---
 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java |  123 +++++++++++++++++++++++++---------------
 1 files changed, 76 insertions(+), 47 deletions(-)

diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
index dad22e8..933a84b 100644
--- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
+++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
@@ -278,6 +278,21 @@
                     .eq("studyId", one.getId())
                     .eq("week", week));
             if (studyId != null) {
+                // 判断当前周目配置的题目数量
+                List<String> subjectId = getSubjectId(week);
+                List<String> newSubjectId = subjectId.stream().map(data -> {
+                    if (data.startsWith(Constants.REDUCE)) {
+                        data = data.replace(Constants.REDUCE, Constants.EMPTY_STR);
+                    }
+                    return data;
+                }).distinct().collect(Collectors.toList());
+                // 判断周目下题目是否足够
+                if (newSubjectId.size() < game.getCount()) {
+                    return R.fail("超级听力:当前周目下day1 - day5题目不足!");
+                }
+                if (newSubjectId.size() < game.getAnswerCount()) {
+                    return R.fail("超级记忆:当前周目下day1 - day5题目不足!");
+                }
                 studyId.setWeek(dto.getWeek());
                 studyId.setStudyId(one.getId());
                 studyId.setCount(game.getCount());
@@ -290,6 +305,21 @@
                 studyId.setAnswerRate(game.getAnswerRate());
                 gameService.updateById(studyId);
             } else {
+                // 判断当前周目配置的题目数量
+                List<String> subjectId = getSubjectId(week);
+                List<String> newSubjectId = subjectId.stream().map(data -> {
+                    if (data.startsWith(Constants.REDUCE)) {
+                        data = data.replace(Constants.REDUCE, Constants.EMPTY_STR);
+                    }
+                    return data;
+                }).distinct().collect(Collectors.toList());
+                // 判断周目下题目是否足够
+                if (newSubjectId.size() < game.getCount()) {
+                    return R.fail("超级听力:当前周目下day1 - day5题目不足!");
+                }
+                if (newSubjectId.size() < game.getAnswerCount()) {
+                    return R.fail("超级记忆:当前周目下day1 - day5题目不足!");
+                }
                 TGame tGame = new TGame();
                 tGame.setWeek(dto.getWeek());
                 tGame.setAnswerRate(game.getAnswerRate());
@@ -1011,76 +1041,75 @@
             Integer type = exitLearn.getType();
             // 更新用户学习完成率
             if (Constants.ONE.equals(type)) {
-                if (1 == exitLearn.getSchedule()) {
-                    userStudy.setListen(Constants.BURDEN_ONE);
-                } else {
-                    // 听音选图
-                    List<TStudyListen> studyListens = studyListenService.listenSelectPicture(quarter, week, day);
-                    int item = 0;
-                    for (TStudyListen studyListen : studyListens) {
-                        item += studyListen.getSubject().split(",").length;
-                    }
-                    int i = (int) (((double) schedule / item) * 100);
-                    if (i > userStudy.getListen()) {
+                if (userStudy.getListen() != 100) {
+                    if (1 == exitLearn.getSchedule()) {
+                        userStudy.setListen(Constants.BURDEN_ONE);
+                    } else {
+                        // 听音选图
+                        List<TStudyListen> studyListens = studyListenService.listenSelectPicture(quarter, week, day);
+                        int item = 0;
+                        for (TStudyListen studyListen : studyListens) {
+                            item += studyListen.getSubject().split(",").length;
+                        }
+                        int i = (int) (((double) schedule / item) * 100);
                         userStudy.setListen(i);
                     }
                 }
             } else if (Constants.TWO.equals(type)) {
-                if (1 == exitLearn.getSchedule()) {
-                    userStudy.setLook(Constants.BURDEN_ONE);
-                } else {
-                    // 看图选音
-                    List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day);
-                    if (!lookList.isEmpty()) {
-                        int item = lookList.size();
-                        int i = (int) (((double) schedule / item) * 100);
-                        if (i > userStudy.getLook()) {
+                if (userStudy.getLook() != 100) {
+                    if (1 == exitLearn.getSchedule()) {
+                        userStudy.setLook(Constants.BURDEN_ONE);
+                    } else {
+                        // 看图选音
+                        List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day);
+                        if (!lookList.isEmpty()) {
+                            int item = lookList.size();
+                            int i = (int) (((double) schedule / item) * 100);
                             userStudy.setLook(i);
                         }
                     }
                 }
             } else if (Constants.THREE.equals(type)) {
-                if (1 == exitLearn.getSchedule()) {
-                    userStudy.setInduction(Constants.BURDEN_ONE);
-                } else {
-                    // 归纳排除
-                    List<TStudyInduction> inductionList = studyInductionService.induceExclude(quarter, week, day);
-                    if (!inductionList.isEmpty()) {
-                        int item = inductionList.size();
-                        int i = (int) (((double) schedule / item) * 100);
-                        if (i > userStudy.getInduction()) {
+                if (userStudy.getInduction() != 100) {
+                    if (1 == exitLearn.getSchedule()) {
+                        userStudy.setInduction(Constants.BURDEN_ONE);
+                    } else {
+                        // 归纳排除
+                        List<TStudyInduction> inductionList = studyInductionService.induceExclude(quarter, week, day);
+                        if (!inductionList.isEmpty()) {
+                            int item = inductionList.size();
+                            int i = (int) (((double) schedule / item) * 100);
                             userStudy.setInduction(i);
                         }
                     }
                 }
             } else if (Constants.FOUR.equals(type)) {
-                if (1 == exitLearn.getSchedule()) {
-                    userStudy.setAnswer(Constants.BURDEN_ONE);
-                } else {
-                    // 有问有答
-                    List<TStudyAnswer> answerList = studyAnswerService.questionsAndAnswers(quarter, week, day);
-                    if (answerList.size() % Constants.TWO == Constants.ZERO) {
-                        int i = (int) (((double) schedule / (answerList.size() / 2)) * 100);
-                        if (i > userStudy.getAnswer()) {
+                if (userStudy.getAnswer() != 100) {
+                    if (1 == exitLearn.getSchedule()) {
+                        userStudy.setAnswer(Constants.BURDEN_ONE);
+                    } else {
+                        // 有问有答
+                        List<TStudyAnswer> answerList = studyAnswerService.questionsAndAnswers(quarter, week, day);
+                        if (answerList.size() % Constants.TWO == Constants.ZERO) {
+                            int i = (int) (((double) schedule / (answerList.size() / 2)) * 100);
                             userStudy.setAnswer(i);
                         }
                     }
                 }
             } else if (Constants.FIVE.equals(type)) {
-                if (1 == exitLearn.getSchedule()) {
-                    userStudy.setPair(Constants.BURDEN_ONE);
-                } else {
-                    // 音图相配
-                    List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day);
-                    if (!pairList.isEmpty()) {
-                        int item = pairList.size();
-                        int i = (int) (((double) schedule / item) * 100);
-                        if (i > userStudy.getPair()) {
+                if (userStudy.getPair() != 100) {
+                    if (1 == exitLearn.getSchedule()) {
+                        userStudy.setPair(Constants.BURDEN_ONE);
+                    } else {
+                        // 音图相配
+                        List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day);
+                        if (!pairList.isEmpty()) {
+                            int item = pairList.size();
+                            int i = (int) (((double) schedule / item) * 100);
                             userStudy.setPair(i);
                         }
                     }
                 }
-
             }
         }
         // 学习时长更新

--
Gitblit v1.7.1