From b05715c83c4e04165a6682f2049e68ca606f656c Mon Sep 17 00:00:00 2001
From: hjl <1657978663@qq.com>
Date: 星期三, 26 六月 2024 10:38:53 +0800
Subject: [PATCH] fix: 学习端bug

---
 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java |  233 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 223 insertions(+), 10 deletions(-)

diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
index 68186aa..60558ec 100644
--- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
+++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
@@ -3,7 +3,6 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.core.constant.Constants;
 import com.ruoyi.common.core.exception.GlobalException;
-import com.ruoyi.common.core.utils.bean.BeanUtils;
 import com.ruoyi.study.domain.*;
 import com.ruoyi.study.dto.StudyWeekDTO;
 import com.ruoyi.study.mapper.TStudyMapper;
@@ -279,12 +278,35 @@
         for (TStudyInduction data : inductionList) {
             List<String> subjectIds = Arrays.stream(data.getSubject().split(",")).collect(Collectors.toList());
             List<TSubject> subjectLists = new ArrayList<>();
-            for (String id : subjectIds) {
+            // 第一组题 固定下标为0,1,2的题
+            for (int i = 0; i < Constants.THREE; i++) {
+                String id = subjectIds.get(i);
+                if (!id.startsWith("-")) {
+                    subjectLists.add(subjectService.getById(id));
+                }
+            }
+            for (int i = 0; i < Constants.THREE; i++) {
+                String id = subjectIds.get(i);
                 if (id.startsWith("-")) {
                     id = id.replace("-", "");
+                    subjectLists.add(subjectService.getById(id));
                 }
-                subjectLists.add(subjectService.getById(id));
             }
+            // 第二组题,固定下标为3,4的题
+            for (int i = Constants.THREE; i < Constants.FIVE; i++) {
+                String id = subjectIds.get(i);
+                if (!id.startsWith("-")) {
+                    subjectLists.add(subjectService.getById(id));
+                }
+            }
+            for (int i = Constants.THREE; i < Constants.FIVE; i++) {
+                String id = subjectIds.get(i);
+                if (id.startsWith("-")) {
+                    id = id.replace("-", "");
+                    subjectLists.add(subjectService.getById(id));
+                }
+            }
+            subjectLists.add(subjectService.getById(subjectIds.get(subjectIds.size() - 1).replace("-", "")));
             subjectList.add(subjectLists);
         }
         return new StudyInductionResultVO(learnStudy, subjectList);
@@ -329,22 +351,34 @@
         QuestionsAnswersSubjectVO oneVO = new QuestionsAnswersSubjectVO();
         TSubject one1 = subjectService.lambdaQuery().eq(TSubject::getId, subject)
                 .eq(TSubject::getDisabled, 0).one();
-        BeanUtils.copyProperties(one1, oneVO);
+        copyProperties(one1, oneVO);
         // 回答题目信息
         QuestionsAnswersSubjectVO twoVO = new QuestionsAnswersSubjectVO();
         TSubject two1 = subjectService.lambdaQuery().eq(TSubject::getId, answerSubject)
                 .eq(TSubject::getDisabled, 0).one();
-        BeanUtils.copyProperties(two1, twoVO);
+        copyProperties(two1, twoVO);
         // 判断第一组题目的问题题目及回答题目,哪个是答案
         if (Constants.ZERO.equals(one.getIsAnswer())) {
-            oneVO.setIsQuestion(0);
-            twoVO.setIsQuestion(1);
-        } else {
             oneVO.setIsQuestion(1);
             twoVO.setIsQuestion(0);
+        } else {
+            oneVO.setIsQuestion(0);
+            twoVO.setIsQuestion(1);
         }
         voList.add(oneVO);
         voList.add(twoVO);
+    }
+
+    private void copyProperties(TSubject subject, QuestionsAnswersSubjectVO vo) {
+        vo.setId(subject.getId());
+        vo.setName(subject.getName());
+        vo.setEnglish(subject.getEnglish());
+        vo.setType(subject.getType());
+        vo.setState(subject.getState());
+        vo.setImg(subject.getImg());
+        vo.setCorrect(subject.getCorrect());
+        vo.setError(subject.getError());
+        vo.setSort(subject.getSort());
     }
 
     @Override
