feat: 新增小说类别查询接口 & 修复小说搜索接口

This commit is contained in:
xiongxiaoyang 2022-05-16 18:04:58 +08:00
parent 2271eac6c0
commit 6d02b77aa5
9 changed files with 135 additions and 16 deletions

View File

@ -25,6 +25,14 @@ public class BookController {
private final BookService bookService; private final BookService bookService;
/**
* 小说分类列表查询接口
*/
@GetMapping("categoryList")
public RestResp<List<BookCategoryRespDto>> listCategory(Integer workDirection) {
return bookService.listCategory(workDirection);
}
/** /**
* 小说搜索接口 * 小说搜索接口
*/ */

View File

@ -54,6 +54,11 @@ public class CacheConsts {
*/ */
public static final String HOME_FRIEND_LINK_CACHE_NAME = "homeFriendLinkCache"; public static final String HOME_FRIEND_LINK_CACHE_NAME = "homeFriendLinkCache";
/**
* 小说分类列表缓存
* */
public static final String BOOK_CATEGORY_LIST_CACHE_NAME = "bookCategoryListCache";
/** /**
* 小说信息缓存 * 小说信息缓存
*/ */
@ -92,6 +97,8 @@ public class CacheConsts {
HOME_FRIEND_LINK_CACHE(2, HOME_FRIEND_LINK_CACHE_NAME, 0, 1), HOME_FRIEND_LINK_CACHE(2, HOME_FRIEND_LINK_CACHE_NAME, 0, 1),
BOOK_CATEGORY_LIST_CACHE(0,BOOK_CATEGORY_LIST_CACHE_NAME,0,2),
BOOK_INFO_CACHE(0, BOOK_INFO_CACHE_NAME, 60 * 60 * 18, 500), BOOK_INFO_CACHE(0, BOOK_INFO_CACHE_NAME, 60 * 60 * 18, 500),
BOOK_CHAPTER_CACHE(0,BOOK_CHAPTER_CACHE_NAME,60 * 60 * 6,5000), BOOK_CHAPTER_CACHE(0,BOOK_CHAPTER_CACHE_NAME,60 * 60 * 6,5000),

View File

@ -10,6 +10,26 @@ import lombok.Getter;
*/ */
public class DatabaseConsts { public class DatabaseConsts {
/**
* 小说类别
*/
public static class BookCategoryTable {
@Getter
public enum ColumnEnum {
WORK_DIRECTION("work_direction");
private String name;
ColumnEnum(String name) {
this.name = name;
}
}
}
/** /**
* 小说表 * 小说表
*/ */

View File

@ -1,7 +1,9 @@
package io.github.xxyopen.novel.dto.req; package io.github.xxyopen.novel.dto.req;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.github.xxyopen.novel.core.common.req.PageReqDto; import io.github.xxyopen.novel.core.common.req.PageReqDto;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date; import java.util.Date;
@ -49,12 +51,15 @@ public class BookSearchReqDto extends PageReqDto {
*/ */
private Integer wordCountMax; private Integer wordCountMax;
private Date updateTimeMin;
/** /**
* 更新时间单位 * 最小更新时间
*/ * 如果使用Get请求直接使用对象接收则可以使用@DateTimeFormat注解进行格式化
private Long updatePeriod; * 如果使用Post请求@RequestBody接收请求体参数默认解析日期格式为yyyy-MM-dd HH:mm:ss ,
* 如果需要接收其他格式的参数则可以使用@JsonFormat注解
* */
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date updateTimeMin;
/** /**
* 排序字段 * 排序字段

View File

@ -0,0 +1,26 @@
package io.github.xxyopen.novel.dto.resp;
import lombok.Builder;
import lombok.Data;
/**
* 小说分类 响应DTO
*
* @author xiongxiaoyang
* @date 2022/5/16
*/
@Data
@Builder
public class BookCategoryRespDto {
/**
* 类别ID
*/
private Long id;
/**
* 类别名
*/
private String name;
}

View File

@ -0,0 +1,42 @@
package io.github.xxyopen.novel.manager;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.github.xxyopen.novel.core.constant.CacheConsts;
import io.github.xxyopen.novel.core.constant.DatabaseConsts;
import io.github.xxyopen.novel.dao.entity.BookCategory;
import io.github.xxyopen.novel.dao.mapper.BookCategoryMapper;
import io.github.xxyopen.novel.dto.resp.BookCategoryRespDto;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 小说分类 缓存管理类
*
* @author xiongxiaoyang
* @date 2022/5/12
*/
@Component
@RequiredArgsConstructor
public class BookCategoryCacheManager {
private final BookCategoryMapper bookCategoryMapper;
/**
* 根据作品方向查询小说分类列表并放入缓存中
*/
@Cacheable(cacheManager = CacheConsts.CAFFEINE_CACHE_MANAGER
, value = CacheConsts.BOOK_CATEGORY_LIST_CACHE_NAME)
public List<BookCategoryRespDto> listCategory(Integer workDirection) {
QueryWrapper<BookCategory> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(DatabaseConsts.BookCategoryTable.ColumnEnum.WORK_DIRECTION.getName(), workDirection);
return bookCategoryMapper.selectList(queryWrapper).stream().map(v ->
BookCategoryRespDto.builder()
.id(v.getId())
.name(v.getName())
.build()).toList();
}
}

View File

@ -96,4 +96,11 @@ public interface BookService {
* @return 小说章节列表 * @return 小说章节列表
* */ * */
RestResp<List<BookChapterRespDto>> listChapters(Long bookId); RestResp<List<BookChapterRespDto>> listChapters(Long bookId);
/**
* 小说分类列表查询
* @param workDirection 作品方向;0-男频 1-女频
* @return 分类列表
* */
RestResp<List<BookCategoryRespDto>> listCategory(Integer workDirection);
} }

View File

@ -11,10 +11,7 @@ import io.github.xxyopen.novel.dao.mapper.BookChapterMapper;
import io.github.xxyopen.novel.dao.mapper.BookInfoMapper; import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
import io.github.xxyopen.novel.dto.req.BookSearchReqDto; import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
import io.github.xxyopen.novel.dto.resp.*; import io.github.xxyopen.novel.dto.resp.*;
import io.github.xxyopen.novel.manager.BookChapterCacheManager; import io.github.xxyopen.novel.manager.*;
import io.github.xxyopen.novel.manager.BookContentCacheManager;
import io.github.xxyopen.novel.manager.BookInfoCacheManager;
import io.github.xxyopen.novel.manager.BookRankCacheManager;
import io.github.xxyopen.novel.service.BookService; import io.github.xxyopen.novel.service.BookService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -38,6 +35,8 @@ import java.util.Random;
@Slf4j @Slf4j
public class BookServiceImpl implements BookService { public class BookServiceImpl implements BookService {
private final BookCategoryCacheManager bookCategoryCacheManager;
private final BookRankCacheManager bookRankCacheManager; private final BookRankCacheManager bookRankCacheManager;
private final BookInfoCacheManager bookInfoCacheManager; private final BookInfoCacheManager bookInfoCacheManager;
@ -193,6 +192,11 @@ public class BookServiceImpl implements BookService {
.build()).toList()); .build()).toList());
} }
@Override
public RestResp<List<BookCategoryRespDto>> listCategory(Integer workDirection) {
return RestResp.ok(bookCategoryCacheManager.listCategory(workDirection));
}
@Override @Override
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) { public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
// 查询章节信息 // 查询章节信息

View File

@ -13,25 +13,25 @@
and work_direction = #{condition.workDirection} and work_direction = #{condition.workDirection}
</if> </if>
<if test="condition.categoryId != null"> <if test="condition.categoryId != null">
and condition.category_id = #{condition.categoryId} and category_id = #{condition.categoryId}
</if> </if>
<if test="condition.isVip != null"> <if test="condition.isVip != null">
and condition.is_vip = #{condition.isVip} and is_vip = #{condition.isVip}
</if> </if>
<if test="condition.bookStatus != null"> <if test="condition.bookStatus != null">
and condition.book_status = #{condition.bookStatus} and book_status = #{condition.bookStatus}
</if> </if>
<if test="condition.wordCountMin != null"> <if test="condition.wordCountMin != null">
and condition.word_count >= #{condition.wordCountMin} and word_count >= #{condition.wordCountMin}
</if> </if>
<if test="condition.wordCountMax != null"> <if test="condition.wordCountMax != null">
and condition.word_count <![CDATA[ < ]]> #{condition.wordCountMax} and word_count <![CDATA[ < ]]> #{condition.wordCountMax}
</if> </if>
<if test="condition.updateTimeMin != null"> <if test="condition.updateTimeMin != null">
and condition.last_chapter_update_time >= #{condition.updateTimeMin} and last_chapter_update_time >= #{condition.updateTimeMin}
</if> </if>
order by #{condition.sort} order by ${condition.sort}
</select> </select>
<update id="addVisitCount"> <update id="addVisitCount">