源码获取:博客首页 "资源" 里下载!
图书租赁管理系统,该系统分为管理员与普通读者两种角色;
管理员主要功能包括:
图书管理:添加、修改、删除;
图书分类管理:添加、修改、删除;
借阅信息:还书;
预定信息:确认借书;
归还信息;
统计管理:借书/归还、营业额、销量;
普通读者主要功能包括:预定图书、待拿图书、借阅中、归还信息等;
客户端的充值,使用的支付宝沙箱测试化境
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 8.0版本;
7.lombok插件安装:本项目需要安装lombok插件,否则运行会有异常;
1. 后端:Spring SpringMVC MyBatis
2. 前端:JSP+bootstrap+jQuery+echarts
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/bm/
/**
* @Description 用户管理
*/
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UsersController {
@Autowired
private UserService userService;
@ApiOperation("用户列表")
@PostMapping("/list")
public R getUsers(@RequestBody PageIn pageIn) {
if (pageIn == null) {
return R.fail(CodeEnum.PARAM_ERROR);
}
// 封装分页出参对象
PageInfo userList = userService.getUserList(pageIn);
PageOut pageOut = new PageOut();
pageOut.setCurrPage(userList.getPageNum());
pageOut.setPageSize(userList.getPageSize());
pageOut.setTotal((int) userList.getTotal());
List 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);
}
/**
* 添加读者操作
* @param users
* @return
*/
@ApiOperation("添加读者")
@ResponseBody
@PostMapping("/addReader")
public R addReader(Users users) {
if (users == null) {
return R.fail(CodeEnum.PARAM_ERROR);
}
if(StringUtils.isEmpty(users.getAvatar())) {
return R.fail(CodeEnum.USER_HEAD_PIC_ERROR);
}
if(StringUtils.isEmpty(users.getUsername())) {
return R.fail(CodeEnum.USERNAME_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(users.getNickname())) {
return R.fail(CodeEnum.NICKNAME_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(users.getTel())) {
return R.fail(CodeEnum.USER_MOBILE_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(users.getEmail())) {
return R.fail(CodeEnum.USER_EMAIL_NOT_EXIST_ERROR);
}
Users byUsername = userService.findByUsername(users.getUsername());
if(byUsername!=null){
return R.fail(CodeEnum.USER_NAME_IS_EXIST_ERROR);
}
// 读者默认是普通用户
users.setIsAdmin(1);
Users users1 = userService.addUser(users);
if(users1==null){
return R.fail(CodeEnum.USER_ADD_ERROR);
}
return R.success(CodeEnum.SUCCESS);
}
/**
* 编辑用户操作
* @param users
* @return
*/
@ApiOperation("编辑用户")
@ResponseBody
@PostMapping("/edit")
public R modifyUsers(Users users) {
if (users == null) {
return R.fail(CodeEnum.PARAM_ERROR);
}
if(StringUtils.isEmpty(users.getAvatar())) {
return R.fail(CodeEnum.USER_HEAD_PIC_ERROR);
}
if(StringUtils.isEmpty(users.getUsername())) {
return R.fail(CodeEnum.USERNAME_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(users.getNickname())) {
return R.fail(CodeEnum.NICKNAME_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(users.getTel())) {
return R.fail(CodeEnum.USER_MOBILE_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(users.getEmail())) {
return R.fail(CodeEnum.USER_EMAIL_NOT_EXIST_ERROR);
}
Users byUsername = userService.findByUsername(users.getUsername());
if(byUsername!=null){
if(!byUsername.getId().equals(users.getId())){
return R.fail(CodeEnum.USER_NAME_IS_EXIST_ERROR);
}
}
if(!userService.updateUser(users)){
return R.fail(CodeEnum.USER_EDIT_ERROR);
}
return R.success(CodeEnum.SUCCESS);
}
@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);
}
@ApiOperation("获取当前用户登陆信息")
@GetMapping("/currUser")
public R getCurrUser() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal!=null) {
Map map = BeanUtil.beanToMap(principal);
String username = (String) map.get("username");
if (StrUtil.isNotBlank(username)) {
Users users = userService.findByUsername(username);
UserOut out = new UserOut();
BeanUtils.copyProperties(users,out);
out.setBirth(DateUtil.format(users.getBirthday(),Constants.DATE_FORMAT));
Integer identity = users.getIdentity();
String ident = "";
if (identity == Constants.STUDENT) {
ident = Constants.STU_STR;
}else if (identity == Constants.TEACHER) {
ident = Constants.TEA_STR;
}else if (identity == Constants.OTHER) {
ident = Constants.OTHER_STR;
}else if (identity == Constants.ADMIN) {
ident = Constants.ADMIN_STR;
}
out.setIdent(ident);
return R.success(CodeEnum.SUCCESS,out);
}
}
return R.fail(CodeEnum.USER_NOT_FOUND);
}
}
@Api(tags = "图书管理")
@RestController
@RequestMapping("/book")
public class BookController {
@Autowired
private BookService bookService;
@ApiOperation("图书搜索列表")
@PostMapping("/list")
public R getBookList(@RequestBody PageIn pageIn) {
if (pageIn == null) {
return R.fail(CodeEnum.PARAM_ERROR);
}
return R.success(CodeEnum.SUCCESS,bookService.getBookList(pageIn));
}
/**
* 添加图片操作
* @param book
* @return
*/
@ApiOperation("添加图书")
@ResponseBody
@PostMapping("/add")
public R addBook(Book book) {
if(StringUtils.isEmpty(book.getName())){
return R.fail(CodeEnum.BOOK_NAME_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(book.getIsbn())){
return R.fail(CodeEnum.BOOK_ISBN_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(book.getPic())){
return R.fail(CodeEnum.BOOK_IMAGE_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(book.getAuthor())){
return R.fail(CodeEnum.BOOK_AUTHOR_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(book.getType())){
return R.fail(CodeEnum.BOOK_TYPE_NOT_EXIST_ERROR);
}
BookOut bookByIsbn = bookService.findBookByIsbn(book.getIsbn());
if(bookByIsbn.getName()!=null){
return R.fail(CodeEnum.BOOK_ISBN_EXIST_ERROR);
}
if(bookService.addBook(book)==null){
return R.fail(CodeEnum.BOOK_ADD_ERROR);
}
return R.success(CodeEnum.SUCCESS);
}
/**
* 编辑图书
* @param book
* @return
*/
@ApiOperation("编辑图书")
@ResponseBody
@PostMapping("/edit")
public R editBook(Book book) {
if(StringUtils.isEmpty(book.getName())){
return R.fail(CodeEnum.BOOK_NAME_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(book.getIsbn())){
return R.fail(CodeEnum.BOOK_ISBN_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(book.getPic())){
return R.fail(CodeEnum.BOOK_IMAGE_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(book.getAuthor())){
return R.fail(CodeEnum.BOOK_AUTHOR_NOT_EXIST_ERROR);
}
if(StringUtils.isEmpty(book.getType())){
return R.fail(CodeEnum.BOOK_TYPE_NOT_EXIST_ERROR);
}
BookOut bookByIsbn = bookService.findBookByIsbn(book.getIsbn());
if(bookByIsbn.getName()!=null){
if(!bookByIsbn.getId().equals(book.getId())){
return R.fail(CodeEnum.BOOK_ISBN_EXIST_ERROR);
}
}
if(!bookService.updateBook(book)){
return R.fail(CodeEnum.BOOK_EDIT_ERROR);
}
return R.success(CodeEnum.SUCCESS);
}
@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) {
BookOut bookByIsbn = bookService.findBookByIsbn(isbn);
if(bookByIsbn.getId()==null){
return R.fail(CodeEnum.BOOK_NOT_EXIST_ERROR);
}
return R.success(CodeEnum.SUCCESS,bookByIsbn);
}
@ApiOperation("删除图书")
@GetMapping("/delete")
public R delBook(Integer id) {
bookService.deleteBook(id);
return R.success(CodeEnum.SUCCESS);
}
}
@Api(tags = "借阅管理")
@RestController
@RequestMapping("/borrow")
public class BorrowController {
@Autowired
private BorrowService borrowService;
@Autowired
private BookService bookService;
@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);
}else if (result == Constants.USER_SIZE_NOT_ENOUGH) {
return R.success(CodeEnum.USER_NOT_ENOUGH);
}else if (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 outs = new ArrayList<>();
if (userId!=null&&userId>0) {
// 获取所有 已借阅 未归还书籍
List borrows = borrowService.findBorrowsByUserIdAndRet(userId, Constants.NO);
for (Borrow borrow : borrows) {
BackOut backOut = new BackOut();
BookOut out = bookService.findBookById(borrow.getBookId());
BeanUtils.copyProperties(out,backOut);
backOut.setBorrowTime(DateUtil.format(borrow.getCreateTime(),Constants.DATE_FORMAT));
String endTimeStr = DateUtil.format(borrow.getEndTime(), Constants.DATE_FORMAT);
backOut.setEndTime(endTimeStr);
// 判断是否逾期
String toDay = DateUtil.format(new Date(), Constants.DATE_FORMAT);
int i = toDay.compareTo(endTimeStr);
if (i>0) {
backOut.setLate(Constants.YES_STR);
}else {
backOut.setLate(Constants.NO_STR);
}
outs.add(backOut);
}
}
return R.success(CodeEnum.SUCCESS,outs);
}
@ApiOperation("归还书籍")
@PostMapping("/ret")
public R retBook(Integer userId, Integer bookId) {
// 归还图书
borrowService.retBook(userId,bookId);
return R.success(CodeEnum.SUCCESS);
}
}
源码获取:博客首页 "资源" 里下载!