mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
feat: 新增小说最新章节相关信息查询接口
This commit is contained in:
parent
5d00606228
commit
2dbcd3f701
@ -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.constant.ApiRouterConsts;
|
||||||
import io.github.xxyopen.novel.core.common.resp.RestResp;
|
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.BookInfoRespDto;
|
||||||
import io.github.xxyopen.novel.dto.resp.BookRankRespDto;
|
import io.github.xxyopen.novel.dto.resp.BookRankRespDto;
|
||||||
import io.github.xxyopen.novel.service.BookService;
|
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}")
|
@GetMapping("content/{chapterId}")
|
||||||
public RestResp<BookContentRespDto> getBookContent(@PathVariable("chapterId") Long chapterId){
|
public RestResp<BookContentAboutRespDto> getBookContentAbout(@PathVariable("chapterId") Long chapterId){
|
||||||
return bookService.getBookContent(chapterId);
|
return bookService.getBookContentAbout(chapterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -10,6 +10,7 @@ import java.time.LocalDateTime;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说章节 响应DTO
|
* 小说章节 响应DTO
|
||||||
|
*
|
||||||
* @author xiongxiaoyang
|
* @author xiongxiaoyang
|
||||||
* @date 2022/5/15
|
* @date 2022/5/15
|
||||||
*/
|
*/
|
||||||
@ -20,6 +21,11 @@ public class BookChapterRespDto implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 章节ID
|
||||||
|
* */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说ID
|
* 小说ID
|
||||||
*/
|
*/
|
||||||
@ -37,13 +43,8 @@ public class BookChapterRespDto implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 章节更新时间
|
* 章节更新时间
|
||||||
* */
|
*/
|
||||||
@JsonFormat(pattern = "yyyy/MM/dd HH:dd")
|
@JsonFormat(pattern = "yyyy/MM/dd HH:dd")
|
||||||
private LocalDateTime chapterUpdateTime;
|
private LocalDateTime chapterUpdateTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 内容概要(20字)
|
|
||||||
*/
|
|
||||||
private String contentSummary;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
@ -5,6 +5,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说信息 响应DTO
|
* 小说信息 响应DTO
|
||||||
|
*
|
||||||
* @author xiongxiaoyang
|
* @author xiongxiaoyang
|
||||||
* @date 2022/5/15
|
* @date 2022/5/15
|
||||||
*/
|
*/
|
||||||
@ -74,7 +75,7 @@ public class BookInfoRespDto {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 首章节ID
|
* 首章节ID
|
||||||
* */
|
*/
|
||||||
private Long firstChapterId;
|
private Long firstChapterId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +28,7 @@ public class BookChapterCacheManager {
|
|||||||
public BookChapterRespDto getChapter(Long chapterId) {
|
public BookChapterRespDto getChapter(Long chapterId) {
|
||||||
BookChapter bookChapter = bookChapterMapper.selectById(chapterId);
|
BookChapter bookChapter = bookChapterMapper.selectById(chapterId);
|
||||||
return BookChapterRespDto.builder()
|
return BookChapterRespDto.builder()
|
||||||
|
.id(chapterId)
|
||||||
.bookId(bookChapter.getBookId())
|
.bookId(bookChapter.getBookId())
|
||||||
.chapterName(bookChapter.getChapterName())
|
.chapterName(bookChapter.getChapterName())
|
||||||
.chapterWordCount(bookChapter.getWordCount())
|
.chapterWordCount(bookChapter.getWordCount())
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package io.github.xxyopen.novel.service;
|
package io.github.xxyopen.novel.service;
|
||||||
|
|
||||||
import io.github.xxyopen.novel.core.common.resp.RestResp;
|
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.BookInfoRespDto;
|
||||||
import io.github.xxyopen.novel.dto.resp.BookRankRespDto;
|
import io.github.xxyopen.novel.dto.resp.BookRankRespDto;
|
||||||
|
|
||||||
@ -36,7 +37,12 @@ public interface BookService {
|
|||||||
RestResp<BookInfoRespDto> getBookById(Long bookId);
|
RestResp<BookInfoRespDto> getBookById(Long bookId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说章节内容查询
|
* 小说内容相关信息查询
|
||||||
* */
|
* */
|
||||||
RestResp<BookContentRespDto> getBookContent(Long chapterId);
|
RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小说最新章节相关信息查询
|
||||||
|
* */
|
||||||
|
RestResp<BookChapterAboutRespDto> getLastChapterAbout(Long bookId);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package io.github.xxyopen.novel.service.impl;
|
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.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.dao.mapper.BookChapterMapper;
|
||||||
import io.github.xxyopen.novel.dto.resp.BookChapterRespDto;
|
import io.github.xxyopen.novel.dto.resp.*;
|
||||||
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.manager.BookChapterCacheManager;
|
import io.github.xxyopen.novel.manager.BookChapterCacheManager;
|
||||||
import io.github.xxyopen.novel.manager.BookContentCacheManager;
|
import io.github.xxyopen.novel.manager.BookContentCacheManager;
|
||||||
import io.github.xxyopen.novel.manager.BookInfoCacheManager;
|
import io.github.xxyopen.novel.manager.BookInfoCacheManager;
|
||||||
@ -57,28 +56,45 @@ public class BookServiceImpl implements BookService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(chapterId);
|
||||||
|
|
||||||
// 查询章节内容
|
// 查询章节内容
|
||||||
String content = bookContentCacheManager.getBookContent(chapterId);
|
String content = bookContentCacheManager.getBookContent(chapterId);
|
||||||
|
|
||||||
// 查询小说信息
|
// 查询小说信息
|
||||||
BookInfoRespDto bookInfo = bookInfoCacheManager.getBookInfo(bookChapter.getBookId());
|
BookInfoRespDto bookInfo = bookInfoCacheManager.getBookInfo(bookChapter.getBookId());
|
||||||
|
|
||||||
// 组装数据并返回
|
// 组装数据并返回
|
||||||
return RestResp.ok(BookContentRespDto.builder()
|
return RestResp.ok(BookContentAboutRespDto.builder()
|
||||||
.authorId(bookInfo.getAuthorId())
|
.bookInfo(bookInfo)
|
||||||
.bookName(bookInfo.getBookName())
|
.chapterInfo(bookChapter)
|
||||||
.authorName(bookInfo.getAuthorName())
|
.bookContent(content)
|
||||||
.bookId(bookInfo.getId())
|
.build());
|
||||||
.content(content)
|
|
||||||
.categoryId(bookInfo.getCategoryId())
|
|
||||||
.categoryName(bookInfo.getCategoryName())
|
|
||||||
.chapterName(bookChapter.getChapterName())
|
|
||||||
.chapterUpdateTime(bookChapter.getChapterUpdateTime())
|
|
||||||
.chapterWordCount(bookChapter.getChapterWordCount())
|
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user