parent
806e7b365f
commit
870338437e
16 changed files with 491 additions and 368 deletions
@ -1,114 +1,96 @@ |
||||
//package com.teaching.backend.controller.favour;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import com.teaching.backend.common.BaseResponse;
|
||||
//import com.teaching.backend.common.ErrorCode;
|
||||
//import com.teaching.backend.common.ResultUtils;
|
||||
//import com.teaching.backend.exception.BusinessException;
|
||||
//import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAddRequest;
|
||||
//import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAllRequest;
|
||||
//import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourQueryRequest;
|
||||
//import com.teaching.backend.model.entity.courses.Courses;
|
||||
//import com.teaching.backend.model.vo.favour.CourseFavourDetailVO;
|
||||
//import com.teaching.backend.service.favour.SeCourseFavourService;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestBody;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * @Author:youhang
|
||||
// * @Date:2024-05-30-20:22
|
||||
// * @Description:
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("/api/course_favour")
|
||||
//@Slf4j
|
||||
//public class SeCourseFavourController {
|
||||
//
|
||||
// @Resource
|
||||
// private SeCourseFavourService seCourseFavourService;
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 收藏/取消收藏
|
||||
// *
|
||||
// * @param courseFavourAddRequest
|
||||
// * @return result 执行情况
|
||||
// */
|
||||
// @PostMapping("/add")
|
||||
// // 加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
|
||||
// public BaseResponse<Boolean> doFavour(@RequestBody CourseFavourAddRequest courseFavourAddRequest) {
|
||||
// System.out.println(courseFavourAddRequest);
|
||||
// //判断字段是否为空
|
||||
// if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId())) {
|
||||
// throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
// }
|
||||
//
|
||||
// return seCourseFavourService.doCourseFavour(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId());
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 课程点赞总数
|
||||
// *
|
||||
// * @param courseFavourAddRequest
|
||||
// * @return result 课程点赞总数
|
||||
// */
|
||||
// @PostMapping("/count")
|
||||
// // HttpServletRequest request 在一个fitter里面进行鉴权操作
|
||||
// public BaseResponse<Long> favourCount(@RequestBody CourseFavourAddRequest courseFavourAddRequest) {
|
||||
// if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId())) {
|
||||
// throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空");
|
||||
// }
|
||||
// return seCourseFavourService.favourCount(courseFavourAddRequest.getCourseId());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 课程下资源和知识点点赞总数
|
||||
// *
|
||||
// * @param courseFavourAllRequest
|
||||
// * @return result 课程下资源和知识点点赞总数
|
||||
// */
|
||||
// @PostMapping("/countAll")
|
||||
// // todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
|
||||
// public BaseResponse<Long> courseCount(@RequestBody CourseFavourAllRequest courseFavourAllRequest) {
|
||||
// if (StringUtils.isAnyBlank(courseFavourAllRequest.getCourseId())) {
|
||||
// throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空");
|
||||
// }
|
||||
// // todo 从数据库中校验是否存在courseid
|
||||
//
|
||||
// return seCourseFavourService.courseCount(courseFavourAllRequest.getCourseId());
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 分页获取课程列表
|
||||
// *
|
||||
// * @return
|
||||
// */
|
||||
// @PostMapping("/list/page")
|
||||
// public BaseResponse<Page<CourseFavourDetailVO>> listPostByPage(@RequestBody CourseFavourQueryRequest courseFavourQueryRequest) {
|
||||
// System.out.println(courseFavourQueryRequest);
|
||||
// long current = courseFavourQueryRequest.getCurrent();
|
||||
// long size = courseFavourQueryRequest.getPageSize();
|
||||
// String userId = courseFavourQueryRequest.getUserId();
|
||||
// List<String> ids = seCourseFavourService.courseList(userId);
|
||||
// QueryWrapper<Courses> courseQueryWrapper = new QueryWrapper<>();
|
||||
// courseQueryWrapper.in("id", ids);
|
||||
// Page<CourseFavourDetailVO> courseFavourDetailVOPage = seCourseFavourService.listCourseFavourByPage(new Page<>(current, size), courseQueryWrapper);
|
||||
//
|
||||
// return ResultUtils.success(courseFavourDetailVOPage);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
package com.teaching.backend.controller.favour; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.common.ErrorCode; |
||||
import com.teaching.backend.common.ResultUtils; |
||||
import com.teaching.backend.exception.BusinessException; |
||||
import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAddRequest; |
||||
import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAllRequest; |
||||
import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourQueryRequest; |
||||
import com.teaching.backend.model.entity.courses.Courses; |
||||
import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; |
||||
import com.teaching.backend.service.favour.SeCourseFavourService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author:youhang |
||||
* @Date:2024-05-30-20:22 |
||||
* @Description: |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/api/course_favour") |
||||
@Slf4j |
||||
public class SeCourseFavourController { |
||||
|
||||
@Resource |
||||
private SeCourseFavourService seCourseFavourService; |
||||
|
||||
|
||||
|
||||
/** |
||||
* 收藏/取消收藏 |
||||
* |
||||
* @param courseFavourAddRequest |
||||
* @return result 执行情况 |
||||
*/ |
||||
@PostMapping("/add") |
||||
// 加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
|
||||
public BaseResponse<Boolean> doFavour(@RequestBody CourseFavourAddRequest courseFavourAddRequest) { |
||||
System.out.println(courseFavourAddRequest); |
||||
//判断字段是否为空
|
||||
if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId())) { |
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR); |
||||
} |
||||
|
||||
return seCourseFavourService.doCourseFavour(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId()); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* 课程点赞总数 |
||||
* |
||||
* @param courseFavourAddRequest |
||||
* @return result 课程点赞总数 |
||||
*/ |
||||
@PostMapping("/count") |
||||
// HttpServletRequest request 在一个fitter里面进行鉴权操作
|
||||
public BaseResponse<Long> favourCount(@RequestBody CourseFavourAddRequest courseFavourAddRequest) { |
||||
if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId())) { |
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空"); |
||||
} |
||||
return seCourseFavourService.favourCount(courseFavourAddRequest.getCourseId()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 分页获取课程列表 |
||||
* |
||||
* @return |
||||
*/ |
||||
@PostMapping("/list/page") |
||||
public BaseResponse<Page<CourseFavourDetailVO>> listPostByPage(@RequestBody CourseFavourQueryRequest courseFavourQueryRequest) { |
||||
System.out.println(courseFavourQueryRequest); |
||||
long current = courseFavourQueryRequest.getCurrent(); |
||||
long size = courseFavourQueryRequest.getPageSize(); |
||||
String userId = courseFavourQueryRequest.getUserId(); |
||||
List<String> ids = seCourseFavourService.courseList(userId); |
||||
QueryWrapper<Courses> courseQueryWrapper = new QueryWrapper<>(); |
||||
courseQueryWrapper.in("id", ids); |
||||
Page<CourseFavourDetailVO> courseFavourDetailVOPage = seCourseFavourService.listCourseFavourByPage(new Page<>(current, size), courseQueryWrapper); |
||||
|
||||
return ResultUtils.success(courseFavourDetailVOPage); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
@ -1,165 +1,149 @@ |
||||
//package com.teaching.backend.service.impl.favour;
|
||||
//
|
||||
//import cn.hutool.core.collection.CollUtil;
|
||||
//import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
//import com.teaching.backend.common.BaseResponse;
|
||||
//import com.teaching.backend.common.ErrorCode;
|
||||
//import com.teaching.backend.common.ResultUtils;
|
||||
//import com.teaching.backend.exception.BusinessException;
|
||||
//import com.teaching.backend.mapper.courses.CoursesMapper;
|
||||
//import com.teaching.backend.mapper.favour.SeCourseFavourMapper;
|
||||
//import com.teaching.backend.model.entity.courses.Courses;
|
||||
//import com.teaching.backend.model.entity.favour.SeCourseFavour;
|
||||
//import com.teaching.backend.model.entity.favour.SeKnowFavour;
|
||||
//import com.teaching.backend.model.entity.favour.SeResourceFavour;
|
||||
//import com.teaching.backend.model.vo.favour.CourseFavourDetailVO;
|
||||
//import com.teaching.backend.service.courses.ICoursesService;
|
||||
//import com.teaching.backend.service.favour.SeCourseFavourService;
|
||||
//import com.teaching.backend.service.favour.SeKnowFavourService;
|
||||
//import com.teaching.backend.service.favour.SeResourceFavourService;
|
||||
//import org.springframework.beans.BeanUtils;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.locks.Lock;
|
||||
//import java.util.concurrent.locks.ReentrantLock;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * @Author:youhang
|
||||
// * @Date:2024-05-30-20:23
|
||||
// * @Description:
|
||||
// */
|
||||
//@Service
|
||||
//public class SeCourseFavourServiceImpl extends ServiceImpl<SeCourseFavourMapper, SeCourseFavour> implements SeCourseFavourService {
|
||||
//
|
||||
//
|
||||
// @Resource
|
||||
// private SeResourceFavourService seResourceFavourService;
|
||||
//
|
||||
// @Resource
|
||||
// SeKnowFavourService seKnowFavourService;
|
||||
//
|
||||
// @Autowired
|
||||
// CoursesMapper coursesMapper;
|
||||
//
|
||||
// @Autowired
|
||||
// ICoursesService coursesService;
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public BaseResponse<Boolean> doCourseFavour(String courseId, String userId) {
|
||||
// System.out.println("进入点赞" + courseId + userId);
|
||||
// //从数据库中校验是否存在courseid
|
||||
// Courses courses = coursesMapper.selectById(courseId);
|
||||
// boolean result = false;
|
||||
// if(courses == null){
|
||||
// return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"课程不存在");
|
||||
// }
|
||||
// //查询数据库记录,该用户是否点赞
|
||||
// SeCourseFavour seCourseFavour = new SeCourseFavour();
|
||||
// seCourseFavour.setCourseId(courseId);
|
||||
// seCourseFavour.setUserId(userId);
|
||||
// QueryWrapper<SeCourseFavour> favourQueryWrapper = new QueryWrapper<>(seCourseFavour);
|
||||
// SeCourseFavour oldSeCourseFavour = this.getOne(favourQueryWrapper);
|
||||
// //已点赞
|
||||
// if (oldSeCourseFavour != null) {
|
||||
// // 取消点赞 删除记录
|
||||
// result = this.remove(favourQueryWrapper);
|
||||
// if (result) {
|
||||
// System.out.println("取消点赞成功");
|
||||
// return ResultUtils.success(result);
|
||||
// } else {
|
||||
// throw new BusinessException(ErrorCode.SYSTEM_ERROR);
|
||||
// }
|
||||
// } else {
|
||||
// // 每个用户串行点赞
|
||||
// // 锁必须要包裹住事务方法
|
||||
// Lock lock = new ReentrantLock();
|
||||
// lock.lock();
|
||||
// try {
|
||||
// result = this.save(seCourseFavour);
|
||||
// } catch (Exception e) {
|
||||
// throw new BusinessException(ErrorCode.OPERATION_ERROR);
|
||||
// } finally {
|
||||
// lock.unlock();
|
||||
// System.out.println("点赞成功");
|
||||
// return ResultUtils.success(result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public BaseResponse<Long>favourCount(String courseId) {
|
||||
// //从数据库中校验是否存在courseid
|
||||
// QueryWrapper<SeCourseFavour> favourQueryWrapper = new QueryWrapper<>();
|
||||
// favourQueryWrapper.eq("course_id", courseId);
|
||||
// long result = this.count(favourQueryWrapper);
|
||||
// if (result == 0) {
|
||||
// throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询参数不存在");
|
||||
// } else {
|
||||
// return ResultUtils.success(result);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public BaseResponse<Long> courseCount(String courseId) {
|
||||
//
|
||||
// QueryWrapper<SeResourceFavour> ResourceQueryWrapper = new QueryWrapper<>();
|
||||
// ResourceQueryWrapper.eq("course_id", courseId);
|
||||
// long result1 = seResourceFavourService.count(ResourceQueryWrapper);
|
||||
// QueryWrapper<SeKnowFavour> KnowQueryWrapper = new QueryWrapper<>();
|
||||
// KnowQueryWrapper.eq("course_id", courseId);
|
||||
// long result2 = seKnowFavourService.count(KnowQueryWrapper);
|
||||
// long result = result1 + result2;
|
||||
// if (result == 0) {
|
||||
// throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询参数不存在");
|
||||
// } else {
|
||||
// return ResultUtils.success(result);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 某个用户课程列表
|
||||
// *
|
||||
// * @param userId
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// public List<String> courseList(String userId) {
|
||||
// QueryWrapper<SeCourseFavour> courseQueryWrapper = new QueryWrapper<>();
|
||||
// courseQueryWrapper.eq("user_id", userId);
|
||||
// List<String> list = this.list(courseQueryWrapper).stream().map(SeCourseFavour::getCourseId).collect(Collectors.toList());
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Page<CourseFavourDetailVO> listCourseFavourByPage(Page<Courses> page, Wrapper<Courses> queryWrapper) {
|
||||
// Page<Courses> coursePage = coursesService.page(page, queryWrapper);
|
||||
// Page<CourseFavourDetailVO> courseFavourVOPage = new Page<>(coursePage.getCurrent(), coursePage.getSize(), coursePage.getTotal());
|
||||
// List<Courses> courseFavourList = coursePage.getRecords();
|
||||
// //若数据为空,直接返回
|
||||
// if (CollUtil.isEmpty(courseFavourList)) {
|
||||
// return courseFavourVOPage;
|
||||
// }
|
||||
// //过滤字段
|
||||
// List<CourseFavourDetailVO> courseFavourDetailVOList = new ArrayList<>();
|
||||
// for (int i = 0; i < courseFavourList.size(); i++) {
|
||||
// CourseFavourDetailVO courseFavourDetailVO = new CourseFavourDetailVO();
|
||||
// BeanUtils.copyProperties(courseFavourList.get(i), courseFavourDetailVO);
|
||||
// courseFavourDetailVOList.add(courseFavourDetailVO);
|
||||
// }
|
||||
// courseFavourVOPage.setRecords(courseFavourDetailVOList);
|
||||
// return courseFavourVOPage;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
package com.teaching.backend.service.impl.favour; |
||||
|
||||
import cn.hutool.core.collection.CollUtil; |
||||
import cn.hutool.core.date.DateTime; |
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.common.ErrorCode; |
||||
import com.teaching.backend.common.ResultUtils; |
||||
import com.teaching.backend.exception.BusinessException; |
||||
import com.teaching.backend.mapper.courses.CoursesMapper; |
||||
import com.teaching.backend.mapper.favour.SeCourseFavourMapper; |
||||
import com.teaching.backend.model.entity.courses.Courses; |
||||
import com.teaching.backend.model.entity.favour.SeCourseFavour; |
||||
import com.teaching.backend.model.entity.favour.SeKnowFavour; |
||||
import com.teaching.backend.model.entity.favour.SeResourceFavour; |
||||
import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; |
||||
import com.teaching.backend.service.courses.ICoursesService; |
||||
import com.teaching.backend.service.favour.SeCourseFavourService; |
||||
import com.teaching.backend.service.favour.SeKnowFavourService; |
||||
|
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.concurrent.locks.Lock; |
||||
import java.util.concurrent.locks.ReentrantLock; |
||||
import java.util.stream.Collectors; |
||||
|
||||
|
||||
/** |
||||
* @Author:youhang |
||||
* @Date:2024-05-30-20:23 |
||||
* @Description: |
||||
*/ |
||||
@Service |
||||
public class SeCourseFavourServiceImpl extends ServiceImpl<SeCourseFavourMapper, SeCourseFavour> implements SeCourseFavourService { |
||||
|
||||
|
||||
|
||||
@Resource |
||||
SeKnowFavourService seKnowFavourService; |
||||
|
||||
@Autowired |
||||
CoursesMapper coursesMapper; |
||||
|
||||
@Autowired |
||||
ICoursesService coursesService; |
||||
|
||||
|
||||
|
||||
@Override |
||||
public BaseResponse<Boolean> doCourseFavour(String courseId, String userId) { |
||||
System.out.println("进入点赞" + courseId + userId); |
||||
//从数据库中校验是否存在courseid
|
||||
Courses courses = coursesMapper.selectById(courseId); |
||||
boolean result = false; |
||||
if(courses == null){ |
||||
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"课程不存在"); |
||||
} |
||||
//查询数据库记录,该用户是否点赞
|
||||
SeCourseFavour seCourseFavour = new SeCourseFavour(); |
||||
seCourseFavour.setCourseId(courseId); |
||||
seCourseFavour.setUserId(userId); |
||||
seCourseFavour.setCreatetime(DateTime.now()); |
||||
QueryWrapper<SeCourseFavour> favourQueryWrapper = new QueryWrapper<>(seCourseFavour); |
||||
SeCourseFavour oldSeCourseFavour = this.getOne(favourQueryWrapper); |
||||
//已点赞
|
||||
if (oldSeCourseFavour != null) { |
||||
// 取消点赞 删除记录
|
||||
result = this.remove(favourQueryWrapper); |
||||
if (result) { |
||||
System.out.println("取消点赞成功"); |
||||
return ResultUtils.success(result); |
||||
} else { |
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR); |
||||
} |
||||
} else { |
||||
// 每个用户串行点赞
|
||||
// 锁必须要包裹住事务方法
|
||||
Lock lock = new ReentrantLock(); |
||||
lock.lock(); |
||||
try { |
||||
result = this.save(seCourseFavour); |
||||
} catch (Exception e) { |
||||
throw new BusinessException(ErrorCode.OPERATION_ERROR); |
||||
} finally { |
||||
lock.unlock(); |
||||
System.out.println("点赞成功"); |
||||
return ResultUtils.success(result); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public BaseResponse<Long>favourCount(String courseId) { |
||||
//从数据库中校验是否存在courseid
|
||||
QueryWrapper<SeCourseFavour> favourQueryWrapper = new QueryWrapper<>(); |
||||
favourQueryWrapper.eq("course_id", courseId); |
||||
long result = this.count(favourQueryWrapper); |
||||
if (result == 0) { |
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询参数不存在"); |
||||
} else { |
||||
return ResultUtils.success(result); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 某个用户课程列表 |
||||
* |
||||
* @param userId |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public List<String> courseList(String userId) { |
||||
QueryWrapper<SeCourseFavour> courseQueryWrapper = new QueryWrapper<>(); |
||||
courseQueryWrapper.eq("user_id", userId); |
||||
List<String> list = this.list(courseQueryWrapper).stream().map(SeCourseFavour::getCourseId).collect(Collectors.toList()); |
||||
return list; |
||||
} |
||||
|
||||
@Override |
||||
public Page<CourseFavourDetailVO> listCourseFavourByPage(Page<Courses> page, Wrapper<Courses> queryWrapper) { |
||||
Page<Courses> coursePage = coursesService.page(page, queryWrapper); |
||||
Page<CourseFavourDetailVO> courseFavourVOPage = new Page<>(coursePage.getCurrent(), coursePage.getSize(), coursePage.getTotal()); |
||||
List<Courses> courseFavourList = coursePage.getRecords(); |
||||
//若数据为空,直接返回
|
||||
if (CollUtil.isEmpty(courseFavourList)) { |
||||
return courseFavourVOPage; |
||||
} |
||||
//过滤字段
|
||||
List<CourseFavourDetailVO> courseFavourDetailVOList = new ArrayList<>(); |
||||
for (int i = 0; i < courseFavourList.size(); i++) { |
||||
CourseFavourDetailVO courseFavourDetailVO = new CourseFavourDetailVO(); |
||||
BeanUtils.copyProperties(courseFavourList.get(i), courseFavourDetailVO); |
||||
courseFavourDetailVOList.add(courseFavourDetailVO); |
||||
} |
||||
courseFavourVOPage.setRecords(courseFavourDetailVOList); |
||||
return courseFavourVOPage; |
||||
} |
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,34 @@ |
||||
package com.teaching.backend.utils.knowGraph; |
||||
|
||||
import com.teaching.backend.common.BaseResponse; |
||||
import com.teaching.backend.model.dto.chapter.ChapterDTO; |
||||
import com.teaching.backend.model.dto.courses.CoursesDTO; |
||||
import com.teaching.backend.model.entity.KnowGraph.KnowChapter; |
||||
import com.teaching.backend.model.entity.KnowGraph.KnowCourse; |
||||
import com.teaching.backend.model.entity.chapter.Chapter; |
||||
import com.teaching.backend.model.entity.courses.Courses; |
||||
import com.teaching.backend.service.KnowGraph.KnowService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
||||
/** |
||||
* @Author:youhang |
||||
* @Date:2024-07-26-17:57 |
||||
* @Description: |
||||
*/ |
||||
@Component |
||||
public class AddNeoKnowByCourse { |
||||
|
||||
@Autowired |
||||
private KnowService knowService; |
||||
|
||||
public BaseResponse<KnowCourse> addCourse(Courses courses){ |
||||
return knowService.createCourseKnow(courses); |
||||
} |
||||
|
||||
public BaseResponse<KnowChapter> addChapter(Chapter chapter){ |
||||
return knowService.createKnowChapter(chapter); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue