无关风月
2024-10-14 b60e601d62c0e2d5c4fd1df9f12fa09f2bf99987
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
package com.xinquan.course.controller.client;
 
 
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinquan.common.core.constant.SecurityConstants;
import com.xinquan.common.core.domain.R;
import com.xinquan.common.core.utils.page.BeanUtils;
import com.xinquan.common.core.utils.page.CollUtils;
import com.xinquan.common.core.utils.page.PageDTO;
import com.xinquan.common.security.utils.SecurityUtils;
import com.xinquan.course.api.domain.Course;
import com.xinquan.course.api.domain.CourseDTO;
import com.xinquan.course.api.vo.CourseVO;
import com.xinquan.course.api.vo.StudyPageVO;
import com.xinquan.course.api.domain.CourseCategory;
import com.xinquan.course.domain.CourseChapter;
import com.xinquan.course.domain.CourseUserFavorite;
import com.xinquan.course.domain.vo.ClientCourseCategoryVO;
import com.xinquan.course.domain.vo.ClientCourseVO;
import com.xinquan.course.service.CourseCategoryService;
import com.xinquan.course.service.CourseChapterService;
import com.xinquan.course.service.CourseService;
import com.xinquan.course.service.CourseUserFavoriteService;
import com.xinquan.meditation.api.domain.Meditation;
import com.xinquan.meditation.api.feign.RemoteMeditationService;
import com.xinquan.system.api.RemoteBannerService;
import com.xinquan.system.api.domain.AppUser;
import com.xinquan.system.api.domain.AppUserCourse;
import com.xinquan.system.api.domain.AppUserViewingHistory;
import com.xinquan.system.api.domain.vo.AppUserVO;
import com.xinquan.system.api.domain.vo.BannerVO;
import com.xinquan.course.api.domain.OrderCourseVO;
import com.xinquan.user.api.feign.RemoteAppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.jaxb.SpringDataJaxb;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
/**
 * <p>
 * 线上课程表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-08-21
 */
@Api(tags = {"用户端-课程相关接口"})
@RestController
@RequiredArgsConstructor
@RequestMapping("/client/course/course")
public class ClientCourseController {
 
    private final CourseCategoryService courseCategoryService;
    private final CourseService courseService;
    private final RemoteBannerService remoteBannerService;
    private final RemoteAppUserService remoteAppUserService;
    @Resource
    private CourseChapterService courseChapterService;
    @Resource
    private CourseUserFavoriteService courseUserFavoriteService;
    @Resource
    private RemoteMeditationService remoteMeditationService;
 
    /**
     * 远程调用 通过课程名字查询课程ids
     * @return
     */
    @PostMapping("/getCourseIdsByName/{name}")
    public R<List<Long>> getCourseIdsByName(@PathVariable("name") String name) {
        List<Long> collect = courseService.lambdaQuery().like(Course::getCourseTitle, name)
                .list().stream().map(Course::getId)
                .collect(Collectors.toList());
        return R.ok(collect);
    }
 
