| | |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xinquan.common.core.constant.SecurityConstants; |
| | | import com.xinquan.common.core.domain.R; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | |
| | | .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); |
| | | .orderByDesc(Course::getCreateTime); |
| | | 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()); |
| | |
| | | long count1 = courseUserFavoriteService.count(new LambdaQueryWrapper<CourseUserFavorite>() |
| | | .eq(CourseUserFavorite::getCourseId, record.getId())); |
| | | record.setCollectCount(count1); |
| | | // 查询学习人数 |
| | | // record.setCount(remoteAppUserService.getUserByCourseId(record.getId()).getData().size()); |
| | | int size1 = courseLearningRecordService.lambdaQuery().eq(CourseLearningRecord::getCourseId, record.getId()) |
| | | .groupBy(CourseLearningRecord::getAppUserId).list().size(); |
| | | List<CourseChapter> list = courseChapterService.lambdaQuery() |
| | | .eq(CourseChapter::getCourseId, record.getId()).list(); |
| | | // 章节列表累加虚拟学习人数 |
| | | int temp = 0; |
| | | int a = 0; |
| | | int b = 0; |
| | | for (CourseChapter courseChapter : list) { |
| | | temp+=courseChapter.getVirtualLearnedNum(); |
| | | a+= courseChapter.getVirtualLearnedNum(); |
| | | Long data1 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | b+=data1; |
| | | courseChapter.setRealLearnedNum(Integer.valueOf(data1+"")); |
| | | } |
| | | record.setCount(size1+temp); |
| | | record.setCount(a+b); |
| | | } |
| | | return R.ok(PageDTO.of(page, Course.class)); |
| | | } |
| | |
| | | } |
| | | List<CourseChapter> list = courseChapterService.lambdaQuery() |
| | | .eq(CourseChapter::getCourseId, uid).list(); |
| | | int temp = 0; |
| | | int temp1 = 0; |
| | | |
| | | int a = 0; |
| | | int b = 0; |
| | | for (CourseChapter courseChapter : list) { |
| | | int size = courseLearningRecordService.lambdaQuery() |
| | | .eq(CourseLearningRecord::getChapterId, courseChapter.getId()) |
| | | .list().size(); |
| | | courseChapter.setRealLearnedNum(size+courseChapter.getVirtualLearnedNum()); |
| | | temp+=courseChapter.getVirtualLearnedNum(); |
| | | temp1+=size; |
| | | a+= courseChapter.getVirtualLearnedNum(); |
| | | Long data1 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | b+=data1; |
| | | courseChapter.setRealLearnedNum(Integer.valueOf(data1+"")); |
| | | } |
| | | int size1 = courseLearningRecordService.lambdaQuery() |
| | | .eq(CourseLearningRecord::getCourseId, uid).groupBy(CourseLearningRecord::getAppUserId) |
| | | .list().size(); |
| | | byId.setVirtualLearnedNum(temp); |
| | | byId.setRealLearnedNum(size1); |
| | | byId.setCount(temp+size1); |
| | | |
| | | byId.setVirtualLearnedNum(a); |
| | | byId.setRealLearnedNum(b); |
| | | byId.setCount(a+b); |
| | | byId.setList(list); |
| | | int size = courseUserFavoriteService.lambdaQuery() |
| | | .eq(CourseUserFavorite::getCourseId, uid).list().size(); |
| | |
| | | @PostMapping("/updateCourse") |
| | | @ApiOperation(value = "修改课程管理", tags = "管理后台-课程管理") |
| | | public R updateCourse(@RequestBody Course homeBackgroundMusic) { |
| | | LambdaUpdateWrapper<Course> courseLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); |
| | | courseLambdaUpdateWrapper.eq(Course::getId, homeBackgroundMusic.getId()); |
| | | courseLambdaUpdateWrapper.set(Course::getDetailUrl, homeBackgroundMusic.getDetailUrl()); |
| | | courseLambdaUpdateWrapper.set(Course::getDetailName, homeBackgroundMusic.getDetailName()); |
| | | courseService.update(homeBackgroundMusic, courseLambdaUpdateWrapper); |
| | | homeBackgroundMusic.setUpdateBy(SecurityUtils.getUsername()); |
| | | homeBackgroundMusic.setUpdateTime(LocalDateTime.now()); |
| | | return R.ok(courseService.updateById(homeBackgroundMusic)); |
| | | courseService.updateById(homeBackgroundMusic); |
| | | return R.ok(); |
| | | } |
| | | @PostMapping("/deleteCourse") |
| | | @ApiOperation(value = "批量删除", tags = "管理后台-课程管理") |
| | |
| | | orderCourseVO.setGeneralPrice(record.getGeneralPrice()); |
| | | orderCourseVO.setIosPrice(record.getIosPrice()); |
| | | orderCourseVO.setCoverUrl(record.getCoverUrl()); |
| | | List<AppUser> data1 = remoteAppUserService.getUserByCourseId(record.getId()).getData(); |
| | | |
| | | List<CourseChapter> list = courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId, record.getId()).list(); |
| | | int temp = 0 ; |
| | | int temp1 = 0 ; |
| | | for (CourseChapter courseChapter : list) { |
| | | temp+= courseChapter.getVirtualLearnedNum(); |
| | | Long data2 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | temp1+=data2; |
| | | } |
| | | int size = courseLearningRecordService.lambdaQuery().eq(CourseLearningRecord::getCourseId, record.getId()) |
| | | .groupBy(CourseLearningRecord::getAppUserId).list().size(); |
| | | orderCourseVO.setCount(temp+size); |
| | | orderCourseVO.setCount(temp+temp1); |
| | | orderCourseVOS.add(orderCourseVO); |
| | | } |
| | | break; |
| | |
| | | @ApiImplicitParam(value = "课程id", name = "id", required = true, dataType = "String"), |
| | | }) |
| | | public R<ClientCourseVO> getPayCourseInfoById(@RequestParam(value = "id")Long id) { |
| | | |
| | | Course byId = courseService.getById(id); |
| | | ClientCourseVO clientCourseVO = new ClientCourseVO(); |
| | | BeanUtils.copyProperties(byId, clientCourseVO); |
| | | clientCourseVO.setIsBuy(2); |
| | | List<AppUser> data = remoteAppUserService.getUserByCourseId(id).getData(); |
| | | if (byId.getChargeType()==1 && tokenService.getLoginUser()==null){ |
| | | if (data!=null){ |
| | |
| | | }else{ |
| | | clientCourseVO.setIsVip(0); |
| | | } |
| | | List<Long> collect9 = data.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | if (!collect9.isEmpty()){ |
| | | if (collect9.contains(userId)){ |
| | | clientCourseVO.setIsBuy(1); |
| | | } |
| | | } |
| | | if(byId.getChargeType() != 1){ |
| | | List<CourseChapter> list = courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId, byId.getId()) |
| | | .list(); |
| | |
| | | b+=courseChapter.getVirtualLearnedNum(); |
| | | } |
| | | clientCourseVO.setCount(a+b); |
| | | clientCourseVO.setIsBuy(1); |
| | | }else if (data!=null){ |
| | | // 查询学习人数和头像列表 |
| | | clientCourseVO.setCount(data.size()); |
| | |
| | | Long data2 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | a+=data2; |
| | | b+=courseChapter.getVirtualLearnedNum(); |
| | | courseChapter.setRealLearnedNum(a+b); |
| | | courseChapter.setVirtualLearnedNum(0); |
| | | courseChapter.setRealLearnedNum(a); |
| | | courseChapter.setVirtualLearnedNum(b); |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser!=null){ |
| | | Integer data1 = remoteAppUserService.getCourseChapterHistoryState(loginUser.getUserid(), courseChapter.getId()).getData(); |
| | |
| | | } |
| | | } |
| | | clientCourseVO.setList(page); |
| | | clientCourseVO.setIsBuy(2); |
| | | |
| | | // 查询推荐课程 |
| | | List<Course> list = courseService.lambdaQuery().eq(Course::getCateId, byId.getCateId()) |
| | | .eq(Course::getCourseType,1) |
| | | .eq(Course::getListingStatus,1) |
| | | .ne(Course::getId,id) |
| | | .eq(Course::getRecommend, 1).list(); |
| | | List<Course> courses = new ArrayList<>(); |
| | | // 随机获取两个课程 |
| | |
| | | int index = (int) (Math.random() * size); |
| | | if (size >= 2){ |
| | | for (int i = 0; i < 2; i++) { |
| | | courses.add(list.get(index)); |
| | | courses.add(list.get(i)); |
| | | } |
| | | }else{ |
| | | courses.add(list.get(index)); |
| | | courses.addAll(list); |
| | | } |
| | | } |
| | | for (Course cours : courses) { |
| | | List<AppUser> data3 = remoteAppUserService.getUserByCourseId(id).getData(); |
| | | cours.setCount(data3.size()); |
| | | } |
| | | clientCourseVO.setList2(courses); |
| | | |
| | | clientCourseVO.setList2(courses); |
| | | if (byId.getChargeType() == 1){ |
| | | byId.setGeneralPrice(new BigDecimal("0")); |
| | | } |
| | | return R.ok(clientCourseVO); |
| | | } |
| | | /** |
| | |
| | | // 查询推荐课程 |
| | | List<Course> list = courseService.lambdaQuery().eq(Course::getCateId, byId.getCateId()) |
| | | .eq(Course::getCourseType,1) |
| | | .eq(Course::getListingStatus,1) |
| | | .ne(Course::getId,id) |
| | | .eq(Course::getRecommend, 1).list(); |
| | | List<Course> courses = new ArrayList<>(); |
| | | // 随机获取两个课程 |
| | |
| | | cours.setCount(data1.size()); |
| | | } |
| | | clientCourseVO.setList2(courses); |
| | | if (byId.getChargeType() == 1){ |
| | | byId.setGeneralPrice(new BigDecimal("0")); |
| | | } |
| | | return R.ok(clientCourseVO); |
| | | } |
| | | |
| | |
| | | Course byId = courseService.getById(courseId); |
| | | AppUser data = remoteAppUserService.getAppUserById(userId + "").getData(); |
| | | byId.setBalance(data.getBalance()); |
| | | System.err.println("课程类型"+byId.getChargeType()); |
| | | if (byId.getChargeType() == 1){ |
| | | byId.setGeneralPrice(new BigDecimal("0")); |
| | | } |
| | | System.err.println("返回数据"+byId); |
| | | return R.ok(byId); |
| | | } |
| | | @PostMapping("/successOrder") |
| | |
| | | Long userId = loginUser.getUserid(); |
| | | Course byId = courseService.getById(courseId); |
| | | List<Course> list = courseService.lambdaQuery().eq(Course::getCateId, byId.getCateId()) |
| | | .eq(Course::getListingStatus,1) |
| | | .ne(Course::getId,courseId) |
| | | .eq(Course::getCourseType, 1).list(); |
| | | for (Course course : list) { |
| | |
| | | course.setRealLearnedNum(a+b); |
| | | course.setVirtualLearnedNum(0); |
| | | BeanUtils.copyProperties(course, courseVO); |
| | | courseVOS.add(courseVO); |
| | | List<Long> collect = courseVOS.stream().map(CourseVO::getId).collect(Collectors.toList()); |
| | | if (!collect.contains(courseVO.getId())){ |
| | | courseVOS.add(courseVO); |
| | | } |
| | | } |
| | | } |
| | | List<Long> data1 = remoteAppUserService.getCourseHistoryByUserId(userId).getData(); |
| | | for (Long l : data1) { |
| | | CourseChapter byId1 = courseChapterService.getById(l); |
| | | Course byId = courseService.getById(byId1.getCourseId()); |
| | | if (byId!=null){ |
| | | CourseVO courseVO = new CourseVO(); |
| | | BeanUtils.copyProperties(byId, courseVO); |
| | | List<CourseChapter> list1 = courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId, byId1.getCourseId()).list(); |
| | | int a = 0; |
| | | int b = 0; |
| | | for (CourseChapter courseChapter : list1) { |
| | | a+= courseChapter.getVirtualLearnedNum(); |
| | | Long data2 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | b+=data2; |
| | | } |
| | | courseVO.setCount(a+b); |
| | | courseVO.setRealLearnedNum(a+b); |
| | | courseVO.setVirtualLearnedNum(0); |
| | | courseVO.setId(byId.getId()); |
| | | courseVO.setCoverUrl(byId.getCoverUrl()); |
| | | List<Long> collect = courseVOS.stream().map(CourseVO::getId).collect(Collectors.toList()); |
| | | if (!collect.contains(courseVO.getId())){ |
| | | courseVOS.add(courseVO); |
| | | } |
| | | } |
| | | } |
| | | // 查询两个相同类型的线上免费课程 |
| | |
| | | .eq(Course::getChargeType, 1) |
| | | .list(); |
| | | // 远程查询用户观看历史 |
| | | List<Long> data1 = remoteAppUserService.getCourseHistoryByUserId(userId).getData(); |
| | | if (!data1.isEmpty()){ |
| | | // 随机获取两个 |
| | | if (CollUtils.isNotEmpty(freeCourseList) && freeCourseList.size() > 2) { |
| | | int size = freeCourseList.size(); |
| | | int index = (int) (Math.random() * size); |
| | | List<Course> courses = new ArrayList<>(); |
| | | for (Course cours : freeCourseList) { |
| | | List<CourseChapter> list1 = courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId, cours.getId()).list(); |
| | |
| | | cours.setVirtualLearnedNum(0); |
| | | } |
| | | for (int i = 0; i < 2; i++) { |
| | | courses.add(freeCourseList.get(index)); |
| | | courses.add(freeCourseList.get(i)); |
| | | } |
| | | studyPageVO.setFreeCourseList(courses); |
| | | }else{ |
| | |
| | | for (Long l : data1) { |
| | | CourseChapter byId1 = courseChapterService.getById(l); |
| | | Course byId = courseService.getById(byId1.getCourseId()); |
| | | CourseVO courseVO = new CourseVO(); |
| | | BeanUtils.copyProperties(byId, courseVO); |
| | | List<CourseChapter> list1 = courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId, byId1.getCourseId()).list(); |
| | | int a = 0; |
| | | int b = 0; |
| | | for (CourseChapter courseChapter : list1) { |
| | | a+= courseChapter.getVirtualLearnedNum(); |
| | | Long data2 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | b+=data2; |
| | | if (byId!=null){ |
| | | CourseVO courseVO = new CourseVO(); |
| | | BeanUtils.copyProperties(byId, courseVO); |
| | | List<CourseChapter> list1 = courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId, byId1.getCourseId()).list(); |
| | | int a = 0; |
| | | int b = 0; |
| | | for (CourseChapter courseChapter : list1) { |
| | | a+= courseChapter.getVirtualLearnedNum(); |
| | | Long data2 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | b+=data2; |
| | | } |
| | | courseVO.setCount(a+b); |
| | | courseVO.setRealLearnedNum(a+b); |
| | | courseVO.setVirtualLearnedNum(0); |
| | | courseVO.setId(byId.getId()); |
| | | courseVO.setCoverUrl(byId.getCoverUrl()); |
| | | List<Long> collect = courseVOS.stream().map(CourseVO::getId).collect(Collectors.toList()); |
| | | if (!collect.contains(courseVO.getId())){ |
| | | courseVOS.add(courseVO); |
| | | } |
| | | } |
| | | courseVO.setCount(a+b); |
| | | courseVO.setRealLearnedNum(a+b); |
| | | courseVO.setVirtualLearnedNum(0); |
| | | courseVOS.add(courseVO); |
| | | } |
| | | studyPageVO.setCourseList(courseVOS); |
| | | return R.ok(studyPageVO); |
| | |
| | | List<Course> courses = new ArrayList<>(); |
| | | courses.add(list1.get(0)); |
| | | courses.add(list1.get(1)); |
| | | for (Course cours : courses) { |
| | | List<CourseChapter> list3 = courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId, cours.getId()).list(); |
| | | int a = 0; |
| | | int b = 0; |
| | | for (CourseChapter courseChapter : list3) { |
| | | a+= courseChapter.getVirtualLearnedNum(); |
| | | Long data2 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | b+=data2; |
| | | } |
| | | cours.setCount(a+b); |
| | | cours.setRealLearnedNum(a+b); |
| | | } |
| | | studyPageVO.setFreeCourseList(courses); |
| | | }else if (list1.size()==1){ |
| | | List<Course> courses = new ArrayList<>(); |
| | |
| | | break; |
| | | } |
| | | } |
| | | for (Course cours : courses) { |
| | | List<CourseChapter> list3 = courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId, cours.getId()).list(); |
| | | int a = 0; |
| | | int b = 0; |
| | | for (CourseChapter courseChapter : list3) { |
| | | a+= courseChapter.getVirtualLearnedNum(); |
| | | Long data2 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); |
| | | b+=data2; |
| | | } |
| | | cours.setCount(a+b); |
| | | cours.setRealLearnedNum(a+b); |
| | | } |
| | | studyPageVO.setFreeCourseList(courses); |
| | | } |
| | | studyPageVO.setCourseList(courseVOS); |
| | | |
| | | return R.ok(studyPageVO); |
| | | } |
| | | |