I believe that it is helpful for you to develop a library management system (reconstructed version) by many people

Posted by ClanCC on Thu, 23 Dec 2021 05:38:29 +0100

Project premise

[project premise]
 master the basic syntax of java
 familiar with use process control
 understand object-oriented ideas
 proficient in encapsulation, inheritance and polymorphism
 be familiar with the use of the interface and avoid any abnormality
 be familiar with using collection
 be familiar with I/o flow related operations
 familiar with database operation
 understand the three-tier architecture and common design patterns
 familiar with Git tools

Project description

 for a long time, people use the traditional manual way to manage the daily business of the library, and its operation process is cumbersome. When borrowing a book, the reader first gives the book to be borrowed and the borrowing card to the staff, then the staff puts the information card of each book and the reader's borrowing card in a small column, and finally fills in the borrowing information on the borrowing card and the borrowing slip pasted on each book. When returning books, readers first give the books to be returned to the staff. The staff find the corresponding book card and borrowing card according to the book information, and fill in the corresponding book return information. Too cumbersome! Therefore, we need to design a library management system to facilitate students' borrowing and library management.
 the system is reconstructed based on project 3, the basic process is adjusted, and the functions of operating the library with different roles of administrator and operator are added.
 the system needs to log in or register first, and operate different functions according to different identities.
 the administrator is mainly responsible for the basic information management of the operator and the setting and viewing of relevant overdue amounts.
 the operator is mainly responsible for the management of readers' information and related books.
 the project will also facilitate data reading and storage in the database.

Project content

Project function flow chart:

