From 4849defaef886ce60c47b27d4f266d67ae5588cd Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Wed, 27 Sep 2023 17:13:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/controller/BookController.java | 50 ++++++++++++++++++- .../book/controller/BookTeachController.java | 8 ++- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/peanut/modules/book/controller/BookController.java b/src/main/java/com/peanut/modules/book/controller/BookController.java index ff3a3083..fa12e293 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookController.java @@ -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 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 wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UserEbookBuyEntity::getUserId,userId); + wrapper.groupBy(UserEbookBuyEntity::getBookId); + List bookIds = userEbookBuyService.getBaseMapper().selectList(wrapper).stream().map(UserEbookBuyEntity::getBookId).collect(Collectors.toList()); + + LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); + wrapper1.eq(BookEntity::getDelFlag,0); + wrapper1.in(BookEntity::getId,bookIds); + Page 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 wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UserEbookBuyEntity::getUserId,userId); + wrapper.groupBy(UserEbookBuyEntity::getBookId); + List bookIds = userEbookBuyService.getBaseMapper().selectList(wrapper).stream().map(UserEbookBuyEntity::getBookId).collect(Collectors.toList()); + + LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); + wrapper1.eq(BookEntity::getDelFlag,0); + wrapper1.notIn(BookEntity::getId,bookIds); + Page 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") diff --git a/src/main/java/com/peanut/modules/book/controller/BookTeachController.java b/src/main/java/com/peanut/modules/book/controller/BookTeachController.java index d8200713..a2fbf3a8 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookTeachController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookTeachController.java @@ -7,6 +7,7 @@ import com.peanut.modules.book.entity.BookEntity; import com.peanut.modules.book.entity.BookTeachEntity; import com.peanut.modules.book.service.BookService; import com.peanut.modules.book.service.BookTeachService; +import com.peanut.modules.book.service.ShopProudictBookService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -23,6 +24,8 @@ public class BookTeachController { private BookTeachService bookTeachService; @Autowired private BookService bookService; + @Autowired + private ShopProudictBookService shopProudictBookService; /** * 获取讲书列表 @@ -59,8 +62,9 @@ public class BookTeachController { */ @RequestMapping("/getTeachDetail") public R getTeachDetail(@RequestParam Integer teachId){ - BookTeachEntity byId = bookTeachService.getById(teachId); - return R.ok().put("bookTeach",byId); + BookTeachEntity teach_info = bookTeachService.getById(teachId); + Integer productByBookId = shopProudictBookService.getProductByBookId(teach_info.getBookId()); + return R.ok().put("bookTeach",teach_info).put("product",productByBookId); }