| | |
| | | import com.ruoyi.common.core.web.domain.BaseModel; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统设置 |
| | |
| | | * 分享可获得积分 |
| | | */ |
| | | private String integralShare; |
| | | /** |
| | | * 每日分享可获积分 |
| | | */ |
| | | private Date acousticsTime; |
| | | } |
| | |
| | | @ApiModelProperty("用户学习信息(学习时长、学习进度)") |
| | | private TUserStudy userStudy; |
| | | |
| | | public UserPersonalCenterVO(TUser user, TUserStudy userStudy) { |
| | | this.user = user; |
| | | this.userStudy = userStudy; |
| | | } |
| | | |
| | | public UserPersonalCenterVO() { |
| | | } |
| | | } |
| | |
| | | String keywords = goodQuery.getKeywords(); |
| | | // 初始化条件构造器 |
| | | QueryWrapper<TGoods> wrapper = new QueryWrapper<>(); |
| | | wrapper = keywords != null && "".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper; |
| | | wrapper = keywords != null && !"".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper; |
| | | |
| | | // 类型匹配 todo |
| | | if (goodQuery.getType() != null && goodQuery.getType().size() > 0) { |
| | | if (goodQuery.getType() != null && !goodQuery.getType().isEmpty()) { |
| | | for (String s : goodQuery.getType()) { |
| | | wrapper.or().apply("FIND_IN_SET('" + s + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | // 将每个类型 ID 应用于 FIND_IN_SET 函数 |
| | | wrapper.or().apply("FIND_IN_SET('" + s + "', typeIds)"); |
| | | } |
| | | } |
| | | wrapper.eq("isDelete", 0); |
| | |
| | | String[] split = byId.getTypeIds().split(","); |
| | | for (String s : split) { |
| | | TGoodsType byId1 = goodsTypeService.getById(s); |
| | | if (byId1!=null){ |
| | | if (byId1 != null) { |
| | | stringBuilder.append(byId1.getName()).append("|"); |
| | | } |
| | | } |
| | |
| | | // 商品分类详情 |
| | | List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list(); |
| | | // 已兑换人数 |
| | | int number = goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId()); |
| | | int number = 0; |
| | | if (null != goods.getBasicCount()) { |
| | | number += goods.getBasicCount(); |
| | | } |
| | | number += orderService.getGoodBuyNumber(goods.getId()); |
| | | return R.ok(new GoodDetailVO(goods, goodsTypes, number)); |
| | | } |
| | | |
| | |
| | | Random random = new Random(); |
| | | StringBuilder randomPart = new StringBuilder(); |
| | | for (int i = 0; i < 3; i++) { |
| | | randomPart.append((char) (random.nextInt(26) + 'A')); // 大写字母 |
| | | // 大写字母 |
| | | randomPart.append((char) (random.nextInt(26) + 'A')); |
| | | } |
| | | // 组合订单编号 |
| | | String orderNumber = formattedDateTime + randomPart.toString(); |
| | | String orderNumber = formattedDateTime + randomPart; |
| | | goodDetailVO.setOrderNumber(orderNumber); |
| | | return R.ok(goodDetailVO); |
| | | } |
| | |
| | | public GoodDetailVO redeemNow(String goodId, Recipient recipient) { |
| | | // 商品详情 |
| | | TGoods goods = lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | | // 库存预热,redisson分布式锁 |
| | | String key = String.format(RedisConstants.GOOD_STOCK, goods.getId()); |
| | | RSemaphore semaphore = redissonClient.getSemaphore(key); |
| | | semaphore.trySetPermits(goods.getSurplus()); |
| | | semaphore.expire(Constants.SIXTY, TimeUnit.MINUTES); |
| | | if (null == goods) { |
| | | throw new GlobalException("商品不存在!"); |
| | | } |
| | | // 商品总数量为 null,可无限兑换,不需要分布式锁进行控制 |
| | | if (null != goods.getTotal()) { |
| | | // 库存预热,redisson分布式锁 |
| | | String key = String.format(RedisConstants.GOOD_STOCK, goods.getId()); |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId) |
| | | .eq(TOrder::getDisabled, 0).list(); |
| | | int sum = orderList.stream().map(TOrder::getCount).mapToInt(Integer::intValue).sum(); |
| | | // 计算商品剩余可兑换数量 |
| | | int number = goods.getTotal() - sum; |
| | | if (number <= 0) { |
| | | throw new GlobalException("商品可兑换数量不足!"); |
| | | } |
| | | // redisson分布式锁 |
| | | RSemaphore semaphore = redissonClient.getSemaphore(key); |
| | | semaphore.trySetPermits(goods.getSurplus()); |
| | | semaphore.expire(Constants.SIXTY, TimeUnit.MINUTES); |
| | | } |
| | | return new GoodDetailVO(goods, recipient); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R goodExchange(GoodExchangeDTO goodExchange, Recipient recipient) { |
| | | public R<String> goodExchange(GoodExchangeDTO goodExchange, Recipient recipient) { |
| | | Integer number = goodExchange.getNumber(); |
| | | Integer goodId = goodExchange.getGoodId(); |
| | | TGoods good = this.getById(goodId); |
| | | TGoods good = lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | | if (null == good) { |
| | | return R.exchangeError("商品不存在,请稍后重试!"); |
| | | } |
| | |
| | | if (user.getIntegral() < needIntegral) { |
| | | return R.exchangeError("兑换失败,当前剩余积分不足!"); |
| | | } |
| | | // 检查用户兑换数量是否超过单用户最大兑换数量 |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) |
| | | .eq(TOrder::getGoodsId, goodId).list(); |
| | | // 该商品订单为空、订单数量未超过商品的单个用户兑换上限数量时,可以进行兑换 |
| | | int totalNumber = orderList.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | boolean canExchange = orderList.isEmpty() || null == good.getUserCount() || |
| | | (totalNumber + number) <= good.getUserCount(); |
| | | if (!canExchange) { |
| | | return R.exchangeError("兑换失败,当前兑换数量已超过最大兑换数量,剩余兑换数量为: " + |
| | | (good.getUserCount() - totalNumber) + "!"); |
| | | if (null != good.getTotal()) { |
| | | // 检查用户兑换数量是否超过单用户最大兑换数量 |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) |
| | | .eq(TOrder::getGoodsId, goodId).list(); |
| | | // 该商品订单为空、订单数量未超过商品的单个用户兑换上限数量时,可以进行兑换 |
| | | int totalNumber = orderList.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | boolean canExchange = orderList.isEmpty() || null == good.getUserCount() || |
| | | (totalNumber + number) <= good.getUserCount(); |
| | | if (!canExchange) { |
| | | return R.exchangeError("兑换失败,当前兑换数量已超过最大兑换数量,剩余兑换数量为: " + |
| | | (good.getUserCount() - totalNumber) + "!"); |
| | | } |
| | | // redisson分布式锁,防止超卖 |
| | | String key = String.format(RedisConstants.GOOD_STOCK, good.getId()); |
| | | RSemaphore semaphore = redissonClient.getSemaphore(key); |
| | | // 请求超时时间 单位:毫秒 |
| | | semaphore.trySetPermits(1000); |
| | | boolean tried = semaphore.tryAcquire(number); |
| | | // 兑换失败,库存不足 |
| | | if (!tried) { |
| | | semaphore.release(number); |
| | | return R.exchangeError("当前商品库存不足"); |
| | | } |
| | | // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务) |
| | | boolean result = exchangeGood(goodExchange, recipient, number, goodId, needIntegral); |
| | | // 扣除库存 |
| | | result = result && this.lambdaUpdate().set(TGoods::getTotal, good.getTotal() - number) |
| | | .eq(TGoods::getId, good.getId()).update(); |
| | | if (!result) { |
| | | semaphore.release(number); |
| | | return R.exchangeError("商品兑换失败!"); |
| | | } |
| | | } else { |
| | | boolean result = exchangeGood(goodExchange, recipient, number, goodId, needIntegral); |
| | | if (!result) { |
| | | return R.exchangeError("商品兑换失败!"); |
| | | } |
| | | } |
| | | // redisson分布式锁,防止超卖 |
| | | String key = String.format(RedisConstants.GOOD_STOCK, good.getId()); |
| | | RSemaphore semaphore = redissonClient.getSemaphore(key); |
| | | // 请求超时时间 单位:毫秒 |
| | | semaphore.trySetPermits(1000); |
| | | boolean tried = semaphore.tryAcquire(number); |
| | | // 兑换失败,库存不足 |
| | | if (!tried) { |
| | | semaphore.release(number); |
| | | return R.exchangeError("当前商品库存不足"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private Boolean exchangeGood(GoodExchangeDTO goodExchange, Recipient recipient, Integer number, |
| | | Integer goodId, int needIntegral) { |
| | | // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务) |
| | | TOrder order = orderInfo(goodExchange, recipient, number, goodId, needIntegral); |
| | | boolean result = orderService.save(order); |
| | |
| | | result = result && studyClient.addIntegralDetail(Constants.BURDEN + needIntegral, Constants.SHOPPING_CONSUME).getData(); |
| | | // 扣除用户积分 |
| | | result = result && studyClient.exchangeIntegral(needIntegral, Constants.BURDEN).getData(); |
| | | // 扣除库存 |
| | | result = result && this.lambdaUpdate().set(TGoods::getSurplus, good.getSurplus() - number) |
| | | .eq(TGoods::getId, good.getId()).update(); |
| | | if (!result) { |
| | | semaphore.release(number); |
| | | return R.exchangeError("商品兑换失败!"); |
| | | } |
| | | return R.ok(); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | <artifactId>ruoyi-api-goods</artifactId> |
| | | <version>3.6.2</version> |
| | | </dependency> |
| | | <!-- |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-api-goods</artifactId> |
| | | <version>3.6.2</version> |
| | | </dependency> |
| | | </dependency> --> |
| | | <!-- SpringCloud Alibaba Nacos --> |
| | | <dependency> |
| | | <groupId>com.alibaba.cloud</groupId> |
| | |
| | | public AjaxResult saveSysSet(SysSetVO vo) { |
| | | TSysSet byId = sysSetService.getById(1); |
| | | BeanUtils.copyProperties(vo, byId); |
| | | // 音效更改及更改音效设置时间 |
| | | if (!byId.getCorrect().equals(vo.getCorrect()) || !byId.getError().equals(vo.getError())) { |
| | | byId.setAcousticsTime(new Date()); |
| | | } |
| | | byId.setId(1); |
| | | sysSetService.updateById(byId); |
| | | return AjaxResult.success("保存成功"); |
| | |
| | | import com.ruoyi.common.core.web.domain.BaseModel; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统设置 |
| | |
| | | * 每日分享可获积分 |
| | | */ |
| | | private String integralShare; |
| | | |
| | | /** |
| | | * ios需要该字段判断是否重新下载正确及错误音效 |
| | | */ |
| | | private Date acousticsTime; |
| | | } |
| | |
| | | if (null == loginStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | TUserStudy result = studyService.studySchedule(String.valueOf(loginStudy.getUserid()), week); |
| | | TUserStudy result = studyService.studySchedule(String.valueOf(loginStudy.getUserid())); |
| | | if (null != result) { |
| | | // 计算当前周 day 1-5的总进度 |
| | | int computeSchedule = studyService.computeSchedule(result, week); |
| | |
| | | public R<List<StudyWeekDTO>> weekList(@RequestParam(defaultValue = "1") Integer type, @RequestParam Integer quarter) { |
| | | List<StudyWeekDTO> result = studyService.weekList(type, quarter); |
| | | return R.ok(result); |
| | | } |
| | | |
| | | /** |
| | | * 获取在线时间赠送积分信息 |
| | | */ |
| | | @GetMapping("/onlineDuration") |
| | | @ApiOperation(value = "获取在线时间赠送积分信息(单位分钟)", tags = {"学习端-首页"}) |
| | | public R<String> onlineDuration() { |
| | | TSysSet sysSet = managementClient.promptVoice().getData(); |
| | | if (null == sysSet) { |
| | | throw new GlobalException("获取在线时间赠送积分信息失败!"); |
| | | } |
| | | // 返回在线时长 |
| | | return R.ok(sysSet.getTime()); |
| | | } |
| | | |
| | | /** |
| | | * 根据在线时间赠送积分(定时任务) |
| | | */ |
| | | @GetMapping("/giveIntegral") |
| | | @ApiOperation(value = "根据在线时间赠送积分(定时任务)", tags = {"学习端-首页"}) |
| | | public R<Boolean> giveIntegral() { |
| | | LoginUserParent loginStudy = tokenService.getLoginUserStudy(); |
| | | if (null == loginStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | TSysSet sysSet = managementClient.promptVoice().getData(); |
| | | if (null == sysSet) { |
| | | throw new GlobalException("获取在线时间赠送积分信息失败!"); |
| | | } |
| | | String integral = sysSet.getIntegral(); |
| | | TUser user = userService.lambdaQuery().eq(TUser::getId, loginStudy.getUserid()) |
| | | .eq(TUser::getDisabled, 0).one(); |
| | | boolean update = userService.lambdaUpdate().set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral)) |
| | | .eq(TUser::getId, loginStudy.getUserid()).update(); |
| | | return R.ok(update); |
| | | } |
| | | |
| | | /** |
| | |
| | | .eq(TSubjectRecord::getDisabled, 0).one(); |
| | | // 返回结果 |
| | | SubjectRecordResultVO result; |
| | | SubjectRecordResultVO data = subjectRecordService.recordResult(subjectRecord, loginStudy.getUserid()); |
| | | if (null != subjectRecord) { |
| | | subjectRecordService.lambdaUpdate().set(TSubjectRecord::getDisabled, 1) |
| | | .eq(TSubjectRecord::getId, subjectRecord.getId()).update(); |
| | |
| | | }) |
| | | public R<StudyGameResultVO> gameHearing(@RequestParam Integer quarter, @RequestParam Integer difficulty, |
| | | @RequestParam Integer week) { |
| | | LoginUserParent userStudy = tokenService.getLoginUserStudy(); |
| | | if (null == userStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | Integer[] array = {0, 1, 2}; |
| | | if (!Arrays.stream(array).collect(Collectors.toList()).contains(difficulty)) { |
| | | throw new GlobalException("请选择符合规则的游戏难度!"); |
| | |
| | | game.setIntegral(game.getIntegral().split(",")[difficulty]); |
| | | game.setTime(game.getTime().split(",")[difficulty]); |
| | | // 检验是否完成难度 |
| | | studyService.checkDifficulty(difficulty, week, game); |
| | | studyService.checkDifficulty(difficulty, week, game, userStudy.getUserid()); |
| | | List<String> subjectId = getSubjectId(week); |
| | | List<String> newSubjectId = subjectId.stream().map(data -> { |
| | | if (data.startsWith(Constants.REDUCE)) { |
| | |
| | | user.setIntegral(user.getIntegral() + availableIntegral); |
| | | add = add && userService.updateById(user); |
| | | } |
| | | return R.ok(add); |
| | | // 超级记忆逻辑 |
| | | 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); |
| | | return R.ok(add && completeStudy.getAccuracy() >= Integer.parseInt(game.getAnswerRate())); |
| | | } else { |
| | | // 超级听力需根据正确率判断是否允许进入下一难度 |
| | | userStudyService.gameHearing(game, userid, completeStudy); |
| | | String rate = game.getRate().split(",")[completeStudy.getDifficulty()]; |
| | | return R.ok(add && completeStudy.getAccuracy() >= Integer.parseInt(rate)); |
| | | } |
| | | } |
| | | |
| | | private List<String> getSubjectId(Integer week) { |
| | |
| | | private String time; |
| | | |
| | | /** |
| | | * 超级听力 通关率 逗号隔开 第一个对应入门 第二个对应中级 |
| | | */ |
| | | @ApiModelProperty("超级听力 通关率 逗号隔开 第一个对应入门 第二个对应中级") |
| | | private String rate; |
| | | |
| | | /** |
| | | * 超级记忆存储该字段 答题时间 |
| | | */ |
| | | @ApiModelProperty("超级记忆 - 答题时间(第一个为入门难度;第二个为中级难度;第三个为困难难度)") |
| | |
| | | @ApiModelProperty("超级记忆游戏题目数量") |
| | | private Integer answerCount; |
| | | |
| | | /** |
| | | * 超级记忆通关率 |
| | | */ |
| | | @ApiModelProperty("超级记忆通关率") |
| | | private String answerRate; |
| | | |
| | | } |
| | |
| | | */ |
| | | @ApiModelProperty(value = "音图相配学习进度(100为已完成)") |
| | | private Integer pair; |
| | | /** |
| | | * 游戏日当前应进行的游戏难度 |
| | | */ |
| | | @ApiModelProperty(value = "游戏日应进行的游戏难度(0入门、1中级、2高级)") |
| | | private Integer gameDifficulty; |
| | | |
| | | /** |
| | | * 当前week学习进度 |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.study.domain.*; |
| | | import com.ruoyi.study.dto.CompleteGameDTO; |
| | | import com.ruoyi.study.dto.StudyWeekDTO; |
| | | import com.ruoyi.study.vo.*; |
| | | |
| | |
| | | * 获取学习进度及学习时长等信息 |
| | | * |
| | | * @param userId 用户id |
| | | * @param week 周目 |
| | | * @return 学习信息 |
| | | */ |
| | | TUserStudy studySchedule(String userId, Integer week); |
| | | TUserStudy studySchedule(String userId); |
| | | |
| | | /** |
| | | * 自主学习1-听音选图 |
| | |
| | | * @param difficulty 难度(0入门、1中级、2高级) |
| | | * @param week 所属周目 |
| | | * @param game 游戏信息 |
| | | * @param userid 用户id |
| | | */ |
| | | void checkDifficulty(Integer difficulty, Integer week, TGame game); |
| | | void checkDifficulty(Integer difficulty, Integer week, TGame game, Integer userid); |
| | | |
| | | /** |
| | | * 自主学习2-看图选音 |
| | |
| | | * @return 积分 |
| | | */ |
| | | int computeTotalIntegral(List<String> studyIds, Integer type, Integer accuracy); |
| | | |
| | | /** |
| | | * 超级记忆正确率达到通关率标准,才能进入下一周目学习 |
| | | * |
| | | * @param game 游戏信息 |
| | | * @param userid 用户id |
| | | * @param completeStudy 游戏完成信息 |
| | | */ |
| | | void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy); |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.study.domain.TSubjectRecord; |
| | | import com.ruoyi.study.vo.ExitLearnVO; |
| | | import com.ruoyi.study.vo.SubjectRecordResultVO; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | Boolean exitLearning(ExitLearnVO exitLearn, Integer userid); |
| | | |
| | | /** |
| | | * 获取学习进度 |
| | | * |
| | | * @param subjectRecord 已存在的学习进度 |
| | | * @param userid 用户id |
| | | * @return 结果 |
| | | */ |
| | | SubjectRecordResultVO recordResult(TSubjectRecord subjectRecord, Integer userid); |
| | | } |
| | |
| | | package com.ruoyi.study.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.study.domain.TGame; |
| | | 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 java.util.List; |
| | |
| | | * 获取学习进度及学习时长等信息 |
| | | * |
| | | * @param userId 用户id |
| | | * @param week 周目 |
| | | * @return 学习信息 |
| | | */ |
| | | TUserStudy studySchedule(String userId, Integer week); |
| | | TUserStudy studySchedule(String userId); |
| | | |
| | | /** |
| | | * 定时任务 清空用户学习时长 |
| | |
| | | * @return 更改结果 |
| | | */ |
| | | Boolean exchangeStudyRecord(List<TStudy> studyList, Integer userId, CompleteStudyDTO completeStudy); |
| | | |
| | | /** |
| | | * 超级记忆正确率达到通关率标准,才能进入下一周目学习 |
| | | * |
| | | * @param game 游戏信息 |
| | | * @param userid 用户id |
| | | * @param completeStudy 游戏完成信息 |
| | | * @param studyList 学习配置列表 |
| | | */ |
| | | void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList); |
| | | |
| | | /** |
| | | * 超级听力需根据正确率判断是否允许进入下一难度 |
| | | * |
| | | * @param game 游戏信息 |
| | | * @param userid 用户id |
| | | * @param completeStudy 游戏完成信息 |
| | | */ |
| | | void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy); |
| | | } |
| | |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.study.domain.*; |
| | | import com.ruoyi.study.dto.CompleteGameDTO; |
| | | import com.ruoyi.study.dto.StudyWeekDTO; |
| | | import com.ruoyi.study.mapper.TStudyMapper; |
| | | import com.ruoyi.study.service.*; |
| | |
| | | private ITSubjectService subjectService; |
| | | @Resource |
| | | private ITGameRecordService gameRecordService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private ITStudyAnswerService studyAnswerService; |
| | | @Resource |
| | |
| | | // 有问有答 |
| | | List<TStudyAnswer> answerList = studyAnswerService.lambdaQuery().eq(TStudyAnswer::getStudyId, id) |
| | | .eq(TStudyAnswer::getDisabled, 0).list(); |
| | | total += answerList.stream().map(TStudyAnswer::getIntegral).mapToInt(Integer::intValue).sum(); |
| | | Optional<TStudyAnswer> answerOptional = answerList.stream().findAny(); |
| | | if (answerOptional.isPresent()) { |
| | | total += answerOptional.get().getIntegral(); |
| | | } |
| | | // 归纳判断 |
| | | List<TStudyInduction> inductionList = studyInductionService.lambdaQuery().eq(TStudyInduction::getStudyId, id) |
| | | .eq(TStudyInduction::getDisabled, 0).list(); |
| | | total += inductionList.stream().map(TStudyInduction::getIntegral).mapToInt(Integer::intValue).sum(); |
| | | Optional<TStudyInduction> inductionOptional = inductionList.stream().findAny(); |
| | | if (inductionOptional.isPresent()) { |
| | | total += inductionOptional.get().getIntegral(); |
| | | } |
| | | // 看图选音 |
| | | List<TStudyLook> lookList = studyLookService.lambdaQuery().eq(TStudyLook::getStudyId, id) |
| | | .eq(TStudyLook::getDisabled, 0).list(); |
| | | total += lookList.stream().map(TStudyLook::getIntegral).mapToInt(Integer::intValue).sum(); |
| | | Optional<TStudyLook> lookOptional = lookList.stream().findAny(); |
| | | if (lookOptional.isPresent()) { |
| | | total += lookOptional.get().getIntegral(); |
| | | } |
| | | // 听音选图 |
| | | List<TStudyListen> listenList = studyListenService.lambdaQuery().eq(TStudyListen::getStudyId, id) |
| | | .eq(TStudyListen::getDisabled, 0).list(); |
| | | total += listenList.stream().map(TStudyListen::getIntegral).mapToInt(Integer::intValue).sum(); |
| | | Optional<TStudyListen> listenOptional = listenList.stream().findAny(); |
| | | if (listenOptional.isPresent()) { |
| | | total += listenOptional.get().getIntegral(); |
| | | } |
| | | // 音图相配 |
| | | List<TStudyPair> pairList = studyPairService.lambdaQuery().eq(TStudyPair::getStudyId, id) |
| | | .eq(TStudyPair::getDisabled, 0).list(); |
| | | total += pairList.stream().map(TStudyPair::getIntegral).mapToInt(Integer::intValue).sum(); |
| | | Optional<TStudyPair> pairOptional = pairList.stream().findAny(); |
| | | if (pairOptional.isPresent()) { |
| | | total += pairOptional.get().getIntegral(); |
| | | } |
| | | // 自主游戏 |
| | | List<TGame> gameList = gameService.lambdaQuery().eq(TGame::getStudyId, id) |
| | | .eq(TGame::getDisabled, 0).list(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public TUserStudy studySchedule(String userId, Integer week) { |
| | | return userStudyService.studySchedule(userId, week); |
| | | public TUserStudy studySchedule(String userId) { |
| | | return userStudyService.studySchedule(userId); |
| | | } |
| | | |
| | | @Override |
| | | public void checkDifficulty(Integer difficulty, Integer week, TGame game) { |
| | | public void checkDifficulty(Integer difficulty, Integer week, TGame game, Integer userid) { |
| | | // 判断用户是否完成上一个等级 |
| | | if (!Constants.ZERO.equals(difficulty)) { |
| | | Integer level = GAME_DIFFICULTY_MAP.get(difficulty); |
| | | if (null == level) { |
| | | throw new GlobalException("游戏等级异常,请重试!"); |
| | | } |
| | | // 游戏通关率 |
| | | String clearanceRate = game.getRate().split(",")[level]; |
| | | // 获取用户游戏进度 |
| | | Integer userId = tokenService.getLoginUserStudy().getUserid(); |
| | | List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userId) |
| | | List<TGameRecord> list = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, userid) |
| | | .eq(TGameRecord::getGameId, game.getId()) |
| | | .eq(TGameRecord::getAccuracy, 100) |
| | | .ge(TGameRecord::getAccuracy, clearanceRate) |
| | | .eq(TGameRecord::getGameDifficulty, level).list(); |
| | | if (list.isEmpty()) { |
| | | throw new GlobalException("请先完成上一难度再挑战当前难度!"); |
| | |
| | | return (int) (sum * ((double) accuracy / 100)); |
| | | } |
| | | |
| | | @Override |
| | | public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy) { |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | return this.save(subjectRecord); |
| | | } |
| | | |
| | | @Override |
| | | public SubjectRecordResultVO recordResult(TSubjectRecord subjectRecord, Integer userid) { |
| | | return null; |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | 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.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.ITUserStudyService; |
| | |
| | | */ |
| | | private static final Map<String, Integer> DAY_MAP = new HashMap<>(12); |
| | | |
| | | /** |
| | | * 所属day map |
| | | */ |
| | | private static final Map<Integer, Integer> GAME_DIFFICULTY_MAP = new HashMap<>(12); |
| | | |
| | | static { |
| | | // 所属day |
| | | DAY_MAP.put(Constants.ONE_STR, Constants.TWO); |
| | | DAY_MAP.put(Constants.TWO_STR, Constants.THREE); |
| | | DAY_MAP.put(Constants.THREE_STR, Constants.FOUR); |
| | | DAY_MAP.put(Constants.FOUR_STR, Constants.FIVE); |
| | | DAY_MAP.put(Constants.FIVE_STR, Constants.ONE); |
| | | // DAY_MAP.put(Constants.SIX_STR, Constants.SEVEN); |
| | | // DAY_MAP.put(Constants.SEVEN_STR, Constants.ONE); |
| | | DAY_MAP.put(Constants.FIVE_STR, Constants.SIX); |
| | | DAY_MAP.put(Constants.SIX_STR, Constants.ONE); |
| | | // 游戏难度 |
| | | GAME_DIFFICULTY_MAP.put(Constants.ZERO, Constants.ONE); |
| | | GAME_DIFFICULTY_MAP.put(Constants.ONE, Constants.TWO); |
| | | GAME_DIFFICULTY_MAP.put(Constants.TWO, Constants.ZERO); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public TUserStudy studySchedule(String userId, Integer week) { |
| | | public TUserStudy studySchedule(String userId) { |
| | | LambdaQueryChainWrapper<TUserStudy> wrapper = lambdaQuery().eq(TUserStudy::getUserId, userId); |
| | | wrapper = null != week ? wrapper.eq(TUserStudy::getWeek, week) : wrapper; |
| | | return wrapper.eq(TUserStudy::getDisabled, 0).one(); |
| | | } |
| | | |
| | |
| | | userStudyRecord.setPair(Constants.BURDEN_ONE); |
| | | } else if (Constants.FOUR.equals(type)) { |
| | | userStudyRecord.setAnswer(Constants.ONE_HUNDRED); |
| | | userStudyRecord.setPair(Constants.BURDEN_ONE); |
| | | } else if (Constants.FIVE.equals(type)) { |
| | | // 类型五,说明当前day已经全部完成,更新学习记录的 day |
| | | userStudyRecord.setPair(Constants.ONE_HUNDRED); |
| | | // type为5并且day为5应该进入游戏日 |
| | | Integer nextDay = DAY_MAP.get(String.valueOf(userStudyRecord.getDay())); |
| | | userStudyRecord.setDay(nextDay); |
| | | // 游戏难度初始化 0(入门难度) |
| | | userStudyRecord.setGameDifficulty(Constants.ZERO); |
| | | // 学习day已切换更新学习进度及学习时长 |
| | | userStudyRecord.setListen(Constants.BURDEN_ONE); |
| | | userStudyRecord.setLook(Constants.BURDEN_ONE); |
| | | userStudyRecord.setInduction(Constants.BURDEN_ONE); |
| | | userStudyRecord.setAnswer(Constants.BURDEN_ONE); |
| | | userStudyRecord.setPair(Constants.BURDEN_ONE); |
| | | // userStudyRecord.setListen(Constants.BURDEN_ONE); |
| | | // userStudyRecord.setLook(Constants.BURDEN_ONE); |
| | | // userStudyRecord.setInduction(Constants.BURDEN_ONE); |
| | | // userStudyRecord.setAnswer(Constants.BURDEN_ONE); |
| | | // userStudyRecord.setPair(Constants.BURDEN_ONE); |
| | | // 下一day为 1说明该周目已完成,应更改为下一周目 |
| | | if (Constants.ONE.equals(nextDay)) { |
| | | // 获取下一周目信息 |
| | | int index = -1; |
| | | for (int i = 0; i < studyList.size(); i++) { |
| | | if (studyList.get(i).getWeek().equals(userStudyRecord.getWeek())) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | int nextIndex = (index + 1) % studyList.size(); |
| | | TStudy nextStudy = studyList.get(nextIndex); |
| | | // 更新学习进度及学习时长 |
| | | userStudyRecord.setWeek(nextStudy.getWeek()); |
| | | } |
| | | } |
| | | // 更新学习时长 |
| | | userStudyRecord.setTotalStudy(userStudyRecord.getTotalStudy() + studyTime); |
| | |
| | | return this.updateById(userStudyRecord); |
| | | } |
| | | |
| | | @Override |
| | | public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy, List<TStudy> studyList) { |
| | | String answerRate = game.getAnswerRate(); |
| | | // 正确率达到通关率 |
| | | if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate)) { |
| | | // 获取用户超级记忆游戏记录 |
| | | TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one(); |
| | | Integer nextDay = DAY_MAP.get(String.valueOf(userStudy.getDay())); |
| | | userStudy.setDay(nextDay); |
| | | if (Constants.ONE.equals(nextDay)) { |
| | | // 获取下一周目信息 |
| | | int index = -1; |
| | | for (int i = 0; i < studyList.size(); i++) { |
| | | if (studyList.get(i).getWeek().equals(userStudy.getWeek())) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | int nextIndex = (index + 1) % studyList.size(); |
| | | TStudy nextStudy = studyList.get(nextIndex); |
| | | // 更新学习进度及学习时长 |
| | | userStudy.setWeek(nextStudy.getWeek()); |
| | | } |
| | | this.updateById(userStudy); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void gameHearing(TGame game, Integer userid, CompleteGameDTO completeStudy) { |
| | | // 超级听力通关率 |
| | | String answerRate = game.getRate().split(",")[completeStudy.getDifficulty()]; |
| | | if (completeStudy.getAccuracy() >= Integer.parseInt(answerRate)) { |
| | | // 获取用户超级记忆游戏记录 |
| | | TUserStudy userStudy = this.lambdaQuery().eq(TUserStudy::getUserId, userid).one(); |
| | | // 更新游戏难度学习记录 |
| | | userStudy.setGameDifficulty(GAME_DIFFICULTY_MAP.get(completeStudy.getDifficulty())); |
| | | this.updateById(userStudy); |
| | | } |
| | | } |
| | | |
| | | } |