feat: 新增小说最新章节相关信息查询接口

This commit is contained in:
xiongxiaoyang 2022-05-15 18:04:17 +08:00
parent 5d00606228
commit 2dbcd3f701
9 changed files with 125 additions and 101 deletions

View File

@ -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<BookChapterAboutRespDto> getLastChapterAbout(Long bookId){
return bookService.getLastChapterAbout(bookId);
}
/**
* 小说内容相关信息查询接口
* */
@GetMapping("content/{chapterId}")
public RestResp<BookContentRespDto> getBookContent(@PathVariable("chapterId") Long chapterId){
return bookService.getBookContent(chapterId);
public RestResp<BookContentAboutRespDto> getBookContentAbout(@PathVariable("chapterId") Long chapterId){
return bookService.getBookContentAbout(chapterId);
}
/**

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
/**

View File

@ -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())

View File

@ -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<BookInfoRespDto> getBookById(Long bookId);
/**
* 小说章节内容查询
* 小说内容相关信息查询
* */
RestResp<BookContentRespDto> getBookContent(Long chapterId);
RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId);
/**
* 小说最新章节相关信息查询
* */
RestResp<BookChapterAboutRespDto> getLastChapterAbout(Long bookId);
}

View File

@ -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<BookContentRespDto> getBookContent(Long chapterId) {
public RestResp<BookChapterAboutRespDto> getLastChapterAbout(Long bookId) {
// 查询小说信息
BookInfoRespDto bookInfo = bookInfoCacheManager.getBookInfo(bookId);
// 查询最新章节信息
BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(bookInfo.getLastChapterId());
// 查询章节内容
String content = bookContentCacheManager.getBookContent(bookInfo.getLastChapterId());
// 查询章节总数
QueryWrapper<BookChapter> 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<BookContentAboutRespDto> 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());
}
}