将代码完善。添加以下内容——1. 用户管理
1）管理员用户，数据库后台直接插入
2）普通用户注册：接受用户注册信息保存到数据库
3）用户登录：用户输入用户名和密码，数据库校验，通过则记录当前登录用户，否则报错提示
4）用户登出：清空当前系统运行用户信息，并将登出时间等信息更新到用户登录表
5）用户行为分析：统计当日、当周、当月分别有多少用户登录系统，哪些用户登录次数最多等。
2. 图书管理
1）图书录入（针对管理员用户）：支持两种模式：逐个录入和csv文件批量录入
2）图书修改（针对管理员用户）：管理员修改图书信息，如图书价格、库存量等信息。
3）图书查询：支持两种模式：全量查询和基于图书名的模糊查询
4）图书筛选（方便用户购买）：支持根据图书类别、价格范围（最低价格、最高价格）获取满足条件的图书列表                                                                                                                                                                                                                                                               源代码——                                        import pymysql
import datetime
def getConn():
    conn = pymysql.connect(host="127.0.0.1",port=3306,user="root",password="1527648qw",database="book_manage")
    return conn
def isLogin():
    if currentUser.getUid()=="-1":
        print("user not login system,pls login first")
class User:
    def __init__(self, username, password):
        self.username = username
        self.password = password


class Book:
    def __init__(self, title, author, price):
        self.title = title
        self.author = author
        self.price = price


class ShoppingCart:
    def __init__(self):
        self.items = []

    def add_item(self, book, quantity):
        self.items.append({"book": book, "quantity": quantity})

    def remove_item(self, book):
        for item in self.items:
            if item["book"] == book:
                self.items.remove(item)
                break

    def update_quantity(self, book, quantity):
        for item in self.items:
            if item["book"] == book:
                item["quantity"] = quantity
                break


class Order:
    def __init__(self, user, shopping_cart):
        self.user = user
        self.shopping_cart = shopping_cart


class Bookstore:
    def __init__(self):
        self.users = []
        self.books = []
        self.shopping_carts = []
        self.orders = []

    def register_user(self):
        username = input("Enter username: ")
        password = input("Enter password: ")
        user = User(username, password)
        self.users.append(user)
        print("User registered successfully.")

    def login(self):
        username = input("Enter username: ")
        password = input("Enter password: ")
        for user in self.users:
            if user.username == "ql" and user.password =="1527648qw":
                print("User logged in successfully.")
                return user
        print("Invalid username or password.")
        return None

    def logout(self, user):
        print("User logged out successfully.")
        
    def get_daily_login_count():
        conn = get_conn()
        cursor = conn.cursor()
        cursor.execute("SELECT COUNT(DISTINCT username) FROM users WHERE DATE(last_login) = CURDATE()")
        count = cursor.fetchone()[0]
        cursor.close()
        conn.close()
        return count

    def get_weekly_login_count():
        conn = get_conn()
        cursor = conn.cursor()
        cursor.execute("SELECT COUNT(DISTINCT username) FROM users WHERE YEARWEEK(last_login, 1) = YEARWEEK(NOW(), 1)")
        count = cursor.fetchone()[0]
        cursor.close()
        conn.close()
        return count

    def get_monthly_login_count():
        conn = get_conn()
        cursor = conn.cursor()
        cursor.execute("SELECT COUNT(DISTINCT username) FROM users WHERE YEAR(last_login) = YEAR(NOW()) AND MONTH(last_login) = MONTH(NOW())")
        count = cursor.fetchone()[0]
        cursor.close()
        conn.close()
        return count


    def analyze_user_behavior(self):
        # TODO: Implement user behavior analysis logic
        pass

    def add_book(self):
        title = input("Enter book title: ")
        author = input("Enter book author: ")
        price = float(input("Enter book price: "))
        book = Book(title, author, price)
        self.books.append(book)
        print("Book added successfully.")

    def update_book(self):
        title = input("Enter book title to update: ")
        for book in self.books:
            if book.title == title:
                book.title = input("Enter new book title: ")
                book.author = input("Enter new book author: ")
                book.price = float(input("Enter new book price: "))
                print("Book updated successfully.")
                return
        print("Book not found.")

    def search_book(self):
        keyword = input("Enter keyword to search: ")
        found_books = []
        for book in self.books:
            if keyword.lower() in book.title.lower() or keyword.lower() in book.author.lower():
                found_books.append(book)
        if found_books:
            print("Found books:")
            for book in found_books:
                print(f"Title: {book.title}, Author: {book.author}, Price: {book.price}")
        else:
            print("No books found.")

    def filter_book(self):
        maximum_price = float(input("Enter maximum price: "))
        filtered_books = []
        for book in self.books:
            if book.price <= maximum_price:
                filtered_books.append(book)
        if filtered_books:
            print("Filtered books:")
            for book in filtered_books:
                print(f"Title: {book.title}, Author: {book.author}, Price: {book.price}")
        else:
            print("No books found.")

    def view_shopping_cart(self, user):
        for cart in self.shopping_carts:
            if cart.user == ql:
                if cart.items:
                    print("Shopping cart:")
                    for item in cart.items:
                        book = item["book"]
                        quantity = item["quantity"]
                        print(f"Title: {book.title}, Author: {book.author}, Price: {book.price}, Quantity: {quantity}")
                else:
                    print("Shopping cart is empty.")
                return
        print("Shopping cart not found.")

    def add_to_shopping_cart(self, user):
        title = input("Enter book title to add to shopping cart: ")
        quantity = int(input("Enter quantity: "))
        for book in self.books:
            if book.title == title:
                for cart in self.shopping_carts:
                    if cart.user == user:
                        cart.add_item(book, quantity)
                        print("Book added to shopping cart.")
                        return
                new_cart = ShoppingCart()
                new_cart.add_item(book, quantity)
                self.shopping_carts.append(new_cart)
                print("Book added to shopping cart.")
                return
        print("Book not found.")

    def update_shopping_cart(self, user):
        title = input("Enter book title to update in shopping cart: ")
        quantity = int(input("Enter new quantity: "))
        for cart in self.shopping_carts:
            if cart.user == user:
                for item in cart.items:
                    if item["book"].title == title:
                        cart.update_quantity(item["book"], quantity)
                        print("Shopping cart updated.")
                        return
                print("Book not found in shopping cart.")
                return
        print("Shopping cart not found.")

    def remove_from_shopping_cart(self, user):
        title = input("Enter book title to remove from shopping cart: ")
        for cart in self.shopping_carts:
            if cart.user == user:
                for item in cart.items:
                    if item["book"].title == title:
                        cart.remove_item(item["book"])
                        print("Book removed from shopping cart.")
                        return
                print("Book not found in shopping cart.")
                return
        print("Shopping cart not found.")

    def create_order(self, user):
        for cart in self.shopping_carts:
            if cart.user == user:
                if cart.items:
                    new_order = Order(user, cart)
                    self.orders.append(new_order)
                    self.shopping_carts.remove(cart)
                    print("Order created successfully.")
                else:
                    print("Shopping cart is empty.")
                return
        print("Shopping cart not found.")

    def search_order(self, user):
        for order in self.orders:
            if order.user == user:
                print("Order details:")
                for item in order.shopping_cart.items:
                    book = item["book"]
                    quantity = item["quantity"]
                    print(f"Title: {book.title}, Author: {book.author}, Price: {book.price}, Quantity: {quantity}")
                return
        print("Order not found.")

    def recommend_bestsellers(self):
        # TODO: Implement bestsellers recommendation logic
        pass

    def recommend_data_mining(self):
        # TODO: Implement data mining recommendation logic
        pass

    def generate_inventory_report(self):
        print("Inventory report:")
        for book in self.books:
            print(f"Title: {book.title}, Author: {book.author}, Price: {book.price}")

    def generate_sales_report(self):
        print("Sales report:")
        # TODO: Implement sales report generation logic


