From 9ee310626ef0f52dfb0f333783de679180092251 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期五, 19 七月 2024 11:11:41 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/DolphinEnglish --- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java | 186 ++++++++++++++++++++++++++++++ ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java | 120 +++++++++++-------- ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java | 22 +- 3 files changed, 261 insertions(+), 67 deletions(-) diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java index 963d895..661ab20 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java @@ -220,17 +220,17 @@ String userkey = JwtUtils.getUserKeyStudy(token); user = redisService.getCacheObject(getTokenKeyStudy(userkey)); // 再次判断登录状态是否已过期 -// if (null == user) { -// throw new StudyLoginException("登录信息已过期,请重新登录!", 504); -// } -// // 优先判断当前账号是否已在其他设备登录 -// if (!user.getIsCanLogin()) { -// throw new StudyLoginException("当前登录账号在其他设备登录!", 505); -// } -// // 再次判断登录状态是否已过期 -// if (System.currentTimeMillis() > user.getExpireTime()) { -// throw new StudyLoginException("登录信息已过期,请重新登录!", 504); -// } + if (null == user) { + throw new StudyLoginException("登录信息已过期,请重新登录!", 504); + } + // 优先判断当前账号是否已在其他设备登录 + if (!user.getIsCanLogin()) { + throw new StudyLoginException("当前登录账号在其他设备登录!", 505); + } + // 再次判断登录状态是否已过期 + if (System.currentTimeMillis() > user.getExpireTime()) { + throw new StudyLoginException("登录信息已过期,请重新登录!", 504); + } return user; } return user; 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 32d01c0..a23ed3d 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 @@ -1,5 +1,4 @@ package com.ruoyi.study.controller; -import java.util.Date; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -22,7 +21,6 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import org.jetbrains.annotations.TestOnly; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; @@ -86,7 +84,7 @@ private ITUserPresentRecordService userPresentRecordService; @PostMapping("/testAddData") - @ApiOperation(value = "测试分片", tags = {"测试分片"}) + @ApiOperation(value = "测试分片", tags = {"测试分片"}) public R<Object> testAddData() { TIntegralRecord tIntegralRecord = new TIntegralRecord(); tIntegralRecord.setIntegral("1"); @@ -146,6 +144,7 @@ return R.ok(); } + @PostMapping("/storyList") // @ApiOperation(value = "配置学习类型选择故事", tags = {"题目管理"}) public R<PageInfo<TStory>> storyList(@RequestBody ChoiceStory query) { @@ -768,6 +767,22 @@ } /** + * 获取当前季度游戏难度 + */ + @GetMapping("/userGameDifficulty") + @ApiOperation(value = "获取当前季度游戏难度", tags = {"学习端-首页"}) + public R<Integer> userGameDifficulty(@RequestParam Integer week) { + LoginUserParent loginStudy = tokenService.getLoginUserStudy(); + if (null == loginStudy) { + return R.tokenError("登录失效!"); + } + Integer userid = loginStudy.getUserid(); + TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) + .eq(TUserStudy::getDisabled, 0).one(); + return R.ok(studyService.userGameDifficulty(studyRecord, week)); + } + + /** * 首次页面加载时调用,获取学习进度及学习时长等信息 * * @param week 周目 @@ -996,76 +1011,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); } } } - } } // 学习时长更新 @@ -1794,6 +1808,7 @@ .eq(TGameRecord::getDisabled, 0) .orderByDesc(TGameRecord::getCreateTime) .list(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm"); if (null != studyRecord) { // 学习时长格式转换 Integer todayStudy = studyRecord.getTodayStudy(); @@ -1806,6 +1821,9 @@ int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum(); Integer totalStudy = studyRecord.getTotalStudy(); studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); + for (TGameRecord tGameRecord : gameRecordList) { + tGameRecord.setTime(simpleDateFormat.format(tGameRecord.getCreateTime())); + } // 剩余周目 List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) .eq(TStudy::getType, Constants.ONE) @@ -1902,7 +1920,7 @@ @GetMapping("/getIntegral") @ApiOperation(value = "获取剩余积分", tags = {"家长端-获取剩余积分"}) public R<Integer> getIntegral() { - if (tokenService.getLoginUser1() == null){ + if (tokenService.getLoginUser1() == null) { return R.tokenError("登录失效"); } Integer userId = tokenService.getLoginUser1().getUserid(); 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 80945a6..49ce7df 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 @@ -158,7 +158,7 @@ // 自主故事 - 看图配音 total += storyListenList.stream().map(TStoryListen::getLookIntegral).mapToInt(Integer::intValue).sum(); // 判断周目是否可以进入学习 - Boolean canStudy = checkWeekCanStudy(userId, item); + Boolean canStudy = checkWeekCanStudy(userId, item, week); result.add(new StudyWeekDTO(week, type, quarter, title, total, canStudy)); } return result; @@ -248,10 +248,16 @@ /** * @param userId 用户id + * @param week 该季度下的周目 * @return 当前周目是否学习 */ - private Boolean checkWeekCanStudy(Integer userId, TStudy study) { - TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userId) + private Boolean checkWeekCanStudyNew(Integer userId, TStudy study, Integer week) { + // 剩余周目 + List<TStudy> studyList = this.lambdaQuery().eq(TStudy::getDisabled, 0) + .eq(TStudy::getType, Constants.ONE) + .orderByAsc(TStudy::getWeek).list(); + TUserStudy userStudy = userStudyService.lambdaQuery() + .eq(TUserStudy::getUserId, userId) .eq(TUserStudy::getDisabled, 0).one(); if (null == userStudy) { userStudy = new TUserStudy(); @@ -272,8 +278,122 @@ userStudy.setPair(Constants.BURDEN_ONE); userStudyService.save(userStudy); } - // 学习记录所属周目大于当前学习周目,判断为已学习 - return userStudy.getWeek() >= study.getWeek(); + // 获取当前学习周目为哪一个季度 + TStudy studyQuarterVo = this.lambdaQuery() + .eq(TStudy::getWeek, userStudy.getWeek()) + .eq(TStudy::getDisabled, 0).one(); + // 已学习到的周目 + Integer studyWeek = userStudy.getWeek(); + // 学习到的季度 + Integer studyQuarter = studyQuarterVo.getQuarter(); + // 当前所点击进入的周目所属季度 + Integer currentQuarter = 1; + // 根据季度分组封装 + Map<Integer, List<TStudy>> integerListMap = getIntegerListMap(studyList); + for (Map.Entry<Integer, List<TStudy>> map : integerListMap.entrySet()) { + List<TStudy> list = map.getValue(); +// for (TStudy data : list) { +// Integer itemWeek = data.getWeek(); +// if (studyWeek.equals(itemWeek)) { +// studyQuarter = map.getKey(); +// break; +// } +// } + for (TStudy data : list) { + Integer itemWeek = data.getWeek(); + if (week.equals(itemWeek)) { + currentQuarter = map.getKey(); + break; + } + } + } + // 已学习季度 大于当前周目所属季度,所有学习均已完成 + if (studyQuarter > currentQuarter) { + return Boolean.TRUE; + } else if (studyQuarter < currentQuarter) { + return Boolean.FALSE; + } else { + List<TStudy> tStudies = integerListMap.get(studyQuarter); + List<Integer> weekList = tStudies.stream().map(TStudy::getWeek).collect(Collectors.toList()); + int i = weekList.indexOf(studyWeek); + int i1 = weekList.indexOf(week); + if (i >= i1) { + return Boolean.TRUE; + } else { + return Boolean.FALSE; + } + } + } + + /** + * @param userId 用户id + * @return 当前周目是否学习 + */ + private Boolean checkWeekCanStudy(Integer userId, TStudy study, Integer week) { + // 剩余周目 + List<TStudy> studyList = this.lambdaQuery().eq(TStudy::getDisabled, 0) + .eq(TStudy::getType, Constants.ONE) + .orderByAsc(TStudy::getWeek).list(); + TUserStudy userStudy = userStudyService.lambdaQuery() + .eq(TUserStudy::getUserId, userId) + .eq(TUserStudy::getDisabled, 0).one(); + if (null == userStudy) { + userStudy = new TUserStudy(); + userStudy.setUserId(userId); + // 学习周目 + TStudy tStudy = this.lambdaQuery().eq(TStudy::getQuarter, Constants.ONE) + .orderByAsc(TStudy::getWeek).last("limit 1").one(); + userStudy.setWeek(tStudy.getWeek()); + userStudy.setDay(Constants.ONE); + userStudy.setTotalStudy(Constants.ZERO); + userStudy.setTodayStudy(Constants.ZERO); + userStudy.setWeekStudy(Constants.ZERO); + userStudy.setMonthStudy(Constants.ZERO); + userStudy.setListen(Constants.BURDEN_ONE); + userStudy.setLook(Constants.BURDEN_ONE); + userStudy.setInduction(Constants.BURDEN_ONE); + userStudy.setAnswer(Constants.BURDEN_ONE); + userStudy.setPair(Constants.BURDEN_ONE); + userStudyService.save(userStudy); + } + // 获取当前学习周目为哪一个季度 + TStudy studyQuarterVo = this.lambdaQuery() + .eq(TStudy::getWeek, userStudy.getWeek()) + .eq(TStudy::getDisabled, 0).one(); + // 已学习到的周目 + Integer studyWeek = userStudy.getWeek(); + // 学习到的季度 + Integer studyQuarter = studyQuarterVo.getQuarter(); + // 当前所点击进入的周目所属季度 + Integer currentQuarter = 1; + // 根据季度分组封装 + Map<Integer, List<TStudy>> integerListMap = getIntegerListMap(studyList); + for (Map.Entry<Integer, List<TStudy>> map : integerListMap.entrySet()) { + List<TStudy> list = map.getValue(); + for (TStudy data : list) { + Integer itemWeek = data.getWeek(); + if (week.equals(itemWeek)) { + currentQuarter = map.getKey(); + break; + } + } + } + // 已学习季度 大于当前周目所属季度,所有学习均已完成 + if (studyQuarter > currentQuarter) { + return Boolean.TRUE; + } else if (studyQuarter < currentQuarter) { + return Boolean.FALSE; + } else { + List<TStudy> tStudies = integerListMap.get(studyQuarter); + List<Integer> weekList = tStudies.stream().map(TStudy::getWeek).collect(Collectors.toList()); + int i = weekList.indexOf(studyWeek); + int i1 = weekList.indexOf(week); + if (i >= i1) { + return Boolean.TRUE; + } else { + return Boolean.FALSE; + } + } } @Override @@ -813,4 +933,60 @@ } } + @Override + public Integer userGameDifficulty(TUserStudy studyRecord, Integer week) { + List<TStudy> studyList = this.lambdaQuery().eq(TStudy::getDisabled, 0) + .eq(TStudy::getType, 1) + .orderByAsc(TStudy::getWeek).list(); + // 基础学习进度 + Integer day = studyRecord.getDay(); + 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); + } + // 学习进度所属季度 + 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 = 2; + } 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 = 2; + } else if (studyIndex < weekIndex) { + defaultSchedule = 0; + } else { + defaultSchedule = studyRecord.getGameDifficulty(); + } + } + return defaultSchedule; + } + } -- Gitblit v1.7.1