Skip to content

Commit

Permalink
Merge pull request zhanghuanhao#1 from isCharlesChang/dev
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
zhanghuanhao authored Jan 19, 2019
2 parents 0ca603c + 7e3a441 commit f27dd93
Show file tree
Hide file tree
Showing 52 changed files with 409 additions and 551 deletions.
25 changes: 13 additions & 12 deletions library.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE DATABASE library;
USE library;
set names utf8;

SET NAMES utf8;
START TRANSACTION;
CREATE TABLE `admin` ( `admin_id` BIGINT NOT NULL PRIMARY KEY, `password` VARCHAR ( 15 ) NOT NULL, `username` VARCHAR ( 15 ) DEFAULT NULL ) ENGINE = INNODB DEFAULT CHARSET = utf8;
INSERT INTO `admin`
Expand All @@ -17,7 +18,7 @@ CREATE TABLE `book_info` (
`price` DECIMAL ( 10, 2 ) NOT NULL,
`pub_date` date NOT NULL,
`class_id` INT DEFAULT NULL,
`number` INT DEFAULT NULL
`number` INT DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = utf8;
ALTER TABLE `book_info` MODIFY `book_id` BIGINT NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 1;
Expand Down Expand Up @@ -67,26 +68,26 @@ CREATE TABLE `lend_list` (
`book_id` VARCHAR ( 15 ) NOT NULL,
`reader_id` BIGINT NOT NULL,
`lend_date` date DEFAULT NULL,
`back_date` date DEFAULT NULL
`back_date` date DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = utf8;
ALTER TABLE `lend_list` MODIFY `ser_num` BIGINT NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 1;
INSERT INTO `lend_list`
VALUES
( 1, 10000001, 1501014101, '2017-03-15', '2017-06-16' ),
( 2, 10000003, 1501014101, '2017-06-10', '2017-09-02' ),
( 3, 10000006, 1501014101, '2017-06-12', '2017-09-02' ),
( 4, 50000004, 1501014101, '2017-03-15', '2017-09-03' ),
( 5, 50000005, 1501014103, '2017-06-15', NULL ),
( 6, 50000010, 1501014104, '2017-06-15', NULL ),
( 7, 10000001, 1501014101, '2017-09-02', '2017-09-02' );
( 1, 1, 10000, '2017-03-15', '2017-06-16' ),
( 2, 2, 10001, '2017-06-10', '2017-09-02' ),
( 3, 3, 10003, '2017-06-12', '2017-09-02' ),
( 4, 4, 10000, '2017-03-15', '2017-09-03' ),
( 5, 5, 10002, '2017-06-15', NULL ),
( 6, 6, 10000, '2017-06-15', NULL ),
( 7, 1, 10001, '2017-09-02', '2017-09-02' );
CREATE TABLE `reader_info` (
`reader_id` BIGINT NOT NULL PRIMARY KEY,
`name` VARCHAR ( 10 ) NOT NULL,
`sex` VARCHAR ( 2 ) NOT NULL,
`birth` date NOT NULL,
`address` VARCHAR ( 50 ) NOT NULL,
`phone` VARCHAR ( 15 ) NOT NULL
`phone` VARCHAR ( 15 ) NOT NULL
) ENGINE = INNODB DEFAULT CHARSET = utf8;
ALTER TABLE `reader_info` MODIFY `reader_id` BIGINT NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 10000;
Expand All @@ -107,4 +108,4 @@ VALUES
( 10003, '张明华', '123456' ),
( 10004, '李一琛', '123456' ),
( 10005, '李二飞', '123456' );
COMMIT;
COMMIT;
5 changes: 4 additions & 1 deletion src/main/java/com/library/dao/BookDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class BookDao {
private final static String QUERY_BOOK_SQL = "SELECT * FROM book_info WHERE book_id like ? or name like ? ";
private final static String MATCH_BOOK_SQL = "SELECT count(*) FROM book_info WHERE book_id like ? or name like ? ";
private final static String GET_BOOK_SQL = "SELECT * FROM book_info where book_id = ? ";
private final static String DELETE_BOOK_SQL = "DELETE FROM book_info where book_id = ? ";

public int matchBook(String searchWord) {
String search = "%" + searchWord + "%";
Expand Down Expand Up @@ -82,7 +83,6 @@ public ArrayList<Book> getAllBooks() {
}
});
return books;

}

public int addBook(Book book) {
Expand All @@ -106,4 +106,7 @@ public int editBook(Book book) {
return jdbcTemplate.update(EDIT_BOOK_SQL, objects);
}

public int deleteBook(long bookId) {
return jdbcTemplate.update(DELETE_BOOK_SQL, bookId);
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/library/dao/LendDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LendDao {
private final static String LEND_BOOK_TWO_SQL = "UPDATE book_info SET number = number - 1 WHERE book_id = ? ";
private final static String LEND_LIST_SQL = "SELECT * FROM lend_list";
private final static String MY_LEND_LIST_SQL = "SELECT * FROM lend_list WHERE reader_id = ? ";
private final static String DELETE_BOOK_SQL = "DELETE FROM lend_list WHERE ser_num = ?";
private final static String DELETE_LEND_SQL = "DELETE FROM lend_list WHERE ser_num = ?";

public int returnBookOne(long bookId, long readerId) {
return jdbcTemplate.update(RETURN_BOOK_ONE_SQL, df.format(new Date()), bookId, readerId);
Expand Down Expand Up @@ -73,7 +73,7 @@ public ArrayList<Lend> myLendList(long readerId) {
return list;
}

public int deleteBook(long serNum) {
return jdbcTemplate.update(DELETE_BOOK_SQL, serNum);
public int deleteLend(long serNum) {
return jdbcTemplate.update(DELETE_LEND_SQL, serNum);
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/library/dao/ReaderCardDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ReaderCardDao {
@Autowired
private JdbcTemplate jdbcTemplate;
private final static String MATCH_READER_ID_SQL = "select count(*) from reader_card where reader_id = ? and password = ? ";
private final static String MATCH_READER_NAME_SQL = "select count(*) from reader_card where username = ? and password = ? ";
private final static String GET_PASSWORD_SQL = "select password from reader_card where reader_id = ? ";
private final static String FIND_READER_BY_USERID = "select * from reader_card where reader_id = ? ";
private final static String RE_PASSWORD_SQL = "UPDATE reader_card set password = ? where reader_id = ? ";
private final static String ADD_READERCARD_SQL = "INSERT INTO reader_card values ( ? , ? , ?)";
Expand Down Expand Up @@ -41,4 +41,7 @@ public int addReaderCard(ReaderInfo readerInfo,String password) {
return jdbcTemplate.update(ADD_READERCARD_SQL, readerId, username, password);
}

public String getPassword(long readerId) {
return jdbcTemplate.queryForObject(GET_PASSWORD_SQL, new Object[]{readerId}, String.class);
}
}
25 changes: 15 additions & 10 deletions src/main/java/com/library/service/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,32 @@ public class BookService {
@Autowired
private BookDao bookDao;

public ArrayList<Book> queryBook(String searchWord){
return bookDao.queryBook(searchWord);
public ArrayList<Book> queryBook(String searchWord) {
return bookDao.queryBook(searchWord);
}

public ArrayList<Book> getAllBooks(){
public ArrayList<Book> getAllBooks() {
return bookDao.getAllBooks();
}

public boolean matchBook(String searchWord){
return bookDao.matchBook(searchWord)>0;
public boolean matchBook(String searchWord) {
return bookDao.matchBook(searchWord) > 0;
}

public boolean addBook(Book book){
return bookDao.addBook(book)>0;
public boolean addBook(Book book) {
return bookDao.addBook(book) > 0;
}

public Book getBook(Long bookId){
public Book getBook(Long bookId) {
return bookDao.getBook(bookId);
}
public boolean editBook(Book book){
return bookDao.editBook(book)>0;

public boolean editBook(Book book) {
return bookDao.editBook(book) > 0;
}

public boolean deleteBook(Long bookId) {
return bookDao.deleteBook(bookId) > 0;
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/library/service/LendService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public ArrayList<Lend> myLendList(long readerId){
return lendDao.myLendList(readerId);
}

public int deleteBook(long serNum) {
return lendDao.deleteBook(serNum);
public int deleteLend(long serNum) {
return lendDao.deleteLend(serNum);
}

}
14 changes: 7 additions & 7 deletions src/main/java/com/library/service/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.library.dao.AdminDao;
import com.library.dao.ReaderCardDao;
import com.library.dao.ReaderInfoDao;
import com.library.domain.ReaderCard;
import com.library.domain.ReaderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -14,8 +12,6 @@ public class LoginService {
@Autowired
private ReaderCardDao readerCardDao;
@Autowired
private ReaderInfoDao readerInfoDao;
@Autowired
private AdminDao adminDao;

public boolean hasMatchReader(long readerId,String password){
Expand All @@ -29,9 +25,6 @@ public String getAdminUsername(long adminId) {
public ReaderCard findReaderCardByReaderId(long readerId){
return readerCardDao.findReaderByReaderId(readerId);
}
public ReaderInfo findReaderInfoByReaderId(long readerId){
return readerInfoDao.findReaderInfoByReaderId(readerId);
}

public boolean hasMatchAdmin(long adminId,String password){
return adminDao.getMatchCount(adminId, password) == 1;
Expand All @@ -44,6 +37,13 @@ public String getAdminPassword(long adminId){
return adminDao.getPassword(adminId);
}

public boolean readerRePassword(long readerId, String newPassword) {
return readerCardDao.resetPassword(readerId, newPassword) > 0;
}

public String getReaderPassword(long readerId) {
return readerCardDao.getPassword(readerId);
}


}
46 changes: 32 additions & 14 deletions src/main/java/com/library/web/BookController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.library.web;

import com.library.domain.Book;
import com.library.domain.Lend;
import com.library.domain.ReaderCard;
import com.library.service.BookService;
import com.library.service.LendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -19,6 +22,8 @@
public class BookController {
@Autowired
private BookService bookService;
@Autowired
private LendService lendService;

private Date getDate(String pubstr) {
try {
Expand All @@ -42,25 +47,20 @@ public ModelAndView queryBookDo(String searchWord) {
}
}

@RequestMapping("/reader_books.html")
public ModelAndView readerQueryBook() {
return new ModelAndView("reader_books");

}

@RequestMapping("/reader_querybook_do.html")
public String readerQueryBookDo(String searchWord, RedirectAttributes redirectAttributes) {
public ModelAndView readerQueryBookDo(String searchWord) {
if (bookService.matchBook(searchWord)) {
ArrayList<Book> books = bookService.queryBook(searchWord);
redirectAttributes.addFlashAttribute("books", books);
ModelAndView modelAndView = new ModelAndView("reader_books");
modelAndView.addObject("books", books);
return modelAndView;
} else {
redirectAttributes.addFlashAttribute("error", "没有匹配的图书");
return new ModelAndView("reader_books", "error", "没有匹配的图书");
}
return "redirect:/reader_querybook.html";
}

@RequestMapping("/allbooks.html")
public ModelAndView allBook() {
@RequestMapping("/admin_books.html")
public ModelAndView adminBooks() {
ArrayList<Book> books = bookService.getAllBooks();
ModelAndView modelAndView = new ModelAndView("admin_books");
modelAndView.addObject("books", books);
Expand All @@ -80,7 +80,7 @@ public String addBookDo(@RequestParam(value = "pubstr") String pubstr, Book book
} else {
redirectAttributes.addFlashAttribute("succ", "图书添加失败!");
}
return "redirect:/allbooks.html";
return "redirect:/admin_books.html";
}

@RequestMapping("/updatebook.html")
Expand All @@ -100,7 +100,7 @@ public String bookEditDo(@RequestParam(value = "pubstr") String pubstr, Book boo
} else {
redirectAttributes.addFlashAttribute("error", "图书修改失败!");
}
return "redirect:/allbooks.html";
return "redirect:/admin_books.html";
}

@RequestMapping("/bookdetail.html")
Expand Down Expand Up @@ -130,4 +130,22 @@ public ModelAndView admin_header() {
public ModelAndView reader_header() {
return new ModelAndView("reader_header");
}

@RequestMapping("/reader_books.html")
public ModelAndView readerBooks(HttpServletRequest request) {
ArrayList<Book> books = bookService.getAllBooks();
ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard");
ArrayList<Lend> myAllLendList = lendService.myLendList(readerCard.getReaderId());
ArrayList<Long> myLendList = new ArrayList<>();
for (Lend lend : myAllLendList) {
// 是否已归还
if (lend.getBackDate() == null) {
myLendList.add(lend.getBookId());
}
}
ModelAndView modelAndView = new ModelAndView("reader_books");
modelAndView.addObject("books", books);
modelAndView.addObject("myLendList", myLendList);
return modelAndView;
}
}
Loading

0 comments on commit f27dd93

Please sign in to comment.