Skip to content

Commit

Permalink
整理结构
Browse files Browse the repository at this point in the history
  • Loading branch information
penley277 committed Nov 24, 2019
1 parent c470058 commit 39074d7
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 74 deletions.
47 changes: 7 additions & 40 deletions list/BookList.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,7 @@ def addBook(self, other):
self.db.insert_values('book', [other.getBookNo(), other.getBookName(),
other.getAuthor(), other.getPublisher(),
other.getBookCnt(), other.getBorrowCnt(),
other.getPubTime(), " "])

def getBookByName(self, name):
"""
通过书籍的名字,获取书籍
:param name: 书籍的名字
:return: 返回书籍
"""
select = self.db.select_items('book', '*', '%s%s%s' % ('where bookName like \'%', name, '%\''))
if len(select) == 0:
return Error.NoneBook

i = 0
bi = []
while i < len(select):
bi.append(Book(select[i][0], select[i][1], select[i][2], select[i][3], select[i][4], select[i][5],
select[i][6], select[i][7]))
i = i + 1
return bi
other.getPubTime(), other.getComment()])

def getBookByNo(self, num):
"""
Expand All @@ -71,24 +53,9 @@ def updateBorrowAndCnt(self, bookno, bookCnt, borrowCnt):
self.db.update_values('book', {'bookCnt': bookCnt, 'borrowCnt': borrowCnt},
'%s%s%s' % ('where bookNum=\'', bookno, '\''))

def getBookByAuthor(self, author):
"""
通过书籍的书号,获取书籍
:param author: 作者
:param num: 书籍的书号
:return: 返回书籍
"""

select = self.db.select_items('book', '*', '%s%s%s' % ('where author like \'%', author, '%\''))
if len(select) == 0:
return Error.NoneBook
i = 0
bi = []
while i < len(select):
bi.append(Book(select[i][0], select[i][1], select[i][2], select[i][3], select[i][4], select[i][5],
select[i][6], select[i][7]))
i = i + 1
return bi
def modifyBookByParam(self, param, bookno, inform):
self.db.update_values('book', {param: inform},
'%s%s%s' % ('where bookNum=\'', bookno, '\''))

def removeBook(self, num):
"""
Expand All @@ -98,14 +65,14 @@ def removeBook(self, num):
"""
self.db.delete_values('book', '%s%s%s' % ('where bookNum=\'', num, '\''))

def getBookByPublisher(self, publisher):
def getBookByParam(self, param, publisher):
"""
通过书籍的书号,获取书籍
通过书籍的字段,获取书籍
:param author: 作者
:param num: 书籍的书号
:return: 返回书籍
"""
select = self.db.select_items('book', '*', '%s%s%s' % ('where publisher like \'%', publisher, '%\''))
select = self.db.select_items('book', '*', '%s%s%s%s%s' % ('where ', param,' like \'%', publisher, '%\''))

if len(select) == 0:
return Error.NoneBook
Expand Down
39 changes: 11 additions & 28 deletions list/StudentList.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from DButil.DBO import DBO
from models.Student import Student
from util import Error
Expand Down Expand Up @@ -42,34 +41,24 @@ def getStuByNo(self, no):
return Error.NoneStu
return Student(select[0][0], select[0][1], select[0][2], select[0][3], select[0][4], select[0][5])


def modify(self, param, no, name):
self.db.update_values('student', {'%s%s%s' % ('\'', param, '\''): name}, '%s%s%s' % ('where studNo=\'', no, '\''))

"""
修改学生的某个属性的值,不包括学生号
:param param: 修改的属性名
:param no: 学号
:param name: 姓名
:return:
"""
self.db.update_values('student', {'%s%s%s' % ('\'', param, '\''): name},
'%s%s%s' % ('where studNo=\'', no, '\''))

def getStuByName(self, name):
def getStuByParam(self, param, other):
"""
通过学生的名字,获取学生
:param name: 想要找到的学生的名字
:return: 某个学生列表
"""
select = self.db.select_items('student', '*', '%s%s%s' % ('where studName like \'%', name, '%\''))
if len(select) == 0:
return Error.NoneStu
i = 0
bi = []
while i < len(select):
bi.append(Student(select[i][0], select[i][1], select[i][2], select[i][3], select[i][4], select[i][5]))
i = i + 1
return bi

def getStuByPhNum(self, phone):
"""
通过学生的手机号,获取该学生
:param phone: 想要找到的学生的手机号
:return: 某个学生
"""
select = self.db.select_items('student', '*', '%s%s%s' % ('where phoneNum like \'%', phone, '%\''))
select = self.db.select_items('student', '*', '%s%s%s%s%s' % ('where ', param, ' like \'%', other, '%\''))
if len(select) == 0:
return Error.NoneStu
i = 0
Expand Down Expand Up @@ -114,9 +103,3 @@ def addStuByFile(self, filename):

def closeDB(self):
self.db.close_database()

if __name__ == '__main__':
stu = StudentList('system.db')
stu.getStuByName('李').pop(0).print()
stu.getStuByNo('1113000001').print()
stu.getStuByPhNum('13941698396').pop(0).print()
Empty file added services/AdminManager.py
Empty file.
104 changes: 104 additions & 0 deletions services/BookManagerService.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from list.BookList import BookList
from models.Book import Book
from util import Error, Success


class BookManagerService(object):

def __init__(self, database_name):
"""
学生服务类,提供程序的各项功能
:param database_name:
"""
self.booklist = BookList(database_name)

def addBook(self, no, name, author, publisher, bookCnt, pubTime, comment=None):
if comment == None:
comment= ''
other = Book(no, name, author, publisher, bookCnt, 0, pubTime, comment)
self.booklist.addBook(other)

def getBookByNo(self, no):
"""
使用书号,获取书籍信息
:param no: 书号
:return: 书籍信息的列表
@see$Error.NoneBook: 书籍不存在
"""
return self.booklist.getBookByNo(no)

def getBookByName(self, name):
"""
使用书名,查找书籍信息
:param name: 书名
:return: 返回书籍信息列表
@see$Error.Nonebook: 书籍信息不存在
"""
return self.booklist.getBookByParam('bookName', name)

def getBookByAuthor(self, author):
"""
使用书名,查找书籍信息
:param name: 书名
:return: 返回书籍信息列表
@see$Error.Nonebook: 书籍信息不存在
"""
return self.booklist.getBookByParam('author', author)

def getBookByPublisher(self, publisher):
"""
使用书名,查找书籍信息
:param name: 书名
:return: 返回书籍信息列表
@see$Error.Nonebook: 书籍信息不存在
"""
return self.booklist.getBookByParam('publisher', publisher)

def getBookByPubTime(self, time):
"""
使用发布时间,查找书籍信息
:param time: 发布时间
:return: 返回书籍信息列表
@see$Error.Nonebook: 书籍信息不存在
"""
return self.booklist.getBookByParam('pubTime', time)

def modifyBookName(self, no, name):
if self.booklist.getBookByNo(no) == Error.NoneBook:
return Error.NoneBook
self.booklist.modifyBookByParam('bookName', no, name)
return Success.FinishModify

def modifyBookAuthor(self, no, author):
if self.booklist.getBookByNo(no) == Error.NoneBook:
return Error.NoneBook
self.booklist.modifyBookByParam('author', no, author)
return Success.FinishModify

def modifyBookPublisher(self, no, publisher):
if self.booklist.getBookByNo(no) == Error.NoneBook:
return Error.NoneBook
self.booklist.modifyBookByParam('author', no, publisher)
return Success.FinishModify

def modifyBookPubTime(self, no, pubTime):
if self.booklist.getBookByNo(no) == Error.NoneBook:
return Error.NoneBook
self.booklist.modifyBookByParam('pubTime', no, pubTime)
return Success.FinishModify

def displayAllBook(self):
return self.booklist.outputBookList()

def addBookByPatch(self, filename):
if filename[-3:] != '.txt':
return Error.FileNameFalse
self.booklist.addBookByFile(filename)
return Success.FinishAddBook

if __name__ == '__main__':
book = BookManagerService('../system.db')
book.getBookByNo('XW3001').pop(0).print()
book.getBookByName('史').pop(0).print()
book.modifyBookPubTime('XW3001', '2001-10-1')
book.getBookByNo('XW3001').pop(0).print()
45 changes: 45 additions & 0 deletions services/StuManagerService.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,58 @@ def addStuByPatch(self, filename):
self.studlist.addStuByFile(filename)
return Success.FinishAddStu

#############################学生信息获取部分##############################
def displayAllStu(self):
"""
显示所有的学生信息
:return: 所有学生信息的类的列表
"""
return self.studlist.outputStuList()

def getStudentByNo(self, no):
"""
通过学号获取某个学生的信息
:param no: 使用学生学号,进行精确查询
:return: 返回学生的信息列表
"""
return self.studlist.getStuByNo(no)

def getStudentByName(self, name):
"""
通过姓名,获取学生信息
:param name: 学生名字,模糊查询
:return:@see$Student 学生信息的列表
@see$Error: NoneStu
"""
return self.studlist.getStuByParam('studName', name)

def getStudentByMajor(self, major):
"""
通过专业,获取学生信息
:param major: 学生名字,模糊查询
:return:@see$Student 学生信息的列表
@see$Error: NoneStu
"""
return self.studlist.getStuByParam('major', major)

def getStudentByClassNum(self, classNum):
"""
通过班级,获取学生信息
:param classNum: 学生名字,模糊查询
:return:@see$Student 学生信息的列表
@see$Error: NoneStu
"""
return self.studlist.getStuByParam('classNum', classNum)

def getStudentByPhoneNum(self, phone):
"""
通过手机号,获取学生信息
:param phone: 手机号,模糊查询
:return:@see$Student 学生信息的列表
@see$Error: NoneStu
"""
return self.studlist.getStuByParam('phoneNum', phone)
#############################学生信息获取部分##############################

if __name__ == '__main__':
stu = StuMangerService('../system.db')
Expand Down
37 changes: 31 additions & 6 deletions services/StudentService.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ def borrowBook(self, stuno, bookno):
图书借阅功能
:param stuno: 借阅学生的学号
:param bookno: 借阅的书号
:return: @see$Error.NoneBook : 没有这本书的借阅信息
@see$Error.FinishBorrow : 借阅成功
:return:@see$Error.NoneBook : 没有这本书的借阅信息
@see$Error.BookCnt0: 书籍已经借空,不能借阅
@see$Error.FinishBorrow : 借阅成功
"""
book = self.booklist.getBookByNo(bookno)
if book is Error.NoneBook:
return Error.NoneBook

