|
@@ -10,10 +10,7 @@ import com.book.server.dao.entity.example.BookCategoryExample;
|
|
import com.book.server.dao.entity.example.BookExample;
|
|
import com.book.server.dao.entity.example.BookExample;
|
|
import com.book.server.dao.entity.example.ManageBlockExample;
|
|
import com.book.server.dao.entity.example.ManageBlockExample;
|
|
import com.book.server.dao.entity.example.ManageBlockResourceExample;
|
|
import com.book.server.dao.entity.example.ManageBlockResourceExample;
|
|
-import com.book.server.dao.mapper.BookCategoryMapper;
|
|
|
|
-import com.book.server.dao.mapper.BookMapper;
|
|
|
|
-import com.book.server.dao.mapper.ManageBlockMapper;
|
|
|
|
-import com.book.server.dao.mapper.ManageBlockResourceMapper;
|
|
|
|
|
|
+import com.book.server.dao.mapper.*;
|
|
import com.book.server.model.VO.BlockRes;
|
|
import com.book.server.model.VO.BlockRes;
|
|
import com.book.server.model.VO.BookRes;
|
|
import com.book.server.model.VO.BookRes;
|
|
import com.book.server.model.VO.ManageBlockResourceRes;
|
|
import com.book.server.model.VO.ManageBlockResourceRes;
|
|
@@ -34,6 +31,8 @@ import java.util.stream.Collectors;
|
|
public class BookServiceImpl implements BookService {
|
|
public class BookServiceImpl implements BookService {
|
|
@Autowired
|
|
@Autowired
|
|
private BookMapper bookMapper;
|
|
private BookMapper bookMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private BookMapper2 bookMapper2;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ManageBlockMapper manageBlockMapper;
|
|
private ManageBlockMapper manageBlockMapper;
|
|
@@ -52,44 +51,22 @@ public class BookServiceImpl implements BookService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public PageResult<BookRes> query(QueryVO queryVO) {
|
|
|
|
- BookExample example = BookExample.newAndCreateCriteria().example();
|
|
|
|
- example.or().andNameLike("%" + queryVO.getQuery() + "%");
|
|
|
|
- example.or().andAuthorLike("%" + queryVO.getQuery() + "%");
|
|
|
|
- long count = bookMapper.countByExample(example);
|
|
|
|
- if (count <= 0) {
|
|
|
|
- return new PageResult<>(queryVO.getPage(), queryVO.getSize(), 0L, null);
|
|
|
|
- }
|
|
|
|
- example.page(queryVO.getPage(), queryVO.getSize());
|
|
|
|
- List<Book> books = bookMapper.selectByExample(example);
|
|
|
|
- //查询关联表
|
|
|
|
- List<BookCategory> allCategory = getAllCategory();
|
|
|
|
- HashMap<Integer, String> map = new HashMap<>();
|
|
|
|
- for (BookCategory bookCategory : allCategory) {
|
|
|
|
- map.put(bookCategory.getId(), bookCategory.getName());
|
|
|
|
- }
|
|
|
|
- //转存
|
|
|
|
- ArrayList<BookRes> bookResList = new ArrayList<>();
|
|
|
|
- for (Book book : books) {
|
|
|
|
- BookRes bookRes = new BookRes();
|
|
|
|
- BeanUtils.copyProperties(book,bookRes);
|
|
|
|
- bookRes.setCategoryName(map.get(book.getBookCategoryId()));
|
|
|
|
- bookResList.add(bookRes);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return new PageResult<>(queryVO.getPage(), queryVO.getSize(), count, bookResList);
|
|
|
|
|
|
+ public List<BookRes> query(QueryVO queryVO) {
|
|
|
|
+ queryVO.setQuery("%"+queryVO.getQuery()+"%");
|
|
|
|
+ List<BookRes> bookResList = bookMapper2.queryBookRes(queryVO, queryVO.getPage() * queryVO.getSize(), queryVO.getSize());
|
|
|
|
+ return bookResList;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public PageResult<Book> recommendByRead(QueryVO queryVO) {
|
|
|
|
|
|
+ public List<Book> recommendByRead(QueryVO queryVO) {
|
|
BookExample example = BookExample.newAndCreateCriteria()
|
|
BookExample example = BookExample.newAndCreateCriteria()
|
|
|
|
+ .andStateEqualTo("1")
|
|
.andSexEqualTo(queryVO.getPageId())
|
|
.andSexEqualTo(queryVO.getPageId())
|
|
.example();
|
|
.example();
|
|
- long count = bookMapper.countByExample(example);
|
|
|
|
example.orderBy(Book.Column.readNum.desc());
|
|
example.orderBy(Book.Column.readNum.desc());
|
|
example.page(queryVO.getPage(), queryVO.getSize());
|
|
example.page(queryVO.getPage(), queryVO.getSize());
|
|
List<Book> books = bookMapper.selectByExample(example);
|
|
List<Book> books = bookMapper.selectByExample(example);
|
|
- return new PageResult<>(queryVO.getPage(), queryVO.getSize(), count, books);
|
|
|
|
|
|
+ return books;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|