Files
nuttyreading-java/src/main/java/com/peanut/modules/book/controller/BookController.java
wangjinlei 3cef570c97 1
2024-03-15 10:19:03 +08:00

869 lines
32 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.Query;
import com.peanut.common.utils.ReadProvinceUtil;
import com.peanut.modules.common.dao.BookDao;
import com.peanut.modules.common.dao.BookForumArticlesDao;
import com.peanut.modules.book.service.*;
import com.peanut.modules.book.vo.BookIndexVo;
import com.peanut.modules.common.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
/**
* 图书表
*
* @author yl
* @email yl328572838@163.com
* @date 2022-08-04 15:36:59
*/
@Slf4j
@RestController
@RequestMapping("book/book")
public class BookController {
@Autowired
private BookService bookService;
@Autowired
private BookChapterService bookChapterService;
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private AuthorService authorService;
@Autowired
private PublisherService publisherService;
@Autowired
private BookShelfService bookShelfService;
@Autowired
private BookReadRateService bookReadRateService;
@Autowired
private MyUserService myUserService;
@Autowired
private ProvinceService provinceService;
@Autowired
private CityService cityService;
@Autowired
private CountyService countyService;
@Autowired
private UserEbookBuyService userEbookBuyService;
@Autowired
private BookDao bookDao;
@Autowired
private ShopProductService shopProductService;
@Autowired
private ShopProductBookService shopProductBookService;
@Autowired
private ShopProductToLabelService shopProductToLabelService;
@Autowired
private MedicaldesBookService medicaldesBookService;
@Autowired
private BookForumArticlesDao bookForumArticlesDao;
final ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);
/**
* 列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params) {
PageUtils page = bookService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 列表
*/
@RequestMapping("/listbooks")
public R listbooks(@RequestParam Map<String, Object> params) {
PageUtils page = bookService.queryPagebooks(params);
return R.ok().put("page", page);
}
/**
* 获取精品图书
* @return
*/
@RequestMapping("/getJPBooks")
public R getJPBooks(){
LambdaQueryWrapper<ShopProductToLabelEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopProductToLabelEntity::getSplId,5);//精选图书
wrapper.eq(ShopProductToLabelEntity::getDelFlag,0);
List<Integer> pIds = shopProductToLabelService.getBaseMapper().selectList(wrapper).stream().map(ShopProductToLabelEntity::getProductId).collect(Collectors.toList());
List<ShopProduct> shopProductEntities = shopProductService.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProduct>().in(ShopProduct::getProductId, pIds));
return R.ok().put("Products",shopProductEntities);
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
// @RequiresPermissions("book:book:info")
public R info(@PathVariable("id") Integer id) {
BookEntity book = bookService.getById(id);
//返回结果添加图书类型
LambdaQueryWrapper<MedicaldesBook> wrapper = new LambdaQueryWrapper();
wrapper.eq(MedicaldesBook::getBookId,id);
List<MedicaldesBook> list = medicaldesBookService.list(wrapper);
if (list.size() > 0) {
String type = "";
for (MedicaldesBook mb : list) {
if (StringUtils.isEmpty(type)){
type += mb.getTypeId();
}else {
type += "," + mb.getTypeId();
}
}
book.setMedicaldesBookType(type);
}
return R.ok().put("book", book);
}
/**
* 获取书详情
* @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(shopProductBookService.getProductByBookId(bookId));
LambdaQueryWrapper<UserEbookBuyEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserEbookBuyEntity::getUserId,userId);
wrapper.eq(UserEbookBuyEntity::getBookId,bookId);
List<UserEbookBuyEntity> userEbookBuyEntities = userEbookBuyService.getBaseMapper().selectList(wrapper);
book_info.setIsBuy(userEbookBuyEntities.size()==0?false:true);
return R.ok().put("book",book_info);
}
/**
* 信息
*/
@RequestMapping("/appinfo/{id}/{userId}")
// @RequiresPermissions("book:book:info")
public R appinfo(@PathVariable("id") Integer id,
@PathVariable("userId") Integer userId) {
BookEntity book = bookService.getById(id);
book.setIsBuy(true);
boolean b = myUserService.bookAuthen(id, userId);
if (!b) {
// 无权限
book.setIsBuy(false);
}
//书籍详情返回,购买状态,免费章节数
String authorName = "";
String publisherName = "";
String authorId = book.getAuthorId();
String[] authorIds = authorId.split(",");
List<String> authorList = Arrays.asList(authorIds);
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
for (AuthorEntity authorEntity : authorEntities) {
authorName += "," + authorEntity.getAuthorName();
}
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
//查询书籍阅读进度
BookReadRateEntity bookReadRateEntity = bookReadRateService.getBaseMapper().selectOne(new QueryWrapper<BookReadRateEntity>()
.eq("book_id", id)
.eq("user_id", userId)
);
if (bookReadRateEntity != null) {
Integer chapterId = bookReadRateEntity.getChapterId();
String chapterName = bookReadRateEntity.getChapterName();
book.setChapterName(chapterName);
book.setChapterId(chapterId);
// 查询 书籍 章节 number
BookChapterEntity bookChapterEntity = bookChapterService.getById(chapterId);
if (bookChapterEntity != null) {
Integer number = bookChapterEntity.getNumber();
book.setChapterNum(number);
}
}
//查询书籍是否加入书架
Integer integer = bookShelfService.getBaseMapper().selectCount(new QueryWrapper<BookShelfEntity>()
.eq("book_id", id)
.eq("user_id", userId));
boolean flag = false;
if (integer > 0) {
flag = true;
}
book.setAuthorName(authorName);
book.setPublisherName(publisherName);
book.setFlag(flag);
return R.ok().put("book", book);
}
/**
* 保存
*/
@RequestMapping("/save")
public R save(@RequestBody BookEntity book) {
bookService.save(book);
//添加图书类型关系表
if (StringUtils.isNotEmpty(book.getMedicaldesBookType())){
String[] types = book.getMedicaldesBookType().split(",");
if (types.length > 0) {
for (int i = 0; i < types.length; i++) {
MedicaldesBook medicaldesBook = new MedicaldesBook();
medicaldesBook.setBookId(book.getId());
medicaldesBook.setTypeId(Integer.parseInt(types[i]));
medicaldesBookService.save(medicaldesBook);
}
}
}
return R.ok();
}
/**
* 获取用户未拥有的可听图书
* @return
*/
@RequestMapping("/getUserNobuyBooks")
public R getUserNobuyBooks(@RequestParam Integer userId,@RequestParam Integer limit,@RequestParam Integer page){
List<UserEbookBuyEntity> bookids = userEbookBuyService.getBaseMapper().selectList(new QueryWrapper<UserEbookBuyEntity>()
.select("book_id").eq("user_id", userId));
List bids = new ArrayList();
for (UserEbookBuyEntity b :bookids){
bids.add(b.getBookId());
}
// Integer start = (page-1)*limit;
QueryWrapper<BookEntity> wrapper = new QueryWrapper<>();
wrapper.eq("can_listen",1);
wrapper.eq("book_type",0);
if(bids.size()>0){
wrapper.notIn("id",bids);
}
Page<BookEntity> bookEntityPage = bookService.getBaseMapper().selectPage(new Page<BookEntity>(page, limit), wrapper);
// Integer start = (page-1)*limit;
// QueryWrapper<BookEntity> wrapper = new QueryWrapper<>();
// wrapper.eq("t.can_listen",1);
// wrapper.notIn("t1.Book_id",bids);
// List<BookEntity> bookEntities = bookDao.queryUserListenBooksNobuy(wrapper,start,limit);
// Integer count = bookDao.queryUserListenBooksNobuyCount(wrapper);
return R.ok().put("page",bookEntityPage);
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody BookEntity book) {
bookService.updateById(book);
//修改图书类型关系表
//先删除
LambdaQueryWrapper<MedicaldesBook> wrapper = new LambdaQueryWrapper();
wrapper.eq(MedicaldesBook::getBookId,book.getId());
List<MedicaldesBook> list = medicaldesBookService.list(wrapper);
if (list.size() > 0) {
for (MedicaldesBook b : list) {
medicaldesBookService.removeById(b.getId());
}
}
//再添加
if (StringUtils.isNotEmpty(book.getMedicaldesBookType())){
String[] types = book.getMedicaldesBookType().split(",");
if (types.length > 0) {
for (int i = 0; i < types.length; i++) {
MedicaldesBook medicaldesBook = new MedicaldesBook();
medicaldesBook.setBookId(book.getId());
medicaldesBook.setTypeId(Integer.parseInt(types[i]));
medicaldesBookService.save(medicaldesBook);
}
}
}
return R.ok();
}
/**
* 获取全部古籍书
* @return
*/
@RequestMapping("/getAncientBooks")
public R getAncientBooks(){
List<BookEntity> ancientBooks = bookService.getAncientBooks();
return R.ok().put("books",ancientBooks);
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids) {
bookService.removeByIds(Arrays.asList(ids));
return R.ok();
}
/**
* 常规章节拆分
*/
@RequestMapping("/getChapter")
public R getChapter(@RequestParam("id") Integer id) {
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
singleThreadExecutor.execute(new Runnable() {
@Override
public void run() {
// bookService.getWordChapter(id);
// bookService.getChapter(id);
// bookService.getWord(id);
bookService.getWordSection(id);
}
});
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
bookEntity.setChapterStatus("2");
bookService.updateById(bookEntity);
return R.ok();
}
/**
* 章节拆分 2.0
*/
@RequestMapping("/getWord")
public R getWord(@RequestParam("id") Integer id) {
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
singleThreadExecutor.execute(new Runnable() {
@Override
public void run() {
//2.0
bookService.getWord(id);
}
});
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
bookEntity.setChapterStatus("2");
bookService.updateById(bookEntity);
return R.ok();
}
/**
* 章节拆分 3.0小节
*/
@RequestMapping("/WordSection")
public R getWordSection(@RequestParam("id") Integer id) {
// List<BookChapterEntity> kid = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>().eq("book_id", id));
// if (kid != null) {
// for (BookChapterEntity bookChapterEntity : kid) {
// // 调用删除方法进行删除
// Integer id1 = bookChapterEntity.getId();
// System.out.println("===========id1=="+id1);
//// bookChapterService.removeById(id1);
// }
//
//
// }
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
singleThreadExecutor.execute(new Runnable() {
@Override
public void run() {
//3.0 大小章拆分
bookService.getWordSection(id);
// bookService.getChapter(id);
}
});
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
bookEntity.setChapterStatus("2");
bookService.updateById(bookEntity);
return R.ok();
}
/**
* 获取书的章节
* @param bookId
* @param userId
* @return
*/
@RequestMapping("/getBookCatalogue")
public R getBookCatalogue(@RequestParam Integer bookId,@RequestParam Integer userId){
BookEntity book_info = bookService.getById(bookId);
LambdaQueryWrapper<BookChapterEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BookChapterEntity::getBookId,bookId);
wrapper.eq(BookChapterEntity::getDelFlag,0);
wrapper.orderByAsc(BookChapterEntity::getNumber);
List<BookChapterEntity> 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);
if (bookEntity.getImages()==null) {
return R.error("电子书目录为空");
}
String images = bookEntity.getImages() ;
Integer freeChapterCount = bookEntity.getFreeChapterCount();
UserEbookBuyEntity userEbookBuyEntity1 = userEbookBuyService.getBaseMapper().selectOne(new QueryWrapper<UserEbookBuyEntity>().eq("book_id", id).eq("user_id", userid));
List<BookChapterEntity> bookChapterEntities = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>().eq("book_id", id));
List<HashMap<Object, Object>> chapterList = new ArrayList<>();
for (BookChapterEntity bookEntitys : bookChapterEntities) {
HashMap<Object, Object> map = new HashMap<>();
map.put("bookid",id);
map.put("number", bookEntitys.getNumber());
map.put("chapterId", bookEntitys.getId());
map.put("chapterName", bookEntitys.getChapter());
//freeChapterCount
map.put("images",images);
chapterList.add(map);
}
//true免费 false付费
if (userEbookBuyEntity1!=null) {
return R.ok().put("BookCatalogue", chapterList).put("buy",true);
}
return R.ok().put("BookCatalogue", chapterList).put("buy",false).put("freeChapterCount",freeChapterCount);
}
/**
* app 电子书目录
*/
@RequestMapping("/getCatalogue")
public R getCatalogue(@RequestParam("bookid") Integer id
) {
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
if (bookEntity == null) {
return R.error("当前图书不存在或已删除");
}
String images = bookEntity.getImages() ;
Integer number=null;
List<BookChapterEntity> bookChapterEntities = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>().eq("book_id", id));
List<HashMap<Object, Object>> chapterList = new ArrayList<>();
for (BookChapterEntity bookEntitys : bookChapterEntities) {
number = bookEntitys.getNumber();
HashMap<Object, Object> map = new HashMap<>();
map.put("bookid",id);
map.put("number", bookEntitys.getNumber());
map.put("chapterId", bookEntitys.getId());
map.put("chapterName", bookEntitys.getChapter());
//freeChapterCount
map.put("images",images);
chapterList.add(map);
}
if (number==null) {
return R.error("当前电子书目录为空");
}else{
return R.ok().put("BookCatalogue",chapterList);
}
}
//书籍详情返回,购买状态,免费章节数
/**
* app 获取免费章节数
*/
@RequestMapping("/getfreeChapter")
public R getfreeChapter(@RequestParam("bookid") Integer id
) {
BookEntity bookEntity = bookService.getBaseMapper().selectById(id);
if (bookEntity == null) {
return R.error("当前图书不存在或已删除");
}
Integer freeChapterCount = bookEntity.getFreeChapterCount();
if (freeChapterCount == null) {
return R.error("当前电子书目录为空");
} else {
return R.ok().put("freeChapterCount", freeChapterCount);
}
}
/**
* 对外图标列表
*/
@RequestMapping("/listForWebsite")
// @RequiresPermissions("book:book:list")
public R listForWebsite(@RequestParam Map<String, Object> params) {
PageUtils page = bookService.queryPage(params);
return R.ok().put("page", page);
}
/**
* app首页数据
*/
@RequestMapping("/bookIndex")
// @RequiresPermissions("book:book:list")
public R bookIndex() {
HashMap<Object, Object> map = new HashMap<>();
List list = new ArrayList<>();
List topList = new ArrayList<>();
List saleList = new ArrayList<>();
// 新书
List<BookEntity> newBookList = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("state", 1).last("limit 6").orderByDesc("create_time"));
for (BookEntity book : newBookList) {
String authorName = "";
String publisherName = "";
BookIndexVo bookIndexVo = new BookIndexVo();
String authorId = book.getAuthorId();
String[] authorIds = authorId.split(",");
List<String> authorList = Arrays.asList(authorIds);
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
for (AuthorEntity authorEntity : authorEntities) {
authorName += "," + authorEntity.getAuthorName();
}
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
bookIndexVo.setBookName(book.getName());
bookIndexVo.setAuthorName(authorName);
bookIndexVo.setBookid(book.getId());
bookIndexVo.setImage(book.getImages());
bookIndexVo.setIntroduce(book.getDescription());
bookIndexVo.setPublisherName(publisherName);
bookIndexVo.setIsVip(book.getIsVip());
list.add(bookIndexVo);
}
// 推荐
List<BookEntity> topBookList = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("state", 1).eq("istop", 1).last("limit 6").orderByDesc("sort"));
for (BookEntity book : topBookList) {
String authorName = "";
String publisherName = "";
BookIndexVo bookIndexVo = new BookIndexVo();
String authorId = book.getAuthorId();
String[] authorIds = authorId.split(",");
List<String> authorList = Arrays.asList(authorIds);
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
for (AuthorEntity authorEntity : authorEntities) {
authorName += "," + authorEntity.getAuthorName();
}
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
bookIndexVo.setBookName(book.getName());
bookIndexVo.setAuthorName(authorName);
bookIndexVo.setBookid(book.getId());
bookIndexVo.setImage(book.getImages());
bookIndexVo.setIntroduce(book.getDescription());
bookIndexVo.setPublisherName(publisherName);
bookIndexVo.setIsVip(book.getIsVip());
topList.add(bookIndexVo);
}
//秒杀
List<BookEntity> saleBookList = bookService.getBaseMapper().selectList(new QueryWrapper<BookEntity>().eq("state", 1).eq("is_sale", 1).last("limit 6").orderByDesc("create_time"));
for (BookEntity book : saleBookList) {
String authorName = "";
String publisherName = "";
BookIndexVo bookIndexVo = new BookIndexVo();
String authorId = book.getAuthorId();
String[] authorIds = authorId.split(",");
List<String> authorList = Arrays.asList(authorIds);
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
for (AuthorEntity authorEntity : authorEntities) {
authorName += "," + authorEntity.getAuthorName();
}
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
bookIndexVo.setBookName(book.getName());
bookIndexVo.setAuthorName(authorName);
bookIndexVo.setBookid(book.getId());
bookIndexVo.setImage(book.getImages());
bookIndexVo.setIntroduce(book.getDescription());
bookIndexVo.setPublisherName(publisherName);
bookIndexVo.setIsVip(book.getIsVip());
bookIndexVo.setPrice(book.getPrice());
bookIndexVo.setSalePrice(book.getSalePrice());
saleList.add(bookIndexVo);
}
map.put("newBookList", list);
map.put("topBookList", topList);
map.put("saleList", saleList);
return R.ok().put("bookIndex", map);
}
//精选
@RequestMapping("/getBestBook")
public R getBestBook(@RequestParam Map<String, Object> params) {
PageUtils page = bookService.getBestBook(params);
return R.ok().put("page", page);
}
/**
* 获取我的已购图书
* @param userId
* @param limit
* @param page
* @return
*/
@RequestMapping("/getMyBooks")
public R getMyBooks(Integer userId,Integer limit,Integer page,Integer type){
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());
Page<BookEntity> bookEntityPage = null;
if(bookIds.size()>0){
MPJLambdaWrapper<BookEntity> wrapper1 = new MPJLambdaWrapper<>();
wrapper1.eq(BookEntity::getDelFlag,0);
wrapper1.in(BookEntity::getId,bookIds);
if (type!=null){
wrapper1.selectAll(BookEntity.class);
wrapper1.leftJoin(MedicaldesBook.class,MedicaldesBook::getBookId,BookEntity::getId);
wrapper1.eq(MedicaldesBook::getTypeId,type);
}
bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper1);
}
for (BookEntity b:bookEntityPage.getRecords()){
LambdaQueryWrapper<BookForumArticlesEntity> bookForumArticlesEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
bookForumArticlesEntityLambdaQueryWrapper.eq(BookForumArticlesEntity::getBookid,b.getId());
Integer integer = bookForumArticlesDao.selectCount(bookForumArticlesEntityLambdaQueryWrapper);
b.setForumNum(integer);
}
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.eq(BookEntity::getState,1);
wrapper1.eq(BookEntity::getBookType,0);
if(bookIds.size()>0){
wrapper1.notIn(BookEntity::getId,bookIds);
}
Page<BookEntity> bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper1);
for (BookEntity b : bookEntityPage.getRecords()){
b.setProductId(shopProductBookService.getProductByBookId(b.getId()));
}
return R.ok().put("page",bookEntityPage);
}
//新书
@RequestMapping("/getNewBook")
public R getNewBook(@RequestParam Map<String, Object> params) {
PageUtils page = bookService.getNewBook(params);
return R.ok().put("page", page);
}
//特价
@RequestMapping("/getSaleBook")
public R getSaleBook(@RequestParam Map<String, Object> params) {
PageUtils page = bookService.getSaleBook(params);
return R.ok().put("page", page);
}
//生成电子书 目录
@RequestMapping("/getWordChapter")
public R getWordChapter(@RequestParam Map<String, Object> params) {
bookService.getWordChapter(14);
return R.ok();
}
@RequestMapping("/file")
public String getFile() {
String filePath = "C:\\Users\\Administrator\\IdeaProjects\\peanut_book\\2020年8月中华人民共和国县以上行政区划代码.json";
List<Province> provinceList = ReadProvinceUtil.getFile(filePath);
// System.out.println(provinceList);
if (provinceList != null && provinceList.size() > 0) {
for (Province province : provinceList) {
// ProvinceEntity provinceEntity = new ProvinceEntity();
// provinceEntity.setProvName(province.getProvName());
// provinceEntity.setCreateDate(province.getCreateDate());
// provinceEntity.setRegionCode(province.getRegionCode());
provinceService.save(province);
List<City> cityList = province.getCityList();
if (cityList != null && cityList.size() > 0) {
for (City city : cityList) {
// CityEntity cityEntity = new CityEntity();
// cityEntity.setCreateDate(city.getCreateDate());
// cityEntity.setCityName(city.getCityName());
// cityEntity.setRegionCode(city.getRegionCode());
// city.setProvId(province.getProvId());
city.setProvId(province.getProvId());
cityService.save(city);
List<County> countyList = city.getCountyList();
if (countyList != null && countyList.size() > 0) {
for (County county : countyList) {
// CountyEntity countyEntity = new CountyEntity();
county.setCityId(city.getCityId());
// countyEntity.setCountyName(county.getCountyName());
// countyEntity.setCreateDate(county.getCreateDate());
// countyEntity.setRegionCode(county.getRegionCode());
countyService.save(county);
}
}
}
}
}
}
return null;
}
//中医经典列表
@RequestMapping("/getClassicsBookList")
public R getClassicsBookList(@RequestBody Map<String,Object> params) {
LambdaQueryWrapper<BookEntity> wrapper = new LambdaQueryWrapper();
wrapper.eq(BookEntity::getBookType,params.get("bookType"));
IPage<BookEntity> page = bookService.page(
new Query<BookEntity>().getPage(params),wrapper);
return R.ok().put("page", page);
}
}