From 13fce7e5526de855f36e62fa0abb6864a15ef818 Mon Sep 17 00:00:00 2001 From: hjl <1657978663@qq.com> Date: 星期五, 19 七月 2024 18:19:59 +0800 Subject: [PATCH] fix: 学习端bug --- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java | 247 ++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 200 insertions(+), 47 deletions(-) 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 01dfeac..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 @@ -83,6 +83,68 @@ @Resource private ITUserPresentRecordService userPresentRecordService; + @PostMapping("/testAddData") + @ApiOperation(value = "测试分片", tags = {"测试分片"}) + public R<Object> testAddData() { + TIntegralRecord tIntegralRecord = new TIntegralRecord(); + tIntegralRecord.setIntegral("1"); + tIntegralRecord.setMethod("1"); + tIntegralRecord.setUserId(23); + tIntegralRecord.setGameId(1); + tIntegralRecord.setGameDifficulty(1); + tIntegralRecord.setStoryId(1); + tIntegralRecord.setStoryType(1); + integralRecordService.save(tIntegralRecord); + TGameRecord tGameRecord = new TGameRecord(); + tGameRecord.setUserId(33); + tGameRecord.setAccuracy(0); + tGameRecord.setGameName(""); + tGameRecord.setUseTime(0); + tGameRecord.setUseTime1(""); + tGameRecord.setGameId(0); + tGameRecord.setGameDifficulty(0); + tGameRecord.setTime(""); + tGameRecord.setDisabled(false); + tGameRecord.setCreateBy(""); + tGameRecord.setCreateTime(new Date()); + tGameRecord.setUpdateBy(""); + tGameRecord.setUpdateTime(new Date()); + gameRecordService.save(tGameRecord); + TSubjectRecord tSubjectRecord = new TSubjectRecord(); + tSubjectRecord.setUserId(22); + tSubjectRecord.setWeek(0); + tSubjectRecord.setDay(0); + tSubjectRecord.setBeforeSubject(""); + tSubjectRecord.setType(0); + tSubjectRecord.setCompleteSubject(""); + tSubjectRecord.setAnswerNumber(0); + tSubjectRecord.setCorrectNumber(0); + tSubjectRecord.setDisabled(false); + tSubjectRecord.setCreateBy(""); + tSubjectRecord.setCreateTime(new Date()); + tSubjectRecord.setUpdateBy(""); + tSubjectRecord.setUpdateTime(new Date()); + subjectRecordService.save(tSubjectRecord); + TUserPresentRecord tUserPresentRecord = new TUserPresentRecord(); + tUserPresentRecord.setUserId(44); + tUserPresentRecord.setPresentTime(new Date()); + tUserPresentRecord.setIsDelete(0); + userPresentRecordService.save(tUserPresentRecord); + + TUserStudyRecord tUserStudyRecord = new TUserStudyRecord(); + tUserStudyRecord.setUserId(17); + tUserStudyRecord.setQuarter(0); + tUserStudyRecord.setWeek(0); + tUserStudyRecord.setDay(0); + tUserStudyRecord.setObtainedIntegral(0); + tUserStudyRecord.setType(0); + tUserStudyRecord.setStudyType(0); + tUserStudyRecord.setStoryId(0); + studyRecordService.save(tUserStudyRecord); + + return R.ok(); + } + @PostMapping("/storyList") // @ApiOperation(value = "配置学习类型选择故事", tags = {"题目管理"}) public R<PageInfo<TStory>> storyList(@RequestBody ChoiceStory query) { @@ -705,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 周目 @@ -740,6 +818,27 @@ Integer totalStudy = studyRecord.getTotalStudy(); studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600)); studyRecord = studyService.studySchedule(studyRecord, week); + // 数据库保存的是已完成的学习进度,返回前端时需要转换为剩余学习进度 + Integer look = studyRecord.getLook(); + if (look != 100 && look != -1) { + studyRecord.setLook(100 - look); + } + Integer pair = studyRecord.getPair(); + if (pair != 100 && pair != -1) { + studyRecord.setPair(100 - pair); + } + Integer answer = studyRecord.getAnswer(); + if (answer != 100 && answer != -1) { + studyRecord.setAnswer(100 - answer); + } + Integer induction = studyRecord.getInduction(); + if (induction != 100 && induction != -1) { + studyRecord.setInduction(100 - induction); + } + Integer listen = studyRecord.getListen(); + if (listen != 100 && listen != -1) { + studyRecord.setListen(100 - listen); + } } return R.ok(studyRecord); } @@ -862,20 +961,16 @@ // 返回结果 SubjectRecordResultVO result; if (null != subjectRecord) { - subjectRecordService.lambdaUpdate().set(TSubjectRecord::getDisabled, 1) - .eq(TSubjectRecord::getId, subjectRecord.getId()).update(); - // 题组id + /*// 题组id List<Integer> teamIds = Arrays.stream(subjectRecord.getBeforeSubject().split(",")).map(Integer::parseInt) .collect(Collectors.toList()); // 题目id List<Integer> topicIds = Arrays.stream(subjectRecord.getCompleteSubject().split(",")).map(Integer::parseInt) - .collect(Collectors.toList()); - result = new SubjectRecordResultVO(teamIds, topicIds, subjectRecord.getAnswerNumber(), subjectRecord.getCorrectNumber()); + .collect(Collectors.toList());*/ + result = new SubjectRecordResultVO(null, null, subjectRecord.getAnswerNumber(), subjectRecord.getCorrectNumber(), subjectRecord.getSchedule()); } else { result = null; } - subjectRecordService.lambdaUpdate().set(TSubjectRecord::getDisabled, 0) - .eq(TSubjectRecord::getUserId, loginStudy.getUserid()).update(); return R.ok(result); } @@ -889,7 +984,18 @@ if (null == loginStudy) { return R.tokenError("登录失效!"); } + // 退出学习如果已经存在中途学习记录,则删除记录,保存新学习记录 Integer userid = loginStudy.getUserid(); + TSubjectRecord subjectRecord = subjectRecordService.lambdaQuery() + .eq(TSubjectRecord::getUserId, userid) + .eq(TSubjectRecord::getWeek, exitLearn.getWeek()) + .eq(TSubjectRecord::getDay, exitLearn.getDay()) + .eq(TSubjectRecord::getType, exitLearn.getType()) + .eq(TSubjectRecord::getDisabled, 0) + .one(); + if (null != subjectRecord) { + subjectRecordService.removeById(subjectRecord); + } // 判断当前week和day是否已完成学习 TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, userid) .eq(TUserStudy::getDisabled, 0).one(); @@ -899,58 +1005,80 @@ Integer quarter = exitLearn.getQuarter(); Integer week = exitLearn.getWeek(); Integer day = exitLearn.getDay(); - int schedule = exitLearn.getSchedule() == null ? 0 : exitLearn.getSchedule(); + int schedule = exitLearn.getSchedule() - 1; if (userStudy.getWeek().equals(exitLearn.getWeek()) && userStudy.getDay().equals(exitLearn.getDay())) { // 计算完成率 Integer type = exitLearn.getType(); // 更新用户学习完成率 if (Constants.ONE.equals(type)) { - // 听音选图 - List<TStudyListen> studyListens = studyListenService.listenSelectPicture(quarter, week, day); - int item = 0; - for (TStudyListen studyListen : studyListens) { - item += studyListen.getSubject().split(",").length; - } - int i = (int) ((double) (exitLearn.getTopicIds().split(",").length / item) * 100); - if (i > userStudy.getListen()) { - userStudy.setListen(100 - i); + 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)) { - // 看图选音 - 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()) { - userStudy.setLook(100 - i); + 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)) { - // 归纳排除 - 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()) { - userStudy.setInduction(100 - i); + 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)) { - // 有问有答 - 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()) { - userStudy.setAnswer(100 - i); + 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)) { - // 音图相配 - List<TStudyPair> pairList = studyPairService.pictureMateVoice(quarter, week, day); - int item = pairList.size(); - int i = (int) ((double) (schedule / item)) * 100; - if (i > userStudy.getPair()) { - userStudy.setPair(100 - i); + 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); + } + } } } } @@ -1158,7 +1286,18 @@ // 登录用户id Integer userId = userStudy.getUserid(); // 判断是否已完成该题组 - boolean update = true; + boolean update; + // 清除中途退出记录 + TSubjectRecord subjectRecord = subjectRecordService.lambdaQuery() + .eq(TSubjectRecord::getUserId, userId) + .eq(TSubjectRecord::getWeek, completeStudy.getWeek()) + .eq(TSubjectRecord::getDay, completeStudy.getDay()) + .eq(TSubjectRecord::getType, completeStudy.getType()) + .eq(TSubjectRecord::getDisabled, 0) + .one(); + if (null != subjectRecord) { + subjectRecordService.removeById(subjectRecord); + } List<String> studyIds = Arrays.stream(completeStudy.getStudyIds().split(",")) .collect(Collectors.toList()); Integer type = completeStudy.getType(); @@ -1399,6 +1538,10 @@ } else { throw new GlobalException("该次游戏积分计算异常!"); } + Integer accuracy = completeStudy.getAccuracy(); + if (accuracy >= 100) { + accuracy = 100; + } int gameAvailableIntegral = (int) (integral * ((double) completeStudy.getAccuracy() / 100)); Integer availableIntegral = gameService.countIntegral(userid, game, completeStudy, gameAvailableIntegral, integralRecordList); // 游戏测试记录 @@ -1586,6 +1729,9 @@ if (null == accuracy) { throw new GlobalException("自主故事-看图配音正确率异常!"); } + if (accuracy >= 100) { + accuracy = 100; + } // 看图配音模式,也需要根据游戏正确率计算积分 double d = (double) accuracy / 100; int integral = (int) (storyListen.getLookIntegral() * d); @@ -1662,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(); @@ -1674,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) @@ -1718,7 +1868,7 @@ tGameRecord.setTime(simpleDateFormat.format(tGameRecord.getCreateTime())); } Integer totalStudy = studyRecord.getTotalStudy(); - studyRecord.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600)); + studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); // 剩余周目 List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) .eq(TStudy::getType, Constants.ONE) @@ -1762,7 +1912,7 @@ .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)); + studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600)); StudyRecordResultVO studyRecordResultVO = new StudyRecordResultVO(studyRecord, gameRecordList); return R.ok(studyRecordResultVO); } @@ -1770,6 +1920,9 @@ @GetMapping("/getIntegral") @ApiOperation(value = "获取剩余积分", tags = {"家长端-获取剩余积分"}) public R<Integer> getIntegral() { + if (tokenService.getLoginUser1() == null) { + return R.tokenError("登录失效"); + } Integer userId = tokenService.getLoginUser1().getUserid(); return R.ok(userService.getById(userId).getIntegral()); } @@ -1818,7 +1971,7 @@ return R.tokenError("登录失效"); } IPage<TIntegralRecord> page = integralRecordService.integralDetail(new Page<>(pageNum, pageSize), - tokenService.getLoginUserStudy().getUserid(), time); + tokenService.getLoginUser1().getUserid(), time); for (TIntegralRecord record : page.getRecords()) { if (!record.getIntegral().startsWith("-")) { record.setIntegral("+" + record.getIntegral()); -- Gitblit v1.7.1