hjl
2024-06-19 aa34f5b4a80eec408185cc36500149679e1a71c9
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
@@ -2,7 +2,6 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
@@ -712,7 +711,8 @@
        if (null == loginStudy) {
            return R.tokenError("登录失效!");
        }
        TUserStudy result = studyService.studySchedule(String.valueOf(loginStudy.getUserid()));
        TUserStudy result = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, loginStudy.getUserid())
                .eq(TUserStudy::getDisabled, 0).one();
        if (null != result) {
            // 计算当前周 day 1-5的总进度
            int computeSchedule = studyService.computeSchedule(result, week);
@@ -840,25 +840,29 @@
            int completionRate = exitLearn.getTopicIds().split(",").length * 5;
            Integer type = exitLearn.getType();
            // 更新用户学习完成率
            LambdaUpdateChainWrapper<TUserStudy> wrapper = userStudyService.lambdaUpdate();
            if (Constants.ONE.equals(type) && userStudy.getListen() < completionRate) {
                // 听音选图
                wrapper.set(TUserStudy::getListen, completionRate);
                userStudy.setListen(completionRate);
            } else if (Constants.TWO.equals(type) && userStudy.getLook() < completionRate) {
                // 看图选音
                wrapper.set(TUserStudy::getLook, completionRate);
                userStudy.setLook(completionRate);
            } else if (Constants.THREE.equals(type) && userStudy.getInduction() < completionRate) {
                // 归纳排除
                wrapper.set(TUserStudy::getInduction, completionRate);
                userStudy.setInduction(completionRate);
            } else if (Constants.FOUR.equals(type) && userStudy.getAnswer() < completionRate) {
                // 有问有答
                wrapper.set(TUserStudy::getAnswer, completionRate);
                userStudy.setAnswer(completionRate);
            } else if (Constants.FIVE.equals(type) && userStudy.getPair() < completionRate) {
                // 音图相配
                wrapper.set(TUserStudy::getPair, completionRate);
                userStudy.setPair(completionRate);
            }
            wrapper.eq(TUserStudy::getUserId, userid).update();
        }
        // 学习时长更新
        userStudy.setTotalStudy(userStudy.getTotalStudy() + exitLearn.getStudyTime());
        userStudy.setTodayStudy(userStudy.getTodayStudy() + exitLearn.getStudyTime());
        userStudy.setWeekStudy(userStudy.getWeekStudy() + exitLearn.getStudyTime());
        userStudy.setMonthStudy(userStudy.getMonthStudy() + exitLearn.getStudyTime());
        userStudyService.updateById(userStudy);
        return R.ok(subjectRecordService.exitLearning(exitLearn, userid));
    }
@@ -1362,21 +1366,35 @@
    @ApiImplicitParams({
            @ApiImplicitParam(value = "故事id", name = "storyId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "类型(1:看图配音;2:超级记忆)", name = "type", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "正确率", name = "accuracy", dataType = "Integer")
            @ApiImplicitParam(value = "正确率", name = "accuracy", dataType = "Integer"),
            @ApiImplicitParam(value = "学习时长(秒)", name = "studyTime", dataType = "Integer", required = true)
    })
    public R<Boolean> completeStory(@RequestParam Integer storyId, @RequestParam Integer type, Integer accuracy) {
    public R<Boolean> completeStory(@RequestParam Integer storyId, @RequestParam Integer type,
                                    Integer accuracy, @RequestParam Integer studyTime) {
        TStoryListen storyListen = storyListenService.lambdaQuery().eq(TStoryListen::getId, storyId)
                .eq(TStoryListen::getDisabled, 0).one();
        if (null == storyListen) {
            throw new GlobalException("当前故事学习失败,故事信息异常,请重试!");
        }
        LoginUserParent userStudy = tokenService.getLoginUserStudy();
        if (null == userStudy) {
        LoginUserParent loginUserStudy = tokenService.getLoginUserStudy();
        if (null == loginUserStudy) {
            return R.tokenError("登录失效!");
        }
        // 用户信息
        Integer userId = userStudy.getUserid();
        Integer userId = loginUserStudy.getUserid();
        Boolean result = true;
        // 学习时长更新
        TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId)
                .eq(TUserStudy::getDisabled, 0).one();
        userStudy.setTotalStudy(userStudy.getTotalStudy() + studyTime);
        userStudy.setTodayStudy(userStudy.getTodayStudy() + studyTime);
        userStudy.setWeekStudy(userStudy.getWeekStudy() + studyTime);
        userStudy.setMonthStudy(userStudy.getMonthStudy() + studyTime);
        boolean update = userStudyService.updateById(userStudy);
        if (!update) {
            throw new GlobalException("学习时长更新失败!");
        }
        // 根据故事类型不同,逻辑处理
        if (Constants.ONE.equals(type)) {
            if (null == accuracy) {
                throw new GlobalException("自主故事-看图配音正确率异常!");
@@ -1391,7 +1409,8 @@
            if (list.isEmpty()) {
                obtainedIntegral = 0;
            } else {
                obtainedIntegral = list.stream().map(TUserStudyRecord::getObtainedIntegral).mapToInt(Integer::intValue).sum();
                obtainedIntegral = list.stream().map(TUserStudyRecord::getObtainedIntegral)
                        .mapToInt(Integer::intValue).sum();
            }
            // 可获得积分计算
            if (integral > obtainedIntegral) {
@@ -1432,9 +1451,23 @@
        // 学习记录
        TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId)
                .eq(TUserStudy::getDisabled, 0).one();
        // 游戏测试成绩
        // 学习时长格式转换
        Integer todayStudy = studyRecord.getTodayStudy();
        studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600));
        Integer weekStudy = studyRecord.getWeekStudy();
        studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600));
        Integer monthStudy = studyRecord.getMonthStudy();
        studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600));
        // 总时长还需计算上游戏测试成绩时长
        List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId)
                .eq(TGameRecord::getDisabled, 0).list();
        int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum();
        Integer totalStudy = studyRecord.getTotalStudy();
        studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600));
        // 剩余周目
        int size = studyService.list(new QueryWrapper<TStudy>()
                .eq("type", 1)).size();
        studyRecord.setSurplus(size - studyRecord.getWeek());
        return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList));
    }
@@ -1461,9 +1494,19 @@
                    .eq("type", 1)).size());
            studyRecord = tUserStudy;
        }
        // 游戏测试成绩
        // 学习时长格式转换
        Integer todayStudy = studyRecord.getTodayStudy();
        studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600));
        Integer weekStudy = studyRecord.getWeekStudy();
        studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600));
        Integer monthStudy = studyRecord.getMonthStudy();
        studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600));
        // 总时长还需计算上游戏测试成绩时长
        List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId)
                .eq(TGameRecord::getDisabled, 0).list();
        int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum();
        Integer totalStudy = studyRecord.getTotalStudy();
        studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600));
        return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList));
    }
@@ -1505,10 +1548,10 @@
            @ApiImplicitParam(value = "每页显示条数", name = "pageSize", required = true)
    })
    public R<IPage<TIntegralRecord>> integralDetailParent(String time,
                                                         @RequestParam("pageNum")  Integer pageNum,
                                                         @RequestParam("pageSize") Integer pageSize) {
        System.err.println("页码"+pageNum);
        System.err.println("页数"+ pageSize);
                                                          @RequestParam("pageNum") Integer pageNum,
                                                          @RequestParam("pageSize") Integer pageSize) {
        System.err.println("页码" + pageNum);
        System.err.println("页数" + pageSize);
        if (tokenService.getLoginUser1() == null) {
            return R.tokenError("登录失效");
        }