From 9c417afa127156025810f8637a6eb99f9233469f Mon Sep 17 00:00:00 2001
From: hjl <1657978663@qq.com>
Date: 星期四, 18 七月 2024 18:01:32 +0800
Subject: [PATCH] fix: 学习端bug
---
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java | 56 ++++++++++++++++++++++++++++
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java | 27 +++++++++++--
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java | 22 +++++-----
3 files changed, 90 insertions(+), 15 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..dad22e8 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) {
@@ -765,6 +764,22 @@
@ApiOperation(value = "获取正确及错误提示音效", tags = {"学习端-首页"})
public R<TSysSet> promptVoice() {
return R.ok(managementClient.promptVoice().getData());
+ }
+
+ /**
+ * 获取当前季度游戏难度
+ */
+ @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));
}
/**
@@ -1794,6 +1809,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 +1822,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 +1921,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 24caf4c..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
@@ -933,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