This commit is contained in:
wangjinlei
2023-09-27 17:13:11 +08:00
parent c3ba1d9691
commit 4849defaef
2 changed files with 55 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package com.peanut.modules.book.controller;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -111,7 +112,7 @@ public class BookController {
wrapper.eq(UserEbookBuyEntity::getUserId,userId);
wrapper.eq(UserEbookBuyEntity::getBookId,bookId);
List<UserEbookBuyEntity> userEbookBuyEntities = userEbookBuyService.getBaseMapper().selectList(wrapper);
book_info.setIsBuy(userEbookBuyEntities==null?false:true);
book_info.setIsBuy(userEbookBuyEntities.size()==0?false:true);
return R.ok().put("book",book_info);
}
@@ -653,6 +654,53 @@ public class BookController {
return R.ok().put("page", page);
}
/**
* 获取我的已购图书
* @param userId
* @param limit
* @param page
* @return
*/
@RequestMapping("/getMyBooks")
public R getMyBooks(@RequestParam Integer userId,@RequestParam Integer limit,@RequestParam Integer page){
LambdaQueryWrapper<UserEbookBuyEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserEbookBuyEntity::getUserId,userId);
wrapper.groupBy(UserEbookBuyEntity::getBookId);
List<Integer> bookIds = userEbookBuyService.getBaseMapper().selectList(wrapper).stream().map(UserEbookBuyEntity::getBookId).collect(Collectors.toList());
LambdaQueryWrapper<BookEntity> wrapper1 = new LambdaQueryWrapper<>();
wrapper1.eq(BookEntity::getDelFlag,0);
wrapper1.in(BookEntity::getId,bookIds);
Page<BookEntity> bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper1);
return R.ok().put("page",bookEntityPage);
}
/**
* 获取我的推荐图书
* @param userId
* @param limit
* @param page
* @return
*/
@RequestMapping("/getBestBooks")
public R getBestBooks(@RequestParam Integer userId,@RequestParam Integer limit,@RequestParam Integer page){
LambdaQueryWrapper<UserEbookBuyEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserEbookBuyEntity::getUserId,userId);
wrapper.groupBy(UserEbookBuyEntity::getBookId);
List<Integer> bookIds = userEbookBuyService.getBaseMapper().selectList(wrapper).stream().map(UserEbookBuyEntity::getBookId).collect(Collectors.toList());
LambdaQueryWrapper<BookEntity> wrapper1 = new LambdaQueryWrapper<>();
wrapper1.eq(BookEntity::getDelFlag,0);
wrapper1.notIn(BookEntity::getId,bookIds);
Page<BookEntity> bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper1);
for (BookEntity b : bookEntityPage.getRecords()){
b.setProductId(shopProudictBookService.getProductByBookId(b.getId()));
}
return R.ok().put("page",bookEntityPage);
}
//新书
@RequestMapping("/getNewBook")