@@ -382,12 +416,95 @@
 
     @Override
     public int computeSchedule(TUserStudy result, Integer week) {
+        List<TStudy> studyList = this.lambdaQuery().eq(TStudy::getDisabled, 0)
+                .eq(TStudy::getType, 1)
+                .orderByAsc(TStudy::getWeek).list();
         // 基础学习进度
         Integer day = result.getDay();
+        Integer studyWeek = result.getWeek();
+        Map<Integer, List<TStudy>> studyMap = new HashMap<>(8);
+        for (TStudy study : studyList) {
+            Integer quarter = study.getQuarter();
+            List<TStudy> itemList = studyMap.get(quarter);
+            if (null == itemList) {
+                itemList = new ArrayList<>();
+            }
+            itemList.add(study);
+            studyMap.put(quarter, itemList);
+        }
+        // 临时判断参数
+        boolean itemBool = false;
+        // 学习进度所属季度
+        int studyQuarter = 1;
+        // 当前进入周目所属季度
+        int thisQuarter = 1;
+        for (Map.Entry<Integer, List<TStudy>> map : studyMap.entrySet()) {
+            Integer key = map.getKey();
+            List<TStudy> list = map.getValue();
+            List<Integer> collect = list.stream().map(TStudy::getWeek).collect(Collectors.toList());
+            if (collect.contains(studyWeek)) {
+                studyQuarter = key;
+            }
+            if (collect.contains(week)) {
+                thisQuarter = key;
+            }
+        }
         // 默认进度为 0
         int defaultSchedule;
+        // 季度判断
+        if (studyQuarter > thisQuarter) {
+            defaultSchedule = 100;
+        } else if (studyQuarter < thisQuarter) {
+            defaultSchedule = 0;
+        } else {
+            List<TStudy> tStudies = studyMap.get(studyQuarter);
+            List<Integer> weekList = tStudies.stream().map(TStudy::getWeek).collect(Collectors.toList());
+            int studyIndex = weekList.indexOf(studyWeek);
+            int weekIndex = weekList.indexOf(week);
+            if (studyIndex > weekIndex) {
+                defaultSchedule = 100;
+            } else if (studyIndex < weekIndex) {
+                defaultSchedule = 0;
+            }else {
+                // 根据day初始化学习进度
+                if (Constants.ONE.equals(day)) {
+                    defaultSchedule = 0;
+                } else if (Constants.TWO.equals(day)) {
+                    defaultSchedule = 20;
+                } else if (Constants.THREE.equals(day)) {
+                    defaultSchedule = 40;
+                } else if (Constants.FOUR.equals(day)) {
+                    defaultSchedule = 60;
+                } else if (Constants.FIVE.equals(day)) {
+                    defaultSchedule = 80;
+                } else {
+                    defaultSchedule = 0;
+                }
+                // 根据五种学习计算进度
+                Integer listen = result.getListen();
+                if (!Constants.BURDEN_ONE.equals(listen)) {
+                    defaultSchedule += (int) (((double) listen / 100) * 4);
+                }
+                Integer look = result.getLook();
+                if (!Constants.BURDEN_ONE.equals(look)) {
+                    defaultSchedule += (int) (((double) look / 100) * 4);
+                }
+                Integer induction = result.getInduction();
+                if (!Constants.BURDEN_ONE.equals(induction)) {
+                    defaultSchedule += (int) (((double) induction / 100) * 4);
+                }
+                Integer answer = result.getAnswer();
+                if (!Constants.BURDEN_ONE.equals(answer)) {
+                    defaultSchedule += (int) (((double) answer / 100) * 4);
+                }
+                Integer pair = result.getPair();
+                if (!Constants.BURDEN_ONE.equals(pair)) {
+                    defaultSchedule += (int) (((double) pair / 100) * 4);
+                }
+            }
+        }
         // week以超过当前week,进度为 100%
-        if (result.getWeek() > week) {
+        /*if (itemBool) {
             defaultSchedule = 100;
         } else {
             // 根据day初始化学习进度
@@ -404,7 +521,28 @@
             } else {
                 defaultSchedule = 0;
             }
-        }
+            // 根据五种学习计算进度
+            Integer listen = result.getListen();
+            if (!Constants.BURDEN_ONE.equals(listen)) {
+                defaultSchedule += (int) (((double) listen / 100) * 4);
+            }
+            Integer look = result.getLook();
+            if (!Constants.BURDEN_ONE.equals(look)) {
+                defaultSchedule += (int) (((double) look / 100) * 4);
+            }
+            Integer induction = result.getInduction();
+            if (!Constants.BURDEN_ONE.equals(induction)) {
+                defaultSchedule += (int) (((double) induction / 100) * 4);
+            }
+            Integer answer = result.getAnswer();
+            if (!Constants.BURDEN_ONE.equals(answer)) {
+                defaultSchedule += (int) (((double) answer / 100) * 4);
+            }
+            Integer pair = result.getPair();
+            if (!Constants.BURDEN_ONE.equals(pair)) {
+                defaultSchedule += (int) (((double) pair / 100) * 4);
+            }
+        }*/
         return defaultSchedule;
     }
 
@@ -452,4 +590,79 @@
         return (int) (sum * ((double) accuracy / 100));
     }
 
