hjl
2024-06-18 a7d177dd48ca8c8a7e154573f7306e2b86dd1a77
fix: 学习端bug
16个文件已修改
420 ■■■■ 已修改文件
ruoyi-api/ruoyi-api-management/src/main/java/com/ruoyi/management/api/model/TSysSet.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-study/src/main/java/com/ruoyi/study/api/vo/UserPersonalCenterVO.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/TGoodsServiceImpl.java 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-management/pom.xml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-management/src/main/java/com/ruoyi/management/controller/TSysSetController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-management/src/main/java/com/ruoyi/management/domain/TSysSet.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TGame.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TUserStudy.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITStudyService.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITSubjectRecordService.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITUserStudyService.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java 47 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TSubjectRecordServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java 91 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-management/src/main/java/com/ruoyi/management/api/model/TSysSet.java
@@ -6,6 +6,8 @@
import com.ruoyi.common.core.web.domain.BaseModel;
import lombok.Data;
import java.util.Date;
/**
 * <p>
 * 系统设置
@@ -57,4 +59,8 @@
     * 分享可获得积分
     */
    private String integralShare;
    /**
     * 每日分享可获积分
     */
    private Date acousticsTime;
}
ruoyi-api/ruoyi-api-study/src/main/java/com/ruoyi/study/api/vo/UserPersonalCenterVO.java
@@ -19,11 +19,4 @@
    @ApiModelProperty("用户学习信息(学习时长、学习进度)")
    private TUserStudy userStudy;
    public UserPersonalCenterVO(TUser user, TUserStudy userStudy) {
        this.user = user;
        this.userStudy = userStudy;
    }
    public UserPersonalCenterVO() {
    }
}
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
@@ -106,12 +106,13 @@
        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);
@@ -240,7 +241,7 @@
                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("|");
                    }
                }
@@ -622,7 +623,11 @@
        // 商品分类详情
        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));
    }
@@ -720,10 +725,11 @@
        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);
    }
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/TGoodsServiceImpl.java
@@ -58,20 +58,35 @@
    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("商品不存在,请稍后重试!");
        }
@@ -85,29 +100,50 @@
        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);
@@ -115,14 +151,7 @@
        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
ruoyi-service/ruoyi-management/pom.xml
@@ -33,11 +33,12 @@
            <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>
ruoyi-service/ruoyi-management/src/main/java/com/ruoyi/management/controller/TSysSetController.java
@@ -62,6 +62,10 @@
    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("保存成功");
ruoyi-service/ruoyi-management/src/main/java/com/ruoyi/management/domain/TSysSet.java
@@ -6,6 +6,8 @@
import com.ruoyi.common.core.web.domain.BaseModel;
import lombok.Data;
import java.util.Date;
/**
 * <p>
 * 系统设置
@@ -57,4 +59,9 @@
     * 每日分享可获积分
     */
    private String integralShare;
    /**
     * ios需要该字段判断是否重新下载正确及错误音效
     */
    private Date acousticsTime;
}
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
@@ -710,7 +710,7 @@
        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);
@@ -734,6 +734,42 @@
    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);
    }
    /**
@@ -762,7 +798,6 @@
                .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();
@@ -1064,6 +1099,10 @@
    })
    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("请选择符合规则的游戏难度!");
@@ -1075,7 +1114,7 @@
        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)) {
@@ -1218,7 +1257,23 @@
            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) {
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TGame.java
@@ -53,6 +53,12 @@
    private String time;
    /**
     * 超级听力 通关率 逗号隔开 第一个对应入门 第二个对应中级
     */
    @ApiModelProperty("超级听力 通关率 逗号隔开 第一个对应入门 第二个对应中级")
    private String rate;
    /**
     * 超级记忆存储该字段 答题时间
     */
    @ApiModelProperty("超级记忆 - 答题时间(第一个为入门难度;第二个为中级难度;第三个为困难难度)")
@@ -68,5 +74,10 @@
    @ApiModelProperty("超级记忆游戏题目数量")
    private Integer answerCount;
    /**
     * 超级记忆通关率
     */
    @ApiModelProperty("超级记忆通关率")
    private String answerRate;
}
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/domain/TUserStudy.java
@@ -94,6 +94,11 @@
     */
    @ApiModelProperty(value = "音图相配学习进度(100为已完成)")
    private Integer pair;
    /**
     * 游戏日当前应进行的游戏难度
     */
    @ApiModelProperty(value = "游戏日应进行的游戏难度(0入门、1中级、2高级)")
    private Integer gameDifficulty;
    /**
     * 当前week学习进度
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITStudyService.java
@@ -2,6 +2,7 @@
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.*;
@@ -30,10 +31,9 @@
     * 获取学习进度及学习时长等信息
     *
     * @param userId 用户id
     * @param week   周目
     * @return 学习信息
     */
    TUserStudy studySchedule(String userId, Integer week);
    TUserStudy studySchedule(String userId);
    /**
     * 自主学习1-听音选图
@@ -51,8 +51,9 @@
     * @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-看图选音
@@ -112,4 +113,13 @@
     * @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);
}
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITSubjectRecordService.java
@@ -3,7 +3,6 @@
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>
@@ -24,12 +23,4 @@
     */
    Boolean exitLearning(ExitLearnVO exitLearn, Integer userid);
    /**
     * 获取学习进度
     *
     * @param subjectRecord 已存在的学习进度
     * @param userid        用户id
     * @return 结果
     */
    SubjectRecordResultVO recordResult(TSubjectRecord subjectRecord, Integer userid);
}
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/ITUserStudyService.java
@@ -1,8 +1,10 @@
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;
@@ -21,10 +23,9 @@
     * 获取学习进度及学习时长等信息
     *
     * @param userId 用户id
     * @param week   周目
     * @return 学习信息
     */
    TUserStudy studySchedule(String userId, Integer week);
    TUserStudy studySchedule(String userId);
    /**
     * 定时任务 清空用户学习时长
@@ -42,4 +43,23 @@
     * @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);
}
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TStudyServiceImpl.java
@@ -4,8 +4,8 @@
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.*;
@@ -33,8 +33,6 @@
    private ITSubjectService subjectService;
    @Resource
    private ITGameRecordService gameRecordService;
    @Resource
    private TokenService tokenService;
    @Resource
    private ITStudyAnswerService studyAnswerService;
    @Resource
@@ -72,23 +70,38 @@
            // 有问有答
            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();
@@ -118,23 +131,24 @@
    }
    @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("请先完成上一难度再挑战当前难度!");
@@ -438,4 +452,9 @@
        return (int) (sum * ((double) accuracy / 100));
    }
    @Override
    public void checkRate(TGame game, Integer userid, CompleteGameDTO completeStudy) {
    }
}
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TSubjectRecordServiceImpl.java
@@ -48,8 +48,4 @@
        return this.save(subjectRecord);
    }
    @Override
    public SubjectRecordResultVO recordResult(TSubjectRecord subjectRecord, Integer userid) {
        return null;
    }
}
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/service/impl/TUserStudyServiceImpl.java
@@ -3,8 +3,10 @@
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;
@@ -31,20 +33,29 @@
     */
    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();
    }
@@ -100,32 +111,20 @@
            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);
@@ -136,4 +135,44 @@
        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);
        }
    }
}