@ApiOperation("图书搜索列表") @PostMapping("/list") public R getBookList(@RequestBody PageIn pageIn){ if (pageIn == null) { return R.fail(CodeEnum.PARAM_ERROR); }
@ApiOperation("添加图书") @PostMapping("/add") public R addBook(@RequestBody Book book){ return R.success(CodeEnum.SUCCESS,bookService.addBook(book)); }
@ApiOperation("编辑图书") @PostMapping("/update") public R modifyBook(@RequestBody Book book){ return R.success(CodeEnum.SUCCESS,bookService.updateBook(book)); }
@ApiOperation("图书详情") @GetMapping("/detail") public R bookDetail(Integer id){ return R.success(CodeEnum.SUCCESS,bookService.findBookById(id)); }
@ApiOperation("图书详情 根据ISBN获取") @GetMapping("/detailByIsbn") public R bookDetailByIsbn(String isbn){ return R.success(CodeEnum.SUCCESS,bookService.findBookByIsbn(isbn)); }
@ApiOperation("删除图书") @GetMapping("/delete") public R delBook(Integer id){ bookService.deleteBook(id); return R.success(CodeEnum.SUCCESS); }
@ApiOperation("借阅列表") @GetMapping("/list") public R getBorrowList(Integer userId){ return R.success(CodeEnum.SUCCESS,borrowService.findAllBorrowByUserId(userId)); }
@ApiOperation("借阅图书") @PostMapping("/add") public R addBorrow(@RequestBody Borrow borrow){ Integer result = borrowService.addBorrow(borrow); if (result == Constants.BOOK_BORROWED) { return R.success(CodeEnum.BOOK_BORROWED); }elseif (result == Constants.USER_SIZE_NOT_ENOUGH) { return R.success(CodeEnum.USER_NOT_ENOUGH); }elseif (result == Constants.BOOK_SIZE_NOT_ENOUGH) { return R.success(CodeEnum.BOOK_NOT_ENOUGH); } return R.success(CodeEnum.SUCCESS,Constants.OK); }
@ApiOperation("编辑借阅") @PostMapping("/update") public R modifyBorrow(@RequestBody Borrow borrow){ return R.success(CodeEnum.SUCCESS,borrowService.updateBorrow(borrow)); }
@ApiOperation("借阅详情") @GetMapping("/detail") public R borrowDetail(Integer id){ return R.success(CodeEnum.SUCCESS,borrowService.findById(id)); }
@ApiOperation("删除归还记录") @GetMapping("/delete") public R delBorrow(Integer id){ borrowService.deleteBorrow(id); return R.success(CodeEnum.SUCCESS); }
@ApiOperation("已借阅列表") @GetMapping("/borrowed") public R borrowedList(Integer userId){ List<BackOut> outs = new ArrayList<>(); if (userId!=null&&userId>0) { // 获取所有 已借阅 未归还书籍 List<Borrow> borrows = borrowService.findBorrowsByUserIdAndRet(userId, Constants.NO); for (Borrow borrow : borrows) { BackOut backOut = new BackOut(); BookOut out = bookService.findBookById(borrow.getBookId()); BeanUtils.copyProperties(out,backOut);
@ApiOperation("用户列表") @PostMapping("/list") public R getUsers(@RequestBody PageIn pageIn){ if (pageIn == null) { return R.fail(CodeEnum.PARAM_ERROR); } // 封装分页出参对象 PageInfo<Users> userList = userService.getUserList(pageIn); PageOut pageOut = new PageOut(); pageOut.setCurrPage(userList.getPageNum()); pageOut.setPageSize(userList.getPageSize()); pageOut.setTotal((int) userList.getTotal()); List<UserOut> outs = new ArrayList<>(); for (Users users : userList.getList()) { UserOut out = new UserOut(); BeanUtils.copyProperties(users,out); out.setIdent(ConvertUtil.identStr(users.getIdentity())); out.setBirth(DateUtil.format(users.getBirthday(),Constants.DATE_FORMAT)); outs.add(out); }
pageOut.setList(outs);
return R.success(CodeEnum.SUCCESS,pageOut); }
// @ApiOperation("添加用户") // @PostMapping("/add") // public R addUsers(@RequestBody Users users) { // return R.success(CodeEnum.SUCCESS,userService.addUser(users)); // }
@ApiOperation("添加读者") @PostMapping("/addReader") public R addReader(@RequestBody Users users){ if (users == null) { return R.fail(CodeEnum.PARAM_ERROR); } // 读者默认是普通用户 users.setIsAdmin(1); return R.success(CodeEnum.SUCCESS,userService.addUser(users)); }
@ApiOperation("添加管理员") @PostMapping("/addAdmin") public R addAdmin(@RequestBody Users users){ if (users == null) { return R.fail(CodeEnum.PARAM_ERROR); } // 设置管理员权限 users.setIsAdmin(0); return R.success(CodeEnum.SUCCESS,userService.addUser(users)); }
@ApiOperation("编辑用户") @PostMapping("/update") public R modifyUsers(@RequestBody Users users){ return R.success(CodeEnum.SUCCESS,userService.updateUser(users)); }
@ApiOperation("用户详情") @GetMapping("/detail") public R userDetail(Integer id){ Users user = userService.findUserById(id); if (user!=null) { UserOut out = new UserOut(); BeanUtils.copyProperties(user,out); out.setBirth(DateUtil.format(user.getBirthday(),Constants.DATE_FORMAT)); out.setIdent(ConvertUtil.identStr(user.getIdentity())); return R.success(CodeEnum.SUCCESS,out); }
return R.fail(CodeEnum.NOT_FOUND); }
@ApiOperation("删除用户") @GetMapping("/delete") public R delUsers(Integer id){ userService.deleteUser(id); return R.success(CodeEnum.SUCCESS); }