Nowadays so much data is stored and circulated electronically, a library might seem to be a slightly outdated concept. However, a huge proportion of the world's information and learning is still not available electronically, so libraries retain their importance for research and study.
Possessing millions of books and periodicals, our school library receives thousands of readers every day, which brings much workload to the library staff. Consequently, there is an urgent need to adopt a kind of digital management. And that is what we are going to develop.
Peking University Library does this well. Here is the URL of their lending rules and regulations.
https://www.lib.pku.edu.cn/portal/cn/jy/jybl/jiehuanxujie
As you can see, readers get self-service in most cases. Readers search for and order books online, and come to library to fetch books with scanning their reader cards and barcode on books. After that, they can renew books online at any time if permitted.
There are some patterns we can learn from. Library staff has no need to deal with books lending and return in person, which can be handled by the software system.
What is more, we hope that totally digital management can be realized with the help of software system. Considering of the huge workload, we divide the management into two parts. The former is in charge of books: to create, update and delete books' information, while the latter is in charge of readers: to create and delete readers' information as well as to query borrowing records, etcetera.
According to the demand analysis, we provide a diagram of the system overall function modules below.
Number | Name | Meaning | Type | Length |
---|---|---|---|---|
1 | UserID | To identify a user | Character string | 15 |
2 | UserName | A user's personal name | Character string | 20 |
3 | Password | Secret word for a user to login | Character string | 255 |
4 | A user's email address | Character string | 255 | |
5 | Phone | A user's phone number | Character string | 11 |
6 | Debt | A user's fine for overdue borrowing or losing books | Decimal | 10 |
7 | Authority | A user's authority to access the system | Integer | 1 |
8 | BookID | To identify a book | Integer | 10 |
9 | ISBN | A book's International Standard Book Number | Character string | 17 |
10 | Title | A book's title | Character string | 50 |
11 | Author | Name of a book's author | Character string | 50 |
12 | Publisher | Name of a book's publisher | Character string | 50 |
13 | Cover | URL of a book's cover picture | Character string | 255 |
14 | Intro | A book's introduction | Character string | 255 |
15 | Price | A book's price | Decimal | 10 |
16 | Total | Total quantity of a book | Integer | 10 |
17 | Available | Available quantity of a book | Integer | 10 |
18 | Location | A book's location in the library | Character string | 50 |
19 | CategoryID | To identify a category of books | Integer | 10 |
20 | CategoryName | Name of a category of books | Character string | 10 |
21 | Lent_at | Date and time when a user borrow a book | Timestamp | |
22 | Due_at | Due time when a user need to return a book | Timestamp | |
23 | Returned_at | Date and time when a user return a book | Timestamp | |
24 | Renewed | Whether the book has been renewed | Integer | 1 |
Number | Name | Meaning | Composition |
---|---|---|---|
1 | User | To define a user | UserID + UserName + Password + Email + Phone + Debt + Authority |
2 | Book | To define a book | BookID + ISBN + Title + Author + Publisher + Cover + Intro + Price + Total + Available + Location + CategoryID + CategoryName |
Number | Name | Source | Destination | Composition |
---|---|---|---|---|
1 | Books' base info | Reader, Books admin | Search for books | Title + CategoryName |
2 | Books' detailed info | [Books] | Search for books | BookID + ISBN + Title + Author + Publisher + Cover + Intro + Price + Total + Available + Location + CategoryID + CategoryName |
3 | Borrowing info | Reader | Borrow books | UserID + BookID + Lent_at + Due_at |
4 | Returning info | Reader | Return books | UserID + BookID + Lent_at + Returned_at |
5 | Renewing info | Reader | Renew books | UserID + BookID + Lent_at + Due_at |
6 | Payment info | Reader | Pay fine | UserID + Debt |
7 | New books info | Books admin | Create books | BookID + ISBN + Title + Author + Publisher + Cover + Intro + Price + Total + Available + Location + CategoryID |
8 | Books update info | Books admin | Update books | BookID + ISBN + Title + Author + Publisher + Cover + Intro + Price + Total + Available + Location + CategoryID |
9 | Books deletion info | Books admin | Delete books | BookID |
10 | Readers basic info | Readers admin | Search for readers | UserID + UserName |
11 | Readers detailed info | [Users], [Lent], [Returned] | Search for readers | UserID + UserName + + Email + Phone + Debt + BookID + Lent_at + Due_at + Returned_at |
12 | New readers info | Readers admin | Create readers | UserID + UserName + Password + Email + Phone |
13 | Readers update info | Readers admin | Update readers | UserID + UserName + Password + Email + Phone |
14 | Readers deletion info | Readers admin | Delete readers | UserID |
15 | Admins basic info | Superuser | Search for admins | UserID + UserName |
16 | Admins detailed info | [Users] | Search for admins | UserID + UserName + + Email + Phone |
17 | New admins info | Superuser | Create admins | UserID + UserName + Password + Email + Phone + authority |
18 | Admins update info | Superuser | Update admins | UserID + UserName + Password + Email + Phone + authority |
19 | Admins deletion info | Superuser | Delete admins | UserID |
Number | Name | Meaning | Inflows | Outflows |
---|---|---|---|---|
1 | Books | To storage information of books | Books basic info | Books detailed info |
2 | Users | To storage information of users | Readers basic info, Admins basic info, Payment info | Readers detailed info, Admins detailed info |
3 | Lent | To storage information of books' lending | Borrowing info | Readers detailed info |
4 | Returned | To storage information of books' returning | Returning info | Readers detailed info |
Number | Name | Meaning | Inflows | Outflows | Processing logic |
---|---|---|---|---|---|
1 | Search for books | Readers search for books by inputting keywords | Books base info | Books detailed info | System validates readers' account and indexes books by keywords and returns result |
2 | Borrow books | Readers borrow books by scanning their card and books' code | Books borrowing info | (Feedback) | System validates readers' account and inserts lending records into table |
3 | Return books | Readers return books by scanning their card and books' code | Books returning info | (Feedback) | System validates readers' account and inserts returning records into table |
4 | Renew books | Readers renew books they are keeping | Books renewing info | (Feedback) | System validates readers' account and updates lending records in the table |
5 | Pay fine | Readers pay fine for overdue or lost books | Payment info | (Feedback) | System validates readers' account and updates their debt info in the table |
6 | Create books | Books admins add information of new or existing books | New books info | (Feedback) | System validates admins' account and inserts new books' records into table |
7 | Update books | Books admins update information of existing books | Books update info | (Feedback) | System validates admins' account and updates records of books in the table |
8 | Delete books | Books admins delete information of existing books | Books deletion info | (Feedback) | System validates admins' account and deletes records of books in the table |
9 | Search for readers | Readers admins search for readers by inputting keywords | Readers basic info | Readers detailed info | System validates admins' account and indexes readers by keywords and returns result |
10 | Create readers | Readers admins add information of new readers | New readers info | (Feedback) | System validates admins' account and inserts new readers' records into table |
11 | Update readers | Readers admins update information existing readers | Readers update info | (Feedback) | System validates admins' account and updates records of readers in the table |
12 | Delete readers | Readers admins delete information existing readers | Readers deletion info | (Feedback) | System validates admins' account and deletes records of readers in the table |
13 | Create admins | Superuser adds information of new admins | New admins info | (Feedback) | System validates superuser's account and inserts new admins' records into table |
14 | Update admins | Superuser updates information existing readers | Admins update info | (Feedback) | System validates superuser's account and updates records of admins in the table |
15 | Delete admins | Superuser deletes information existing readers | Admins deletion info | (Feedback) | System validates superuser's account and deletes records of admins in the table |
-
users (id, name, password, email, phone, debt, authority)
-
books (id, isbn)
-
books_info (isbn, title, category, author, publisher, cover, intro, price, total, available, location)
-
categories (id, name)
-
lent (uid, bid, lent_at, due_at, renewed)
-
returned (uid, bid, lent_at, returned_at)
users
Number | Name | Meaning | Type | Length | Primary key |
---|---|---|---|---|---|
1 | id | To identify a user | varchar | 15 | ✔ |
2 | name | A user's personal name | varchar | 20 | |
3 | password | Secret word for a user to login | varchar | 255 | |
4 | A user's email address | varchar | 255 | ||
5 | phone | A user's phone number | varchar | 11 | |
6 | debt | A user's fine for overdue borrowing or losing books | decimal | 10 | |
7 | authority | A user's authority to access the system | tinyint | 1 |
books
Number | Name | Meaning | Type | Length | Primary key |
---|---|---|---|---|---|
1 | id | To identify a book | int | 10 | ✔ |
2 | isbn | A book's International Standard Book Number | varchar | 17 |
books_info
Number | Name | Meaning | Type | Length | Primary key |
---|---|---|---|---|---|
1 | isbn | A book's International Standard Book Number | varchar | 17 | ✔ |
2 | title | A book's title | varchar | 50 | |
3 | author | Name of a book's author | varchar | 50 | |
4 | publisher | Name of a book's publisher | varchar | 50 | |
5 | cover | URL of a book's cover picture | varchar | 255 | |
6 | intro | A book's introduction | varchar | 255 | |
7 | price | A book's price | decimal | 10 | |
8 | total | Total quantity of a book | int | 10 | |
9 | available | Available quantity of a book | int | 10 | |
10 | location | A book's location in the library | varchar | 50 |
categories
Number | Name | Meaning | Type | Length | Primary key |
---|---|---|---|---|---|
1 | id | To identify a category of books | int | 10 | ✔ |
2 | name | Name of a category of books | varchar | 20 |
lent
Number | Name | Meaning | Type | Length | Primary key |
---|---|---|---|---|---|
1 | uid | To identify a user | varchar | 15 | |
2 | bid | To identify a book | int | 10 | ✔ |
3 | lent_at | Date and time when a user borrow a book | timestamp | ✔ | |
4 | due_at | Due time when a user need to return a book | timestamp | ||
5 | renewed | Whether the book has been renewed | tinyint | 1 |
returned
Number | Name | Meaning | Type | Length | Primary key |
---|---|---|---|---|---|
1 | uid | To identify a user | varchar | 15 | |
2 | bid | To identify a book | int | 10 | ✔ |
3 | lent_at | Date and time when a user borrow a book | timestamp | ||
4 | returned_at | Date and time when a user return a book | timestamp | ✔ |
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for books
-- ----------------------------
DROP TABLE IF EXISTS `books`;
CREATE TABLE `books` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`isbn` varchar(13) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
KEY `id` (`id`),
KEY `isbn` (`isbn`),
CONSTRAINT `books_fk_1` FOREIGN KEY (`isbn`) REFERENCES `books_info` (`isbn`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=89 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for books_info
-- ----------------------------
DROP TABLE IF EXISTS `books_info`;
CREATE TABLE `books_info` (
`isbn` varchar(13) NOT NULL,
`title` varchar(50) NOT NULL,
`category` int(10) NOT NULL AUTO_INCREMENT,
`author` varchar(50) NOT NULL,
`publisher` varchar(50) NOT NULL,
`cover` varchar(255) DEFAULT NULL,
`intro` varchar(255) DEFAULT NULL,
`price` decimal(10,2) NOT NULL,
`total` int(10) NOT NULL,
`available` int(10) NOT NULL,
`location` varchar(50) NOT NULL,
PRIMARY KEY (`isbn`),
KEY `isbn` (`isbn`),
KEY `category` (`category`),
CONSTRAINT `books_info_fk_1` FOREIGN KEY (`category`) REFERENCES `categories` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for categories
-- ----------------------------
DROP TABLE IF EXISTS `categories`;
CREATE TABLE `categories` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for lent
-- ----------------------------
DROP TABLE IF EXISTS `lent`;
CREATE TABLE `lent` (
`uid` varchar(15) NOT NULL,
`bid` int(10) NOT NULL AUTO_INCREMENT,
`lent_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`due_at` timestamp NULL DEFAULT NULL,
`renewed` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`bid`,`lent_at`) USING BTREE,
KEY `bid` (`bid`),
KEY `uid` (`uid`),
CONSTRAINT `lent_fk_1` FOREIGN KEY (`uid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `lent_fk_2` FOREIGN KEY (`bid`) REFERENCES `books` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=82 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for password_resets
-- ----------------------------
DROP TABLE IF EXISTS `password_resets`;
CREATE TABLE `password_resets` (
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY `password_resets_email_index` (`email`(191)) USING BTREE,
KEY `password_resets_token_index` (`token`(191)) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- ----------------------------
-- Table structure for returned
-- ----------------------------
DROP TABLE IF EXISTS `returned`;
CREATE TABLE `returned` (
`uid` varchar(15) NOT NULL,
`bid` int(10) NOT NULL AUTO_INCREMENT,
`lent_at` timestamp NULL DEFAULT NULL,
`returned_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`bid`,`returned_at`) USING BTREE,
KEY `bid` (`bid`),
KEY `uid` (`uid`),
CONSTRAINT `returned_fk_1` FOREIGN KEY (`uid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `returned_fk_2` FOREIGN KEY (`bid`) REFERENCES `books` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` varchar(15) NOT NULL,
`name` varchar(20) NOT NULL,
`password` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`phone` varchar(11) NOT NULL,
`debt` decimal(10,2) NOT NULL DEFAULT '0.00',
`authority` tinyint(1) NOT NULL DEFAULT '0',
`remember_token` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id` (`id`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- View structure for view_books
-- ----------------------------
DROP VIEW IF EXISTS `view_books`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_books` AS select `books_info`.`isbn` AS `isbn`,`books_info`.`title` AS `title`,`categories`.`name` AS `category`,`books_info`.`total` AS `total`,`books_info`.`available` AS `available` from (`books_info` join `categories`) where (`books_info`.`category` = `categories`.`id`);
-- ----------------------------
-- View structure for view_overdue
-- ----------------------------
DROP VIEW IF EXISTS `view_overdue`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_overdue` AS select `users`.`id` AS `id`,`users`.`name` AS `name`,`books_info`.`title` AS `title`,`lent`.`lent_at` AS `borrow_at`,`lent`.`due_at` AS `due_at` from (((`users` join `books_info`) join `books`) join `lent`) where ((`users`.`id` = `lent`.`uid`) and (`books_info`.`isbn` = `books`.`isbn`) and (`books`.`id` = `lent`.`bid`) and (`lent`.`due_at` < now()));
-- ----------------------------
-- Procedure structure for query_records
-- ----------------------------
DROP PROCEDURE IF EXISTS `query_records`;
delimiter $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `query_records`(IN uid VARCHAR(15))
BEGIN
SELECT books.id AS bid, books_info.isbn AS isbn, title, lent_at, due_at
FROM users, books, books_info, lent
WHERE users.id = uid AND users.id = lent.uid AND books.id = lent.bid AND books.isbn = books_info.isbn;
SELECT books.id AS bid, books_info.isbn AS isbn, title, lent_at, returned_at
FROM users, books, books_info, returned
WHERE users.id = uid AND users.id = returned.uid AND books.id = returned.bid AND books.isbn = books_info.isbn;
END$$
delimiter ;
-- ----------------------------
-- Procedure structure for update_debt
-- ----------------------------
DROP PROCEDURE IF EXISTS `update_debt`;
delimiter $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `update_debt`()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE uid VARCHAR(15);
DECLARE cur CURSOR FOR SELECT view_overdue.id FROM view_overdue;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
OPEN cur;
REPEAT
FETCH cur INTO uid;
if done != 1 THEN
UPDATE users SET debt = debt + 0.5 WHERE users.id = uid;
END IF;
UNTIL done END REPEAT;
CLOSE cur;
END$$
delimiter ;
SET FOREIGN_KEY_CHECKS = 1;