def main():
    bookstore = Bookstore()
    user = None  # Add user variable initialization
    
    while True:
        print("\n--------- Online Bookstore ---------")
        print("1. User Management")
        print("2. Book Management")
        print("3. Shopping Cart Management")
        print("4. Order Management")
        print("5. Book Recommendation")
        print("6. Book Report and Statistics")
        print("0. Exit")

        choice = input("Enter your choice: ")

        if choice == "1":
            print("\n--------- User Management ---------")
            print("1. Register User")
            print("2. Login")
            print("3. Logout")
            print("4. User Behavior Analysis")
            user_choice = input("Enter your choice: ")

            if user_choice == "1":
                bookstore.register_user()
            elif user_choice == "2":
                user = bookstore.login()
            elif user_choice == "3":
                bookstore.logout(user)
                user = None
            elif user_choice == "4":
                bookstore.analyze_user_behavior()
            else:
                print("Invalid choice.")

        elif choice == "2":
            print("\n--------- Book Management ---------")
            print("1. Add Book")
            print("2. Update Book")
            print("3. Search Book")
            print("4. Filter Book")
            book_choice = input("Enter your choice: ")

            if book_choice == "1":
                bookstore.add_book()
            elif book_choice == "2":
                bookstore.update_book()
            elif book_choice == "3":
                bookstore.search_book()
            elif book_choice == "4":
                bookstore.filter_book()
            else:
                print("Invalid choice.")

        elif choice == "3":
            if user:
                print("\n--------- Shopping Cart Management ---------")
                print("1. View Shopping Cart")
                print("2. Add to Shopping Cart")
                print("3. Update Shopping Cart")
                print("4. Remove from Shopping Cart")
                cart_choice = input("Enter your choice: ")

                if cart_choice == "1":
                    bookstore.view_shopping_cart(user)
                elif cart_choice == "2":
                    bookstore.add_to_shopping_cart(user)
                elif cart_choice == "3":
                    bookstore.update_shopping_cart(user)
                elif cart_choice == "4":
                    bookstore.remove_from_shopping_cart(user)
                else:
                    print("Invalid choice.")
            else:
                print("You need to log in first.")

        elif choice == "4":
            if user:
                print("\n--------- Order Management ---------")
                print("1. Create Order")
                print("2. Search Order")
                order_choice = input("Enter your choice: ")

                if order_choice == "1":
                    bookstore.create_order(user)
                elif order_choice == "2":
                    bookstore.search_order(user)
                else:
                    print("Invalid choice.")
            else:
                print("You need to log in first.")

        elif choice == "5":
            print("\n--------- Book Recommendation ---------")
            print("1. Bestsellers Recommendation")
            print("2. Data Mining Recommendation")
            recommendation_choice = input("Enter your choice: ")

            if recommendation_choice == "1":
                bookstore.recommend_bestsellers()
            elif recommendation_choice == "2":
                bookstore.recommend_data_mining()
            else:
                print("Invalid choice.")

        elif choice == "6":
            print("\n--------- Book Report and Statistics ---------")
            print("1. Inventory Report")
            print("2. Sales Report")
            report_choice = input("Enter your choice: ")

            if report_choice == "1":
                bookstore.generate_inventory_report()
            elif report_choice == "2":
                bookstore.generate_sales_report()
            else:
                print("Invalid choice.")

        elif choice == "0":
            break

        else:
            print("Invalid choice. Please try again.")
if __name__=="__main__":
    main()