master
wenyu441069198 8 months ago
parent e8b488e943
commit 0f003ac422
  1. 13
      pom.xml
  2. 2
      src/main/java/com/teaching/TeachingBackendApplication.java
  3. 34
      src/main/java/com/teaching/backend/common/BaseResponse.java
  4. 43
      src/main/java/com/teaching/backend/common/ErrorCode.java
  5. 52
      src/main/java/com/teaching/backend/common/ResultUtils.java
  6. 9
      src/main/java/com/teaching/backend/common/test1.java
  7. 29
      src/main/java/com/teaching/backend/config/MyBatisPlusConfig.java
  8. 21
      src/main/java/com/teaching/backend/controller/UserController.java
  9. 110
      src/main/java/com/teaching/backend/controller/favour/SeCourseFavourController.java
  10. 50
      src/main/java/com/teaching/backend/controller/favour/SeKnowFavourController.java
  11. 51
      src/main/java/com/teaching/backend/controller/favour/SeResourceFavourController.java
  12. 87
      src/main/java/com/teaching/backend/controller/thumb/SeCourseThumbController.java
  13. 49
      src/main/java/com/teaching/backend/controller/thumb/SeKnowThumbController.java
  14. 49
      src/main/java/com/teaching/backend/controller/thumb/SeResourceThumbController.java
  15. 37
      src/main/java/com/teaching/backend/exception/BusinessException.java
  16. 9
      src/main/java/com/teaching/backend/exception/test1.java
  17. 15
      src/main/java/com/teaching/backend/mapper/favour/SeCourseFavourMapper.java
  18. 16
      src/main/java/com/teaching/backend/mapper/favour/SeKnowFavourMapper.java
  19. 17
      src/main/java/com/teaching/backend/mapper/favour/SeResourceFavourMapper.java
  20. 9
      src/main/java/com/teaching/backend/mapper/test1.java
  21. 15
      src/main/java/com/teaching/backend/mapper/thumb/SeCourseThumbMapper.java
  22. 16
      src/main/java/com/teaching/backend/mapper/thumb/SeKnowThumbMapper.java
  23. 17
      src/main/java/com/teaching/backend/mapper/thumb/SeResourceThumbMapper.java
  24. 24
      src/main/java/com/teaching/backend/model/dto/favour/courseFavour/CourseFavourAddRequest.java
  25. 20
      src/main/java/com/teaching/backend/model/dto/favour/courseFavour/CourseFavourAllRequest.java
  26. 20
      src/main/java/com/teaching/backend/model/dto/favour/courseFavour/CourseFavourListRequest.java
  27. 29
      src/main/java/com/teaching/backend/model/dto/favour/knowFavour/KnowFavourAddRequest.java
  28. 29
      src/main/java/com/teaching/backend/model/dto/favour/resourceFavour/ResourceFavourAddRequest.java
  29. 9
      src/main/java/com/teaching/backend/model/dto/test1.java
  30. 24
      src/main/java/com/teaching/backend/model/dto/thumb/coursethumb/CourseThumbAddRequest.java
  31. 20
      src/main/java/com/teaching/backend/model/dto/thumb/coursethumb/CourseThumbAllRequest.java
  32. 29
      src/main/java/com/teaching/backend/model/dto/thumb/knowthumb/KnowThumbAddRequest.java
  33. 29
      src/main/java/com/teaching/backend/model/dto/thumb/resourcethumb/ResourceThumbAddRequest.java
  34. 35
      src/main/java/com/teaching/backend/model/entity/favour/SeCourseFavour.java
  35. 40
      src/main/java/com/teaching/backend/model/entity/favour/SeKnowFavour.java
  36. 40
      src/main/java/com/teaching/backend/model/entity/favour/SeResourceFavour.java
  37. 9
      src/main/java/com/teaching/backend/model/entity/test1.java
  38. 36
      src/main/java/com/teaching/backend/model/entity/thumb/SeCourseThumb.java
  39. 40
      src/main/java/com/teaching/backend/model/entity/thumb/SeKnowThumb.java
  40. 40
      src/main/java/com/teaching/backend/model/entity/thumb/SeResourceThumb.java
  41. 9
      src/main/java/com/teaching/backend/model/test1.java
  42. 51
      src/main/java/com/teaching/backend/service/favour/SeCourseFavourService.java
  43. 22
      src/main/java/com/teaching/backend/service/favour/SeKnowFavourService.java
  44. 22
      src/main/java/com/teaching/backend/service/favour/SeResourceFavourService.java
  45. 123
      src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java
  46. 64
      src/main/java/com/teaching/backend/service/impl/favour/SeKnowFavourServiceImpl.java
  47. 65
      src/main/java/com/teaching/backend/service/impl/favour/SeResourceFavourServiceImpl.java
  48. 105
      src/main/java/com/teaching/backend/service/impl/thumb/SeCourseThumbServiceImpl.java
  49. 63
      src/main/java/com/teaching/backend/service/impl/thumb/SeKnowThumbServiceImpl.java
  50. 63
      src/main/java/com/teaching/backend/service/impl/thumb/SeResourceThumbServiceImpl.java
  51. 9
      src/main/java/com/teaching/backend/service/test1.java
  52. 40
      src/main/java/com/teaching/backend/service/thumb/SeCourseThumbService.java
  53. 22
      src/main/java/com/teaching/backend/service/thumb/SeKnowThumbService.java
  54. 22
      src/main/java/com/teaching/backend/service/thumb/SeResourceThumbService.java
  55. 18
      src/main/resources/application.yml
  56. 18
      src/main/resources/mapper/SeCourseThumbMapper.xml

