无关风月
2024-07-02 fb9f95e888411a348652f4bd210bd998fee01afd
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
@@ -97,15 +97,12 @@
            wrapper.like("type", query.getType());
        }
        wrapper.eq("state", 1);
        List<TStory> tStories = new ArrayList<>();
        switch (query.getStoryType()) {
            case 2:
                List<TStory> list = storyService.list(wrapper);
                List<TStory> tSubjects = new ArrayList<>();
                for (TStory tSubject : list) {
                    if (!tSubject.getError().isEmpty()) {
                        tSubjects.add(tSubject);
                    }
                }
                List<TStory> tSubjects = new ArrayList<>(list);
                res.setRecords(tSubjects);
                res.setTotal(tSubjects.size());
                return R.ok(res);
@@ -113,8 +110,13 @@
                // 查询出error字段不为空的数据
                wrapper.isNotNull("error");
                List<TStory> list1 = storyService.list(wrapper);
                res.setRecords(list1);
                res.setTotal(list1.size());
                for (TStory tStory : list1) {
                    if (tStory.getError()!=null && (!tStory.getError().isEmpty())){
                        tStories.add(tStory);
                    }
                }
                res.setRecords(tStories);
                res.setTotal(tStories.size());
                return R.ok(res);
        }
@@ -736,6 +738,7 @@
            int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum();
            Integer totalStudy = studyRecord.getTotalStudy();
            studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600));
            studyRecord = studyService.studySchedule(studyRecord,week);
        }
        return R.ok(studyRecord);
    }
@@ -957,6 +960,31 @@
        userStudy.setMonthStudy(userStudy.getMonthStudy() + exitLearn.getStudyTime());
        userStudyService.updateById(userStudy);
        return R.ok(subjectRecordService.exitLearning(exitLearn, userid));
    }
    /**
     * 退出游戏/故事学习
     */
    @GetMapping("/exitGameOrStory")
    @ApiOperation(value = "退出游戏/故事学习", tags = {"学习端-题目"})
    public R<Boolean> exitGameOrStory(@RequestParam Integer studyTime) {
        LoginUserParent loginStudy = tokenService.getLoginUserStudy();
        if (null == loginStudy) {
            return R.tokenError("登录失效!");
        }
        Integer userid = loginStudy.getUserid();
        // 判断当前week和day是否已完成学习
        TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid)
                .eq(TUserStudy::getDisabled, 0).one();
        if (null == userStudy) {
            userStudy = createUserStudy(userid);
        }
        // 学习时长更新
        userStudy.setTotalStudy(userStudy.getTotalStudy() + studyTime);
        userStudy.setTodayStudy(userStudy.getTodayStudy() + studyTime);
        userStudy.setWeekStudy(userStudy.getWeekStudy() + studyTime);
        userStudy.setMonthStudy(userStudy.getMonthStudy() + studyTime);
        return R.ok(userStudyService.updateById(userStudy));
    }
    /**
@@ -1695,6 +1723,43 @@
        studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600));
        return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList));
    }
    @PostMapping("/recordManagement/{id}")
    @ApiOperation(value = "游戏测试成绩", tags = {"管理后台-查看用户详情"})
    public R<StudyRecordResultVO> recordManagement(@PathVariable("id")Integer id) {
        // 学习记录
        TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, id)
                .eq(TUserStudy::getDisabled, 0).one();
        // 查询剩余周目
        if (studyRecord != null) {
            int size = studyService.list(new QueryWrapper<TStudy>()
                    .eq("type", 1)).size();
            studyRecord.setSurplus(size - studyRecord.getWeek());
        } else {
            TUserStudy tUserStudy = new TUserStudy();
            tUserStudy.setSurplus(studyService.list(new QueryWrapper<TStudy>()
                    .eq("type", 1)).size());
            tUserStudy.setTodayStudy(Constants.ZERO);
            tUserStudy.setTotalStudy(Constants.ZERO);
            tUserStudy.setWeekStudy(Constants.ZERO);
            tUserStudy.setMonthStudy(Constants.ZERO);
            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, id)
                .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));
        StudyRecordResultVO studyRecordResultVO = new StudyRecordResultVO(studyRecord, gameRecordList);
        return R.ok(studyRecordResultVO);
    }
    @GetMapping("/getIntegral")
    @ApiOperation(value = "获取剩余积分", tags = {"家长端-获取剩余积分"})