hjl
2024-06-20 eed4e2af4645f1dfc3abc047a86e90ad8fe149b3
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
@@ -79,6 +79,8 @@
    private IUserStudyRecordService studyRecordService;
    @Resource
    private ManagementClient managementClient;
    @Resource
    private ITUserPresentRecordService userPresentRecordService;
    @PostMapping("/storyList")
//    @ApiOperation(value = "配置学习类型选择故事", tags = {"题目管理"})
@@ -788,11 +790,39 @@
            throw new GlobalException("获取在线时间赠送积分信息失败!");
        }
        String integral = sysSet.getIntegral();
        // 计算时间间隔
        TUserPresentRecord record = userPresentRecordService.lambdaQuery()
                .eq(TUserPresentRecord::getUserId, loginStudy.getUserid())
                .orderByDesc(TUserPresentRecord::getPresentTime)
                .eq(TUserPresentRecord::getIsDelete, 0).last("limit 1").one();
        boolean result = true;
        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))
        if (null == record) {
            // 赠送积分
            result = userService.lambdaUpdate().set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral))
                .eq(TUser::getId, loginStudy.getUserid()).update();
        return R.ok(update);
            // 添加赠送积分记录
            TUserPresentRecord data = new TUserPresentRecord();
            data.setUserId(loginStudy.getUserid());
            data.setPresentTime(new Date());
            data.setIsDelete(0);
            result = result && userPresentRecordService.save(data);
        } else {
            if (System.currentTimeMillis() - record.getPresentTime().getTime() >= 10 * 60) {
                // 赠送积分
                result = userService.lambdaUpdate()
                        .set(TUser::getIntegral, user.getIntegral() + Integer.parseInt(integral))
                        .eq(TUser::getId, loginStudy.getUserid()).update();
                // 添加赠送积分记录
                TUserPresentRecord data = new TUserPresentRecord();
                data.setUserId(loginStudy.getUserid());
                data.setPresentTime(new Date());
                data.setIsDelete(0);
                result = result && userPresentRecordService.save(data);
            }
        }
        return R.ok(result);
    }
    /**
@@ -1105,6 +1135,7 @@
                .eq(TUserStudyRecord::getWeek, completeStudy.getWeek())
                .eq(TUserStudyRecord::getDay, completeStudy.getDay())
                .eq(TUserStudyRecord::getType, 0)
                .eq(TUserStudyRecord::getStudyType, completeStudy.getType())
                .eq(TUserStudyRecord::getUserId, userId).list();
        if (list.isEmpty()) {
            obtainedIntegral = 0;