|
@@ -2,10 +2,14 @@ package com.sf.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.sf.dto.resp.BookCategoryRespDto;
|
|
|
import com.sf.dto.req.BookSearchReqDto;
|
|
|
import com.sf.dto.resp.BookInfoRespDto;
|
|
|
+import com.sf.dto.resp.BookRankRespDto;
|
|
|
import com.sf.dto.resp.PageRespDto;
|
|
|
+import com.sf.entity.BookCategory;
|
|
|
import com.sf.entity.BookInfo;
|
|
|
+import com.sf.mapper.BookCategoryMapper;
|
|
|
import com.sf.mapper.BookInfoMapper;
|
|
|
import com.sf.service.IBookInfoService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -31,6 +35,9 @@ public class BookInfoServiceImpl extends ServiceImpl<BookInfoMapper, BookInfo>
|
|
|
@Autowired
|
|
|
private BookInfoMapper bookInfoMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BookCategoryMapper bookCategoryMapper;
|
|
|
+
|
|
|
// 分页的本质是limit select * from book_info
|
|
|
@Override
|
|
|
public PageRespDto<BookInfoRespDto> searchBooks(BookSearchReqDto bookSearchReqDto) {
|
|
@@ -58,7 +65,66 @@ public class BookInfoServiceImpl extends ServiceImpl<BookInfoMapper, BookInfo>
|
|
|
return bookInfoRespDto;
|
|
|
}).toList();
|
|
|
PageRespDto<BookInfoRespDto> pageRespDto = PageRespDto.of(
|
|
|
- bookSearchReqDto.getPageNum(), bookSearchReqDto.getPageSize(), 0, bookInfoRespDtos);
|
|
|
+ bookSearchReqDto.getPageNum(), bookSearchReqDto.getPageSize(), page.getTotal(), bookInfoRespDtos);
|
|
|
return pageRespDto;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BookCategoryRespDto> listCategory(Integer workDirection) {
|
|
|
+ LambdaQueryWrapper<BookCategory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (workDirection != null) {
|
|
|
+ queryWrapper.eq(BookCategory::getWorkDirection, workDirection);
|
|
|
+ }
|
|
|
+ return bookCategoryMapper.selectList(queryWrapper).stream().map(bookCategory ->
|
|
|
+ BookCategoryRespDto.builder()
|
|
|
+ .id(bookCategory.getId())
|
|
|
+ .name(bookCategory.getName())
|
|
|
+ .build()).toList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BookRankRespDto> listVisitRankBooks() {
|
|
|
+ LambdaQueryWrapper<BookInfo> bookInfoQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ bookInfoQueryWrapper.orderByDesc(BookInfo::getVisitCount);
|
|
|
+ return listRankBooks(bookInfoQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询小说新书榜列表,并放入缓存中
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<BookRankRespDto> listNewestRankBooks() {
|
|
|
+ LambdaQueryWrapper<BookInfo> bookInfoQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ bookInfoQueryWrapper.orderByDesc(BookInfo::getCreateTime);
|
|
|
+ return listRankBooks(bookInfoQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询小说更新榜列表,并放入缓存中
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<BookRankRespDto> listUpdateRankBooks() {
|
|
|
+ LambdaQueryWrapper<BookInfo> bookInfoQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ bookInfoQueryWrapper.orderByDesc(BookInfo::getUpdateTime);
|
|
|
+ return listRankBooks(bookInfoQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<BookRankRespDto> listRankBooks(LambdaQueryWrapper<BookInfo> bookInfoQueryWrapper) {
|
|
|
+ bookInfoQueryWrapper.gt(BookInfo::getWordCount, 0).last("limit 30");
|
|
|
+ return bookInfoMapper.selectList(bookInfoQueryWrapper).stream().map(v -> {
|
|
|
+ BookRankRespDto respDto = new BookRankRespDto();
|
|
|
+ respDto.setId(v.getId());
|
|
|
+ respDto.setCategoryId(v.getCategoryId());
|
|
|
+ respDto.setCategoryName(v.getCategoryName());
|
|
|
+ respDto.setBookName(v.getBookName());
|
|
|
+ respDto.setAuthorName(v.getAuthorName());
|
|
|
+ respDto.setPicUrl(v.getPicUrl());
|
|
|
+ respDto.setBookDesc(v.getBookDesc());
|
|
|
+ respDto.setLastChapterName(v.getLastChapterName());
|
|
|
+ respDto.setLastChapterUpdateTime(v.getLastChapterUpdateTime());
|
|
|
+ respDto.setWordCount(v.getWordCount());
|
|
|
+ return respDto;
|
|
|
+ }).toList();
|
|
|
+ }
|
|
|
+
|
|
|
}
|