| | |
| | | |
| | | |
| | | 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.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 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 io.swagger.models.auth.In; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.data.domain.jaxb.SpringDataJaxb; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 获取轮播图列表 |
| | |
| | | @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)); |
| | | } |
| | | /** |
| | | * 课程详情 |
| | |
| | | } |
| | | } |
| | | clientCourseVO.setList2(courses); |
| | | // 查询是否已收藏课程 |
| | | clientCourseVO.setIsCollect(courseUserFavoriteService.lambdaQuery() |
| | | .eq(CourseUserFavorite::getAppUserId, userId) |
| | | .eq(CourseUserFavorite::getCourseId, id) == null ? 2 : 1); |
| | | return R.ok(clientCourseVO); |
| | | } |
| | | |
| | |
| | | } |
| | | @GetMapping("/studyPage") |
| | | @ApiOperation(value = "学习") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer") |
| | | }) |
| | | public R<StudyPageVO> studyPage(@RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, |
| | | @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | |
| | | 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(pageCurr, pageSize).getData(); |
| | | 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()); |
| | | Page<Course> page = courseService.lambdaQuery() |
| | | List<Course> page = courseService.lambdaQuery() |
| | | .in(Course::getId, courseIds) |
| | | .page(new Page<>(pageCurr, pageSize)); |
| | | if (CollUtils.isEmpty(page.getRecords())) { |
| | | PageDTO<CourseVO> empty = PageDTO.empty(page); |
| | | studyPageVO.setCourseList(empty); |
| | | }else{ |
| | | PageDTO<CourseVO> courseChapterPageDTO = PageDTO.of(page, CourseVO.class); |
| | | studyPageVO.setCourseList(courseChapterPageDTO); |
| | | .list(); |
| | | for (Course course : page) { |
| | | CourseVO courseVO = new CourseVO(); |
| | | BeanUtils.copyProperties(course, courseVO); |
| | | courseVOS.add(courseVO); |
| | | studyPageVO.setCourseList(courseVOS); |
| | | } |
| | | } |
| | | // 查询两个相同类型的线上免费课程 |