From c3ba1d96915e66bf6ae512ba238d1f3e4e55d8b3 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Wed, 27 Sep 2023 15:57:35 +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 --- .../BookChapterContentController.java | 29 +++++++++- .../controller/BookChapterController.java | 11 ++++ .../book/controller/BookController.java | 57 ++++++++++++++++++- .../book/entity/BookChapterEntity.java | 7 ++- .../modules/book/entity/BookEntity.java | 14 +++-- .../book/service/ShopProductService.java | 3 + .../book/service/ShopProudictBookService.java | 2 + .../service/impl/ShopProductServiceImpl.java | 7 ++- .../impl/ShopProudictBookServiceImpl.java | 26 +++++++++ 9 files changed, 144 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/peanut/modules/book/controller/BookChapterContentController.java b/src/main/java/com/peanut/modules/book/controller/BookChapterContentController.java index 9e44f6ea..55931e66 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookChapterContentController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookChapterContentController.java @@ -8,6 +8,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.alibaba.druid.util.StringUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peanut.common.utils.BaiduVoicesUtils; import com.peanut.modules.book.entity.*; @@ -51,6 +52,8 @@ public class BookChapterContentController { private MyUserService myUserService; @Autowired private UserEbookBuyService userEbookBuyService; + @Autowired + private ShopProudictBookService shopProudictBookService; /** * 列表 @@ -346,14 +349,36 @@ public class BookChapterContentController { } + /** + * 获取章节音频地址 + * @return + */ + @RequestMapping("/getBooksCatalogue") + public R getBooksCatalogue(@RequestParam Integer chapterId, + @RequestParam Integer bookId, + @RequestParam Integer userId){ + //鉴权阶段 + BookEntity book_info = bookService.getById(bookId); + BookChapterEntity chapter_info = bookChapterService.getById(chapterId); + UserEbookBuyEntity userEbookBuyEntity = userEbookBuyService.getBaseMapper().selectOne(new LambdaQueryWrapper(). + eq(UserEbookBuyEntity::getUserId,userId).eq(UserEbookBuyEntity::getBookId,bookId)); + if(chapter_info.getNumber()>book_info.getFreeChapterCount()&&userEbookBuyEntity==null){ + Integer productByBookId = shopProudictBookService.getProductByBookId(bookId); + return R.ok().put("jq",false).put("product",productByBookId); + } + + + + return R.ok().put("chapter",chapter_info); + } /** * app 获取电子书章节内容 2.0 (在用鉴权) */ -@RequestMapping("/appBooksChapterContent") -public R getBooksCatalogue(@RequestParam("chapterid") Integer id, +@RequestMapping("/appBooksChapterContent1") +public R getBooksCatalogue1(@RequestParam("chapterid") Integer id, @RequestParam("bookid") Integer bookid, @RequestParam("userId") Integer userId) { // TODO 验证 当前请求的书 是否存在免费章节数 diff --git a/src/main/java/com/peanut/modules/book/controller/BookChapterController.java b/src/main/java/com/peanut/modules/book/controller/BookChapterController.java index 9ee6f6c8..46e71fa4 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookChapterController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookChapterController.java @@ -137,6 +137,17 @@ public class BookChapterController { } + @RequestMapping("/updateBookChapter") + public R updateBookChapter(@RequestBody BookChapterEntity bookChapter){ + BookChapterEntity old_info = bookChapterService.getById(bookChapter.getId()); + if(!old_info.getContent().equals(bookChapter.getContent())){ + bookChapter.setVoices(""); // 设置voices字段为空 + } + bookChapterService.updateById(bookChapter); + return R.ok(); + } + + /** * 修改 */ 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 cdac580e..ff3a3083 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,8 @@ package com.peanut.modules.book.controller; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; @@ -52,6 +54,10 @@ public class BookController { private UserEbookBuyService userEbookBuyService; @Autowired private BookDao bookDao; + @Autowired + private ShopProductService shopProductService; + @Autowired + private ShopProudictBookService shopProudictBookService; final ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10); /** @@ -89,6 +95,27 @@ public class BookController { } + /** + * 获取书详情 + * @param bookId + * @return + */ + @RequestMapping("/getBookInfo") + public R getBookInfo(@RequestParam Integer bookId,@RequestParam Integer userId){ + BookEntity book_info = bookService.getById(bookId); + book_info.setAuthor(authorService.getById(book_info.getAuthorId())); + book_info.setPublisher(publisherService.getById(book_info.getPublisherId())); + book_info.setProductId(shopProudictBookService.getProductByBookId(bookId)); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UserEbookBuyEntity::getUserId,userId); + wrapper.eq(UserEbookBuyEntity::getBookId,bookId); + List userEbookBuyEntities = userEbookBuyService.getBaseMapper().selectList(wrapper); + book_info.setIsBuy(userEbookBuyEntities==null?false:true); + return R.ok().put("book",book_info); + } + + /** * 信息 */ @@ -339,10 +366,36 @@ public class BookController { } /** - * app 获取电子书目录 + * 获取书的章节 + * @param bookId + * @param userId + * @return */ @RequestMapping("/getBookCatalogue") - public R getBookCatalogue(@RequestParam("bookid") Integer id, + public R getBookCatalogue(@RequestParam Integer bookId,@RequestParam Integer userId){ + BookEntity book_info = bookService.getById(bookId); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(BookChapterEntity::getBookId,bookId); + wrapper.eq(BookChapterEntity::getDelFlag,0); + wrapper.orderByAsc(BookChapterEntity::getNumber); + List chapters = bookChapterService.getBaseMapper().selectList(wrapper); + for (BookChapterEntity b : chapters){ + if(b.getNumber()<=book_info.getFreeChapterCount()){ + b.setIsFree(1); + }else{ + b.setIsFree(0); + } + b.setBookImage(book_info.getImages()); + } + return R.ok().put("BookCatalogue",chapters); + } + + + /** + * app 获取电子书目录 + */ + @RequestMapping("/getBookCatalogue1") + public R getBookCatalogue1(@RequestParam("bookid") Integer id, @RequestParam("userid") Integer userid) { BookEntity bookEntity = bookService.getBaseMapper().selectById(id); diff --git a/src/main/java/com/peanut/modules/book/entity/BookChapterEntity.java b/src/main/java/com/peanut/modules/book/entity/BookChapterEntity.java index 5dd10627..5ad57d94 100644 --- a/src/main/java/com/peanut/modules/book/entity/BookChapterEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/BookChapterEntity.java @@ -65,10 +65,13 @@ public class BookChapterEntity implements Serializable { @TableLogic private Integer delFlag; + @TableField(exist = false) + private Integer isFree; - - + @TableField(exist = false) + private String bookImage; @TableField(exist = false) private String picAndWord; + } diff --git a/src/main/java/com/peanut/modules/book/entity/BookEntity.java b/src/main/java/com/peanut/modules/book/entity/BookEntity.java index 0d21caac..0605df5a 100644 --- a/src/main/java/com/peanut/modules/book/entity/BookEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/BookEntity.java @@ -147,6 +147,12 @@ public class BookEntity implements Serializable { @TableField(exist = false) private String publisherName; + @TableField(exist = false) + private AuthorEntity author; + + @TableField(exist = false) + private PublisherEntity publisher; + @TableField(exist = false) private String authorName; @@ -168,14 +174,12 @@ public class BookEntity implements Serializable { @TableField(exist = false) private Integer forumNum; - -// @TableField(exist = false) -// private Boolean bookAuthen; - - @TableField("can_listen") private Boolean canListen; + @TableField(exist = false) + private Integer productId; + private Integer clockIn; diff --git a/src/main/java/com/peanut/modules/book/service/ShopProductService.java b/src/main/java/com/peanut/modules/book/service/ShopProductService.java index 190d5b17..b4f258ae 100644 --- a/src/main/java/com/peanut/modules/book/service/ShopProductService.java +++ b/src/main/java/com/peanut/modules/book/service/ShopProductService.java @@ -31,5 +31,8 @@ public interface ShopProductService extends IService { PageUtils queryPageproductSales(Map params); PageUtils queryPageactivityprice(Map params); + + + } diff --git a/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java b/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java index 789f1a6e..7c5d4d25 100644 --- a/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java +++ b/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java @@ -17,4 +17,6 @@ public interface ShopProudictBookService extends IService getBookidsByProductId(Integer productId); + Integer getProductByBookId(Integer bookId); + } diff --git a/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java index 2663072b..eb3307e5 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/ShopProductServiceImpl.java @@ -1,6 +1,10 @@ package com.peanut.modules.book.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.peanut.common.utils.ExcludeEmptyQueryWrapper; import com.peanut.modules.book.entity.ShopCategoryEntity; +import com.peanut.modules.book.entity.ShopProudictBookEntity; +import com.peanut.modules.book.service.ShopProudictBookService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -20,6 +24,7 @@ import com.peanut.modules.book.service.ShopProductService; @Service("shopProductService") public class ShopProductServiceImpl extends ServiceImpl implements ShopProductService { + @Override public PageUtils queryPage(Map params) { String userid = (String) params.get("userid"); @@ -73,7 +78,6 @@ public class ShopProductServiceImpl extends ServiceImpl().getPage(params), new QueryWrapper().orderByDesc("sum_sales") ); - System.out.println("page"+page); return new PageUtils(page); } @@ -86,4 +90,5 @@ public class ShopProductServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ShopProudictBookEntity::getBookId,bookId); + wrapper.eq(ShopProudictBookEntity::getDelFlag,0); + wrapper.groupBy(ShopProudictBookEntity::getProudictId); + List shopProudictBookEntities = this.getBaseMapper().selectList(wrapper); + List ids = new ArrayList(); + for (ShopProudictBookEntity s : shopProudictBookEntities){ + ids.add(s.getProudictId()); + } + if(ids.size()==0){ + return null; + } + + LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); + wrapper1.eq(ShopProductEntity::getDelFlag,0); + wrapper1.in(ShopProductEntity::getProductId,ids); + wrapper1.orderByAsc(ShopProductEntity::getPrice); + wrapper1.last("limit 1"); + List shopProductEntities = shopProductService.getBaseMapper().selectList(wrapper1); + ShopProductEntity shopProductEntity = shopProductEntities.get(0); + return shopProductEntity.getProductId(); + } + }