diff --git a/src/main/java/io/github/xxyopen/novel/controller/front/BookController.java b/src/main/java/io/github/xxyopen/novel/controller/front/BookController.java index 29ddca1..a4e4f2e 100644 --- a/src/main/java/io/github/xxyopen/novel/controller/front/BookController.java +++ b/src/main/java/io/github/xxyopen/novel/controller/front/BookController.java @@ -2,7 +2,8 @@ package io.github.xxyopen.novel.controller.front; import io.github.xxyopen.novel.core.constant.ApiRouterConsts; import io.github.xxyopen.novel.core.common.resp.RestResp; -import io.github.xxyopen.novel.dto.resp.BookContentRespDto; +import io.github.xxyopen.novel.dto.resp.BookChapterAboutRespDto; +import io.github.xxyopen.novel.dto.resp.BookContentAboutRespDto; import io.github.xxyopen.novel.dto.resp.BookInfoRespDto; import io.github.xxyopen.novel.dto.resp.BookRankRespDto; import io.github.xxyopen.novel.service.BookService; @@ -36,11 +37,19 @@ public class BookController { } /** - * 小说章节内容查询接口 + * 小说最新章节相关信息查询接口 + * */ + @GetMapping("lastChapterAbout") + public RestResp getLastChapterAbout(Long bookId){ + return bookService.getLastChapterAbout(bookId); + } + + /** + * 小说内容相关信息查询接口 * */ @GetMapping("content/{chapterId}") - public RestResp getBookContent(@PathVariable("chapterId") Long chapterId){ - return bookService.getBookContent(chapterId); + public RestResp getBookContentAbout(@PathVariable("chapterId") Long chapterId){ + return bookService.getBookContentAbout(chapterId); } /** diff --git a/src/main/java/io/github/xxyopen/novel/dto/resp/BookChapterAboutRespDto.java b/src/main/java/io/github/xxyopen/novel/dto/resp/BookChapterAboutRespDto.java new file mode 100644 index 0000000..50b87c8 --- /dev/null +++ b/src/main/java/io/github/xxyopen/novel/dto/resp/BookChapterAboutRespDto.java @@ -0,0 +1,28 @@ +package io.github.xxyopen.novel.dto.resp; + +import lombok.Builder; +import lombok.Data; + +/** + * 小说章节相关 响应DTO + * + * @author xiongxiaoyang + * @date 2022/5/15 + */ +@Data +@Builder +public class BookChapterAboutRespDto { + + private BookChapterRespDto chapterInfo; + + /** + * 章节总数 + */ + private Long chapterTotal; + + /** + * 内容概要(30字) + */ + private String contentSummary; + +} diff --git a/src/main/java/io/github/xxyopen/novel/dto/resp/BookChapterRespDto.java b/src/main/java/io/github/xxyopen/novel/dto/resp/BookChapterRespDto.java index ebe2da4..cc7ce21 100644 --- a/src/main/java/io/github/xxyopen/novel/dto/resp/BookChapterRespDto.java +++ b/src/main/java/io/github/xxyopen/novel/dto/resp/BookChapterRespDto.java @@ -10,6 +10,7 @@ import java.time.LocalDateTime; /** * 小说章节 响应DTO + * * @author xiongxiaoyang * @date 2022/5/15 */ @@ -20,6 +21,11 @@ public class BookChapterRespDto implements Serializable { @Serial private static final long serialVersionUID = 1L; + /** + * 章节ID + * */ + private Long id; + /** * 小说ID */ @@ -37,13 +43,8 @@ public class BookChapterRespDto implements Serializable { /** * 章节更新时间 - * */ + */ @JsonFormat(pattern = "yyyy/MM/dd HH:dd") private LocalDateTime chapterUpdateTime; - /** - * 内容概要(20字) - */ - private String contentSummary; - } diff --git a/src/main/java/io/github/xxyopen/novel/dto/resp/BookContentAboutRespDto.java b/src/main/java/io/github/xxyopen/novel/dto/resp/BookContentAboutRespDto.java new file mode 100644 index 0000000..bb8c01c --- /dev/null +++ b/src/main/java/io/github/xxyopen/novel/dto/resp/BookContentAboutRespDto.java @@ -0,0 +1,31 @@ +package io.github.xxyopen.novel.dto.resp; + +import lombok.Builder; +import lombok.Data; + +/** + * 小说内容相关 响应DTO + * + * @author xiongxiaoyang + * @date 2022/5/15 + */ +@Data +@Builder +public class BookContentAboutRespDto { + + /** + * 小说信息 + */ + private BookInfoRespDto bookInfo; + + /** + * 章节信息 + */ + private BookChapterRespDto chapterInfo; + + /** + * 章节内容 + */ + private String bookContent; + +} diff --git a/src/main/java/io/github/xxyopen/novel/dto/resp/BookContentRespDto.java b/src/main/java/io/github/xxyopen/novel/dto/resp/BookContentRespDto.java deleted file mode 100644 index bb4b507..0000000 --- a/src/main/java/io/github/xxyopen/novel/dto/resp/BookContentRespDto.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.github.xxyopen.novel.dto.resp; - -import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 小说内容 响应DTO - * @author xiongxiaoyang - * @date 2022/5/15 - */ -@Data -@Builder -public class BookContentRespDto { - - /** - * 小说 ID - */ - private Long bookId; - - /** - * 类别ID - */ - private Long categoryId; - - /** - * 类别名 - */ - private String categoryName; - - /** - * 小说名 - */ - private String bookName; - - /** - * 作家id - */ - private Long authorId; - - /** - * 作家名 - */ - private String authorName; - - /** - * 章节名 - */ - private String chapterName; - - /** - * 章节字数 - */ - private Integer chapterWordCount; - - /** - * 章节更新时间 - * */ - @JsonFormat(pattern = "yyyy/MM/dd HH:dd") - private LocalDateTime chapterUpdateTime; - - /** - * 章节内容 - */ - private String content; - -} diff --git a/src/main/java/io/github/xxyopen/novel/dto/resp/BookInfoRespDto.java b/src/main/java/io/github/xxyopen/novel/dto/resp/BookInfoRespDto.java index e955c2a..51c1c52 100644 --- a/src/main/java/io/github/xxyopen/novel/dto/resp/BookInfoRespDto.java +++ b/src/main/java/io/github/xxyopen/novel/dto/resp/BookInfoRespDto.java @@ -5,6 +5,7 @@ import lombok.Data; /** * 小说信息 响应DTO + * * @author xiongxiaoyang * @date 2022/5/15 */ @@ -74,7 +75,7 @@ public class BookInfoRespDto { /** * 首章节ID - * */ + */ private Long firstChapterId; /** diff --git a/src/main/java/io/github/xxyopen/novel/manager/BookChapterCacheManager.java b/src/main/java/io/github/xxyopen/novel/manager/BookChapterCacheManager.java index d8296d8..28f0ff5 100644 --- a/src/main/java/io/github/xxyopen/novel/manager/BookChapterCacheManager.java +++ b/src/main/java/io/github/xxyopen/novel/manager/BookChapterCacheManager.java @@ -28,6 +28,7 @@ public class BookChapterCacheManager { public BookChapterRespDto getChapter(Long chapterId) { BookChapter bookChapter = bookChapterMapper.selectById(chapterId); return BookChapterRespDto.builder() + .id(chapterId) .bookId(bookChapter.getBookId()) .chapterName(bookChapter.getChapterName()) .chapterWordCount(bookChapter.getWordCount()) diff --git a/src/main/java/io/github/xxyopen/novel/service/BookService.java b/src/main/java/io/github/xxyopen/novel/service/BookService.java index c28a018..aa39f15 100644 --- a/src/main/java/io/github/xxyopen/novel/service/BookService.java +++ b/src/main/java/io/github/xxyopen/novel/service/BookService.java @@ -1,7 +1,8 @@ package io.github.xxyopen.novel.service; import io.github.xxyopen.novel.core.common.resp.RestResp; -import io.github.xxyopen.novel.dto.resp.BookContentRespDto; +import io.github.xxyopen.novel.dto.resp.BookChapterAboutRespDto; +import io.github.xxyopen.novel.dto.resp.BookContentAboutRespDto; import io.github.xxyopen.novel.dto.resp.BookInfoRespDto; import io.github.xxyopen.novel.dto.resp.BookRankRespDto; @@ -36,7 +37,12 @@ public interface BookService { RestResp getBookById(Long bookId); /** - * 小说章节内容查询 + * 小说内容相关信息查询 * */ - RestResp getBookContent(Long chapterId); + RestResp getBookContentAbout(Long chapterId); + + /** + * 小说最新章节相关信息查询 + * */ + RestResp getLastChapterAbout(Long bookId); } diff --git a/src/main/java/io/github/xxyopen/novel/service/impl/BookServiceImpl.java b/src/main/java/io/github/xxyopen/novel/service/impl/BookServiceImpl.java index 0793d71..0f11fb2 100644 --- a/src/main/java/io/github/xxyopen/novel/service/impl/BookServiceImpl.java +++ b/src/main/java/io/github/xxyopen/novel/service/impl/BookServiceImpl.java @@ -1,11 +1,10 @@ package io.github.xxyopen.novel.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.github.xxyopen.novel.core.common.resp.RestResp; +import io.github.xxyopen.novel.dao.entity.BookChapter; import io.github.xxyopen.novel.dao.mapper.BookChapterMapper; -import io.github.xxyopen.novel.dto.resp.BookChapterRespDto; -import io.github.xxyopen.novel.dto.resp.BookContentRespDto; -import io.github.xxyopen.novel.dto.resp.BookInfoRespDto; -import io.github.xxyopen.novel.dto.resp.BookRankRespDto; +import io.github.xxyopen.novel.dto.resp.*; import io.github.xxyopen.novel.manager.BookChapterCacheManager; import io.github.xxyopen.novel.manager.BookContentCacheManager; import io.github.xxyopen.novel.manager.BookInfoCacheManager; @@ -57,28 +56,45 @@ public class BookServiceImpl implements BookService { } @Override - public RestResp getBookContent(Long chapterId) { + public RestResp getLastChapterAbout(Long bookId) { + // 查询小说信息 + BookInfoRespDto bookInfo = bookInfoCacheManager.getBookInfo(bookId); + + // 查询最新章节信息 + BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(bookInfo.getLastChapterId()); + + // 查询章节内容 + String content = bookContentCacheManager.getBookContent(bookInfo.getLastChapterId()); + + // 查询章节总数 + QueryWrapper chapterQueryWrapper = new QueryWrapper<>(); + chapterQueryWrapper.eq("book_id", bookId); + Long chapterTotal = bookChapterMapper.selectCount(chapterQueryWrapper); + + // 组装数据并返回 + return RestResp.ok(BookChapterAboutRespDto.builder() + .chapterInfo(bookChapter) + .chapterTotal(chapterTotal) + .contentSummary(content.substring(0, 30)) + .build()); + } + + @Override + public RestResp getBookContentAbout(Long chapterId) { // 查询章节信息 BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(chapterId); // 查询章节内容 - String content = bookContentCacheManager.getBookContent(chapterId); + String content = bookContentCacheManager.getBookContent(chapterId); // 查询小说信息 BookInfoRespDto bookInfo = bookInfoCacheManager.getBookInfo(bookChapter.getBookId()); // 组装数据并返回 - return RestResp.ok(BookContentRespDto.builder() - .authorId(bookInfo.getAuthorId()) - .bookName(bookInfo.getBookName()) - .authorName(bookInfo.getAuthorName()) - .bookId(bookInfo.getId()) - .content(content) - .categoryId(bookInfo.getCategoryId()) - .categoryName(bookInfo.getCategoryName()) - .chapterName(bookChapter.getChapterName()) - .chapterUpdateTime(bookChapter.getChapterUpdateTime()) - .chapterWordCount(bookChapter.getChapterWordCount()) - .build()); + return RestResp.ok(BookContentAboutRespDto.builder() + .bookInfo(bookInfo) + .chapterInfo(bookChapter) + .bookContent(content) + .build()); } }