From 06ef610424755d914df7c2392e26b4b6f1c7f152 Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <773861846@qq.com> Date: Mon, 16 May 2022 09:36:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=B0=8F=E8=AF=B4?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/front/BookController.java | 10 +++ .../novel/core/config/MybatisPlusConfig.java | 28 +++++++++ .../novel/dao/mapper/BookInfoMapper.java | 14 +++++ .../novel/dto/req/BookSearchReqDto.java | 63 +++++++++++++++++++ .../novel/dto/resp/BookInfoRespDto.java | 5 ++ .../xxyopen/novel/service/BookService.java | 28 +++++++++ .../xxyopen/novel/service/HomeService.java | 1 + .../xxyopen/novel/service/NewsService.java | 1 + .../novel/service/impl/BookServiceImpl.java | 23 +++++++ src/main/resources/mapper/BookInfoMapper.xml | 32 ++++++++++ 10 files changed, 205 insertions(+) create mode 100644 src/main/java/io/github/xxyopen/novel/core/config/MybatisPlusConfig.java create mode 100644 src/main/java/io/github/xxyopen/novel/dto/req/BookSearchReqDto.java 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 2605719..f4f8115 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 @@ -1,7 +1,9 @@ package io.github.xxyopen.novel.controller.front; +import io.github.xxyopen.novel.core.common.resp.PageRespDto; import io.github.xxyopen.novel.core.constant.ApiRouterConsts; import io.github.xxyopen.novel.core.common.resp.RestResp; +import io.github.xxyopen.novel.dto.req.BookSearchReqDto; import io.github.xxyopen.novel.dto.resp.*; import io.github.xxyopen.novel.service.BookService; import lombok.RequiredArgsConstructor; @@ -23,6 +25,14 @@ public class BookController { private final BookService bookService; + /** + * 小说搜索接口 + * */ + @GetMapping("search") + public RestResp> searchBooks(BookSearchReqDto condition){ + return bookService.searchBooks(condition); + } + /** * 小说信息查询接口 * */ diff --git a/src/main/java/io/github/xxyopen/novel/core/config/MybatisPlusConfig.java b/src/main/java/io/github/xxyopen/novel/core/config/MybatisPlusConfig.java new file mode 100644 index 0000000..1bc30cb --- /dev/null +++ b/src/main/java/io/github/xxyopen/novel/core/config/MybatisPlusConfig.java @@ -0,0 +1,28 @@ +package io.github.xxyopen.novel.core.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Mybatis-Plus 配置类 + * + * @author xiongxiaoyang + * @date 2022/5/16 + */ +@Configuration +public class MybatisPlusConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } + +} diff --git a/src/main/java/io/github/xxyopen/novel/dao/mapper/BookInfoMapper.java b/src/main/java/io/github/xxyopen/novel/dao/mapper/BookInfoMapper.java index 3b587c0..2284441 100644 --- a/src/main/java/io/github/xxyopen/novel/dao/mapper/BookInfoMapper.java +++ b/src/main/java/io/github/xxyopen/novel/dao/mapper/BookInfoMapper.java @@ -1,9 +1,14 @@ package io.github.xxyopen.novel.dao.mapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import io.github.xxyopen.novel.dao.entity.BookInfo; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.github.xxyopen.novel.dto.req.BookSearchReqDto; +import io.github.xxyopen.novel.dto.resp.BookInfoRespDto; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** *