+    @Override
+    public int residueWeek(TUserStudy studyRecord, List<TStudy> studyList) {
+        // 已学习周目
+        int residueWeek = 0;
+        // 已学习到的周目
+        Integer studyWeek = studyRecord.getWeek();
+        // 根据季度分组封装
+        Map<Integer, List<TStudy>> studyMap = new HashMap<>(8);
+        for (TStudy study : studyList) {
+            Integer quarter = study.getQuarter();
+            List<TStudy> itemList = studyMap.get(quarter);
+            if (null == itemList) {
+                itemList = new ArrayList<>();
+            }
+            itemList.add(study);
+            studyMap.put(quarter, itemList);
+        }
+        // 顺序排序
+        Map<Integer, List<TStudy>> itemMap = new HashMap<>(8);
+        List<Integer> keyList = new ArrayList<>();
+        for (Map.Entry<Integer, List<TStudy>> map : studyMap.entrySet()) {
+            Integer key = map.getKey();
+            keyList.add(key);
+        }
+        Collections.sort(keyList);
+        for (Integer key : keyList) {
+            List<TStudy> itemList = studyMap.get(key);
+            itemMap.put(key, itemList);
+        }
+        // 计算已学习周目
+        boolean v = false;
+        for (Map.Entry<Integer, List<TStudy>> map : itemMap.entrySet()) {
+            List<TStudy> list = map.getValue();
+            for (int i = 0; i < list.size(); i++) {
+                TStudy item = list.get(i);
+                if (item.getWeek().equals(studyWeek)) {
+                    Integer listen = studyRecord.getListen();
+                    Integer answer = studyRecord.getAnswer();
+                    Integer look = studyRecord.getLook();
+                    Integer induction = studyRecord.getInduction();
+                    Integer pair = studyRecord.getPair();
+                    Integer gameDifficulty = studyRecord.getGameDifficulty();
+                    // 听音选图、看图选音、音图相配、有问有答、归纳排除的进度是否 100%,并且超级听力的游戏难度是否为2
+                    boolean isStudy = Constants.ONE_HUNDRED.equals(listen) && Constants.ONE_HUNDRED.equals(look) &&
+                            Constants.ONE_HUNDRED.equals(induction) && Constants.ONE_HUNDRED.equals(pair) &&
+                            Constants.ONE_HUNDRED.equals(answer) && Constants.TWO.equals(gameDifficulty);
+                    if (isStudy) {
+                        residueWeek++;
+                    }
+                    v = true;
+                    break;
+                } else {
+                    residueWeek++;
+                }
+            }
+            if (v) {
+                break;
+            }
+        }
+        return studyList.size() - residueWeek;
+    }
+
+    @Override
+    public void checkClearance(TGame game, Integer userid) {
+        String rate = game.getRate().split(",")[Constants.TWO];
+        // 获取用户游戏进度
+        List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid)
+                .eq(TGameRecord::getGameId, game.getId())
+                .ge(TGameRecord::getAccuracy, rate)
+                .eq(TGameRecord::getGameDifficulty, Constants.TWO).list();
+        if (list.isEmpty()) {
+            throw new GlobalException("超级听力暂未通关!");
+        }
+    }
+
 }

--
Gitblit v1.7.1