无关风月
2024-09-10 26249d6bda4001cbba8c276a089eb6514f4cf29a
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
package com.xinquan.course.controller.client;
 
 
import com.alibaba.nacos.common.utils.StringUtils;
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.course.api.domain.Course;
import com.xinquan.course.domain.CourseChapter;
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.system.api.RemoteBannerService;
import com.xinquan.system.api.domain.vo.BannerVO;
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.util.List;
import java.util.Objects;
 
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
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 appUserService;
    @Resource
    private CourseChapterService courseChapterService;
 
    /**
     * 获取轮播图列表
     *
     * @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());
    }
    /**
     * 课程详情
     *
     * @return 课程详情
     */
    @GetMapping("/getCourseInfoById")
    @ApiOperation(value = "根据id获取课程详情-线下课程")
    public R<Course> getCourseInfoById(String id) {
        return R.ok(courseService.getById(id));
    }
    /**
     * 课程详情
     *
     * @return 课程详情
     */
    @GetMapping("/getPayCourseInfoById")
    @ApiOperation(value = "根据id获取课程详情-付费课程")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "课程id", name = "id", required = true, dataType = "String"),
            @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"),
            @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer")
    })
    public R<ClientCourseVO> getPayCourseInfoById(@RequestParam(value = "id")Long id,
                                                  @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Course byId = courseService.getById(id);
        ClientCourseVO clientCourseVO = new ClientCourseVO();
        BeanUtils.copyProperties(byId, clientCourseVO);
        // 查询章节
        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);
            clientCourseVO.setList(empty);
        }
        // 查询学习人数和头像列表
        List<String> data = appUserService.getUserByCourseId(id).getData();
        if (data!=null){
            clientCourseVO.setCount(data.size());
        }
        clientCourseVO.setHeaders(data);
        // 查询推荐课程
 
        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));
    }
}