package com.xinquan.course.controller.client;
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
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.extension.plugins.pagination.Page;
|
import com.xinquan.common.core.constant.SecurityConstants;
|
import com.xinquan.common.core.domain.R;
|
import com.xinquan.common.core.utils.WebUtils;
|
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.core.web.domain.BaseModel;
|
import com.xinquan.common.security.service.TokenService;
|
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.api.domain.CourseChapter;
|
import com.xinquan.course.domain.CourseLearningRecord;
|
import com.xinquan.course.domain.CourseUserFavorite;
|
import com.xinquan.course.domain.export.CourseExport;
|
import com.xinquan.course.domain.export.CourseOffExport;
|
import com.xinquan.course.domain.vo.ClientCourseCategoryVO;
|
import com.xinquan.course.domain.vo.ClientCourseVO;
|
import com.xinquan.course.service.*;
|
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.system.api.model.LoginUser;
|
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.io.IOException;
|
import java.net.URLEncoder;
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
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.apache.poi.ss.usermodel.Workbook;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.ServletOutputStream;
|
import javax.servlet.http.HttpServletResponse;
|
|
/**
|
* <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;
|
@Resource
|
private CourseLearningRecordService courseLearningRecordService;
|
|
@GetMapping("/getCourseCount")
|
public R<String> getCourseCount() {
|
StringBuilder stringBuilder = new StringBuilder();
|
List<Course> list = courseService.lambdaQuery().eq(BaseModel::getDelFlag, 0)
|
.eq(Course::getCourseType,1).list();
|
List<Course> list1 = courseService.lambdaQuery().eq(BaseModel::getDelFlag, 0)
|
.eq(Course::getCourseType, 2).list();
|
stringBuilder.append(list.size()+list1.size()).append(",");
|
List<Course> collect1 = list.stream().filter(t -> t.getChargeType() == 1).collect(Collectors.toList());
|
List<Course> collect2 = list.stream().filter(t -> t.getChargeType() == 2).collect(Collectors.toList());
|
List<Course> collect3 = list.stream().filter(t -> t.getChargeType() == 3).collect(Collectors.toList());
|
stringBuilder.append(collect1.size()).append(",");
|
stringBuilder.append(collect2.size()).append(",");
|
stringBuilder.append(collect3.size()).append(",");
|
stringBuilder.append(list1.size());
|
return R.ok(stringBuilder.toString());
|
}
|
/**
|
* 根据课程id 查询学习人数
|
* @param id
|
* @return
|
*/
|
@GetMapping("/getCountByCourseId/{id}")
|
public R<Integer> getCountByCourseId(
|
@PathVariable("id")String id)
|
{
|
int size = courseLearningRecordService.lambdaQuery().eq(CourseLearningRecord::getCourseId, id)
|
.groupBy(CourseLearningRecord::getAppUserId).list().size();
|
|
return R.ok(size);
|
}
|
/**
|
* 根据课程id 查询章节列表
|
* @param id
|
* @return
|
*/
|
@GetMapping("/getChapterByCourseId/{id}")
|
public R<List<CourseChapter>> getChapterByCourseId(
|
@PathVariable("id")String id)
|
{
|
return R.ok(courseChapterService.lambdaQuery().eq(CourseChapter::getCourseId,id).list());
|
}
|
|
|
|
|
@GetMapping("/getCourseByIds/{pageCurr}/{pageSize}/{ids}")
|
public R<Page<Course>> getCourseByIds(@PathVariable("pageCurr") Integer pageCurr,
|
@PathVariable("pageSize") Integer pageSize,
|
@PathVariable("ids")String ids)
|
{
|
List<Long> collect = courseChapterService.lambdaQuery().in(CourseChapter::getId, Arrays.asList(ids.split(",")))
|
.list().stream().map(CourseChapter::getCourseId).collect(Collectors.toList());
|
if(collect.isEmpty()){
|
collect.add(-1L);
|
}
|
Page<Course> page = courseService
|
.lambdaQuery()
|
.in(Course::getId,collect)
|
.page(new Page<>(pageCurr, pageSize));
|
|
if (page.getRecords().isEmpty()){
|
return R.ok(page);
|
}
|
// 查询人数
|
return R.ok(page);
|
}
|
|
/**
|
* 远程调用 通过课程名字查询课程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);
|
}
|
|
@ApiOperation(value = "课程管理列表导出", tags = {"管理后台-课程管理"})
|
@PutMapping("/export")
|
public void export(@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.getIds())){
|
courseLambdaQueryWrapper.in(Course::getId, Arrays.asList(courseDTO.getIds().split(",")));
|
}
|
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);
|
}
|
List<Course> page = courseService.list(courseLambdaQueryWrapper);
|
List<CourseExport> courseExports = new ArrayList<>();
|
List<CourseOffExport> courseOffExports = new ArrayList<>();
|
for (Course record : page) {
|
CourseExport courseExport = new CourseExport();
|
CourseOffExport courseOffExport = new CourseOffExport();
|
CourseCategory byId = courseCategoryService.getById(record.getCateId());
|
if (Objects.nonNull(byId)){
|
record.setCategoryName(byId.getName());
|
courseExport.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);
|
int size1 = courseLearningRecordService.lambdaQuery().eq(CourseLearningRecord::getCourseId, record.getId())
|
.groupBy(CourseLearningRecord::getAppUserId).list().size();
|
// 查询学习人数
|
// int size = remoteAppUserService.getUserByCourseId(record.getId()).getData().size();
|
record.setCount(size1);
|
courseExport.setName(record.getCourseTitle());
|
courseExport.setTutor(record.getTutor());
|
if (record.getCourseType()==1){
|
switch (record.getChargeType()){
|
case 1:
|
courseExport.setGeneralPrice("免费");
|
break;
|
case 2:
|
courseExport.setGeneralPrice("会员免费");
|
break;
|
case 3:
|
courseExport.setGeneralPrice("¥"+record.getGeneralPrice());
|
break;
|
}
|
}
|
|
courseExport.setCourseChapterCount(count+"");
|
courseExport.setListingStatus(record.getListingStatus()+"");
|
courseExport.setRealLearnedNum(size1+"");
|
courseExport.setCollectCount(count1+"");
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
String format = df.format(record.getCreateTime());
|
courseExport.setCreateTime(format);
|
courseExports.add(courseExport);
|
// 线下
|
courseOffExport.setName(record.getCourseTitle());
|
courseOffExport.setTutor(record.getTutor());
|
courseOffExport.setAddress(record.getAddress()+record.getAddressDetail());
|
courseOffExport.setListingStatus(record.getListingStatus()+"");
|
courseOffExport.setCollectCount(count1+"");
|
courseOffExport.setCreateTime(format);
|
courseOffExports.add(courseOffExport);
|
}
|
if (courseDTO.getCourseType()==1){
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), CourseExport.class, courseExports);
|
HttpServletResponse response = WebUtils.response();
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("utf-8");
|
ServletOutputStream outputStream = null;
|
try {
|
String fileName = URLEncoder.encode("线上课程导出.xls", "utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
response.setHeader("Pragma", "no-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
outputStream = response.getOutputStream();
|
workbook.write(outputStream);
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
outputStream.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}else{
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), CourseOffExport.class, courseOffExports);
|
HttpServletResponse response = WebUtils.response();
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("utf-8");
|
ServletOutputStream outputStream = null;
|
try {
|
String fileName = URLEncoder.encode("线下课程导出.xls", "utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
response.setHeader("Pragma", "no-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
outputStream = response.getOutputStream();
|
workbook.write(outputStream);
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
outputStream.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
@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);
|
// 查询学习人数
|
// 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;
|
for (CourseChapter courseChapter : list) {
|
temp+=courseChapter.getVirtualLearnedNum();
|
}
|
record.setCount(size1+temp);
|
}
|
return R.ok(PageDTO.of(page, Course.class));
|
}
|
@PostMapping("/addCourse")
|
@ApiOperation(value = "新增课程管理", tags = "管理后台-课程管理")
|
public R addCourse(@RequestBody Course homeBackgroundMusic) {
|
homeBackgroundMusic.setCreateBy(SecurityUtils.getUsername());
|
homeBackgroundMusic.setCreateTime(LocalDateTime.now());
|
return R.ok(courseService.save(homeBackgroundMusic));
|
}
|
@GetMapping("/detailCourse")
|
@ApiOperation(value = "查看详情课程管理", tags = "管理后台-课程管理")
|
public R<Course> detailCourse(String uid) {
|
Course byId = courseService.getById(uid);
|
CourseCategory byId1 = courseCategoryService.getById(byId.getCateId());
|
if (byId1!=null){
|
byId.setCategoryName(byId1.getName());
|
}
|
List<CourseChapter> list = courseChapterService.lambdaQuery()
|
.eq(CourseChapter::getCourseId, uid).list();
|
int temp = 0;
|
int temp1 = 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;
|
}
|
int size1 = courseLearningRecordService.lambdaQuery()
|
.eq(CourseLearningRecord::getCourseId, uid).groupBy(CourseLearningRecord::getAppUserId)
|
.list().size();
|
byId.setVirtualLearnedNum(temp);
|
byId.setRealLearnedNum(size1);
|
byId.setCount(temp+size1);
|
byId.setList(list);
|
int size = courseUserFavoriteService.lambdaQuery()
|
.eq(CourseUserFavorite::getCourseId, uid).list().size();
|
byId.setCollectCount((long) size);
|
return R.ok(byId);
|
}
|
@GetMapping("/updateState")
|
@ApiOperation(value = "修改课程上下架状态", tags = "管理后台-课程管理")
|
public R updateState(String uid) {
|
Course byId = courseService.getById(uid);
|
if (byId.getListingStatus() == 1){
|
byId.setListingStatus(2);
|
}else {
|
byId.setListingStatus(1);
|
}
|
courseService.updateById(byId);
|
return R.ok();
|
}
|
@PostMapping("/updateCourse")
|
@ApiOperation(value = "修改课程管理", tags = "管理后台-课程管理")
|
public R updateCourse(@RequestBody Course homeBackgroundMusic) {
|
homeBackgroundMusic.setUpdateBy(SecurityUtils.getUsername());
|
homeBackgroundMusic.setUpdateTime(LocalDateTime.now());
|
return R.ok(courseService.updateById(homeBackgroundMusic));
|
}
|
@PostMapping("/deleteCourse")
|
@ApiOperation(value = "批量删除", tags = "管理后台-课程管理")
|
public R deleteCourse(String ids) {
|
return R.ok(courseService.removeBatchByIds(Arrays.asList(ids.split(",")).stream().map(Long::valueOf).collect(Collectors.toList())));
|
}
|
|
|
|
@GetMapping("/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));
|
}
|
@Autowired
|
private TokenService tokenService;
|
@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<List<OrderCourseVO>> myCollect(@RequestParam(value = "state")Integer state,
|
@RequestParam(value = "pageCurr")Integer pageCurr,
|
@RequestParam(value = "pageSize")Integer pageSize) {
|
LoginUser loginUser = tokenService.getLoginUser();
|
if (loginUser==null){
|
return R.tokenError("登录失效");
|
}
|
Long userId = loginUser.getUserid();
|
List<OrderCourseVO> orderCourseVOS = new ArrayList<>();
|
|
switch (state){
|
case 1:
|
Page<Meditation> data = remoteMeditationService.getMeditationById(pageCurr, pageSize,userId)
|
.getData();
|
for (Meditation meditation : data.getRecords()) {
|
OrderCourseVO orderCourseVO = new OrderCourseVO();
|
orderCourseVO.setBusinessId(meditation.getId());
|
orderCourseVO.setCourseTitle(meditation.getMeditationTitle());
|
orderCourseVO.setDescription(meditation.getDetailDescription());
|
orderCourseVO.setChargeType(meditation.getChargeType());
|
orderCourseVO.setGeneralPrice(meditation.getGeneralPrice());
|
orderCourseVO.setIosPrice(meditation.getIosPrice());
|
orderCourseVO.setCoverUrl(meditation.getCoverUrl());
|
orderCourseVO.setCount(meditation.getRealLearnedNum()+meditation.getVirtualLearnedNum());
|
orderCourseVOS.add(orderCourseVO);
|
}
|
break;
|
case 2:
|
List<Long> collect = courseUserFavoriteService.lambdaQuery()
|
.eq(CourseUserFavorite::getAppUserId, userId).list().stream()
|
.map(CourseUserFavorite::getCourseId).collect(Collectors.toList());
|
if(collect.isEmpty())collect.add(-1L);
|
Page<Course> page = courseService
|
.lambdaQuery()
|
.in(Course::getId, collect)
|
.page(new Page<>(pageCurr, pageSize));
|
for (Course record : page.getRecords()) {
|
OrderCourseVO orderCourseVO = new OrderCourseVO();
|
orderCourseVO.setBusinessId(record.getId());
|
orderCourseVO.setCourseTitle(record.getCourseTitle());
|
orderCourseVO.setDescription(record.getDescription());
|
orderCourseVO.setChargeType(record.getChargeType());
|
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 ;
|
for (CourseChapter courseChapter : list) {
|
temp+= courseChapter.getVirtualLearnedNum();
|
}
|
int size = courseLearningRecordService.lambdaQuery().eq(CourseLearningRecord::getCourseId, record.getId())
|
.groupBy(CourseLearningRecord::getAppUserId).list().size();
|
orderCourseVO.setCount(temp+size);
|
orderCourseVOS.add(orderCourseVO);
|
}
|
break;
|
}
|
return R.ok(orderCourseVOS);
|
}
|
@PostMapping("/collectCourse")
|
@ApiOperation(value = "收藏/取消课程")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "课程id", name = "id", required = true, dataType = "Long"),
|
})
|
public R collectCourse(@RequestParam(value = "id")Long id) {
|
LoginUser loginUser = tokenService.getLoginUser();
|
if (loginUser==null){
|
return R.tokenError("登录失效");
|
}
|
Long userId = loginUser.getUserid();
|
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("/getCourseByIdAny")
|
public R<OrderCourseVO> getCourseByIdAny(@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) {
|
|
Course byId = courseService.getById(id);
|
ClientCourseVO clientCourseVO = new ClientCourseVO();
|
BeanUtils.copyProperties(byId, clientCourseVO);
|
List<AppUser> data = remoteAppUserService.getUserByCourseId(id).getData();
|
if (byId.getChargeType()==1 && tokenService.getLoginUser()==null){
|
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()));
|
}
|
}
|
}else{
|
LoginUser loginUser = tokenService.getLoginUser();
|
if (loginUser==null){
|
return R.tokenError("登录失效");
|
}
|
Long userId = loginUser.getUserid();
|
AppUser data1 = remoteAppUserService.getAppUserById(userId + "").getData();
|
if (data1.getVipExpireTime()!=null && data1.getVipExpireTime().isAfter(LocalDateTime.now())){
|
clientCourseVO.setIsVip(1);
|
}else{
|
clientCourseVO.setIsVip(0);
|
}
|
// 查询学习人数和头像列表
|
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::getId).collect(Collectors.toList());
|
if (!collect.isEmpty()){
|
if (collect.contains(userId)){
|
clientCourseVO.setIsBuy(1);
|
}
|
}
|
}
|
// 查询是否已收藏课程
|
clientCourseVO.setIsCollect(courseUserFavoriteService.lambdaQuery()
|
.eq(CourseUserFavorite::getAppUserId, userId)
|
.eq(CourseUserFavorite::getCourseId, id).one() == null ? 2 : 1);
|
}
|
|
|
// 查询用户是否已购买该课程
|
// 查询章节
|
List<CourseChapter> page = courseChapterService.lambdaQuery()
|
.eq(CourseChapter::getCourseId, id)
|
.orderByDesc(CourseChapter::getSortNum)
|
.list();
|
for (CourseChapter courseChapter : page) {
|
int size = courseLearningRecordService.lambdaQuery()
|
.eq(CourseLearningRecord::getChapterId, courseChapter.getId())
|
.list().size();
|
courseChapter.setRealLearnedNum(size+courseChapter.getVirtualLearnedNum());
|
}
|
clientCourseVO.setList(page);
|
clientCourseVO.setIsBuy(0);
|
|
|
// 查询推荐课程
|
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));
|
}
|
}
|
for (Course cours : courses) {
|
List<AppUser> data3 = remoteAppUserService.getUserByCourseId(id).getData();
|
cours.setCount(data3.size());
|
}
|
clientCourseVO.setList2(courses);
|
|
return R.ok(clientCourseVO);
|
}
|
/**
|
* 课程详情
|
*
|
* @return 课程详情
|
*/
|
@PostMapping("/getPayCourseInfoByIdShare")
|
@ApiOperation(value = "根据id获取课程详情",tags = "分享H5")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "课程id", name = "id", required = true, dataType = "String"),
|
})
|
public R<ClientCourseVO> getPayCourseInfoByIdShare(@RequestParam(value = "id")Long id) {
|
|
Course byId = courseService.getById(id);
|
ClientCourseVO clientCourseVO = new ClientCourseVO();
|
BeanUtils.copyProperties(byId, clientCourseVO);
|
// 查询章节
|
List<CourseChapter> page = courseChapterService.lambdaQuery()
|
.eq(CourseChapter::getCourseId, id)
|
.orderByDesc(CourseChapter::getSortNum)
|
.list();
|
for (CourseChapter courseChapter : page) {
|
int size = courseLearningRecordService.lambdaQuery()
|
.eq(CourseLearningRecord::getChapterId, courseChapter.getId())
|
.list().size();
|
courseChapter.setRealLearnedNum(size+courseChapter.getVirtualLearnedNum());
|
}
|
clientCourseVO.setList(page);
|
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());
|
}
|
// 查询推荐课程
|
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));
|
}
|
}
|
for (Course cours : courses) {
|
List<AppUser> data1 = remoteAppUserService.getUserByCourseId(id).getData();
|
cours.setCount(data1.size());
|
}
|
clientCourseVO.setList2(courses);
|
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) {
|
PageDTO<ClientCourseVO> coursePageList = courseService.getCoursePageList(courseTitle, cateId, pageCurr, pageSize);
|
|
for (ClientCourseVO record : coursePageList.getList()) {
|
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;
|
for (CourseChapter courseChapter : list) {
|
temp+=courseChapter.getVirtualLearnedNum();
|
}
|
record.setCount(size1+temp);
|
}
|
return R.ok(coursePageList);
|
}
|
@PostMapping("/studyPageByChapterId")
|
@ApiOperation(value = "课程学习页面")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "章节id", name = "chapterId", required = true, dataType = "Long"),
|
})
|
public R<List<CourseChapter>> studyPageByChapterId(@RequestParam(value = "chapterId")Long chapterId) {
|
|
CourseChapter byId1 = courseChapterService.getById(chapterId);
|
Course byId = courseService.getById(byId1.getCourseId());
|
Long id = byId1.getCourseId();
|
// 查询章节
|
List<CourseChapter> page = courseChapterService.lambdaQuery()
|
.eq(CourseChapter::getCourseId, id)
|
.orderByDesc(CourseChapter::getSortNum)
|
.list();
|
|
for (CourseChapter courseChapter : page) {
|
AppUserViewingHistory data = remoteAppUserService.getCourseStudyHistory(courseChapter.getId()).getData();
|
if (data!=null){
|
courseChapter.setMinuteLook(data.getMinuteLook());
|
courseChapter.setSecondLook(data.getSecondLook());
|
courseChapter.setIsOver(data.getIsOver());
|
}
|
int size = courseLearningRecordService
|
.lambdaQuery().eq(CourseLearningRecord::getChapterId, courseChapter.getId())
|
.list().size();
|
courseChapter.setRealLearnedNum(size+courseChapter.getVirtualLearnedNum());
|
}
|
if (byId.getChargeType() == 1&&tokenService.getLoginUser()==null){
|
return R.ok(page);
|
}else{
|
LoginUser loginUser = tokenService.getLoginUser();
|
if (loginUser==null){
|
return R.tokenError("登录失效");
|
}
|
Long userid = loginUser.getUserid();
|
// 新增学习记录
|
CourseLearningRecord one = courseLearningRecordService.lambdaQuery().eq(CourseLearningRecord::getAppUserId, userid)
|
.eq(CourseLearningRecord::getChapterId, chapterId).one();
|
if (one==null){
|
CourseLearningRecord courseLearningRecord = new CourseLearningRecord();
|
courseLearningRecord.setAppUserId(userid);
|
if (byId!=null){
|
courseLearningRecord.setCourseId(byId.getId());
|
}
|
courseLearningRecord.setChapterId(chapterId);
|
courseLearningRecordService.save(courseLearningRecord);
|
}
|
|
return R.ok(page);
|
|
}
|
|
}
|
@PostMapping("/confirmOrder")
|
@ApiOperation(value = "确认订单页面")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "课程id", name = "courseId", required = true, dataType = "Long")
|
})
|
public R<Course> confirmOrder(@RequestParam(value = "courseId")Long courseId) {
|
LoginUser loginUser = tokenService.getLoginUser();
|
if (loginUser==null){
|
return R.tokenError("登录失效");
|
}
|
Long userId = loginUser.getUserid();
|
|
Course byId = courseService.getById(courseId);
|
AppUser data = remoteAppUserService.getAppUserById(userId + "").getData();
|
byId.setBalance(data.getBalance());
|
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) {
|
LoginUser loginUser = tokenService.getLoginUser();
|
if (loginUser==null){
|
return R.tokenError("登录失效");
|
}
|
Long userId = loginUser.getUserid();
|
Course byId = courseService.getById(courseId);
|
List<Course> list = courseService.lambdaQuery().eq(Course::getCateId, byId.getCateId())
|
.ne(Course::getId,courseId)
|
.eq(Course::getCourseType, 1).list();
|
for (Course course : list) {
|
List<AppUser> data = remoteAppUserService.getUserByCourseId(courseId).getData();
|
course.setCount(data.size()+course.getVirtualLearnedNum());
|
course.setRealLearnedNum(data.size()+course.getVirtualLearnedNum());
|
}
|
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() {
|
LoginUser loginUser = tokenService.getLoginUser();
|
if (loginUser==null){
|
return R.tokenError("登录失效");
|
}
|
Long userId = loginUser.getUserid();
|
if(userId ==null || userId == 0)return R.tokenError("登录失效");
|
StudyPageVO studyPageVO = new StudyPageVO();
|
List<CourseVO> courseVOS = new ArrayList<>();
|
|
PageDTO<AppUserCourse> data = remoteAppUserService.getPayCourse(1, 909999,userId+"").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();
|
// 远程查询用户观看历史
|
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 (int i = 0; i < 2; i++) {
|
courses.add(freeCourseList.get(index));
|
}
|
studyPageVO.setFreeCourseList(courses);
|
}else{
|
studyPageVO.setFreeCourseList(freeCourseList);
|
}
|
return R.ok(studyPageVO);
|
}else{
|
List<Course> list1 = courseService.lambdaQuery()
|
.eq(Course::getChargeType, 1)
|
.eq(Course::getListingStatus, 1)
|
.list();
|
if (list1.size()>=2){
|
List<Course> courses = new ArrayList<>();
|
courses.add(list1.get(0));
|
courses.add(list1.get(1));
|
studyPageVO.setFreeCourseList(courses);
|
}else if (list1.size()==1){
|
List<Course> courses = new ArrayList<>();
|
courses.add(list1.get(0));
|
for (Course course : freeCourseList) {
|
if (!course.getId().equals(list1.get(0).getId())){
|
courses.add(course);
|
break;
|
}
|
}
|
studyPageVO.setFreeCourseList(courses);
|
}
|
return R.ok(studyPageVO);
|
}
|
|
}
|
}
|