|
@@ -1,7 +1,6 @@
|
|
|
package com.book.server.service.impl;
|
|
|
|
|
|
|
|
|
-import com.book.server.common.entity.Result;
|
|
|
import com.book.server.common.util.JsonUtils;
|
|
|
import com.book.server.dao.entity.*;
|
|
|
import com.book.server.dao.entity.example.*;
|
|
@@ -40,6 +39,8 @@ public class BookServiceImpl implements BookService {
|
|
|
private BookCategoryMapper bookCategoryMapper;
|
|
|
@Autowired
|
|
|
private SearchKeywordMapper searchKeywordMapper;
|
|
|
+ @Autowired
|
|
|
+ private ManageBlockResource2Mapper manageBlockResource2Mapper;
|
|
|
|
|
|
public List<BookCategory> getAllCategory() {
|
|
|
List<BookCategory> bookCategories = bookCategoryMapper.selectByExample(
|
|
@@ -57,14 +58,13 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Book> recommendByRead(QueryVO queryVO) {
|
|
|
- BookExample example = BookExample.newAndCreateCriteria()
|
|
|
- .andStateEqualTo("1")
|
|
|
- .andSexEqualTo(queryVO.getPageId())
|
|
|
- .example();
|
|
|
- example.orderBy(Book.Column.readNum.desc());
|
|
|
- example.page(queryVO.getPage(), queryVO.getSize());
|
|
|
- List<Book> books = bookMapper.selectByExample(example);
|
|
|
+ public List<BookRes> recommendByRead(QueryVO queryVO) {
|
|
|
+ ArrayList<BookRes> bookRes = new ArrayList<>();
|
|
|
+ if (queryVO.getPage() == 5) {
|
|
|
+ return bookRes;
|
|
|
+ }
|
|
|
+ List<BookRes> books = bookMapper2.novelEndRecommend(queryVO,
|
|
|
+ queryVO.getPage() * queryVO.getSize(), queryVO.getSize());
|
|
|
return books;
|
|
|
}
|
|
|
|
|
@@ -78,48 +78,26 @@ public class BookServiceImpl implements BookService {
|
|
|
manageBlockExample.orderBy(ManageBlock.Column.weigh.desc());
|
|
|
List<ManageBlock> manageBlocks = manageBlockMapper.selectByExample(manageBlockExample);
|
|
|
|
|
|
- // 获取板块内部数据
|
|
|
- for (ManageBlock manageBlock : manageBlocks) {
|
|
|
- ManageBlockResourceExample manageBlockResourceExample = ManageBlockResourceExample.newAndCreateCriteria()
|
|
|
- .andBlockIdEqualTo(manageBlock.getId())
|
|
|
- .example();
|
|
|
- manageBlockResourceExample.orderBy(ManageBlockResource.Column.weigh.desc());
|
|
|
- //获取内部书籍资源
|
|
|
- List<ManageBlockResource> manageBlockResources = manageBlockResourceMapper.selectByExample(manageBlockResourceExample);
|
|
|
- ArrayList<ManageBlockResourceRes> manageBlockResourceResList = new ArrayList<>();
|
|
|
- if (manageBlockResources.size() > 0) {
|
|
|
- List<Long> collect = manageBlockResources.stream()
|
|
|
- .map(ManageBlockResource::getBookId).collect(Collectors.toList());
|
|
|
- List<Book> books = bookMapper.selectByExample(
|
|
|
- BookExample.newAndCreateCriteria()
|
|
|
- .andIdIn(collect)
|
|
|
- .example()
|
|
|
- );
|
|
|
- HashMap<Long, Book> bookHashMap = new HashMap<>();
|
|
|
- books.forEach(x -> {
|
|
|
- bookHashMap.put(x.getId(), x);
|
|
|
- });
|
|
|
- manageBlockResources.forEach(x -> {
|
|
|
- ManageBlockResourceRes manageBlockResourceRes = new ManageBlockResourceRes();
|
|
|
- BeanUtils.copyProperties(x, manageBlockResourceRes);
|
|
|
- manageBlockResourceResList.add(manageBlockResourceRes);
|
|
|
-
|
|
|
- Book book = bookHashMap.get(x.getBookId());
|
|
|
- if (book != null) {
|
|
|
- manageBlockResourceRes.setBookName(book.getName());
|
|
|
- manageBlockResourceRes.setBookDescription(book.getDescription());
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- }
|
|
|
- BlockRes blockRes = new BlockRes();
|
|
|
- blockRes.setName(manageBlock.getName());
|
|
|
- blockRes.setSecondName(manageBlock.getSecondName());
|
|
|
- blockRes.setType(manageBlock.getType());
|
|
|
- blockRes.setResources(manageBlockResourceResList);
|
|
|
|
|
|
+ // 获取已有版本的所有书籍
|
|
|
+ List<Integer> blockIds = manageBlocks.stream().map(ManageBlock::getId).collect(Collectors.toList());
|
|
|
+ List<ManageBlockResourceRes> blockResourceResList = manageBlockResource2Mapper.getBooks(blockIds);
|
|
|
+
|
|
|
+ // 合并相同 block 书籍
|
|
|
+ HashMap<Integer, TreeSet<ManageBlockResourceRes>> map = new HashMap<>();
|
|
|
+ blockResourceResList.forEach(x -> {
|
|
|
+ TreeSet<ManageBlockResourceRes> set = map.computeIfAbsent(x.getBlockId(), k -> new TreeSet<>((o1, o2) -> o2.getWeigh() - o1.getWeigh()));
|
|
|
+ set.add(x);
|
|
|
+ });
|
|
|
+
|
|
|
+ manageBlocks.forEach(x -> {
|
|
|
+ BlockRes blockRes = new BlockRes();
|
|
|
+ blockRes.setName(x.getName());
|
|
|
+ blockRes.setType(x.getType());
|
|
|
+ blockRes.setSecondName(x.getSecondName());
|
|
|
+ blockRes.setResources(map.getOrDefault(x.getId(), new TreeSet<>()));
|
|
|
list.add(blockRes);
|
|
|
- }
|
|
|
+ });
|
|
|
return list;
|
|
|
}
|
|
|
|
|
@@ -278,10 +256,16 @@ public class BookServiceImpl implements BookService {
|
|
|
|
|
|
@Override
|
|
|
public List<BookRes> topRecommend(QueryVO queryVO) {
|
|
|
- List<BookRes> bookRes = bookMapper2.queryReturnRecommand(queryVO, 0, 20);
|
|
|
+ List<BookRes> bookRes = bookMapper2.topRecommend(queryVO, 0, 20);
|
|
|
return getRandom(bookRes);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<BookRes> smartRecommand(QueryVO queryVO) {
|
|
|
+ List<BookRes> bookRes = bookMapper2.smartRecommand(queryVO);
|
|
|
+ return bookRes;
|
|
|
+ }
|
|
|
+
|
|
|
private List<BookRes> getRandom(List<BookRes> bookRes) {
|
|
|
if (bookRes.size() <= 4) {
|
|
|
return bookRes;
|