hjl
2024-06-21 a9bf1fc6ffb80c2de56e1730595b3abde4910484
fix: 学习端bug
4个文件已修改
104 ■■■■ 已修改文件
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/TGoodsServiceImpl.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/TGoodsServiceImpl.java
@@ -68,7 +68,10 @@
            String key = String.format(RedisConstants.GOOD_STOCK, goods.getId());
            List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId)
                    .eq(TOrder::getDisabled, 0).list();
            int sum = orderList.stream().map(TOrder::getCount).mapToInt(Integer::intValue).sum();
            int sum = 0;
            if (!orderList.isEmpty()) {
                sum = orderList.stream().map(TOrder::getCount).mapToInt(Integer::intValue).sum();
            }
            // 计算商品剩余可兑换数量
            int number = goods.getTotal() - sum;
            if (number <= 0) {
@@ -127,9 +130,6 @@
            }
            // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务)
            boolean result = exchangeGood(goodExchange, recipient, number, goodId, needIntegral);
            // 扣除库存
            result = result && this.lambdaUpdate().set(TGoods::getTotal, good.getTotal() - number)
                    .eq(TGoods::getId, good.getId()).update();
            if (!result) {
                semaphore.release(number);
                return R.exchangeError("商品兑换失败!");
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
@@ -809,7 +809,7 @@
            data.setIsDelete(0);
            result = result && userPresentRecordService.save(data);
        } else {
            if (System.currentTimeMillis() - record.getPresentTime().getTime() >= 10 * 60) {
            if (System.currentTimeMillis() - record.getPresentTime().getTime() >= 10 * 60 * 1000) {
                // 赠送积分
                result = userService.lambdaUpdate()
                        .set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral))
@@ -889,6 +889,7 @@
        Integer quarter = exitLearn.getQuarter();
        Integer week = exitLearn.getWeek();
        Integer day = exitLearn.getDay();
        int schedule = exitLearn.getSchedule() == null ? 0 : exitLearn.getSchedule();
        if (userStudy.getWeek().equals(exitLearn.getWeek()) && userStudy.getDay().equals(exitLearn.getDay())) {
            // 计算完成率
            Integer type = exitLearn.getType();
@@ -909,7 +910,7 @@
                List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day);
                if (!lookList.isEmpty()) {
                    int item = lookList.size();
                    int i = (int) ((double) (exitLearn.getSchedule() / item)) * 100;
                    int i = (int) ((double) (schedule / item)) * 100;
                    if (i > userStudy.getLook()) {
                        userStudy.setLook(100 - i);
                    }
@@ -919,7 +920,7 @@
                List<TStudyInduction> inductionList = studyInductionService.induceExclude(quarter, week, day);
                if (!inductionList.isEmpty()) {
                    int item = inductionList.size();
                    int i = (int) ((double) (exitLearn.getSchedule() / item)) * 100;
                    int i = (int) ((double) (schedule / item)) * 100;
                    if (i > userStudy.getInduction()) {
                        userStudy.setInduction(100 - i);
                    }
@@ -928,7 +929,7 @@
                // 有问有答
                List<TStudyAnswer> answerList = studyAnswerService.questionsAndAnswers(quarter, week, day);
                if (answerList.size() % Constants.TWO == Constants.ZERO) {
                    int i = (int) ((double) (exitLearn.getSchedule() / (answerList.size() / 2))) * 100;
                    int i = (int) ((double) (schedule / (answerList.size() / 2))) * 100;
                    if (i > userStudy.getAnswer()) {
                        userStudy.setAnswer(100 - i);
                    }
@@ -937,7 +938,7 @@
                // 音图相配
                List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day);
                int item = pairList.size();
                int i = (int) ((double) (exitLearn.getSchedule() / item)) * 100;
                int i = (int) ((double) (schedule / item)) * 100;
                if (i > userStudy.getPair()) {
                    userStudy.setPair(100 - i);
                }
@@ -1162,6 +1163,8 @@
            record.setQuarter(completeStudy.getQuarter());
            record.setWeek(completeStudy.getWeek());
            record.setDay(completeStudy.getDay());
            // 学习类型
            record.setStudyType(completeStudy.getType());
            record.setObtainedIntegral(integral);
            record.setType(Constants.ZERO);
            update = update && studyRecordService.save(record);
@@ -1354,11 +1357,12 @@
                .eq(TUserStudy::getDisabled, 0).one();
        if (null == userStudy) {
            userStudy = createUserStudy(userid);
        }
        // 学习时长
            userStudy.setTotalStudy(userStudy.getTotalStudy() + completeStudy.getUseTime());
            userStudy.setTodayStudy(userStudy.getTodayStudy() + completeStudy.getUseTime());
            userStudy.setWeekStudy(userStudy.getWeekStudy() + completeStudy.getUseTime());
            userStudy.setMonthStudy(userStudy.getMonthStudy() + completeStudy.getUseTime());
        }
        boolean update = userStudyService.updateById(userStudy);
        // 超级记忆逻辑
        if (Constants.MEMORY.equals(completeStudy.getGameName())) {
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
@@ -416,12 +416,39 @@
    @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;
        for (Map.Entry<Integer, List<TStudy>> map : studyMap.entrySet()) {
            List<TStudy> list = map.getValue();
            List<Integer> collect = list.stream().map(TStudy::getWeek).collect(Collectors.toList());
            if (collect.contains(studyWeek)) {
                int i = collect.indexOf(studyWeek);
                if (collect.contains(week)) {
                    int x = collect.indexOf(week);
                    itemBool = i > x;
                }
            }
        }
        // 默认进度为 0
        int defaultSchedule;
        // week以超过当前week,进度为 100%
        if (result.getWeek() > week) {
        if (itemBool) {
            defaultSchedule = 100;
        } else {
            // 根据day初始化学习进度
@@ -438,6 +465,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;
    }
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java
@@ -50,8 +50,6 @@
        // 游戏难度
        GAME_DIFFICULTY_MAP.put(Constants.ZERO, Constants.ONE);
        GAME_DIFFICULTY_MAP.put(Constants.ONE, Constants.TWO);
        GAME_DIFFICULTY_MAP.put(Constants.TWO, Constants.ZERO);
    }
    @Override
@@ -115,12 +113,20 @@
                userStudyRecord.setAnswer(Constants.ONE_HUNDRED);
                userStudyRecord.setPair(Constants.BURDEN_ONE);
            } else if (Constants.FIVE.equals(type)) {
                userStudyRecord.setPair(Constants.ONE_HUNDRED);
                // type为5并且day为5应该进入游戏日
                Integer nextDay = DAY_MAP.get(String.valueOf(userStudyRecord.getDay()));
                userStudyRecord.setDay(nextDay);
                // type为5并且day为5应该进入游戏日
                if (Constants.FIVE.equals(completeStudy.getDay())) {
                    userStudyRecord.setPair(Constants.ONE_HUNDRED);
                // 游戏难度初始化 0(入门难度)
                userStudyRecord.setGameDifficulty(Constants.ZERO);
                } else {
                    userStudyRecord.setListen(Constants.BURDEN_ONE);
                    userStudyRecord.setLook(Constants.BURDEN_ONE);
                    userStudyRecord.setInduction(Constants.BURDEN_ONE);
                    userStudyRecord.setAnswer(Constants.BURDEN_ONE);
                    userStudyRecord.setPair(Constants.BURDEN_ONE);
                }
                userStudyRecord.setDay(nextDay);
            }
        }
        // 更新学习时长
@@ -160,13 +166,13 @@
            for (int i = 0; i < studyList1.size(); i++) {
                TStudy tStudy = studyList1.get(i);
                if (tStudy.getWeek().equals(userStudy.getWeek())) {
                    if (studyList1.size() == 1 || i + 1 == studyList1.size() - 1) {
                    // 是否为当前季度最后一周目
                    if (i + 1 == studyList1.size() - 1) {
                        List<TStudy> studyList2 = studyMap.get(quarterItem + 1);
                        // 下一季度数据为空
                        if (null != studyList2 && !studyList2.isEmpty()) {
                            TStudy tStudy1 = studyList2.get(Constants.ZERO);
                            tStudy.setWeek(tStudy1.getWeek());
                            userStudy.setWeek(tStudy1.getWeek());
                        }
                    } else {
                        TStudy tStudy1 = studyList1.get(i + 1);
@@ -174,6 +180,13 @@
                    }
                }
            }
            userStudy.setDay(DAY_MAP.get(String.valueOf(userStudy.getDay())));
            userStudy.setLook(Constants.BURDEN_ONE);
            userStudy.setPair(Constants.BURDEN_ONE);
            userStudy.setInduction(Constants.BURDEN_ONE);
            userStudy.setListen(Constants.BURDEN_ONE);
            userStudy.setAnswer(Constants.BURDEN_ONE);
            userStudy.setGameDifficulty(Constants.ZERO);
            this.updateById(userStudy);
        }
    }
@@ -186,7 +199,9 @@
            // 获取用户超级记忆游戏记录
            TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one();
            // 更新游戏难度学习记录
            if (!Constants.TWO.equals(userStudy.getGameDifficulty())) {
            userStudy.setGameDifficulty(GAME_DIFFICULTY_MAP.get(completeStudy.getDifficulty()));
            }
            this.updateById(userStudy);
        }
    }