if self.borrowlist.getInformByStudNoBookNo(stuno, bookno) is Error.NoBorrowInform:
book = book.pop(0)
if book.getBookCnt() == 0:
return Error.BookCnt0

self.borrowlist.addInformByNos(stuno, bookno)
self.booklist.updateBorrowAndCnt(bookno, book.getBookCnt()-1, book.getBorrowCnt()+1)
return Success.FinishBorrow
Expand All @@ -52,10 +56,6 @@ def returnBookWithComment(self, stuno, bookno, comment=None):
return Error.NoneBook
book = self.booklist.getBookByNo(bookno).pop(0)

# 图书是否已经借空
if book.getBookCnt() == 0:
return Error.BookCnt0

# 删除借阅记录
self.borrowlist.deleteInform(stuno, bookno)

Expand Down Expand Up @@ -87,6 +87,30 @@ def renewBook(self, stuno, bookno):

return Error.NoBorrowInform

###############################图书信息的条件查询###########################
def getBookByNo(self, no):
"""
使用书号,获取书籍信息
:param no: 书号
:return: 书籍信息的列表
@see$Error.NoneBook: 书籍不存在
"""
return self.booklist.getBookByNo(no)

def getBookByName(self, name):
return self.booklist.getBookByParam('bookName', name)

def getBookByAuthor(self, author):
return self.booklist.getBookByParam('author', author)

def getBookByPublisher(self, publisher):
return self.booklist.getBookByParam('publisher', publisher)

def getBookByPubTime(self, time):
return self.booklist.getBookByParam('pubTime', time)

###############################图书信息的条件查询###########################

def renewAllBook(self, stuno):
"""
续借单本书籍
Expand Down Expand Up @@ -152,6 +176,7 @@ def subBook(self, stuno, bookno):
if __name__ == '__main__':
stu = StudentService('../system.db')
print(stu.subBook('1113000004', 'XW3004'))
stu.getBookByName('史').pop(0).print()

b, t = stu.getTopBooks()
b.pop(0).print()
Expand Down
Binary file modified system.db
Binary file not shown.

0 comments on commit 39074d7

Please sign in to comment.