138 lines
4.9 KiB
Java
138 lines
4.9 KiB
Java
package com.peanut.modules.book.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.peanut.common.utils.R;
|
|
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.ShopProductBookService;
|
|
import com.peanut.modules.book.to.PageIdDto;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
@RestController
|
|
@RequestMapping("book/teach")
|
|
public class BookTeachController {
|
|
@Autowired
|
|
private BookTeachService bookTeachService;
|
|
@Autowired
|
|
private BookService bookService;
|
|
@Autowired
|
|
private ShopProductBookService shopProductBookService;
|
|
|
|
/**
|
|
* 获取讲书列表
|
|
*
|
|
* @return
|
|
*/
|
|
@RequestMapping("/getTeachBooks")
|
|
public R getTeachBooks(@RequestParam Integer limit, @RequestParam Integer page) {
|
|
LambdaQueryWrapper<BookEntity> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.eq(BookEntity::getDelFlag, 0);
|
|
wrapper.eq(BookEntity::getTeachIn, 1);
|
|
Page<BookEntity> bookEntityPage = bookService.getBaseMapper().selectPage(new Page<BookEntity>(page, limit), wrapper);
|
|
|
|
return R.ok().put("page", bookEntityPage);
|
|
}
|
|
|
|
/**
|
|
* 获取讲书目录
|
|
*
|
|
* @return
|
|
*/
|
|
@RequestMapping("/getBookTeachItems")
|
|
public R getBookTeachItems(@RequestParam Integer bookId, @RequestParam Integer limit, @RequestParam Integer page) {
|
|
LambdaQueryWrapper<BookTeachEntity> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.eq(BookTeachEntity::getBookId, bookId);
|
|
wrapper.eq(BookTeachEntity::getDelFlag, 0);
|
|
wrapper.orderByAsc(BookTeachEntity::getChapter);
|
|
Page<BookTeachEntity> bookTeachEntityPage = bookTeachService.getBaseMapper().selectPage(new Page<BookTeachEntity>(page, limit), wrapper);
|
|
return R.ok().put("page", bookTeachEntityPage);
|
|
}
|
|
|
|
/**
|
|
* 获取讲书的详情
|
|
*
|
|
* @param teachId
|
|
* @return
|
|
*/
|
|
@RequestMapping("/getTeachDetail")
|
|
public R getTeachDetail(@RequestParam Integer teachId) {
|
|
BookTeachEntity teach_info = bookTeachService.getById(teachId);
|
|
Integer productByBookId = shopProductBookService.getProductByBookId(teach_info.getBookId());
|
|
return R.ok().put("bookTeach", teach_info).put("product", productByBookId);
|
|
}
|
|
|
|
/**
|
|
* 获取讲书的已购列表
|
|
* @param pageIdDto
|
|
* @return
|
|
*/
|
|
@RequestMapping("/getUserTeachBooks")
|
|
public R getUserTeachBooks(@RequestBody PageIdDto pageIdDto){
|
|
String exist_sql = "select 1 from user_ebook_buy where book.id = book_id and user_id = "+pageIdDto.getId();
|
|
LambdaQueryWrapper<BookEntity> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.eq(BookEntity::getTeachIn,1);
|
|
wrapper.eq(BookEntity::getDelFlag,0);
|
|
wrapper.exists(exist_sql);
|
|
Page<BookEntity> bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(pageIdDto.getPage(), pageIdDto.getLimit()), wrapper);
|
|
return R.ok().put("page",bookEntityPage);
|
|
}
|
|
|
|
/**
|
|
* 获取讲书的推荐列表
|
|
* @param pageIdDto
|
|
* @return
|
|
*/
|
|
@RequestMapping("/getUserBestTeachBooks")
|
|
public R getUserBestTeachBooks(@RequestBody PageIdDto pageIdDto){
|
|
String exist_sql = "select 1 from user_ebook_buy where book.id = book_id and user_id = "+pageIdDto.getId();
|
|
LambdaQueryWrapper<BookEntity> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.eq(BookEntity::getTeachIn,1);
|
|
wrapper.eq(BookEntity::getDelFlag,0);
|
|
wrapper.notExists(exist_sql);
|
|
Page<BookEntity> bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(pageIdDto.getPage(), pageIdDto.getLimit()), wrapper);
|
|
return R.ok().put("page",bookEntityPage);
|
|
|
|
}
|
|
|
|
/**
|
|
* 添加讲书的章节
|
|
*
|
|
* @param bookTeach
|
|
* @return
|
|
*/
|
|
@RequestMapping("/addTeach1")
|
|
public R addTeach1(@RequestBody BookTeachEntity bookTeach) {
|
|
bookTeachService.save(bookTeach);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 删除讲书章节
|
|
*
|
|
* @return
|
|
*/
|
|
@RequestMapping("/delTeach")
|
|
public R delTeach(@RequestBody BookTeachEntity bookTeach) {
|
|
bookTeachService.removeById(bookTeach.getTeachId());
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 编辑讲书的章节
|
|
*
|
|
* @return
|
|
*/
|
|
@RequestMapping("/updateTeach")
|
|
public R updateTeach(@RequestBody BookTeachEntity bookTeach) {
|
|
bookTeachService.updateById(bookTeach);
|
|
return R.ok();
|
|
}
|
|
}
|