@ -41,6 +41,7 @@
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
<dependency>
<groupId>com.baomidou</groupId>
@ -63,6 +64,18 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://doc.xiaominfo.com/docs/quick-start#openapi2 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>

@ -1,9 +1,11 @@
package com.teaching;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.teaching.backend.mapper")
public class TeachingBackendApplication {
public static void main(String[] args) {

@ -0,0 +1,34 @@
package com.teaching.backend.common;
import lombok.Data;
import java.io.Serializable;
/**
* 通用返回类
*
* @param <T>
*/
@Data
public class BaseResponse<T> implements Serializable {
private int code;
private T data;
private String message;
public BaseResponse(int code, T data, String message) {
this.code = code;
this.data = data;
this.message = message;
}
public BaseResponse(int code, T data) {
this(code, data, "");
}
public BaseResponse(ErrorCode errorCode) {
this(errorCode.getCode(), null, errorCode.getMessage());
}
}

@ -0,0 +1,43 @@
package com.teaching.backend.common;
/**
* 自定义错误码
*
* @author <a href="https://github.com/liyh">程序员鱼皮</a>
* @from <a href="https://yh.icu">编程导航知识星球</a>
*/
public enum ErrorCode {
SUCCESS(0, "ok"),
PARAMS_ERROR(40000, "请求参数错误"),
NOT_LOGIN_ERROR(40100, "未登录"),
NO_AUTH_ERROR(40101, "无权限"),
NOT_FOUND_ERROR(40400, "请求数据不存在"),
FORBIDDEN_ERROR(40300, "禁止访问"),
SYSTEM_ERROR(50000, "系统内部异常"),
OPERATION_ERROR(50001, "操作失败");
/**
* 状态码
*/
private final int code;
/**
* 信息
*/
private final String message;
ErrorCode(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}

@ -0,0 +1,52 @@
package com.teaching.backend.common;
/**
* 返回工具类
*
* @author <a href="https://github.com/liyh">程序员鱼皮</a>
* @from <a href="https://yh.icu">编程导航知识星球</a>
*/
public class ResultUtils {
/**
* 成功
*
* @param data
* @param <T>
* @return
*/
public static <T> BaseResponse<T> success(T data) {
return new BaseResponse<>(0, data, "ok");
}
/**
* 失败
*
* @param errorCode
* @return
*/
public static BaseResponse error(ErrorCode errorCode) {
return new BaseResponse<>(errorCode);
}
/**
* 失败
*
* @param code
* @param message
* @return
*/
public static BaseResponse error(int code, String message) {
return new BaseResponse(code, null, message);
}
/**
* 失败
*
* @param errorCode
* @return
*/
public static BaseResponse error(ErrorCode errorCode, String message) {
return new BaseResponse(errorCode.getCode(), null, message);
}
}

@ -1,9 +0,0 @@
package com.teaching.backend.common;
/**
* @Author:youhang
* @Date:2024-05-30-18:20
* @Description:
*/
public class test1 {
}

@ -0,0 +1,29 @@
package com.teaching.backend.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MyBatis Plus 配置
*/
@Configuration
@MapperScan("com.teaching.backend.mapper")
public class MyBatisPlusConfig {
/**
* 拦截器配置
*
* @return
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 分页插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}

@ -1,21 +0,0 @@
package com.teaching.backend.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @Author:youhang
* @Date:2024-05-30-18:15
* @Description:
*/
@Controller
public class UserController {
@RequestMapping(value = "/1",method = RequestMethod.GET)
@ResponseBody
public String add(){
return "yh";
}
}

@ -0,0 +1,110 @@
package com.teaching.backend.controller.favour;
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.CourseFavourListRequest;
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("/course_favour")
@Slf4j
public class SeCourseFavourController {
@Resource
private SeCourseFavourService seCourseFavourService;
/**
* 点赞
*
* @param courseFavourAddRequest
* @return result 执行情况
*/
@PostMapping("/add")
// todo 后期加上 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);
}
// todo 从数据库中校验是否存在courseid , userid
Boolean result = seCourseFavourService.doCourseFavour(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId());
return ResultUtils.success(result);
}
/**
* 课程点赞总数
*
* @param courseFavourAddRequest
* @return result 课程点赞总数
*/
@PostMapping("/count")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<Long> favourCount(@RequestBody CourseFavourAddRequest courseFavourAddRequest) {
if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空");
}
// todo 从数据库中校验是否存在courseid
Long result = seCourseFavourService.favourCount(courseFavourAddRequest.getCourseId());
return ResultUtils.success(result);
}
/**
* 课程下资源和知识点点赞总数
*
* @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
Long result = seCourseFavourService.courseCount(courseFavourAllRequest.getCourseId());
return ResultUtils.success(result);
}
/**
* 某个用户课程列表
*
* @param courseFavourListRequest
* @return result 某个用户课程列表
*/
@PostMapping("/countList")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<List<String>> courseList(@RequestBody CourseFavourListRequest courseFavourListRequest) {
if (StringUtils.isAnyBlank(courseFavourListRequest.getUserId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数-用户id不能为空");
}
// todo 从数据库中校验是否存在userid
List<String> result = seCourseFavourService.courseList(courseFavourListRequest.getUserId());
return ResultUtils.success(result);
}
}

@ -0,0 +1,50 @@
package com.teaching.backend.controller.favour;
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.knowFavour.KnowFavourAddRequest;
import com.teaching.backend.service.favour.SeKnowFavourService;
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;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
@RestController
@RequestMapping("/know_favour")
@Slf4j
public class SeKnowFavourController {
@Resource
private SeKnowFavourService seKnowFavourService;
/**
* 点赞
*
* @param knowFavourAddRequest
* @return result 执行情况
*/
@PostMapping("/add")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<Boolean> doFavour(@RequestBody KnowFavourAddRequest knowFavourAddRequest) {
if (StringUtils.isAnyBlank(knowFavourAddRequest.getCourseId(), knowFavourAddRequest.getKnowId(), knowFavourAddRequest.getUserId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// todo 从数据库中校验是否存在knowid , userid ,courseid
Boolean result = seKnowFavourService.doKnowFavour(knowFavourAddRequest.getCourseId(), knowFavourAddRequest.getKnowId(), knowFavourAddRequest.getUserId());
return ResultUtils.success(result);
}
}

@ -0,0 +1,51 @@
package com.teaching.backend.controller.favour;
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.resourceFavour.ResourceFavourAddRequest;
import com.teaching.backend.service.favour.SeResourceFavourService;
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;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
@RestController
@RequestMapping("/resource_favour")
@Slf4j
public class SeResourceFavourController {
@Resource
private SeResourceFavourService seResourceFavourService;
/**
* 收藏
*
* @param resourceFavourAddRequest
* @return result 执行情况
*/
@PostMapping("/add")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<Boolean> doFavour(@RequestBody ResourceFavourAddRequest resourceFavourAddRequest) {
if (StringUtils.isAnyBlank(resourceFavourAddRequest.getCourseId(), resourceFavourAddRequest.getResourceId(), resourceFavourAddRequest.getUserId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// todo 从数据库中校验是否存在resourceid , userid ,courseid
Boolean result = seResourceFavourService.doResourceFavour(resourceFavourAddRequest.getCourseId(), resourceFavourAddRequest.getResourceId(), resourceFavourAddRequest.getUserId());
return ResultUtils.success(result);
}
}

@ -0,0 +1,87 @@
package com.teaching.backend.controller.thumb;
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.thumb.coursethumb.CourseThumbAddRequest;
import com.teaching.backend.model.dto.thumb.coursethumb.CourseThumbAllRequest;
import com.teaching.backend.service.thumb.SeCourseThumbService;
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;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
@RestController
@RequestMapping("/course_thumb")
@Slf4j
public class SeCourseThumbController {
@Resource
private SeCourseThumbService seCourseThumbService;
/**
* 点赞/取消点赞
*
* @param courseThumbAddRequest
* @return result 执行情况
*/
@PostMapping("/")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<Boolean> doThumb(@RequestBody CourseThumbAddRequest courseThumbAddRequest) {
if (StringUtils.isAnyBlank(courseThumbAddRequest.getCourseId(), courseThumbAddRequest.getUserId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// todo 从数据库中校验是否存在courseid , userid 从课程表和用户表查询
Boolean result = seCourseThumbService.doCourseThumb(courseThumbAddRequest.getCourseId(), courseThumbAddRequest.getUserId());
return ResultUtils.success(result);
}
/**
* 课程点赞总数
*
* @param courseThumbAddRequest
* @return result 课程点赞总数
*/
@PostMapping("/count")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<Long> thumbCount(@RequestBody CourseThumbAddRequest courseThumbAddRequest) {
if (StringUtils.isAnyBlank(courseThumbAddRequest.getCourseId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空");
}
// todo 从数据库中校验是否存在courseid
Long result = seCourseThumbService.thumbCount(courseThumbAddRequest.getCourseId());
return ResultUtils.success(result);
}
/**
* 课程下资源和知识点点赞总数
*
* @param courseThumbAllRequest
* @return result 课程下资源和知识点点赞总数
*/
@PostMapping("/countAll")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<Long> courseCount(@RequestBody CourseThumbAllRequest courseThumbAllRequest) {
if (StringUtils.isAnyBlank(courseThumbAllRequest.getCourseId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空");
}
// todo 从数据库中校验是否存在courseid
Long result = seCourseThumbService.courseCount(courseThumbAllRequest.getCourseId());
return ResultUtils.success(result);
}
}

@ -0,0 +1,49 @@
package com.teaching.backend.controller.thumb;
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.thumb.knowthumb.KnowThumbAddRequest;
import com.teaching.backend.service.thumb.SeKnowThumbService;
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;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
@RestController
@RequestMapping("/know_thumb")
@Slf4j
public class SeKnowThumbController {
@Resource
private SeKnowThumbService seKnowThumbService;
/**
* 点赞
*
* @param knowThumbAddRequest
* @return result 执行情况
*/
@PostMapping("/add")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<Boolean> doThumb(@RequestBody KnowThumbAddRequest knowThumbAddRequest) {
if (StringUtils.isAnyBlank(knowThumbAddRequest.getCourseId(), knowThumbAddRequest.getKnowId(), knowThumbAddRequest.getUserId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// todo 从数据库中校验是否存在knowid , userid ,courseid
Boolean result = seKnowThumbService.doKnowThumb(knowThumbAddRequest.getCourseId(), knowThumbAddRequest.getKnowId(), knowThumbAddRequest.getUserId());
return ResultUtils.success(result);
}
}

@ -0,0 +1,49 @@
package com.teaching.backend.controller.thumb;
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.thumb.resourcethumb.ResourceThumbAddRequest;
import com.teaching.backend.service.thumb.SeResourceThumbService;
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;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
@RestController
@RequestMapping("/resource_thumb")
@Slf4j
public class SeResourceThumbController {
@Resource
private SeResourceThumbService seResourceThumbService;
/**
* 点赞
*
* @param resourceThumbAddRequest
* @return result 执行情况
*/
@PostMapping("/add")
// todo 后期加上 HttpServletRequest request 在一个fitter里面进行鉴权操作
public BaseResponse<Boolean> doThumb(@RequestBody ResourceThumbAddRequest resourceThumbAddRequest) {
if (StringUtils.isAnyBlank(resourceThumbAddRequest.getCourseId(), resourceThumbAddRequest.getResourceId(), resourceThumbAddRequest.getUserId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// todo 从数据库中校验是否存在resourceid , userid ,courseid
Boolean result = seResourceThumbService.doResourceThumb(resourceThumbAddRequest.getCourseId(), resourceThumbAddRequest.getResourceId(), resourceThumbAddRequest.getUserId());
return ResultUtils.success(result);
}
}

@ -0,0 +1,37 @@
package com.teaching.backend.exception;
import com.teaching.backend.common.ErrorCode;
/**
* 自定义异常类
*
* @author <a href="https://github.com/liyh">程序员鱼皮</a>
* @from <a href="https://yh.icu">编程导航知识星球</a>
*/
public class BusinessException extends RuntimeException {
/**
* 错误码
*/
private final int code;
public BusinessException(int code, String message) {
super(message);
this.code = code;
}
public BusinessException(ErrorCode errorCode) {
super(errorCode.getMessage());
this.code = errorCode.getCode();
}
public BusinessException(ErrorCode errorCode, String message) {
super(message);
this.code = errorCode.getCode();
}
public int getCode() {
return code;
}
}

@ -1,9 +0,0 @@
package com.teaching.backend.exception;
/**
* @Author:youhang
* @Date:2024-05-30-18:20
* @Description:
*/
public class test1 {
}

@ -0,0 +1,15 @@
package com.teaching.backend.mapper.favour;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.favour.SeCourseFavour;
/**
* 课程点赞数据库操作
*/
public interface SeCourseFavourMapper extends BaseMapper<SeCourseFavour> {
}

@ -0,0 +1,16 @@
package com.teaching.backend.mapper.favour;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.favour.SeKnowFavour;
/**
* 知识点赞数据库操作
*/
public interface SeKnowFavourMapper extends BaseMapper<SeKnowFavour> {
}

@ -0,0 +1,17 @@
package com.teaching.backend.mapper.favour;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.favour.SeResourceFavour;
/**
* 课程资源点赞数据库操作
*/
public interface SeResourceFavourMapper extends BaseMapper<SeResourceFavour> {
}

@ -1,9 +0,0 @@
package com.teaching.backend.mapper;
/**
* @Author:youhang
* @Date:2024-05-30-18:20
* @Description:
*/
public class test1 {
}

@ -0,0 +1,15 @@
package com.teaching.backend.mapper.thumb;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.thumb.SeCourseThumb;
/**
* 课程点赞数据库操作
*/
public interface SeCourseThumbMapper extends BaseMapper<SeCourseThumb> {
}

@ -0,0 +1,16 @@
package com.teaching.backend.mapper.thumb;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.thumb.SeKnowThumb;
/**
* 知识点赞数据库操作
*/
public interface SeKnowThumbMapper extends BaseMapper<SeKnowThumb> {
}

@ -0,0 +1,17 @@
package com.teaching.backend.mapper.thumb;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teaching.backend.model.entity.thumb.SeResourceThumb;
/**
* 课程资源点赞数据库操作
*/
public interface SeResourceThumbMapper extends BaseMapper<SeResourceThumb> {
}

@ -0,0 +1,24 @@
package com.teaching.backend.model.dto.favour.courseFavour;
import lombok.Data;
import java.io.Serializable;
/**
* 课程点赞请求
*/
@Data
public class CourseFavourAddRequest implements Serializable {
/**
* 帖子 id
*/
private String courseId;
/**
* user id
*/
private String userId;
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,20 @@
package com.teaching.backend.model.dto.favour.courseFavour;
import lombok.Data;
import java.io.Serializable;
/**
* 课程点赞请求
*/
@Data
public class CourseFavourAllRequest implements Serializable {
/**
* 课程 id
*/
private String courseId;
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,20 @@
package com.teaching.backend.model.dto.favour.courseFavour;
import lombok.Data;
import java.io.Serializable;
/**
* 课程点赞请求
*/
@Data
public class CourseFavourListRequest implements Serializable {
/**
* 用户 id
*/
private String userId;
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,29 @@
package com.teaching.backend.model.dto.favour.knowFavour;
import lombok.Data;
import java.io.Serializable;
/**
* 知识点点赞请求
*/
@Data
public class KnowFavourAddRequest implements Serializable {
/**
* 课程 id
*/
private String courseId;
/**
* 知识点 id
*/
private String knowId;
/**
* user id
*/
private String userId;
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,29 @@
package com.teaching.backend.model.dto.favour.resourceFavour;
import lombok.Data;
import java.io.Serializable;
/**
* 资源点赞请求
*/
@Data
public class ResourceFavourAddRequest implements Serializable {
/**
* 课程 id
*/
private String courseId;
/**
* 知识点 id
*/
private String resourceId;
/**
* user id
*/
private String userId;
private static final long serialVersionUID = 1L;
}

@ -1,9 +0,0 @@
package com.teaching.backend.model.dto;
/**
* @Author:youhang
* @Date:2024-05-30-18:20
* @Description:
*/
public class test1 {
}

@ -0,0 +1,24 @@
package com.teaching.backend.model.dto.thumb.coursethumb;
import lombok.Data;
import java.io.Serializable;
/**
* 课程点赞请求
*/
@Data
public class CourseThumbAddRequest implements Serializable {
/**
* 帖子 id
*/
private String courseId;
/**
* user id
*/
private String userId;
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,20 @@
package com.teaching.backend.model.dto.thumb.coursethumb;
import lombok.Data;
import java.io.Serializable;
/**
* 课程点赞请求
*/
@Data
public class CourseThumbAllRequest implements Serializable {
/**
* 课程 id
*/
private String courseId;
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,29 @@
package com.teaching.backend.model.dto.thumb.knowthumb;
import lombok.Data;
import java.io.Serializable;
/**
* 知识点点赞请求
*/
@Data
public class KnowThumbAddRequest implements Serializable {
/**
* 课程 id
*/
private String courseId;
/**
* 知识点 id
*/
private String knowId;
/**
* user id
*/
private String userId;
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,29 @@
package com.teaching.backend.model.dto.thumb.resourcethumb;
import lombok.Data;
import java.io.Serializable;
/**
* 资源点赞请求
*/
@Data
public class ResourceThumbAddRequest implements Serializable {
/**
* 课程 id
*/
private String courseId;
/**
* 知识点 id
*/
private String resourceId;
/**
* user id
*/
private String userId;
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,35 @@
package com.teaching.backend.model.entity.favour;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 课程点赞
*/
@TableName(value = "se_course_favour")
@Data
public class SeCourseFavour implements Serializable {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 课程 id
*/
private String courseId;
/**
* 创建用户 id
*/
private String userId;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,40 @@
package com.teaching.backend.model.entity.favour;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 知识点点赞
*/
@TableName(value = "se_know_favour")
@Data
public class SeKnowFavour implements Serializable {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 课程 id
*/
private String courseId;
/**
* 创建知识点 id
*/
private String knowId;
/**
* 创建用户 id
*/
private String userId;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,40 @@
package com.teaching.backend.model.entity.favour;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 资源点赞
*/
@TableName(value = "se_resource_favour")
@Data
public class SeResourceFavour implements Serializable {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 课程 id
*/
private String courseId;
/**
* 创建知识点 id
*/
private String resourceId;
/**
* 创建用户 id
*/
private String userId;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

@ -1,9 +0,0 @@
package com.teaching.backend.model.entity;
/**
* @Author:youhang
* @Date:2024-05-30-18:20
* @Description:
*/
public class test1 {
}

@ -0,0 +1,36 @@
package com.teaching.backend.model.entity.thumb;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 课程点赞
*/
@TableName(value = "se_course_thumb")
@Data
public class SeCourseThumb implements Serializable {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 课程 id
*/
private String courseId;
/**
* 创建用户 id
*/
private String userId;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,40 @@
package com.teaching.backend.model.entity.thumb;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 知识点点赞
*/
@TableName(value = "se_know_thumb")
@Data
public class SeKnowThumb implements Serializable {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 课程 id
*/
private String courseId;
/**
* 创建知识点 id
*/
private String knowId;
/**
* 创建用户 id
*/
private String userId;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

@ -0,0 +1,40 @@
package com.teaching.backend.model.entity.thumb;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 资源点赞
*/
@TableName(value = "se_resource_thumb")
@Data
public class SeResourceThumb implements Serializable {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 课程 id
*/
private String courseId;
/**
* 创建知识点 id
*/
private String resourceId;
/**
* 创建用户 id
*/
private String userId;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

@ -1,9 +0,0 @@
package com.teaching.backend.model;
/**
* @Author:youhang
* @Date:2024-05-30-18:20
* @Description:
*/
public class test1 {
}

@ -0,0 +1,51 @@
package com.teaching.backend.service.favour;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.favour.SeCourseFavour;
import java.util.List;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
public interface SeCourseFavourService extends IService<SeCourseFavour> {
/**
* 收藏/取消收藏
*
* @param courseId
* @param userId
* @return
*/
boolean doCourseFavour(String courseId, String userId);
/**
* 收藏总数
*
* @param courseId
* @return
*/
long favourCount(String courseId);
/**
* 课程下资源和知识点的收藏总数
*
* @param courseId
* @return
*/
long courseCount(String courseId);
/**
* 某个用户课程列表
*
* @param userId
* @return
*/
List<String> courseList(String userId);
}

@ -0,0 +1,22 @@
package com.teaching.backend.service.favour;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.favour.SeKnowFavour;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
public interface SeKnowFavourService extends IService<SeKnowFavour> {
/**
* 收藏
*
* @param courseId
* @param userId
* @return
*/
boolean doKnowFavour(String courseId, String resourceId, String userId);
}

@ -0,0 +1,22 @@
package com.teaching.backend.service.favour;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.favour.SeResourceFavour;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
public interface SeResourceFavourService extends IService<SeResourceFavour> {
/**
* 收藏
*
* @param courseId
* @param userId
* @return
*/
boolean doResourceFavour(String courseId, String resourceId, String userId);
}

@ -0,0 +1,123 @@
package com.teaching.backend.service.impl.favour;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.favour.SeCourseFavourMapper;
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.service.favour.SeCourseFavourService;
import com.teaching.backend.service.favour.SeKnowFavourService;
import com.teaching.backend.service.favour.SeResourceFavourService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
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;
@Override
public boolean doCourseFavour(String courseId, String userId) {
System.out.println("进入点赞" + courseId + userId);
// todo 先查询数据库记录,该用户是否点赞
SeCourseFavour seCourseFavour = new SeCourseFavour();
seCourseFavour.setCourseId(courseId);
seCourseFavour.setUserId(userId);
QueryWrapper<SeCourseFavour> favourQueryWrapper = new QueryWrapper<>(seCourseFavour);
SeCourseFavour oldSeCourseFavour = this.getOne(favourQueryWrapper);
boolean result = false;
//已点赞
if (oldSeCourseFavour != null) {
// 取消点赞 删除记录
result = this.remove(favourQueryWrapper);
if (result) {
System.out.println("取消点赞成功");
return 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 result;
}
}
}
@Override
public long favourCount(String courseId) {
System.out.println("进入课程点赞统计" + 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 result;
}
}
@Override
public long courseCount(String courseId) {
System.out.println("进入课程下资源和知识点的点赞统计" + 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 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;
}
}

@ -0,0 +1,64 @@
package com.teaching.backend.service.impl.favour;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.favour.SeKnowFavourMapper;
import com.teaching.backend.model.entity.favour.SeKnowFavour;
import com.teaching.backend.service.favour.SeKnowFavourService;
import org.springframework.stereotype.Service;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* @Author:youhang
* @Date:2024-05-30-20:23
* @Description:
*/
@Service
public class SeKnowFavourServiceImpl extends ServiceImpl<SeKnowFavourMapper, SeKnowFavour> implements SeKnowFavourService {
@Override
public boolean doKnowFavour(String courseId, String knowId, String userId) {
System.out.println("进入知识点点赞" + knowId + userId);
// 先查询数据库记录,该用户是否点赞
SeKnowFavour seKnowFavour = new SeKnowFavour();
seKnowFavour.setKnowId(knowId);
seKnowFavour.setUserId(userId);
seKnowFavour.setCourseId(courseId);
QueryWrapper<SeKnowFavour> favourQueryWrapper = new QueryWrapper<>(seKnowFavour);
SeKnowFavour oldSeKnowFavour = this.getOne(favourQueryWrapper);
boolean result = false;
//已点赞
if (oldSeKnowFavour != null) {
// 取消点赞 删除记录
result = this.remove(favourQueryWrapper);
if (result) {
System.out.println("取消点赞成功");
return result;
} else {
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
}
} else {
// 每个用户串行点赞
// 锁必须要包裹住事务方法
Lock lock = new ReentrantLock();
lock.lock();
try {
result = this.save(seKnowFavour);
} catch (Exception e) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
} finally {
lock.unlock();
System.out.println("点赞成功");
return result;
}
}
}
}

@ -0,0 +1,65 @@
package com.teaching.backend.service.impl.favour;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.favour.SeResourceFavourMapper;
import com.teaching.backend.model.entity.favour.SeResourceFavour;
import com.teaching.backend.service.favour.SeResourceFavourService;
import org.springframework.stereotype.Service;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* @Author:youhang
* @Date:2024-05-30-20:23
* @Description:
*/
@Service
public class SeResourceFavourServiceImpl extends ServiceImpl<SeResourceFavourMapper, SeResourceFavour> implements SeResourceFavourService {
@Override
public boolean doResourceFavour(String courseId, String resourceId, String userId) {
System.out.println("进入知识点点赞" + resourceId + userId);
// 先查询数据库记录,该用户是否点赞
SeResourceFavour seResourceFavour = new SeResourceFavour();
seResourceFavour.setResourceId(resourceId);
seResourceFavour.setUserId(userId);
seResourceFavour.setCourseId(courseId);
QueryWrapper<SeResourceFavour> thumbQueryWrapper = new QueryWrapper<>(seResourceFavour);
SeResourceFavour oldSeResourceFavour = this.getOne(thumbQueryWrapper);
boolean result = false;
//已点赞
if (oldSeResourceFavour != null) {
// 取消点赞 删除记录
result = this.remove(thumbQueryWrapper);
if (result) {
System.out.println("取消点赞成功");
return result;
} else {
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
}
} else {
// 每个用户串行点赞
// 锁必须要包裹住事务方法
Lock lock = new ReentrantLock();
lock.lock();
try {
result = this.save(seResourceFavour);
} catch (Exception e) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
} finally {
lock.unlock();
System.out.println("点赞成功");
return result;
}
}
}
}

@ -0,0 +1,105 @@
package com.teaching.backend.service.impl.thumb;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.thumb.SeCourseThumbMapper;
import com.teaching.backend.model.entity.thumb.SeCourseThumb;
import com.teaching.backend.model.entity.thumb.SeKnowThumb;
import com.teaching.backend.model.entity.thumb.SeResourceThumb;
import com.teaching.backend.service.thumb.SeCourseThumbService;
import com.teaching.backend.service.thumb.SeKnowThumbService;
import com.teaching.backend.service.thumb.SeResourceThumbService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* @Author:youhang
* @Date:2024-05-30-20:23
* @Description:
*/
@Service
public class SeCourseThumbServiceImpl extends ServiceImpl<SeCourseThumbMapper, SeCourseThumb> implements SeCourseThumbService {
@Resource
private SeResourceThumbService seResourceThumbService;
@Resource
SeKnowThumbService seKnowThumbService;
@Override
public boolean doCourseThumb(String courseId, String userId) {
System.out.println("进入点赞" + courseId + userId);
// 先查询数据库记录,该用户是否点赞
SeCourseThumb seCourseThumb = new SeCourseThumb();
seCourseThumb.setCourseId(courseId);
seCourseThumb.setUserId(userId);
QueryWrapper<SeCourseThumb> thumbQueryWrapper = new QueryWrapper<>(seCourseThumb);
SeCourseThumb oldSeCourseThumb = this.getOne(thumbQueryWrapper);
boolean result = false;
//已点赞
if (oldSeCourseThumb != null) {
// 取消点赞 删除记录
result = this.remove(thumbQueryWrapper);
if (result) {
System.out.println("取消点赞成功");
return result;
} else {
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
}
} else {
// 每个用户串行点赞
// 锁必须要包裹住事务方法
Lock lock = new ReentrantLock();
lock.lock();
try {
result = this.save(seCourseThumb);
} catch (Exception e) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
} finally {
lock.unlock();
System.out.println("点赞成功");
return result;
}
}
}
@Override
public long thumbCount(String courseId) {
System.out.println("进入课程点赞统计" + courseId);
QueryWrapper<SeCourseThumb> thumbQueryWrapper = new QueryWrapper<>();
thumbQueryWrapper.eq("course_id", courseId);
long result = this.count(thumbQueryWrapper);
if (result == 0) {
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询参数不存在");
} else {
return result;
}
}
@Override
public long courseCount(String courseId) {
System.out.println("进入课程下资源和知识点的点赞统计" + courseId);
QueryWrapper<SeResourceThumb> ResourceQueryWrapper = new QueryWrapper<>();
ResourceQueryWrapper.eq("course_id", courseId);
long result1 = seResourceThumbService.count(ResourceQueryWrapper);
QueryWrapper<SeKnowThumb> KnowQueryWrapper = new QueryWrapper<>();
KnowQueryWrapper.eq("course_id", courseId);
long result2 = seKnowThumbService.count(KnowQueryWrapper);
long result = result1 + result2;
if (result == 0) {
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询参数不存在");
} else {
return result;
}
}
}

@ -0,0 +1,63 @@
package com.teaching.backend.service.impl.thumb;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.thumb.SeKnowThumbMapper;
import com.teaching.backend.model.entity.thumb.SeKnowThumb;
import com.teaching.backend.service.thumb.SeKnowThumbService;
import org.springframework.stereotype.Service;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* @Author:youhang
* @Date:2024-05-30-20:23
* @Description:
*/
@Service
public class SeKnowThumbServiceImpl extends ServiceImpl<SeKnowThumbMapper, SeKnowThumb> implements SeKnowThumbService {
@Override
public boolean doKnowThumb(String courseId, String knowId, String userId) {
System.out.println("进入知识点点赞" + knowId + userId);
// 先查询数据库记录,该用户是否点赞
SeKnowThumb seKnowThumb = new SeKnowThumb();
seKnowThumb.setKnowId(knowId);
seKnowThumb.setUserId(userId);
seKnowThumb.setCourseId(courseId);
QueryWrapper<SeKnowThumb> thumbQueryWrapper = new QueryWrapper<>(seKnowThumb);
SeKnowThumb oldSeKnowThumb = this.getOne(thumbQueryWrapper);
boolean result = false;
//已点赞
if (oldSeKnowThumb != null) {
// 取消点赞 删除记录
result = this.remove(thumbQueryWrapper);
if (result) {
System.out.println("取消点赞成功");
return result;
} else {
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
}
} else {
// 每个用户串行点赞
// 锁必须要包裹住事务方法
Lock lock = new ReentrantLock();
lock.lock();
try {
result = this.save(seKnowThumb);
} catch (Exception e) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
} finally {
lock.unlock();
System.out.println("点赞成功");
return result;
}
}
}
}

@ -0,0 +1,63 @@
package com.teaching.backend.service.impl.thumb;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teaching.backend.common.ErrorCode;
import com.teaching.backend.exception.BusinessException;
import com.teaching.backend.mapper.thumb.SeResourceThumbMapper;
import com.teaching.backend.model.entity.thumb.SeResourceThumb;
import com.teaching.backend.service.thumb.SeResourceThumbService;
import org.springframework.stereotype.Service;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* @Author:youhang
* @Date:2024-05-30-20:23
* @Description:
*/
@Service
public class SeResourceThumbServiceImpl extends ServiceImpl<SeResourceThumbMapper, SeResourceThumb> implements SeResourceThumbService {
@Override
public boolean doResourceThumb(String courseId, String resourceId, String userId) {
System.out.println("进入知识点点赞" + resourceId + userId);
// 先查询数据库记录,该用户是否点赞
SeResourceThumb seResourceThumb = new SeResourceThumb();
seResourceThumb.setResourceId(resourceId);
seResourceThumb.setUserId(userId);
seResourceThumb.setCourseId(courseId);
QueryWrapper<SeResourceThumb> thumbQueryWrapper = new QueryWrapper<>(seResourceThumb);
SeResourceThumb oldSeResourceThumb = this.getOne(thumbQueryWrapper);
boolean result = false;
//已点赞
if (oldSeResourceThumb != null) {
// 取消点赞 删除记录
result = this.remove(thumbQueryWrapper);
if (result) {
System.out.println("取消点赞成功");
return result;
} else {
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
}
} else {
// 每个用户串行点赞
// 锁必须要包裹住事务方法
Lock lock = new ReentrantLock();
lock.lock();
try {
result = this.save(seResourceThumb);
} catch (Exception e) {
throw new BusinessException(ErrorCode.OPERATION_ERROR);
} finally {
lock.unlock();
System.out.println("点赞成功");
return result;
}
}
}
}

@ -1,9 +0,0 @@
package com.teaching.backend.service;
/**
* @Author:youhang
* @Date:2024-05-30-18:20
* @Description:
*/
public class test1 {
}

@ -0,0 +1,40 @@
package com.teaching.backend.service.thumb;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.thumb.SeCourseThumb;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
public interface SeCourseThumbService extends IService<SeCourseThumb> {
/**
* 点赞
*
* @param courseId
* @param userId
* @return
*/
boolean doCourseThumb(String courseId, String userId);
/**
* 点赞总数
*
* @param courseId
* @return
*/
long thumbCount(String courseId);
/**
* 课程下资源和知识点的点赞总数
*
* @param courseId
* @return
*/
long courseCount(String courseId);
}

@ -0,0 +1,22 @@
package com.teaching.backend.service.thumb;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.thumb.SeKnowThumb;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
public interface SeKnowThumbService extends IService<SeKnowThumb> {
/**
* 点赞
*
* @param courseId
* @param userId
* @return
*/
boolean doKnowThumb(String courseId, String resourceId, String userId);
}

@ -0,0 +1,22 @@
package com.teaching.backend.service.thumb;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.thumb.SeResourceThumb;
/**
* @Author:youhang
* @Date:2024-05-30-20:22
* @Description:
*/
public interface SeResourceThumbService extends IService<SeResourceThumb> {
/**
* 点赞
*
* @param courseId
* @param userId
* @return
*/
boolean doResourceThumb(String courseId, String resourceId, String userId);
}

@ -13,4 +13,20 @@ spring:
password: root
mybatis:
configuration:
map-underscore-to-camel-case: true
map-underscore-to-camel-case: true
mapper-locations:
- classpath:dao/*.xml
- classpath*:com/**/mapper/*.xml
# 接口文档配置
knife4j:
enable: true
openapi:
title: "接口文档"
version: 1.0
group:
default:
api-rule: package
api-rule-resources:
- com.teaching.backend.controller

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.teaching.backend.mapper.thumb.SeCourseThumbMapper">
<resultMap id="BaseResultMap" type="com.teaching.backend.model.entity.thumb.SeCourseThumb">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="courseId" column="course_id" jdbcType="BIGINT"/>
<result property="userId" column="user_id" jdbcType="BIGINT"/>
</resultMap>
<sql id="Base_Column_List">
id
,courseId,
userId
</sql>
</mapper>
Loading…
Cancel
Save