The project functions are as follows:
(1) Login module: it includes login function (login according to two identities (administrator or operator). If there is no user information, you need to enter the registration function for registration. (the reading and storage of login user information should be connected to the database table operation). You also need to forget your password and view the login log records (logs can be streamed into corresponding files through I/O), password modification and other basic functions.
(2) Administrator module: the administrator mainly includes four basic functions: employee work log recording (recording the login time and various operation information of each operator, and the log can be streamed into the corresponding file through I/O), book borrowing amount setting, operator information management (addition, deletion and modification), and book overdue fine general ledger query (the bill records the overdue amount details of all expected books and the total overdue amount of all books in the last Library).
(3) Operator module
(the basic function comes from item 2, and the difference is the storage mode of data (I/O file  database))
(1) Reader information management: including the functions of adding reader information and querying and modifying reader information. After successful login, users can browse the information of all readers and retrieve the information of specific readers; at the same time, they can maintain reader information, including adding, deleting and modifying. Specific information includes reader types (the type of reader determines the maximum number of books he can borrow and the maximum number of days to return), the reader's name, date of birth, gender, telephone number, Department, registration date, etc. (relevant stored data are stored through database and operated by JDBC)
(2) Book information management: including the functions of adding book information and querying and modifying book information. After successful login, users can browse all book information and retrieve the information of specific books; they can also maintain book information, including adding books, deleting books and modifying book information. Specific information includes book ISBN, book name, author and publishing house , publication date, printing times, unit price, book category, etc. (relevant data is stored through database and operated by JDBC)
(3) Book borrowing management: includes the functions of book borrowing and book return. For book borrowing function, first enter the reader's number, then enter the information of the book to be borrowed, and record the current time of the system, that is, the borrowing time; for book return function, enter the reader's number, select the book borrowed under its name, and judge whether the difference between the current date, that is, the return date and the borrowing date exceeds the borrowing date After the specified time limit, calculate the fine, so as to return the books. Specific information includes: borrowing date, return date and penalty. To calculate the penalty, you need to know the reader type of the reader, and judge the number of books that can be borrowed and the number of books that can be borrowed according to the type. (relevant data is stored through database and operated by JDBC)
(4) Basic information maintenance: including book category setting, reader category setting and penalty setting. Book category setting can add, delete, modify and query the category of books; reader category setting can add, delete, modify and query the category of readers; penalty setting can specify the penalty standard for one day overdue. (relevant data is stored through database and operated by JDBC)

Project development

Interface

Entity class

Design pattern

We use the abstract factory pattern here:
Just show you the code. The prime minister needs it

Code in ManagerDao

OperatorDao:

Then there is a userfactory:

The above has a corresponding service
ManagerService and OperatorService and UserFactoryService
Then how to use it? Look at the code:
Create objects with factories

Re call method

This implements the abstract factory

Bug debugging encountered in development

I think the most serious bug is borrowing books, which involves a lot of things. For example, if there is a reader type in the penalty setting, but no penalty is set for this reader type, then the reader created by this reader type cannot return the book after borrowing the book, and a request should be given to set a penalty for this reader type before returning the book. For example, in addition, after using this reader type to create readers, this reader type cannot be deleted.
Of course, we can't show them one by one. Here are one or two. The judgment involved is bug debugging

    @Override
    public void bookReturn() throws SQLException, ParseException {
        QueryRunner runner = new QueryRunner();

        Connection conn = JDBCUtils.getConnection();

        String sql9 = "select * from borrowbook where returndate is null";
        BeanListHandler<BorrowBook> listHandle = new BeanListHandler<>(BorrowBook.class);
        List<BorrowBook> list1 = runner.query(conn, sql9, listHandle);
        if (list1 != null) {
            list1.forEach(System.out::println);
            System.out.println("Please enter the reader number of the reader who needs to return the book:");
            int readerid = TSUtility.readInt();
            String sql1 = "select * from reader where readerid =?";
            BeanHandler<Reader> handler1 = new BeanHandler<>(Reader.class);
            Reader reader = runner.query(conn, sql1, handler1, readerid);
            if (reader != null) {
                String sql = "select * from borrowbook where readerid = ? and returndate is null ";

//            BeanHandler<BorrowBook> handler = new BeanHandler<>(BorrowBook.class);
//            BorrowBook borrowBook = runner.query(conn, sql, handler, readerid);
//            String borrowDate = borrowBook.getBorrowDate();
//            System.out.println(borrowBook);

                BeanListHandler<BorrowBook> listHandler = new BeanListHandler<>(BorrowBook.class);
                List<BorrowBook> list = runner.query(conn, sql, listHandler, readerid);

                if (list.size() != 0) {
                    System.out.println("The reader's borrowing is as follows:");
                    String borrowDate = null;
                    for (int i = 0; i < list.size(); i++) {
                        borrowDate = list.get(i).getBorrowDate();
                        System.out.println(list.get(i));
                    }

//                    String sql6="select * from reader where readerid=?";
//                    BeanHandler<Reader> Handler6 = new BeanHandler<>(Reader.class);
                    int type1 = reader.getType();


                    String sql6 = "select * from readertype where id=?";
                    BeanHandler<ReaderType> handler6 = new BeanHandler<>(ReaderType.class);
                    ReaderType readerType1 = runner.query(conn, sql6, handler6, type1);
                    String typename = readerType1.getTypename();

                    String sql7 = "select * from fine where typename=?";
                    BeanHandler<Fine> handler7 = new BeanHandler<>(Fine.class);
                    Fine fine1 = runner.query(conn, sql7, handler7, typename);
                    if (fine1 != null) {
                        //            System.out.println("please enter the book number of the book to be returned:");
//            int ISBN = TSUtility.readInt();
                        System.out.println("Please enter the borrowing number of the book to be returned:");
                        int id = TSUtility.readInt();

                        String sql5 = "select * from borrowbook where id=? and returndate is null and readerid=? ";
                        BeanHandler<BorrowBook> handler = new BeanHandler<>(BorrowBook.class);
                        BorrowBook query = runner.query(conn, sql5, handler, id, readerid);
                        if (query != null) {
                            System.out.println("Please enter return date:(yyyy-MM-dd)");
                            String returndate = TSUtility.readKeyBoard(20, false);
                            boolean rqFormat = TSUtility.isValidDate(returndate);
                            if (rqFormat) {
                                Integer integer = dayBetween(borrowDate, returndate);
                                if (integer < 0) {
                                    System.out.println("The return time you entered is incorrect");
                                } else {
                                    String sql2 = "select type from reader where readerid = ?";

                                    BeanHandler<Reader> handler3 = new BeanHandler<>(Reader.class);
                                    Reader reader2 = runner.query(conn, sql2, handler3, readerid);
                                    int type = reader2.getType();


                                    String sql3 = "select `limit` from readertype where id=?";
                                    BeanHandler<ReaderType> handler2 = new BeanHandler<>(ReaderType.class);
                                    ReaderType readerType = runner.query(conn, sql3, handler2, type);
                                    int limit = readerType.getLimit();
                                    int number = getNumber(readerid);
                                    int fine = 0;
                                    if (integer > limit) {
                                        fine = (integer - limit) * number;
                                    }
                                    String sql4 = "update borrowbook set returndate = ? ,fine = ? where readerid = ? and id=?";
                                    int count = runner.update(conn, sql4, returndate, fine, readerid, id);
                                    System.out.println("Return the book successfully");
                                    JDBCUtils.closeResource1(conn, null);
                                    IOUtils.storeWorkLog("Added" + count + "Article return");
                                }
                            } else {
                                System.out.println("The date you entered is not in the correct format");
                            }

                        } else {
                            System.out.println("The borrowing number does not exist or is not the reader's borrowing number or the reader has returned it");
                        }
                    } else {
                        System.out.println("There is no penalty set for the reader type of this reader");
                    }

                } else {
                    System.out.println("The reader has no borrowing information");
                }

            } else {
                System.out.println("The reader does not exist");
            }


        } else {
            System.out.println("No borrowing information");
        }
        
    }

There are many such judgments

 @Override
    public void addBook() throws SQLException {

        boolean flog = false;
        System.out.println("All book type numbers and titles are as follows:");
        QueryRunner runner = new QueryRunner();
        Connection conn = JDBCUtils.getConnection();
        String sql = "select * from booktype ";
        BeanListHandler<BookType> ListHandler = new BeanListHandler<>(BookType.class);
        List<BookType> list = runner.query(conn, sql, ListHandler);
        if (list.size() == 0) {
            System.out.println("There is no book type, please add a book type");
        } else {
            for (int i = 0; i < list.size(); i++) {
                BookType bookType = list.get(i);
                System.out.println("Book type number:" + bookType.getId() + "," + "Book type name:" + bookType.getTypeName());
            }


            System.out.println("Please enter the book type number of the added book:");
            int typeid = TSUtility.readInt();

            for (int i = 0; i < list.size(); i++) {
                int id = list.get(i).getId();
                if (typeid == id) {
                    flog = true;
                    break;
                }
            }
            if (flog) {

                System.out.println("Please enter the title of the book:");
                String bookname = TSUtility.readKeyBoard(8, false);

                String sql8 = "select bookname from book where bookname =?";
                BeanHandler<Book> handler = new BeanHandler<>(Book.class);
                Book book = runner.query(conn, sql8, handler, bookname);
                if (book != null) {
                    System.out.println("The book already exists");
                } else {
                    System.out.println("Please enter the author's name:");
                    String author = TSUtility.readKeyBoard(6, false);
                    System.out.println("Please enter the publisher name:");
                    String publish = TSUtility.readKeyBoard(9, false);
                    System.out.println("Please enter publication date:(format:yyyy-MM-dd)");
                    String publishdate = TSUtility.readKeyBoard(20, false);

                    boolean validDate = TSUtility.isValidDate(publishdate);
                    if (validDate) {
                        System.out.println("Please enter the printing times:");
                        int publishtime = TSUtility.readInt();
                        System.out.println("Please enter the book unit price:");
                        int unitprice = TSUtility.readInt();


                        String sql1 = "insert into book(typeid,bookname,author,publish,publishdate,publishtime,unitprice)values(?,?,?,?,?,?,?)";
                        int count = runner.update(conn, sql1, typeid, bookname, author, publish, publishdate, publishtime, unitprice);
                        System.out.println("Successfully added books");
                        JDBCUtils.closeResource1(conn, null);
                        IOUtils.storeWorkLog("Added" + count + "This book");
                    } else {
                        System.out.println("The input date format is incorrect");
                    }
                }
                
            } else {
                System.out.println("The book type number you entered does not exist");
                IOUtils.storeWorkLog("Because the book type number entered does not exist,Failed to add a book");
            }
        }

    }

Some of the above judgments will contact multiple tables. This requires you to think clearly. The code is just an aid to everyone. You should think it out for yourself.

Post development experience

1. First of all, this is a multi person project development, so familiar with git tools

Skillfully pull from remote warehouse to local warehouse to achieve consistency between idea and remote warehouse


2. Start with the requirements document and clarify the development ideas
3. Improve all documents
4. Division of labor development module

I don't write much. I hope it will help you!

Topics: Java Design Pattern Back-end