* 小说信息 Mapper 接口 @@ -20,4 +25,13 @@ public interface BookInfoMapper extends BaseMapper { * @param bookId 小说ID */ void addVisitCount(@Param("bookId") Long bookId); + + /** + * 小说搜索 + * @param page mybatis-plus 分页对象 + * @param condition 搜索条件 + * @return 返回结果 + * */ + List searchBooks(IPage page, BookSearchReqDto condition); + } diff --git a/src/main/java/io/github/xxyopen/novel/dto/req/BookSearchReqDto.java b/src/main/java/io/github/xxyopen/novel/dto/req/BookSearchReqDto.java new file mode 100644 index 0000000..be78a96 --- /dev/null +++ b/src/main/java/io/github/xxyopen/novel/dto/req/BookSearchReqDto.java @@ -0,0 +1,63 @@ +package io.github.xxyopen.novel.dto.req; + +import io.github.xxyopen.novel.core.common.req.PageReqDto; +import lombok.Data; + +import java.util.Date; + +/** + * 小说搜索 请求DTO + * + * @author xiongxiaoyang + * @date 2022/5/16 + */ +@Data +public class BookSearchReqDto extends PageReqDto { + + /** + * 搜索关键字 + */ + private String keyword; + + /** + * 作品方向 + */ + private Byte workDirection; + + /** + * 分类ID + */ + private Integer categoryId; + + /** + * 是否收费,1:收费,0:免费 + */ + private Byte isVip; + + /** + * 小说更新状态,0:连载中,1:已完结 + */ + private Byte bookStatus; + + /** + * 字数最小值 + */ + private Integer wordCountMin; + + /** + * 字数最大值 + */ + private Integer wordCountMax; + + private Date updateTimeMin; + + /** + * 更新时间(单位:天) + */ + private Long updatePeriod; + + /** + * 排序字段 + */ + private String sort = "last_chapter_update_time desc"; +} 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 51c1c52..29fc925 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 @@ -83,5 +83,10 @@ public class BookInfoRespDto { */ private Long lastChapterId; + /** + * 最新章节名 + */ + private String lastChapterName; + } 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 b4f49db..422f68a 100644 --- a/src/main/java/io/github/xxyopen/novel/service/BookService.java +++ b/src/main/java/io/github/xxyopen/novel/service/BookService.java @@ -1,6 +1,8 @@ package io.github.xxyopen.novel.service; +import io.github.xxyopen.novel.core.common.resp.PageRespDto; import io.github.xxyopen.novel.core.common.resp.RestResp; +import io.github.xxyopen.novel.dto.req.BookSearchReqDto; import io.github.xxyopen.novel.dto.resp.*; import java.security.NoSuchAlgorithmException; @@ -14,58 +16,84 @@ import java.util.List; */ public interface BookService { + /** + * 小说搜索 + * @param condition 搜索条件 + * @return 搜索结果 + * */ + RestResp> searchBooks(BookSearchReqDto condition); + /** * 小说点击榜查询 + * @return 小说点击排行列表 * */ RestResp> listVisitRankBooks(); /** * 小说新书榜查询 + * @return 小说新书排行列表 * */ RestResp> listNewestRankBooks(); /** * 小说更新榜查询 + * @return 小说更新排行列表 * */ RestResp> listUpdateRankBooks(); /** * 小说信息查询 + * @param bookId 小说ID + * @return 小说信息 * */ RestResp getBookById(Long bookId); /** * 小说内容相关信息查询 + * @param chapterId 章节ID + * @return 内容相关联的信息 * */ RestResp getBookContentAbout(Long chapterId); /** * 小说最新章节相关信息查询 + * @param bookId 小说ID + * @return 章节相关联的信息 * */ RestResp getLastChapterAbout(Long bookId); /** * 小说推荐列表查询 + * @param bookId 小说ID + * @return 小说信息列表 * */ RestResp> listRecBooks(Long bookId) throws NoSuchAlgorithmException; /** * 增加小说点击量 + * @param bookId 小说ID + * @return 成功状态 * */ RestResp addVisitCount(Long bookId); /** * 获取上一章节ID + * @param chapterId 章节ID + * @return 上一章节ID * */ RestResp getPreChapterId(Long chapterId); /** * 获取下一章节ID + * @param chapterId 章节ID + * @return 下一章节ID * */ RestResp nextChapterId(Long chapterId); /** * 小说章节列表查询 + * @param bookId 小说ID + * @return 小说章节列表 * */ RestResp> listChapters(Long bookId); } diff --git a/src/main/java/io/github/xxyopen/novel/service/HomeService.java b/src/main/java/io/github/xxyopen/novel/service/HomeService.java index 53baed5..027473a 100644 --- a/src/main/java/io/github/xxyopen/novel/service/HomeService.java +++ b/src/main/java/io/github/xxyopen/novel/service/HomeService.java @@ -23,6 +23,7 @@ public interface HomeService { /** * 首页友情链接列表查询 + * @return 友情链接列表 * */ RestResp> listHomeFriendLinks(); } diff --git a/src/main/java/io/github/xxyopen/novel/service/NewsService.java b/src/main/java/io/github/xxyopen/novel/service/NewsService.java index c469273..4f4b5aa 100644 --- a/src/main/java/io/github/xxyopen/novel/service/NewsService.java +++ b/src/main/java/io/github/xxyopen/novel/service/NewsService.java @@ -15,6 +15,7 @@ public interface NewsService { /** * 最新新闻列表查询 + * @return 新闻列表 * */ RestResp> listLatestNews(); } 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 1b7807f..5c6f467 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,15 @@ package io.github.xxyopen.novel.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.github.xxyopen.novel.core.common.resp.PageRespDto; import io.github.xxyopen.novel.core.common.resp.RestResp; import io.github.xxyopen.novel.core.constant.DatabaseConsts; import io.github.xxyopen.novel.dao.entity.BookChapter; +import io.github.xxyopen.novel.dao.entity.BookInfo; import io.github.xxyopen.novel.dao.mapper.BookChapterMapper; import io.github.xxyopen.novel.dao.mapper.BookInfoMapper; +import io.github.xxyopen.novel.dto.req.BookSearchReqDto; import io.github.xxyopen.novel.dto.resp.*; import io.github.xxyopen.novel.manager.BookChapterCacheManager; import io.github.xxyopen.novel.manager.BookContentCacheManager; @@ -48,6 +52,25 @@ public class BookServiceImpl implements BookService { private static final Integer REC_BOOK_COUNT = 4; + @Override + public RestResp> searchBooks(BookSearchReqDto condition) { + Page page = new Page<>(); + page.setCurrent(condition.getPageNum()); + page.setSize(condition.getPageSize()); + List bookInfos = bookInfoMapper.searchBooks(page, condition); + return RestResp.ok(PageRespDto.of(condition.getPageNum(),condition.getPageSize(),page.getTotal() + ,bookInfos.stream().map(v -> BookInfoRespDto.builder() + .id(v.getId()) + .bookName(v.getBookName()) + .categoryId(v.getCategoryId()) + .categoryName(v.getCategoryName()) + .authorId(v.getAuthorId()) + .authorName(v.getAuthorName()) + .wordCount(v.getWordCount()) + .lastChapterName(v.getLastChapterName()) + .build()).toList())); + } + @Override public RestResp> listVisitRankBooks() { return RestResp.ok(bookRankCacheManager.listVisitRankBooks()); diff --git a/src/main/resources/mapper/BookInfoMapper.xml b/src/main/resources/mapper/BookInfoMapper.xml index d1b6cca..b99c98f 100644 --- a/src/main/resources/mapper/BookInfoMapper.xml +++ b/src/main/resources/mapper/BookInfoMapper.xml @@ -2,6 +2,38 @@ + + update book_info set visit_count = visit_count + 1