From 0287a322e16580901ddb8e781df9da616f4751f9 Mon Sep 17 00:00:00 2001 From: hjl <1657978663@qq.com> Date: 星期一, 08 七月 2024 09:00:34 +0800 Subject: [PATCH] fix: 学习端bug --- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java | 6 + ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java | 158 ++++++++++++++++++++++++++++----------- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TSubjectRecordServiceImpl.java | 14 +-- ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/vo/SubjectRecordResultVO.java | 9 ++ ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java | 2 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java | 1 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TSubjectRecord.java | 7 + 7 files changed, 142 insertions(+), 55 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 b2385ee..6993cdb 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 @@ -740,6 +740,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,15 +883,13 @@ // 返回结果 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; } @@ -887,7 +906,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(); @@ -897,60 +927,82 @@ 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) schedule / item) * 100); - if (i > userStudy.getListen()) { - userStudy.setListen(i); + 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()) { + userStudy.setListen(i); + } } } else if (Constants.TWO.equals(type)) { - // 看图选音 - List<TStudyLook> lookList = studyLookService.pictureSelectVoice(quarter, week, day); - int item = 0; - for (TStudyLook studyLook : lookList) { - item += studyLook.getSubject().split(",").length; - } - int i = (int) (((double) schedule / item) * 100); - if (i > userStudy.getLook()) { - userStudy.setLook(i); + 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()) { + 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(i); + 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()) { + 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(i); + 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()) { + 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(i); + 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()) { + userStudy.setPair(i); + } + } } + } } // 学习时长更新 @@ -1157,7 +1209,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(); @@ -1398,6 +1461,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); // 游戏测试记录 @@ -1585,6 +1652,9 @@ if (null == accuracy) { throw new GlobalException("自主故事-看图配音正确率异常!"); } + if (accuracy >= 100) { + accuracy = 100; + } // 看图配音模式,也需要根据游戏正确率计算积分 double d = (double) accuracy / 100; int integral = (int) (storyListen.getLookIntegral() * d); diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java index aad0a7d..5e6aa69 100644 --- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java +++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java @@ -704,6 +704,8 @@ TUserShare record = new TUserShare(); record.setIntegral(integral); record.setUserId(userid); + // 积分明细 + userShareService.save(record); TIntegralRecord tIntegralRecord = new TIntegralRecord(); tIntegralRecord.setIntegral(data.getIntegral()); diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TSubjectRecord.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TSubjectRecord.java index b25b255..fb92b07 100644 --- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TSubjectRecord.java +++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TSubjectRecord.java @@ -73,4 +73,11 @@ @TableField("correctNumber") private Integer correctNumber; + /** + * 页码 + */ + @ApiModelProperty(value = "页码") + @TableField("schedule") + private Integer schedule; + } 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 8565665..80945a6 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 @@ -696,7 +696,11 @@ } else { throw new GlobalException("题目信息异常!"); } - return (int) (sum * ((double) accuracy / 100)); + if (accuracy >= 100) { + return sum; + } else { + return (int) (sum * ((double) accuracy / 100)); + } } @Override diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TSubjectRecordServiceImpl.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TSubjectRecordServiceImpl.java index 9f1410d..d1443db 100644 --- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TSubjectRecordServiceImpl.java +++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TSubjectRecordServiceImpl.java @@ -5,12 +5,7 @@ import com.ruoyi.study.mapper.TSubjectRecordMapper; import com.ruoyi.study.service.ITSubjectRecordService; import com.ruoyi.study.vo.ExitLearnVO; -import com.ruoyi.study.vo.SubjectRecordResultVO; import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; /** * <p> @@ -38,13 +33,14 @@ subjectRecord.setType(type); // 答题次数与答题正确次数 subjectRecord.setAnswerNumber(exitLearn.getAnswerNumber()); + subjectRecord.setSchedule(exitLearn.getSchedule()); subjectRecord.setCorrectNumber(exitLearn.getCorrectNumber()); subjectRecord.setType(type); // 题目与题组需处理 - List<String> teamIdList = Arrays.stream(teamIds.split(",")).collect(Collectors.toList()); - List<String> topicIdList = Arrays.stream(topicIds.split(",")).collect(Collectors.toList()); - subjectRecord.setBeforeSubject(teamIdList.stream().map(String::valueOf).collect(Collectors.joining(","))); - subjectRecord.setCompleteSubject(topicIdList.stream().map(String::valueOf).collect(Collectors.joining(","))); +// List<String> teamIdList = Arrays.stream(teamIds.split(",")).collect(Collectors.toList()); +// List<String> topicIdList = Arrays.stream(topicIds.split(",")).collect(Collectors.toList()); +// subjectRecord.setBeforeSubject(teamIdList.stream().map(String::valueOf).collect(Collectors.joining(","))); +// subjectRecord.setCompleteSubject(topicIdList.stream().map(String::valueOf).collect(Collectors.joining(","))); return this.save(subjectRecord); } diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java index f6827f3..ed73d4c 100644 --- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java +++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java @@ -183,6 +183,7 @@ TStudy tStudy1 = studyList1.get(i + 1); userStudy.setWeek(tStudy1.getWeek()); } + break; } } userStudy.setDay(DAY_MAP.get(String.valueOf(userStudy.getDay()))); diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/vo/SubjectRecordResultVO.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/vo/SubjectRecordResultVO.java index 1bd5bfe..667a2c9 100644 --- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/vo/SubjectRecordResultVO.java +++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/vo/SubjectRecordResultVO.java @@ -36,13 +36,20 @@ @ApiModelProperty(value = "答题正确次数") private Integer correctNumber; + /** + * 页码 + */ + @ApiModelProperty(value = "页码") + private Integer schedule; + public SubjectRecordResultVO() { } - public SubjectRecordResultVO(List<Integer> teamIds, List<Integer> topicIds, Integer answerNumber, Integer correctNumber) { + public SubjectRecordResultVO(List<Integer> teamIds, List<Integer> topicIds, Integer answerNumber, Integer correctNumber, Integer schedule) { this.teamIds = teamIds; this.topicIds = topicIds; this.answerNumber = answerNumber; this.correctNumber = correctNumber; + this.schedule = schedule; } } -- Gitblit v1.7.1