|
|
@@ -21,6 +21,10 @@ import com.njuzr.eaibackend.vo.UserVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.CacheEvict;
|
|
|
+import org.springframework.cache.annotation.CachePut;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.cache.annotation.Caching;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -60,6 +64,7 @@ public class CourseServiceImpl implements CourseService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ @CacheEvict(value = "coursesPages", allEntries = true)
|
|
|
public CourseVO createCourse(CourseDTO courseDTO) {
|
|
|
// 类型转换
|
|
|
Course targetCourse = convertToPO(courseDTO);
|
|
|
@@ -77,12 +82,13 @@ public class CourseServiceImpl implements CourseService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ @Cacheable(value = "coursePages", key = "#page.getPages() + '_' + #page.getSize() + '_' + #courseQueryDTO.isEmpty()", unless = "#page.getSize() <= 1 || !#courseQueryDTO.isEmpty()")
|
|
|
public IPage<CourseVO> findCoursesPage(Page<Course> page, CourseQueryDTO courseQueryDTO) {
|
|
|
- log.info(courseQueryDTO.toString());
|
|
|
+ log.info("课程信息从数据库查询: {}", courseQueryDTO.toString());
|
|
|
+ log.info(String.valueOf(page.getSize() <= 1 || !courseQueryDTO.isEmpty()));
|
|
|
QueryWrapper<Course> wrapper = getCourseQueryWrapper(courseQueryDTO);
|
|
|
|
|
|
IPage<Course> courses = courseMapper.selectPage(page, wrapper);
|
|
|
- log.info(courses.getRecords().get(0).toString());
|
|
|
return PageMapperUtil.convert(courses, this::convertToVO);
|
|
|
}
|
|
|
|
|
|
@@ -148,6 +154,7 @@ public class CourseServiceImpl implements CourseService {
|
|
|
* @param courseUpdateDTO
|
|
|
*/
|
|
|
@Override
|
|
|
+ @CacheEvict(value = "coursePages", allEntries = true)
|
|
|
public CourseVO updateCourse(Long userId, Long courseId, CourseUpdateDTO courseUpdateDTO) {
|
|
|
User targetUser = userMapper.selectById(userId);
|
|
|
Course targetCourse = courseMapper.selectById(courseId);
|
|
|
@@ -182,6 +189,7 @@ public class CourseServiceImpl implements CourseService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @CacheEvict(value = "coursePages", allEntries = true)
|
|
|
public CourseVO updateCourseByPortal(Long userId, Long userPid, Long courseId, CourseUpdateDTO courseUpdateDTO) {
|
|
|
User targetUser;
|
|
|
if (userPid == null){
|
|
|
@@ -232,6 +240,7 @@ public class CourseServiceImpl implements CourseService {
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
+ @CacheEvict(value = "coursePages", allEntries = true)
|
|
|
public void deleteById(MyUserDetails user, Long courseId) {
|
|
|
Course course = courseMapper.selectById(courseId);
|
|
|
if (course == null) {
|