-图书管理系统后端源码
立即下载
资源介绍:
采用JavaEE编写图书管理系统
package com.hlpedu.book.service.impl;
import com.hlpedu.book.bo.BorrowBookBo;
import com.hlpedu.book.bo.BorrowUserBo;
import com.hlpedu.book.mapper.BorrowMapper;
import com.hlpedu.book.pojo.Book;
import com.hlpedu.book.pojo.Borrow;
import com.hlpedu.book.pojo.User;
import com.hlpedu.book.service.BookService;
import com.hlpedu.book.service.BorrowService;
import com.hlpedu.book.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BorrowServiceImpl implements BorrowService {
@Autowired
BorrowMapper borrowMapper;
@Autowired
BookService bookService;
@Autowired
UserService userService;
@Override
public List countBorrowBo() {
List list= borrowMapper.countBorrowBo();
return list;
}
@Override
public List countBorrowUserBo() {
List list= borrowMapper.countBorrowUserBo();
return list;
}
// 统计借阅信息记录
@Override
public int countBorrow(String uname, String bname) {
return borrowMapper.countBorrow(uname,bname);
}
// 分页查询借阅信息
@Override
public List listPageBorrow(Integer page, Integer rows, String uname, String bname) {
return borrowMapper.listPageBorrow((page-1)*rows,rows,uname,bname);
}
// 统计归还信息记录
@Override
public int countHistoryBorrow(String uname, String bname) {
return borrowMapper.countHistoryBorrow(uname,bname);
}
// 分页查询归还信息
@Override
public List listPageHistoryBorrow(Integer page, Integer size, String uname, String bname) {
return borrowMapper.listPageHistoryBorrow((page-1)*size,size,uname,bname);
}
// 新增图书借阅信息
@Override
public void saveBorrowBooks(Borrow borrow) {
System.out.println(borrow.getBook().getBid()+"-----");
//图书ID,通过获得借阅图书库存
Book book = bookService.findBookById(borrow.getBook().getBid());
User user=userService.findUserById(borrow.getUser().getUid());
if (book != null){
if (book.getQuantity() > 0 && book.getQuantity() >= borrow.getQuantity()&& user.getStats()==0){
//借阅图书库存减一
book.setQuantity(book.getQuantity() - borrow.getQuantity());
bookService.updateBook(book);
borrow.setBook(book);
System.out.println(borrow.getUser().getUid());
// User user=userService.findUserById(borrow.getUser().getUid());
// System.out.println(borrow.getUser().getUname());
// User user = userService.findUserByUname(borrow.getUser().getUname());
borrow.setUser(user);
}
}
//借阅图书信息入库
borrowMapper.saveBorrow(borrow);
// //1.查询图书信息
// book = bookService.findBookById(book.getBid());
// //2.新增图书借阅信息
// //如果借阅数量小于等于馆藏图书的数量,则更新馆藏图书数量和借阅数量
// if(borrow.getQuantity() <= book.getQuantity()){
// //2.1 更新馆藏图书数量 =馆藏图书数量-借阅数量
// book.setQuantity(book.getQuantity()-borrow.getQuantity());
// //更新馆藏图书信息
// bookService.changStore(book);
// }
// //添加图书借阅信息
// borrow.setBook(book);
}
//归还图书
@Override
public void backBooksBorrow(Integer boid) {
//1.根据boid查询借阅信息
Borrow borrow = getBorrowByBoid(boid);
//2.根据图书bid查询图书信息
Book book = bookService.findBookById(borrow.getBook().getBid());
//3.最终归还图书,在图书数量上加上借阅的数量
book.setQuantity(book.getQuantity()+borrow.getQuantity());
bookService.changStore(book);
borrow.setStats(1);//更改借阅状态
borrowMapper.updateBorrow(borrow);
}
//根据boid查询借阅信息
private Borrow getBorrowByBoid(Integer boid) {
return borrowMapper.findBorrowByBoid(boid);
}
}
资源文件列表:
BookProject.zip 大约有138个文件