package com.peanut.modules.book.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.R; import com.peanut.modules.book.dao.BookDao; import com.peanut.modules.book.entity.BookEntity; import com.peanut.modules.book.entity.UserEbookBuyEntity; import com.peanut.modules.book.service.BookService; import com.peanut.modules.book.service.UserEbookBuyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.*; /** * 用户购买书籍表 * * */ @RestController @RequestMapping("book/userebookbuy") public class UserEbookBuyController { @Autowired private UserEbookBuyService userEbookBuyService; @Autowired private BookService bookService; @Autowired private BookDao bookDao; /** * 列表 */ @RequestMapping("/list") public R list(@RequestParam Map params){ String userId = (String) params.get("userId"); PageUtils page = userEbookBuyService.queryPage(params); return R.ok().put("page", page); } /** * 获取用户打开书列表 * @return */ @RequestMapping("/getUserClockBookList") public R getUserClockBookList(@RequestParam("userId") Integer userId){ MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); wrapper.selectAll(BookEntity.class); wrapper.leftJoin(UserEbookBuyEntity.class,UserEbookBuyEntity::getBookId,BookEntity::getId); wrapper.eq(UserEbookBuyEntity::getUserId,userId); wrapper.eq(BookEntity::getClockIn,1); wrapper.eq(BookEntity::getDelFlag,0); List bookEntities = bookDao.selectJoinList(BookEntity.class, wrapper); return R.ok().put("books",bookEntities).put("tatol",bookEntities.size()); } /** * 获取用户打卡书列表 */ @RequestMapping("/appbooklist") public R appbooklist(@RequestParam("userId") Integer userId) { String user = String.valueOf(userId); ArrayList maplist = new ArrayList<>(); ArrayList list = new ArrayList<>(); List user_id = userEbookBuyService.getBaseMapper().selectList(new QueryWrapper().eq("user_id", user)); if (user_id==null){ return R.error("您打卡列表暂未添加内容"); } for (UserEbookBuyEntity userEbookBuyEntity : user_id) { Integer bookId = userEbookBuyEntity.getBookId(); list.add(bookId); } int index =0; for (Object S : list) { List books = bookService.getBaseMapper().selectList(new QueryWrapper() .eq("clock_in", 1) .eq("id", S)); for (BookEntity book : books) { Map map = new HashMap<>(); Integer id = book.getId(); map.put("book",book); index++; maplist.add(map); } } if (maplist==null&&maplist.size() > 0){ return R.error("您暂未参与打卡"); } return R.ok().put("resultlist",maplist).put("total",index); } /** * 获取用户可听书列表 * @return */ @RequestMapping("/getUserCanlistenBooks") public R getUserCanlistenBooks(@RequestParam Integer userId,@RequestParam Integer limit,@RequestParam Integer page){ return R.ok(); } @RequestMapping("/buylist") public R buylist(@RequestParam Map params){ String userId = (String) params.get("id"); List list = new ArrayList<>(); List user_id = userEbookBuyService.getBaseMapper().selectList(new QueryWrapper().eq("user_id", userId)); for (UserEbookBuyEntity userEbookBuyEntity : user_id) { Map map = new HashMap<>(); Integer userId1 = userEbookBuyEntity.getUserId(); Integer bookId = userEbookBuyEntity.getBookId(); Integer buyId = userEbookBuyEntity.getBuyId(); List id = bookService.getBaseMapper().selectList(new QueryWrapper().eq("id", bookId)); for (BookEntity bookEntity : id) { String images = bookEntity.getImages(); Integer id1 = bookEntity.getId(); String name1 = bookEntity.getName(); String name = bookEntity.getName(); Boolean canListen = bookEntity.getCanListen(); map.put("canListen", canListen); map.put("bookId",bookId); map.put("userId",userId1); map.put("bookName",name1); map.put("buyId",buyId); map.put("image",images); // map.put("author",author); list.add(map); } } Collections.reverse(list); return R.ok().put("page", list); } /** * 信息 */ @RequestMapping("/info/{buyId}") public R info(@PathVariable("buyId") Integer buyId){ UserEbookBuyEntity userEbookBuy = userEbookBuyService.getById(buyId); return R.ok().put("userEbookBuy", userEbookBuy); } /** * 保存 */ @RequestMapping("/save") public R save(@RequestBody UserEbookBuyEntity userEbookBuy){ userEbookBuyService.save(userEbookBuy); return R.ok(); } /** * 修改 */ @RequestMapping("/update") public R update(@RequestBody UserEbookBuyEntity userEbookBuy){ userEbookBuyService.updateById(userEbookBuy); return R.ok(); } /** * 删除 */ @RequestMapping("/delete") public R delete(@RequestBody Integer[] buyIds){ userEbookBuyService.removeByIds(Arrays.asList(buyIds)); return R.ok(); } }