    @PostMapping("/courseManagementList")
    @ApiOperation(value = "课程管理列表-分页", tags = {"管理后台-课程管理"})
    public R<PageDTO<Course>> courseManagementList(@RequestBody CourseDTO courseDTO) {
        List<Long> longs = new ArrayList<>();
        LambdaQueryWrapper<Course> courseLambdaQueryWrapper = new LambdaQueryWrapper<>();
        courseLambdaQueryWrapper.like(StringUtils.isNotBlank(courseDTO.getTutor()), Course::getTutor, courseDTO.getTutor())
                .eq(Objects.nonNull(courseDTO.getCateId()), Course::getCateId, courseDTO.getCateId())
                .eq(Objects.nonNull(courseDTO.getCourseType()), Course::getCourseType, courseDTO.getCourseType())
                .eq(Objects.nonNull(courseDTO.getChargeType()), Course::getChargeType, courseDTO.getChargeType())
                .eq(Objects.nonNull(courseDTO.getListingStatus()), Course::getListingStatus, courseDTO.getListingStatus())
                .orderByDesc(Course::getSortNum);
        if (org.springframework.util.StringUtils.hasLength(courseDTO.getCourseTitle())){
            List<Long> collect = courseService.lambdaQuery().like(Course::getCourseTitle, courseDTO.getCourseTitle()).list()
                    .stream().map(Course::getId).collect(Collectors.toList());
            longs.addAll(collect);
            List<Long> collect1 = courseChapterService.lambdaQuery().like(CourseChapter::getChapterTitle, courseDTO.getCourseTitle()).list()
                    .stream().map(CourseChapter::getCourseId).collect(Collectors.toList());
            longs.addAll(collect1);
            if (longs.isEmpty()){
                longs.add(-1L);
            }
            courseLambdaQueryWrapper.in(Course::getId, longs);
        }
        Page<Course> page = courseService.page(new Page<>(courseDTO.getPageCurr(), courseDTO.getPageSize()), courseLambdaQueryWrapper);
        if (CollUtils.isEmpty(page.getRecords())) {
            return R.ok(PageDTO.empty(page));
        }
        for (Course record : page.getRecords()) {
            CourseCategory byId = courseCategoryService.getById(record.getCateId());
            if (Objects.nonNull(byId)){
                record.setCategoryName(byId.getName());
            }
            record.setUid(record.getId().toString());
            long count = courseChapterService.count(new LambdaQueryWrapper<CourseChapter>().eq(CourseChapter::getCourseId, record.getId()));
            record.setCourseChapterCount(count);
            // 查询收藏数量
            long count1 = courseUserFavoriteService.count(new LambdaQueryWrapper<CourseUserFavorite>()
                    .eq(CourseUserFavorite::getCourseId, record.getId()));
            record.setCollectCount(count1);
        }
        return R.ok(PageDTO.of(page, Course.class));
    }
    @PostMapping("/addCourse")
    @ApiOperation(value = "新增课程管理", notes = "管理后台-课程管理")
    public R addCourse(@RequestBody Course homeBackgroundMusic) {
        homeBackgroundMusic.setCreateBy(SecurityUtils.getUsername());
        homeBackgroundMusic.setCreateTime(LocalDateTime.now());
        return R.ok(courseService.save(homeBackgroundMusic));
    }
    @GetMapping("/detailCourse")
    @ApiOperation(value = "查看详情课程管理", notes = "管理后台-课程管理")
    public R<Course> detailCourse(String uid) {
        return R.ok(courseService.getById(uid));
    }
    @GetMapping("/updateState")
    @ApiOperation(value = "修改课程上下架状态", notes = "管理后台-课程管理")
    public R updateState(String uid) {
        Course byId = courseService.getById(uid);
        if (byId.getListingStatus() == 1){
            byId.setListingStatus(2);
        }else {
            byId.setListingStatus(1);
        }
        return R.ok();
    }
    @PostMapping("/updateCourse")
    @ApiOperation(value = "修改课程管理", notes = "管理后台-课程管理")
    public R updateCourse(@RequestBody Course homeBackgroundMusic) {
        homeBackgroundMusic.setUpdateBy(SecurityUtils.getUsername());
        homeBackgroundMusic.setUpdateTime(LocalDateTime.now());
        return R.ok(courseService.updateById(homeBackgroundMusic));
    }
    @PostMapping("/deleteCourse")
    @ApiOperation(value = "批量删除", notes = "管理后台-课程管理")
    public R deleteCourse(String ids) {
        return R.ok(courseService.removeBatchByIds(Arrays.asList(ids.split(","))));
    }
 
 
 
