package com.peanut.modules.book.controller; import java.util.Arrays; import java.util.List; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peanut.modules.book.entity.BookBrowseRecordsEntity; import com.peanut.modules.book.service.BookBrowseRecordsService; import com.peanut.modules.book.vo.BookShelfVo; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; 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; import com.peanut.modules.book.entity.BookShelfEntity; import com.peanut.modules.book.service.BookShelfService; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.R; /** * 书架表 * * @author yl * @email yl328572838@163.com * @date 2022-08-29 15:27:44 */ @RestController @RequestMapping("book/bookshelf") public class BookShelfController { @Autowired private BookShelfService bookShelfService; @Autowired private BookBrowseRecordsService bookBrowseRecordsService; /** * 列表 */ @RequestMapping("/list") // @RequiresPermissions("book:bookshelf:list") public R list(@RequestParam Map params){ PageUtils page = bookShelfService.queryPage(params); return R.ok().put("page", page); } /** * 信息 */ @RequestMapping("/info/{id}") // @RequiresPermissions("book:bookshelf:info") public R info(@PathVariable("id") Integer id){ BookShelfEntity bookShelf = bookShelfService.getById(id); return R.ok().put("bookShelf", bookShelf); } /** * 保存 */ @RequestMapping("/save") // @RequiresPermissions("book:bookshelf:save") public R save(@RequestBody BookShelfEntity bookShelf){ // 加入前判断数据库是否加入过 这本书 Integer integer = bookShelfService.getBaseMapper().selectCount(new QueryWrapper() .eq("book_id", bookShelf.getBookId()) .eq("user_id", bookShelf.getUserId())); System.out.println("bookShelf"+bookShelf); if (integer > 0){ return R.error(500,"当前书籍已加入书架"); } bookShelfService.save(bookShelf); return R.ok(); } /** * 修改 */ @RequestMapping("/update") // @RequiresPermissions("book:bookshelf:update") public R update(@RequestBody BookShelfEntity bookShelf){ bookShelfService.updateById(bookShelf); Integer userId = bookShelf.getUserId(); Integer bookId = bookShelf.getBookId(); BookBrowseRecordsEntity one = bookBrowseRecordsService.getOne(new QueryWrapper().eq("user_id", userId).eq("book_id", bookId)); if (one != null) { bookBrowseRecordsService.updateById(one); } return R.ok(); } /** * 删除 */ @RequestMapping("/delete") // @RequiresPermissions("book:bookshelf:delete") public R delete(@RequestBody Integer[] ids){ bookShelfService.removeByIds(Arrays.asList(ids)); return R.ok(); } /** * 获取用户书架 */ @RequestMapping("/getUserBookshelf") public R getUserBookshelf(@RequestParam Integer userId){ List userBookshelf = bookShelfService.getUserBookshelf(userId); return R.ok().put("userBookshelf",userBookshelf); } /** * 获取用户听书书架 getUserBookChapterRead */ @RequestMapping("/getUserBookChapterRead") public R getUserBookChapterRead(@RequestParam Integer userId){ List bookShelfVos = bookShelfService.getUserBookChapterRead(userId); return R.ok().put("bookShelfVos",bookShelfVos); } }