diff --git a/src/main/java/com/guwan/backend/common/Result.java b/src/main/java/com/guwan/backend/common/Result.java index c90bce5..fce4ddb 100644 --- a/src/main/java/com/guwan/backend/common/Result.java +++ b/src/main/java/com/guwan/backend/common/Result.java @@ -10,6 +10,7 @@ public class Result { private Integer code; private String message; private T data; + private Long nums; private String time; public Result() { diff --git a/src/main/java/com/guwan/backend/config/MybatisPlusConfig.java b/src/main/java/com/guwan/backend/config/MybatisPlusConfig.java index 4eb163b..19006d4 100644 --- a/src/main/java/com/guwan/backend/config/MybatisPlusConfig.java +++ b/src/main/java/com/guwan/backend/config/MybatisPlusConfig.java @@ -1,6 +1,9 @@ package com.guwan.backend.config; +import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.guwan.backend.Handler.MyMetaObjectHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -20,4 +23,15 @@ public class MybatisPlusConfig { return new MyMetaObjectHandler(); } + //mybatisplus分页流程为:全量查询 =》本地分页 + // 而如果不对查询结果进行拦截,mybatis将不能执行分页操作,自然也拿不到页数和总数的数据了。 + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + //创建拦截器,对执行的sql进行拦截 + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + //对Mysql拦截 + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } + } \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/constant/CacheConstants.java b/src/main/java/com/guwan/backend/constant/CacheConstants.java index 1c1751b..fa79ed0 100644 --- a/src/main/java/com/guwan/backend/constant/CacheConstants.java +++ b/src/main/java/com/guwan/backend/constant/CacheConstants.java @@ -8,16 +8,13 @@ import java.util.List; public class CacheConstants { /** - * API接口白名单 - * 这些路径可以直接访问,不需要认证 + * + * 缓存内容 */ public static final List CACHE_LIST = List.of( "userCache" ); - /** - * 静态资源白名单 - * 这些路径用于访问静态资源,不需要认证 - */ + } \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/controller/BookCategoryController.java b/src/main/java/com/guwan/backend/controller/BookCategoryController.java deleted file mode 100644 index d43a677..0000000 --- a/src/main/java/com/guwan/backend/controller/BookCategoryController.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.guwan.backend.controller; - -import com.guwan.backend.common.BusinessException; -import com.guwan.backend.common.Result; -import com.guwan.backend.pojo.entity.BookCategory; -import com.guwan.backend.service.BookCategoryService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.web.bind.annotation.*; - -/** - * (BookCategory)表控制层 - * - * @author makejava - * @since 2024-12-20 17:44:07 - */ -@RestController -@RequestMapping("bookCategory") -public class BookCategoryController { - /** - * 服务对象 - */ - @Autowired - private BookCategoryService bookCategoryService; - - /** - * 分页查询 - * - * @param bookCategory 筛选条件 - * @param pageRequest 分页对象 - * @return 查询结果 - */ - @GetMapping - public Result> queryByPage(BookCategory bookCategory, PageRequest pageRequest) { - // return Result.success(this.bookCategoryService.queryByPage(bookCategory, pageRequest)); - - return Result.success(); - - } - - /** - * 通过主键查询单条数据 - * - * @param id 主键 - * @return 单条数据 - */ - @GetMapping("{id}") - public Result queryById(@PathVariable("id") Integer id) { - return Result.success(bookCategoryService.getById(id)); - } - - /** - * 新增数据 - * - * @param bookCategory 实体 - * @return 新增结果 - */ - @PostMapping - public Result add(BookCategory bookCategory) { - - if (bookCategoryService.lambdaQuery() - .eq(BookCategory::getCategoryName, bookCategory.getCategoryName()).one() != null){ - throw new BusinessException("该图书种类已经存在"); - } - - if (bookCategoryService.save(bookCategory)) { - return Result.success(); - }else { - return Result.error("保存失败"); - } - - } - - /** - * 编辑数据 - * - * @param bookCategory 实体 - * @return 编辑结果 - */ - @PutMapping - public Result edit(BookCategory bookCategory) { - //return Result.success(this.bookCategoryService.update(bookCategory)); - return Result.success(); - } - - /** - * 删除数据 - * - * @param id 主键 - * @return 删除是否成功 - */ - @DeleteMapping - public Result deleteById(Integer id) { - bookCategoryService.removeById(id); - return Result.success(); - } - -} - diff --git a/src/main/java/com/guwan/backend/controller/ReadingNoteController.java b/src/main/java/com/guwan/backend/controller/ReadingNoteController.java deleted file mode 100644 index 7257180..0000000 --- a/src/main/java/com/guwan/backend/controller/ReadingNoteController.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.guwan.backend.controller; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.guwan.backend.common.Result; -import com.guwan.backend.pojo.entity.ReadingNote; -import com.guwan.backend.service.ReadingNoteService; -import com.guwan.backend.util.SecurityUtil; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; - -@Slf4j -@Tag(name = "阅读笔记", description = "阅读笔记相关接口") -@RestController -@RequestMapping("/api/reading-notes") -@RequiredArgsConstructor -public class ReadingNoteController { - - private final ReadingNoteService noteService; - private final SecurityUtil securityUtil; - - @Operation(summary = "添加笔记") - @PostMapping - public Result addNote(@RequestBody ReadingNote note) { - try { - note.setUserId(securityUtil.getCurrentUserId()); - return Result.success(noteService.addNote(note)); - } catch (Exception e) { - log.error("添加笔记失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "更新笔记") - @PutMapping("/{id}") - public Result updateNote(@PathVariable Long id, @RequestBody ReadingNote note) { - try { - note.setId(id); - note.setUserId(securityUtil.getCurrentUserId()); - return Result.success(noteService.updateNote(note)); - } catch (Exception e) { - log.error("更新笔记失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "删除笔记") - @DeleteMapping("/{id}") - public Result deleteNote(@PathVariable Long id) { - try { - noteService.deleteNote(id); - return Result.success(); - } catch (Exception e) { - log.error("删除笔记失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取笔记详情") - @GetMapping("/{id}") - public Result getNote(@PathVariable Long id) { - try { - return Result.success(noteService.getNoteById(id)); - } catch (Exception e) { - log.error("获取笔记详情失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取用户的所有笔记") - @GetMapping - public Result> getUserNotes( - @RequestParam(defaultValue = "1") Integer pageNum, - @RequestParam(defaultValue = "10") Integer pageSize) { - try { - Long userId = securityUtil.getCurrentUserId(); - return Result.success(noteService.getUserNotes(userId, pageNum, pageSize)); - } catch (Exception e) { - log.error("获取用户笔记失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取书籍的所有公开笔记") - @GetMapping("/book/{bookId}") - public Result> getBookNotes( - @PathVariable Long bookId, - @RequestParam(defaultValue = "1") Integer pageNum, - @RequestParam(defaultValue = "10") Integer pageSize) { - try { - return Result.success(noteService.getBookNotes(bookId, pageNum, pageSize)); - } catch (Exception e) { - log.error("获取书籍笔记失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取用户在特定书籍上的笔记") - @GetMapping("/book/{bookId}/my") - public Result> getUserBookNotes( - @PathVariable Long bookId, - @RequestParam(defaultValue = "1") Integer pageNum, - @RequestParam(defaultValue = "10") Integer pageSize) { - try { - Long userId = securityUtil.getCurrentUserId(); - return Result.success(noteService.getUserBookNotes(userId, bookId, pageNum, pageSize)); - } catch (Exception e) { - log.error("获取用户书籍笔记失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取所有公开笔记") - @GetMapping("/public") - public Result> getPublicNotes( - @RequestParam(defaultValue = "1") Integer pageNum, - @RequestParam(defaultValue = "10") Integer pageSize) { - try { - return Result.success(noteService.getPublicNotes(pageNum, pageSize)); - } catch (Exception e) { - log.error("获取公开笔记失败", e); - return Result.error(e.getMessage()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/controller/ReadingProgressController.java b/src/main/java/com/guwan/backend/controller/ReadingProgressController.java deleted file mode 100644 index 6eadf01..0000000 --- a/src/main/java/com/guwan/backend/controller/ReadingProgressController.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.guwan.backend.controller; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.guwan.backend.common.Result; -import com.guwan.backend.pojo.dto.ReadingStatistics; -import com.guwan.backend.pojo.entity.ReadingProgress; -import com.guwan.backend.service.ReadingProgressService; -import com.guwan.backend.util.SecurityUtil; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; - -@Slf4j -@Tag(name = "阅读进度", description = "阅读进度相关接口") -@RestController -@RequestMapping("/api/reading-progress") -@RequiredArgsConstructor -public class ReadingProgressController { - - private final ReadingProgressService progressService; - private final SecurityUtil securityUtil; - - @Operation(summary = "更新阅读进度") - @PostMapping - public Result updateProgress(@RequestBody ReadingProgress progress) { - try { - progress.setUserId(securityUtil.getCurrentUserId()); - return Result.success(progressService.updateProgress(progress)); - } catch (Exception e) { - log.error("更新阅读进度失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取书籍阅读进度") - @GetMapping("/book/{bookId}") - public Result getProgress(@PathVariable Long bookId) { - try { - Long userId = securityUtil.getCurrentUserId(); - return Result.success(progressService.getProgress(userId, bookId)); - } catch (Exception e) { - log.error("获取阅读进度失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取用户的所有阅读进度") - @GetMapping - public Result> getUserProgress( - @RequestParam(defaultValue = "1") Integer pageNum, - @RequestParam(defaultValue = "10") Integer pageSize) { - try { - Long userId = securityUtil.getCurrentUserId(); - return Result.success(progressService.getUserProgress(userId, pageNum, pageSize)); - } catch (Exception e) { - log.error("获取用户阅读进度失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取特定状态的书籍") - @GetMapping("/status/{status}") - public Result> getProgressByStatus( - @PathVariable String status, - @RequestParam(defaultValue = "1") Integer pageNum, - @RequestParam(defaultValue = "10") Integer pageSize) { - try { - Long userId = securityUtil.getCurrentUserId(); - return Result.success(progressService.getProgressByStatus(userId, status, pageNum, pageSize)); - } catch (Exception e) { - log.error("获取阅读状态失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "更新阅读时长") - @PostMapping("/{bookId}/reading-time") - public Result updateReadingTime( - @PathVariable Long bookId, - @RequestParam Integer minutes) { - try { - Long userId = securityUtil.getCurrentUserId(); - progressService.updateReadingTime(userId, bookId, minutes); - return Result.success(); - } catch (Exception e) { - log.error("更新阅读时长失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取阅读统计") - @GetMapping("/statistics") - public Result getReadingStatistics() { - try { - Long userId = securityUtil.getCurrentUserId(); - return Result.success(progressService.getReadingStatistics(userId)); - } catch (Exception e) { - log.error("获取阅读统计失败", e); - return Result.error(e.getMessage()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/service/BookCategoryService.java b/src/main/java/com/guwan/backend/service/BookCategoryService.java deleted file mode 100644 index a344aaa..0000000 --- a/src/main/java/com/guwan/backend/service/BookCategoryService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.guwan.backend.service; - -import com.guwan.backend.pojo.entity.BookCategory; -import com.baomidou.mybatisplus.extension.service.IService; - -/** -* @author 12455 -* @description 针对表【book_category】的数据库操作Service -* @createDate 2024-12-20 17:04:09 -*/ -public interface BookCategoryService extends IService { - -} diff --git a/src/main/java/com/guwan/backend/service/impl/BookCategoryServiceImpl.java b/src/main/java/com/guwan/backend/service/impl/BookCategoryServiceImpl.java deleted file mode 100644 index 0881e53..0000000 --- a/src/main/java/com/guwan/backend/service/impl/BookCategoryServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.guwan.backend.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.guwan.backend.pojo.entity.BookCategory; -import com.guwan.backend.service.BookCategoryService; -import com.guwan.backend.mapper.BookCategoryMapper; -import org.springframework.stereotype.Service; - -/** -* @author 12455 -* @description 针对表【book_category】的数据库操作Service实现 -* @createDate 2024-12-20 17:04:09 -*/ -@Service -public class BookCategoryServiceImpl extends ServiceImpl - implements BookCategoryService{ - -} - - - -