    @PostMapping("/cateList")
    public R<List<CourseCategory>> cateList() {
        List<CourseCategory> list = courseCategoryService.list();
        for (CourseCategory courseCategory : list) {
            courseCategory.setUid(courseCategory.getId().toString());
        }
        return R.ok(list);
    }
    @PostMapping("/courseList")
    public R<PageDTO<Course>> courseList(@RequestBody CourseDTO courseDTO) {
        Page<Course> page = courseService.lambdaQuery()
                .like(StringUtils.isNotBlank(courseDTO.getCourseTitle()), Course::getCourseTitle, courseDTO.getCourseTitle())
                .like(StringUtils.isNotBlank(courseDTO.getTutor()), Course::getTutor, courseDTO.getTutor())
                .eq(Objects.nonNull(courseDTO.getCateId()), Course::getCateId, courseDTO.getCateId())
                .eq(Objects.nonNull(courseDTO.getCourseType()), Course::getCourseType, courseDTO.getCourseType())
                .orderByDesc(Course::getSortNum)
                .page(new Page<>(courseDTO.getPageCurr(), courseDTO.getPageSize()));
        if (CollUtils.isEmpty(page.getRecords())) {
            return R.ok(PageDTO.empty(page));
        }
        for (Course record : page.getRecords()) {
            CourseCategory byId = courseCategoryService.getById(record.getCateId());
            if (Objects.nonNull(byId)){
                record.setCategoryName(byId.getName());
            }
            record.setUid(record.getId().toString());
        }
        return R.ok(PageDTO.of(page, Course.class));
    }
    @PostMapping("/myCollect")
    @ApiOperation(value = "我的收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "state", value = "1冥想 2课程", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true)
    })
    public R<PageDTO<OrderCourseVO>> myCollect(@RequestParam(value = "state")Integer state,
                                               @RequestParam(value = "pageCurr")Integer pageCurr,
                                               @RequestParam(value = "pageSize")Integer pageSize) {
        Long userId = SecurityUtils.getUserId();
        if (userId == 0)return R.tokenError("登录失效");
        switch (state){
            case 1:
                Page<Meditation> data = remoteMeditationService.getMeditationById(pageCurr, pageSize)
                        .getData();
                for (Meditation meditation : data.getRecords()) {
 
                }
                break;
            case 2:
                Page<CourseUserFavorite> page = courseUserFavoriteService.lambdaQuery()
                        .eq(CourseUserFavorite::getAppUserId, userId)
                        .page(new Page<>(pageCurr, pageSize));
                PageDTO<OrderCourseVO> courseChapterPageDTO = PageDTO.of(page, OrderCourseVO.class);
                for (CourseUserFavorite record : page.getRecords()) {
 
                }
                break;
        }
        return R.ok();
    }
    @PostMapping("/collectCourse")
    @ApiOperation(value = "收藏/取消课程")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "课程id", name = "id", required = true, dataType = "Long"),
    })
    public R collectCourse(@RequestParam(value = "id")Long id) {
        Long userId = SecurityUtils.getUserId();
        if (userId == 0)return R.tokenError("登录失效");
        CourseUserFavorite one = courseUserFavoriteService.lambdaQuery()
                .eq(CourseUserFavorite::getAppUserId, userId)
                .eq(CourseUserFavorite::getCourseId, id).one();
        if (one==null){
            // 收藏课程
            CourseUserFavorite courseUserFavorite = new CourseUserFavorite();
            courseUserFavorite.setAppUserId(userId);
            courseUserFavorite.setCourseId(id);
            courseUserFavoriteService.save(courseUserFavorite);
        }else{
            // 取消收藏
            courseUserFavoriteService.removeById(one);
        }
        return R.ok();
    }
 
 
    /**
     * 远程调用 根据课程id查询课程信息
     *
     * @return 课程分类列表
     */
    @PostMapping("/getCourseByCourseId/{courseId}")
    public R<OrderCourseVO> getCourseCategoryList(@RequestBody OrderCourseVO req) {
        Course byId = courseService.getById(req.getBusinessId());
        List<AppUser> data = remoteAppUserService.getUserByCourseId(req.getBusinessId()).getData();
        if (data!=null){
            req.setCount(data.size());
            req.setCourseTitle(byId.getCourseTitle());
            req.setDescription(byId.getDescription());
            req.setGeneralPrice(byId.getGeneralPrice());
            req.setIosPrice(byId.getIosPrice());
            req.setCoverUrl(byId.getCoverUrl());
        }
        return R.ok(req);
    }
 
    /**
     * 获取轮播图列表
     *
     * @return 轮播图列表
     */
    @GetMapping("/getBannerList")
    @ApiOperation(value = "获取轮播图列表")
    public R<List<BannerVO>> getBannerList() {
        return remoteBannerService.getBannerList(SecurityConstants.INNER);
    }
 
    /**
     * 获取课程分类列表
     *
     * @return 课程分类列表
     */
    @GetMapping("/getCourseCategoryList")
    @ApiOperation(value = "获取课程分类列表")
    public R<List<ClientCourseCategoryVO>> getCourseCategoryList() {
        return R.ok(courseCategoryService.getCourseCategoryList());
    }
    /**
     * 远程调用 根据分类id 获取分类对象
     *
     * @return 课程分类列表
     */
    @GetMapping("/getCategoryById/{id}")
    public R<CourseCategory> getCategoryById(@PathVariable("id") String id) {
        return R.ok(courseCategoryService.getById(id));
    }
    /**
     * 课程详情
     *
     * @return 课程详情
     */
 
    /**
     * 课程详情
     *
     * @return 课程详情
     */
    @PostMapping("/getPayCourseInfoById")
    @ApiOperation(value = "根据id获取课程详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "课程id", name = "id", required = true, dataType = "String"),
    })
    public R<ClientCourseVO> getPayCourseInfoById(@RequestParam(value = "id")Long id) {
        Long userId = SecurityUtils.getUserId();
        if (userId == 0)return R.tokenError("登录失效");
        AppUserVO data1 = remoteAppUserService.getCurrentUser().getData();
 
        Course byId = courseService.getById(id);
        ClientCourseVO clientCourseVO = new ClientCourseVO();
        BeanUtils.copyProperties(byId, clientCourseVO);
        if (data1.getVipExpireTime()!=null && data1.getVipExpireTime().isAfter(LocalDateTime.now())){
            clientCourseVO.setIsVip(1);
        }else{
            clientCourseVO.setIsVip(0);
        }
        // 查询用户是否已购买该课程
        // 查询章节
        List<CourseChapter> page = courseChapterService.lambdaQuery()
                .eq(CourseChapter::getCourseId, id)
                .orderByDesc(CourseChapter::getSortNum)
                .list();
        clientCourseVO.setIsBuy(0);
        // 查询学习人数和头像列表
        List<AppUser> data = remoteAppUserService.getUserByCourseId(id).getData();
        if (data!=null){
            clientCourseVO.setCount(data.size());
            if (data.size()>=5){
                clientCourseVO.setHeaders(data.stream().limit(5).map(AppUser::getAvatar).collect(Collectors.toList()));
            }else{
                clientCourseVO.setHeaders(data.stream().map(AppUser::getAvatar).collect(Collectors.toList()));
            }
            List<Long> collect = data.stream().map(AppUser::getUserId).collect(Collectors.toList());
            if (!collect.isEmpty()){
                if (collect.contains(userId)){
                    clientCourseVO.setIsBuy(1);
                }
            }
        }
        // 查询推荐课程
        List<Course> list = courseService.lambdaQuery().eq(Course::getCateId, byId.getCateId())
                .eq(Course::getCourseType,1)
                .eq(Course::getRecommend, 1).list();
        List<Course> courses = new ArrayList<>();
        // 随机获取两个课程
        if (CollUtils.isNotEmpty(list)) {
            int size = list.size();
            int index = (int) (Math.random() * size);
            if (size >= 2){
                for (int i = 0; i < 2; i++) {
                    courses.add(list.get(index));
                }
            }else{
                courses.add(list.get(index));
            }
        }
        clientCourseVO.setList2(courses);
        // 查询是否已收藏课程
        clientCourseVO.setIsCollect(courseUserFavoriteService.lambdaQuery()
                .eq(CourseUserFavorite::getAppUserId, userId)
                .eq(CourseUserFavorite::getCourseId, id) == null ? 2 : 1);
        return R.ok(clientCourseVO);
    }
 
    /**
     * 获取课程列表-分页
     *
     * @param courseTitle 课程标题
     * @param cateId      分类id
     * @param pageCurr    分页参数,当前页码
     * @param pageSize    分页参数,每页数量
     * @return 课程分页列表
     */
    @PostMapping("/getCoursePageList")
    @ApiOperation(value = "获取课程列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "课程标题", name = "courseTitle", required = false, dataType = "String"),
            @ApiImplicitParam(value = "课程分类id", name = "cateId", required = false, dataType = "Long"),
            @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"),
            @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer")
    })
    public R<PageDTO<ClientCourseVO>> getCourseList(
            @RequestParam(defaultValue = "", value = "courseTitle", required = false) String courseTitle,
            @RequestParam(required = false) Long cateId,
            @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return R.ok(courseService.getCoursePageList(courseTitle, cateId, pageCurr, pageSize));
    }
    @PostMapping("/studyPageByChapterId")
    @ApiOperation(value = "课程学习页面")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "章节id", name = "chapterId", required = true, dataType = "Long"),
            @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"),
            @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer")
    })
    public R<PageDTO<CourseChapter>> studyPageByChapterId(@RequestParam(value = "chapterId")Long chapterId,
                                                  @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        CourseChapter byId1 = courseChapterService.getById(chapterId);
        Long id = byId1.getCourseId();
        // 查询章节
        Page<CourseChapter> page = courseChapterService.lambdaQuery()
                .eq(CourseChapter::getCourseId, id)
                .orderByDesc(CourseChapter::getSortNum)
                .page(new Page<>(pageCurr, pageSize));
        if (CollUtils.isEmpty(page.getRecords())) {
            PageDTO<CourseChapter> empty = PageDTO.empty(page);
            return R.ok(empty);
        }
        PageDTO<CourseChapter> courseChapterPageDTO = PageDTO.of(page, CourseChapter.class);
        if (CollUtils.isNotEmpty(courseChapterPageDTO.getList())) {
            for (CourseChapter courseChapter : courseChapterPageDTO.getList()) {
                AppUserViewingHistory data = remoteAppUserService.getCourseStudyHistory(courseChapter.getId()).getData();
                if (data!=null){
                    courseChapter.setMinuteLook(data.getMinuteLook());
                    courseChapter.setSecondLook(data.getSecondLook());
                    courseChapter.setIsOver(data.getIsOver());
                }
            }
        }
        return R.ok();
    }
    @PostMapping("/confirmOrder")
    @ApiOperation(value = "确认订单页面")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "课程id", name = "courseId", required = true, dataType = "Long")
    })
    public R<Course> studyPageByChapterId(@RequestParam(value = "courseId")Long courseId) {
        Long userId = SecurityUtils.getUserId();
        if (userId == 0)return R.tokenError("登录失效");
        Course byId = courseService.getById(courseId);
        return R.ok(byId);
    }
    @PostMapping("/successOrder")
    @ApiOperation(value = "支付成功页面")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "课程id", name = "courseId", required = true, dataType = "Long")
    })
    public R<List<Course>> successOrder(@RequestParam(value = "courseId")Long courseId) {
        Long userId = SecurityUtils.getUserId();
        if (userId == 0)return R.tokenError("登录失效");
        Course byId = courseService.getById(courseId);
        List<Course> list = courseService.lambdaQuery().eq(Course::getCateId, byId.getCateId())
                .eq(Course::getCourseType, 1).list();
        for (Course course : list) {
            List<AppUser> data = remoteAppUserService.getUserByCourseId(courseId).getData();
            course.setCount(data.size());
        }
        List<Course> courses = new ArrayList<>();
 
        // 如果list集合数据大于2 随机获取两个返回
        if (CollUtils.isNotEmpty(list) && list.size() > 4) {
            int size = list.size();
            int index = (int) (Math.random() * size);
            for (int i = 0; i < 4; i++) {
                courses.add(list.get(index));
            }
            return R.ok(courses);
        }else {
            return R.ok(list);
        }
    }
    @GetMapping("/studyPage")
    @ApiOperation(value = "学习")
 
    public R<StudyPageVO> studyPage() {
        Long userId = SecurityUtils.getUserId();
        if (userId == 0)return R.tokenError("登录失效");
        StudyPageVO studyPageVO = new StudyPageVO();
        List<CourseVO> courseVOS = new ArrayList<>();
 
        PageDTO<AppUserCourse> data = remoteAppUserService.getPayCourse(1, 909999).getData();
        List<AppUserCourse> list = data.getList();
        if (CollUtils.isNotEmpty(list)) {
            List<Long> courseIds = list.stream().map(AppUserCourse::getCourseId).collect(Collectors.toList());
            List<Course> page = courseService.lambdaQuery()
                    .in(Course::getId, courseIds)
                    .list();
            for (Course course : page) {
                CourseVO courseVO = new CourseVO();
                BeanUtils.copyProperties(course, courseVO);
                courseVOS.add(courseVO);
                studyPageVO.setCourseList(courseVOS);
            }
        }
        // 查询两个相同类型的线上免费课程
        List<Course> freeCourseList = courseService.lambdaQuery()
                .eq(Course::getCourseType, 1)
                .eq(Course::getChargeType, 1)
                .list();
        // 随机获取两个
        if (CollUtils.isNotEmpty(freeCourseList) && freeCourseList.size() > 2) {
            int size = freeCourseList.size();
            int index = (int) (Math.random() * size);
            List<Course> courses = new ArrayList<>();
            for (int i = 0; i < 2; i++) {
                courses.add(freeCourseList.get(index));
            }
            studyPageVO.setFreeCourseList(courses);
        }else{
            studyPageVO.setFreeCourseList(freeCourseList);
        }
        return R.ok(studyPageVO);
    }
}