ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/Constants.java
@@ -317,4 +317,9 @@ */ public static final String MEMORY = "超级记忆"; /** * 每日学习时长 */ public static final String ONLINE_DURATION = "每日学习时长"; } ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/TGoodsServiceImpl.java
@@ -105,6 +105,17 @@ return R.exchangeError("兑换失败,当前剩余积分不足!"); } if (null != good.getTotal()) { // 检查库存总数是否足够 List<TOrder> order = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId) .eq(TOrder::getDisabled, 0).list(); if (!order.isEmpty()) { int totalNumber = order.stream().map(TOrder::getCount).collect(Collectors.toList()) .stream().mapToInt(Integer::intValue).sum(); boolean canBuy = good.getTotal() - totalNumber >= number; if (!canBuy) { throw new GlobalException("商品库存不足,兑换失败!"); } } // 检查用户兑换数量是否超过单用户最大兑换数量 List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) .eq(TOrder::getGoodsId, goodId).list(); ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
@@ -809,7 +809,7 @@ data.setIsDelete(0); result = result && userPresentRecordService.save(data); } else { if (System.currentTimeMillis() - record.getPresentTime().getTime() >= 10 * 60 * 1000) { if (System.currentTimeMillis() - record.getPresentTime().getTime() >= (long) Integer.parseInt(sysSet.getTime()) * 60 * 1000) { // 赠送积分 result = userService.lambdaUpdate() .set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral)) @@ -820,6 +820,12 @@ data.setPresentTime(new Date()); data.setIsDelete(0); result = result && userPresentRecordService.save(data); // 生成积分明细 TIntegralRecord integralRecord = new TIntegralRecord(); integralRecord.setIntegral(sysSet.getIntegral()); integralRecord.setMethod(Constants.ONLINE_DURATION); integralRecord.setUserId(loginStudy.getUserid()); result = result && integralRecordService.save(integralRecord); } } return R.ok(result); @@ -1115,7 +1121,7 @@ */ @PostMapping("/completeLearning") @ApiOperation(value = "完成学习", tags = {"学习端-听-自主学习"}) public R<Boolean> completeLearning(@RequestBody CompleteStudyDTO completeStudy) { public R<Integer> completeLearning(@RequestBody CompleteStudyDTO completeStudy) { LoginUserParent userStudy = tokenService.getLoginUserStudy(); if (null == userStudy) { return R.tokenError("登录失效!"); @@ -1176,7 +1182,7 @@ userStudyRecord = createUserStudy(userId); } Boolean updateStudyRecord = userStudyService.exchangeStudyRecord(userStudyRecord, userId, completeStudy); return R.ok(update && updateStudyRecord); return R.ok(sum > obtainedIntegral ? sum - obtainedIntegral : 0); } /** @@ -1222,7 +1228,7 @@ throw new GlobalException("当前周目下day1 - day5题目不足!"); } // 根据游戏设置数量获取图片及语音 List<String> subjectData = getData(game, newSubjectId); List<String> subjectData = getData(game, newSubjectId, 1); List<TSubject> subjectList = getSubjectList(subjectData); return R.ok(new StudyGameResultVO(game, subjectList)); } @@ -1240,6 +1246,10 @@ @ApiImplicitParam(value = "所属周目", name = "week", dataType = "Integer", required = true) }) public R<StudyGameMemoryVO> gameMemory(@RequestParam Integer quarter, @RequestParam Integer week) { LoginUserParent userStudy = tokenService.getLoginUserStudy(); if (null == userStudy) { return R.tokenError("登录失效!"); } TGame game = gameService.gameHearing(quarter, week); if (null == game) { throw new GlobalException("当前季度该周目暂无配置游戏数据!"); @@ -1254,6 +1264,8 @@ photoList.add(new GameMemoryPhotoVO(tSubject.getId(), tSubject.getImg())); voiceList.add(new GameMemoryVoiceVO(tSubject.getId(), tSubject.getCorrect())); } // 校验超级听力是否通过 // studyService.checkClearance(game,userStudy.getUserid()); // 框架记忆数量翻倍,前端需要根据数量画格子 game.setAnswerCount(game.getAnswerCount() * 2); return R.ok(new StudyGameMemoryVO(game, photoList, voiceList)); @@ -1271,16 +1283,22 @@ throw new GlobalException("当前周目下day1 - day5题目不足!"); } // 根据游戏设置数量获取图片及语音 return getData(game, newSubjectId); return getData(game, newSubjectId, 2); } private List<String> getData(TGame game, List<String> newSubjectId) { private List<String> getData(TGame game, List<String> newSubjectId, int num) { List<String> subjectData = new ArrayList<>(); Random random = new Random(); // 获取列表大小 int dataSize = newSubjectId.size(); // 生成随机索引并获取数据 for (int i = 0; i < game.getCount(); i++) { int index; if (1 == num) { index = game.getCount(); } else { index = game.getAnswerCount(); } for (int i = 0; i < index; i++) { // 生成随机索引 int randomIndex = random.nextInt(dataSize); // 获取对应的数据并加入结果列表 @@ -1312,7 +1330,7 @@ */ @PostMapping("/gameAchievement") @ApiOperation(value = "完成游戏-记录游戏测试成绩", tags = {"学习端-听-自主游戏"}) public R<Boolean> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { public R<Integer> gameAchievement(@RequestBody CompleteGameDTO completeStudy) { LoginUserParent loginUserStudy = tokenService.getLoginUserStudy(); if (null == loginUserStudy) { return R.tokenError("登录失效!"); @@ -1323,19 +1341,31 @@ * 例如:游戏配置的积分是100,他的正确率是50%那么拿50分,下次他再玩这个游戏 正确率是60% 那么他该获得60分 但是上次已经拿了50 所以这次就只给他加10积分 */ Integer userid = loginUserStudy.getUserid(); TGame game = gameService.lambdaQuery().eq(TGame::getId, completeStudy.getGameId()).eq(TGame::getDisabled, 0).one(); TGame game = gameService.lambdaQuery().eq(TGame::getId, completeStudy.getGameId()) .eq(TGame::getDisabled, 0).one(); if (null == game) { throw new GlobalException("游戏信息异常!"); } // 积分明细 List<TIntegralRecord> integralRecordList = integralRecordService.lambdaQuery().eq(TIntegralRecord::getUserId, userid) .eq(TIntegralRecord::getGameId, game.getId()).eq(TIntegralRecord::getDisabled, 0).list(); Integer difficulty = completeStudy.getDifficulty(); List<TIntegralRecord> integralRecordList = integralRecordService.lambdaQuery() .eq(TIntegralRecord::getUserId, userid) .eq(TIntegralRecord::getGameId, game.getId()) .eq(TIntegralRecord::getDisabled, 0) .eq(TIntegralRecord::getGameDifficulty, difficulty).list(); // 本次游戏总共能获取的积分数量 Integer integral; Integer item = null; if (completeStudy.getGameName().equals(Constants.HEARING)) { // 本次游戏总积分 integral = Integer.parseInt(game.getIntegral().split(",")[completeStudy.getDifficulty()]); integral = Integer.parseInt(game.getIntegral().split(",")[difficulty]); item = completeStudy.getDifficulty(); } else if (completeStudy.getGameName().equals(Constants.MEMORY)) { integralRecordList = integralRecordService.lambdaQuery() .eq(TIntegralRecord::getUserId, userid) .eq(TIntegralRecord::getGameId, game.getId()) .eq(TIntegralRecord::getDisabled, 0) .last("and gameDifficulty is null").list(); integral = game.getAnswerIntegral(); } else { throw new GlobalException("该次游戏积分计算异常!"); @@ -1345,8 +1375,9 @@ // 游戏测试记录 Boolean add = gameRecordService.add(completeStudy); // 可获得积分不为null时,才添加积分明细记录 if (null != availableIntegral) { add = add && integralRecordService.add(String.valueOf(availableIntegral), Constants.COMPLETE_GAME, completeStudy.getGameId(), null); if (null != availableIntegral && !Constants.ZERO.equals(availableIntegral)) { add = add && integralRecordService.add(String.valueOf(availableIntegral), Constants.COMPLETE_GAME, completeStudy.getGameId(), null, item, null); // 用户账户添加积分 TUser user = userService.getById(userid); user.setIntegral(user.getIntegral() + availableIntegral); @@ -1363,25 +1394,23 @@ userStudy.setTodayStudy(userStudy.getTodayStudy() + completeStudy.getUseTime()); userStudy.setWeekStudy(userStudy.getWeekStudy() + completeStudy.getUseTime()); userStudy.setMonthStudy(userStudy.getMonthStudy() + completeStudy.getUseTime()); boolean update = userStudyService.updateById(userStudy); userStudyService.updateById(userStudy); // 学习配置列表 List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) .orderByAsc(TStudy::getWeek).list(); if (studyList.isEmpty()) { throw new GlobalException("学习配置列表未配置或数据失效!"); } // 超级记忆逻辑 if (Constants.MEMORY.equals(completeStudy.getGameName())) { // 学习配置列表 List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) .orderByAsc(TStudy::getWeek).list(); if (studyList.isEmpty()) { throw new GlobalException("学习配置列表未配置或数据失效!"); } // 超级记忆正确率达到通关率标准,才能进入下一周目学习 // 校验是否通关超级听力与超级记忆,通关则学习记录更新为下一周目 userStudyService.checkRate(game, userid, completeStudy, studyList); add = add && completeStudy.getAccuracy() >= Integer.parseInt(game.getAnswerRate()); } else { // 超级听力需根据正确率判断是否允许进入下一难度 userStudyService.gameHearing(game, userid, completeStudy); String rate = game.getRate().split(",")[completeStudy.getDifficulty()]; add = add && completeStudy.getAccuracy() >= Integer.parseInt(rate); userStudyService.gameHearing(game, userid, completeStudy, studyList); } return R.ok(add && update); return R.ok(availableIntegral); } private TUserStudy createUserStudy(Integer userid) { @@ -1492,7 +1521,7 @@ @ApiImplicitParam(value = "正确率", name = "accuracy", dataType = "Integer"), @ApiImplicitParam(value = "学习时长(秒)", name = "studyTime", dataType = "Integer", required = true) }) public R<Boolean> completeStory(@RequestParam Integer storyId, @RequestParam Integer type, public R<Integer> completeStory(@RequestParam Integer storyId, @RequestParam Integer type, Integer accuracy, @RequestParam Integer studyTime) { TStoryListen storyListen = storyListenService.lambdaQuery().eq(TStoryListen::getId, storyId) .eq(TStoryListen::getDisabled, 0).one(); @@ -1507,30 +1536,37 @@ Integer userId = loginUserStudy.getUserid(); Boolean result = true; // 学习时长更新 TStudy study = studyService.lambdaQuery().eq(TStudy::getId, storyListen.getStudyId()) .eq(TStudy::getDisabled, 0).one(); 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); } userStudy.setTotalStudy(userStudy.getTotalStudy() + studyTime); userStudy.setTodayStudy(userStudy.getTodayStudy() + studyTime); userStudy.setWeekStudy(userStudy.getWeekStudy() + studyTime); userStudy.setMonthStudy(userStudy.getMonthStudy() + studyTime); boolean update = userStudyService.updateById(userStudy); if (!update) { throw new GlobalException("学习时长更新失败!"); } // 根据故事类型不同,逻辑处理 int sum = 0; if (Constants.ONE.equals(type)) { if (null == accuracy) { throw new GlobalException("自主故事-看图配音正确率异常!"); } // 看图配音模式,也需要根据游戏正确率计算积分 int integral = storyListen.getLookIntegral() * (accuracy / 100); double d = (double) accuracy / 100; int integral = (int) (storyListen.getLookIntegral() * d); int obtainedIntegral; // 看图配音已获取积分数量 List<TUserStudyRecord> list = studyRecordService.lambdaQuery() .eq(TUserStudyRecord::getStoryId, storyId) .eq(TUserStudyRecord::getType, 1) .eq(TUserStudyRecord::getQuarter, study.getQuarter()) .eq(TUserStudyRecord::getWeek, storyListen.getWeek()) .eq(TUserStudyRecord::getUserId, userId).list(); if (list.isEmpty()) { obtainedIntegral = 0; @@ -1539,31 +1575,45 @@ .mapToInt(Integer::intValue).sum(); } // 可获得积分计算 if (integral > obtainedIntegral) { int i = integral - obtainedIntegral; if (i > 0) { TUserStudyRecord data = new TUserStudyRecord(); data.setUserId(userId); data.setObtainedIntegral(integral - obtainedIntegral); data.setObtainedIntegral(i); data.setType(Constants.ONE); data.setStoryId(storyId); data.setQuarter(study.getQuarter()); data.setWeek(storyListen.getWeek()); result = studyRecordService.save(data); sum = i; // 添加积分明细记录 result = integralRecordService.add(String.valueOf(sum), Constants.COMPLETE_STORY, null, storyId, null, Constants.ZERO); TUser user = userService.lambdaQuery().eq(TUser::getId, userId).one(); // 添加积分 user.setIntegral(user.getIntegral() + sum); result = result && userService.updateById(user); } } else { // 超级记忆只有首次才能获取积分 TIntegralRecord integralRecord = integralRecordService.lambdaQuery() .eq(TIntegralRecord::getUserId, userId) .eq(TIntegralRecord::getStoryId, storyId) .eq(TIntegralRecord::getDisabled, 0).one(); .eq(TIntegralRecord::getDisabled, 0) .eq(TIntegralRecord::getStoryType, Constants.ONE) .one(); if (null == integralRecord) { // 添加积分明细记录 result = integralRecordService.add(String.valueOf(storyListen.getIntegral()), Constants.COMPLETE_STORY, null, storyId); Constants.COMPLETE_STORY, null, storyId, null, Constants.ONE); TUser user = userService.lambdaQuery().eq(TUser::getId, userId).one(); // 添加积分 user.setIntegral(user.getIntegral() + storyListen.getIntegral()); result = result && userService.updateById(user); sum = storyListen.getIntegral(); } } return R.ok(result); return R.ok(sum); } @GetMapping("/studyRecord") @@ -1596,7 +1646,7 @@ List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0) .eq(TStudy::getType, Constants.ONE) .orderByAsc(TStudy::getWeek).list(); int size = studyService.residueWeek(studyRecord,studyList); int size = studyService.residueWeek(studyRecord, studyList); studyRecord.setSurplus(size); } return R.ok(new StudyRecordResultVO(studyRecord, gameRecordList)); ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
@@ -381,6 +381,18 @@ } } @PostMapping("/studyPage") @ApiOperation(value = "学习端", tags = {"启动页"}) public R<String> studyPage() { List<TPage> data = managementClient.getPage1().getData(); for (TPage datum : data) { if (datum.getType() == 1) { return R.ok(datum.getImg()); } } return R.ok(); } @PostMapping("/parentPage") @ApiOperation(value = "平板", tags = {"启动页"}) public R<String> parentPage() { ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TGameRecord.java
@@ -1,12 +1,13 @@ package com.ruoyi.study.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.*; import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.common.core.web.domain.BaseModel; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.Date; /** * <p> @@ -60,5 +61,13 @@ @ApiModelProperty(value = "游戏难度(0入门、1中级、2高级)") private Integer gameDifficulty; /** * 创建时间 */ @ApiModelProperty(value = "记录创建时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm") @TableField(value = "createTime", fill = FieldFill.INSERT) private Date createTime; } ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TIntegralRecord.java
@@ -53,16 +53,30 @@ private Integer gameId; /** * 游戏难度 */ @ApiModelProperty("游戏难度") private Integer gameDifficulty; /** * 故事id */ @ApiModelProperty("故事id 对应t_story_listen") private Integer storyId; /** * 故事id */ @ApiModelProperty("故事类型(0:看图配音;1:框架记忆)") private Integer storyType; @ApiModelProperty("积分变动时间") @TableField(exist = false) @JsonFormat(pattern = "yyyy-MM-dd HH:mm") private Date time; /** * 前端用,返回积分变动类型 * ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITIntegralRecordService.java
@@ -28,11 +28,13 @@ /** * 生成积分明细 * * @param integral 积分 (增加积分+ 、减少积分-) * @param method 积分来源 * @param gameId 游戏id * @param storyId 故事id * @param integral 积分 (增加积分+ 、减少积分-) * @param method 积分来源 * @param gameId 游戏id * @param storyId 故事id * @param difficulty 游戏难度 * @param storyType 故事类型(0:看图配音;1:框架记忆) * @return 操作结果 */ Boolean add(String integral, String method, Integer gameId, Integer storyId); Boolean add(String integral, String method, Integer gameId, Integer storyId, Integer difficulty,Integer storyType); } ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITStudyService.java
@@ -122,4 +122,12 @@ * @return 剩余周目 */ int residueWeek(TUserStudy studyRecord, List<TStudy> studyList); /** * 校验超级听力是否通过 * * @param game 游戏信息 * @param userid 用户信息 */ void checkClearance(TGame game, Integer userid); } ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITUserStudyService.java
@@ -60,6 +60,7 @@ * @param game 游戏信息 * @param userid 用户id * @param completeStudy 游戏完成信息 * @param studyList 学习列表 */ void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy); void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList); } ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TGameRecordServiceImpl.java
@@ -1,6 +1,7 @@ package com.ruoyi.study.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.security.service.TokenService; import com.ruoyi.study.domain.TGameRecord; import com.ruoyi.study.dto.CompleteGameDTO; @@ -33,8 +34,10 @@ data.setAccuracy(gameAchievement.getAccuracy()); data.setGameName(gameAchievement.getGameName()); data.setUseTime(gameAchievement.getUseTime()); if (Constants.HEARING.equals(gameAchievement.getGameName())) { data.setGameDifficulty(gameAchievement.getDifficulty()); } data.setGameId(gameAchievement.getGameId()); data.setGameDifficulty(gameAchievement.getDifficulty()); return this.save(data); } } ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TGameServiceImpl.java
@@ -2,19 +2,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.exception.GlobalException; import com.ruoyi.study.domain.TGame; import com.ruoyi.study.domain.TIntegralRecord; import com.ruoyi.study.domain.TSubject; import com.ruoyi.study.dto.CompleteGameDTO; import com.ruoyi.study.mapper.TGameMapper; import com.ruoyi.study.service.ITGameService; import com.ruoyi.study.vo.StudyGameMemoryVO; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.stream.Collectors; /** @@ -36,13 +31,14 @@ return gameAvailableIntegral; } else { // 积分明细不为空,根据正确率及已获取积分数量计算本次答题可获取的积分数量 List<Integer> integralList = integralRecordList.stream().map(TIntegralRecord::getIntegral).collect(Collectors.toList()) List<Integer> integralList = integralRecordList.stream() .map(TIntegralRecord::getIntegral).collect(Collectors.toList()) .stream().map(Integer::parseInt).collect(Collectors.toList()); int sumIntegral = integralList.stream().mapToInt(Integer::intValue).sum(); if (gameAvailableIntegral > sumIntegral) { return gameAvailableIntegral - sumIntegral; } else { return null; return Constants.ZERO; } } } ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TIntegralRecordServiceImpl.java
@@ -33,13 +33,15 @@ @Override @Transactional(rollbackFor = Exception.class) public Boolean add(String integral, String method, Integer gameId, Integer storyId) { public Boolean add(String integral, String method, Integer gameId, Integer storyId, Integer difficulty, Integer storyType) { TIntegralRecord integralRecord = new TIntegralRecord(); integralRecord.setIntegral(integral); integralRecord.setMethod(method); integralRecord.setUserId(tokenService.getLoginUserStudy().getUserid()); integralRecord.setGameId(gameId); integralRecord.setStoryId(storyId); integralRecord.setGameDifficulty(difficulty); integralRecord.setStoryType(storyType); return this.save(integralRecord); } } ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
@@ -65,41 +65,62 @@ Integer id = item.getId(); // 计算总积分 int total = 0; List<Integer> dayList = new ArrayList<>(); // 有问有答 List<TStudyAnswer> answerList = studyAnswerService.lambdaQuery().eq(TStudyAnswer::getStudyId, id) .eq(TStudyAnswer::getDisabled, 0).list(); Optional<TStudyAnswer> answerOptional = answerList.stream().findAny(); if (answerOptional.isPresent()) { total += answerOptional.get().getIntegral(); for (TStudyAnswer data : answerList) { Integer day = data.getDay(); if (!dayList.contains(day)) { total += data.getIntegral(); dayList.add(day); } } dayList.clear(); // 归纳判断 List<TStudyInduction> inductionList = studyInductionService.lambdaQuery().eq(TStudyInduction::getStudyId, id) .eq(TStudyInduction::getDisabled, 0).list(); Optional<TStudyInduction> inductionOptional = inductionList.stream().findAny(); if (inductionOptional.isPresent()) { total += inductionOptional.get().getIntegral(); for (TStudyInduction data : inductionList) { Integer day = data.getDay(); if (!dayList.contains(day)) { total += data.getIntegral(); dayList.add(day); } } dayList.clear(); // 看图选音 List<TStudyLook> lookList = studyLookService.lambdaQuery().eq(TStudyLook::getStudyId, id) .eq(TStudyLook::getDisabled, 0).list(); Optional<TStudyLook> lookOptional = lookList.stream().findAny(); if (lookOptional.isPresent()) { total += lookOptional.get().getIntegral(); for (TStudyLook data : lookList) { Integer day = data.getDay(); if (!dayList.contains(day)) { total += data.getIntegral(); dayList.add(day); } } dayList.clear(); // 听音选图 List<TStudyListen> listenList = studyListenService.lambdaQuery().eq(TStudyListen::getStudyId, id) .eq(TStudyListen::getDisabled, 0).list(); Optional<TStudyListen> listenOptional = listenList.stream().findAny(); if (listenOptional.isPresent()) { total += listenOptional.get().getIntegral(); for (TStudyListen data : listenList) { Integer day = data.getDay(); if (!dayList.contains(day)) { total += data.getIntegral(); dayList.add(day); } } dayList.clear(); // 音图相配 List<TStudyPair> pairList = studyPairService.lambdaQuery().eq(TStudyPair::getStudyId, id) .eq(TStudyPair::getDisabled, 0).list(); Optional<TStudyPair> pairOptional = pairList.stream().findAny(); if (pairOptional.isPresent()) { total += pairOptional.get().getIntegral(); for (TStudyPair data : pairList) { Integer day = data.getDay(); if (!dayList.contains(day)) { total += data.getIntegral(); dayList.add(day); } } dayList.clear(); // 自主游戏 List<TGame> gameList = gameService.lambdaQuery().eq(TGame::getStudyId, id) .eq(TGame::getDisabled, 0).list(); @@ -434,21 +455,77 @@ } // 临时判断参数 boolean itemBool = false; // 学习进度所属季度 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)) { int i = collect.indexOf(studyWeek); if (collect.contains(week)) { int x = collect.indexOf(week); itemBool = i > x; } studyQuarter = key; } if (collect.contains(week)) { thisQuarter = key; } } // 默认进度为 0 int defaultSchedule; // 季度判断 if (studyQuarter > thisQuarter) { defaultSchedule = 100; } 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 = 100; } else if (studyIndex < weekIndex) { defaultSchedule = 0; } else { // 根据day初始化学习进度 if (Constants.ONE.equals(day)) { defaultSchedule = 0; } else if (Constants.TWO.equals(day)) { defaultSchedule = 20; } else if (Constants.THREE.equals(day)) { defaultSchedule = 40; } else if (Constants.FOUR.equals(day)) { defaultSchedule = 60; } else if (Constants.FIVE.equals(day)) { defaultSchedule = 80; } else { defaultSchedule = 0; } // 根据五种学习计算进度 Integer listen = result.getListen(); if (!Constants.BURDEN_ONE.equals(listen)) { defaultSchedule += (int) (((double) listen / 100) * 4); } Integer look = result.getLook(); if (!Constants.BURDEN_ONE.equals(look)) { defaultSchedule += (int) (((double) look / 100) * 4); } Integer induction = result.getInduction(); if (!Constants.BURDEN_ONE.equals(induction)) { defaultSchedule += (int) (((double) induction / 100) * 4); } Integer answer = result.getAnswer(); if (!Constants.BURDEN_ONE.equals(answer)) { defaultSchedule += (int) (((double) answer / 100) * 4); } Integer pair = result.getPair(); if (!Constants.BURDEN_ONE.equals(pair)) { defaultSchedule += (int) (((double) pair / 100) * 4); } } } // week以超过当前week,进度为 100% if (itemBool) { /*if (itemBool) { defaultSchedule = 100; } else { // 根据day初始化学习进度 @@ -468,26 +545,25 @@ // 根据五种学习计算进度 Integer listen = result.getListen(); if (!Constants.BURDEN_ONE.equals(listen)) { defaultSchedule += (int)(((double)listen / 100) * 4); defaultSchedule += (int) (((double) listen / 100) * 4); } Integer look = result.getLook(); if (!Constants.BURDEN_ONE.equals(look)) { defaultSchedule += (int)(((double)look / 100) * 4); defaultSchedule += (int) (((double) look / 100) * 4); } Integer induction = result.getInduction(); if (!Constants.BURDEN_ONE.equals(induction)) { defaultSchedule += (int)(((double)induction / 100) * 4); defaultSchedule += (int) (((double) induction / 100) * 4); } Integer answer = result.getAnswer(); if (!Constants.BURDEN_ONE.equals(answer)) { defaultSchedule += (int)(((double)answer / 100) * 4); defaultSchedule += (int) (((double) answer / 100) * 4); } Integer pair = result.getPair(); if (!Constants.BURDEN_ONE.equals(pair)) { defaultSchedule += (int)(((double)pair / 100) * 4); defaultSchedule += (int) (((double) pair / 100) * 4); } } }*/ return defaultSchedule; } @@ -597,4 +673,17 @@ return studyList.size() - residueWeek; } @Override public void checkClearance(TGame game, Integer userid) { String rate = game.getRate().split(",")[Constants.TWO]; // 获取用户游戏进度 List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid) .eq(TGameRecord::getGameId, game.getId()) .ge(TGameRecord::getAccuracy, rate) .eq(TGameRecord::getGameDifficulty, Constants.TWO).list(); if (list.isEmpty()) { throw new GlobalException("超级听力暂未通关!"); } } } ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java
@@ -4,15 +4,18 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.study.domain.TGame; import com.ruoyi.study.domain.TGameRecord; import com.ruoyi.study.domain.TStudy; import com.ruoyi.study.domain.TUserStudy; import com.ruoyi.study.dto.CompleteGameDTO; import com.ruoyi.study.dto.CompleteStudyDTO; import com.ruoyi.study.mapper.TUserStudyMapper; import com.ruoyi.study.service.ITGameRecordService; import com.ruoyi.study.service.ITUserStudyService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -28,6 +31,9 @@ */ @Service public class TUserStudyServiceImpl extends ServiceImpl<TUserStudyMapper, TUserStudy> implements ITUserStudyService { @Resource private ITGameRecordService gameRecordService; /** * 所属day map @@ -141,6 +147,11 @@ @Override public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList) { String answerRate = game.getAnswerRate(); String rate = game.getRate().split(",")[Constants.TWO]; // 校验是否完成超级听力 List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getGameId, game.getId()) .eq(TGameRecord::getGameDifficulty, Constants.TWO) .ge(TGameRecord::getAccuracy, rate).list(); // 下一周目逻辑 int quarterItem = 1; Map<Integer, List<TStudy>> studyMap = new HashMap<>(8); @@ -160,13 +171,14 @@ // 获取当前季度所有周目 List<TStudy> studyList1 = studyMap.get(quarterItem); // 正确率达到通关率 if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate)) { if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate) && !gameRecordList.isEmpty()) { // 获取用户超级记忆游戏记录 TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one(); for (int i = 0; i < studyList1.size(); i++) { TStudy tStudy = studyList1.get(i); if (tStudy.getWeek().equals(userStudy.getWeek())) { if (studyList1.size() == 1 || i + 1 == studyList1.size() - 1) { if (studyList1.size() == 1 || i + 1 == studyList1.size()) { // 是否为当前季度最后一周目 List<TStudy> studyList2 = studyMap.get(quarterItem + 1); // 下一季度数据为空 @@ -192,7 +204,7 @@ } @Override public void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy) { public void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList) { // 超级听力通关率 String answerRate = game.getRate().split(",")[completeStudy.getDifficulty()]; if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate)) { @@ -200,7 +212,65 @@ TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one(); // 更新游戏难度学习记录 if (!Constants.TWO.equals(userStudy.getGameDifficulty())) { userStudy.setGameDifficulty(GAME_DIFFICULTY_MAP.get(completeStudy.getDifficulty())); // 获取用户游戏进度 List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid) .eq(TGameRecord::getGameId, game.getId()) .ge(TGameRecord::getAccuracy, answerRate) .eq(TGameRecord::getGameDifficulty, completeStudy.getDifficulty()).list(); if (!list.isEmpty()) { Integer integer = GAME_DIFFICULTY_MAP.get(completeStudy.getDifficulty()); userStudy.setGameDifficulty(integer); } } else { // 游戏难度为2,进入下一周目学习 List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getGameId, game.getId()) .eq(TGameRecord::getGameName, Constants.MEMORY) .ge(TGameRecord::getAccuracy, game.getAnswerRate()).list(); // 判断是否完成超级记忆 if (!gameRecordList.isEmpty()) { int quarterItem = 1; 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); // 记录学习季度 if (study.getId().equals(game.getStudyId())) { quarterItem = quarter; } } // 获取当前季度所有周目 List<TStudy> studyList1 = studyMap.get(quarterItem); // 获取用户超级记忆游戏记录 for (int i = 0; i < studyList1.size(); i++) { TStudy tStudy = studyList1.get(i); if (tStudy.getWeek().equals(userStudy.getWeek())) { if (studyList1.size() == 1 || i + 1 == studyList1.size()) { // 是否为当前季度最后一周目 List<TStudy> studyList2 = studyMap.get(quarterItem + 1); // 下一季度数据为空 if (null != studyList2 && !studyList2.isEmpty()) { TStudy tStudy1 = studyList2.get(Constants.ZERO); userStudy.setWeek(tStudy1.getWeek()); } } else { TStudy tStudy1 = studyList1.get(i + 1); userStudy.setWeek(tStudy1.getWeek()); } } } userStudy.setDay(DAY_MAP.get(String.valueOf(userStudy.getDay()))); userStudy.setLook(Constants.BURDEN_ONE); userStudy.setPair(Constants.BURDEN_ONE); userStudy.setInduction(Constants.BURDEN_ONE); userStudy.setListen(Constants.BURDEN_ONE); userStudy.setAnswer(Constants.BURDEN_ONE); userStudy.setGameDifficulty(Constants.ZERO); } } this.updateById(userStudy); }