Esempio n. 1
0
def test_dao(db):
	dao=BorrowDao(db)
	re1 ={}
	re1['bookid']= '3'
	re1['readerid']=3
	re1['borrowdate']='150712'
	re1['returndate']='150812'	
	re2= {}
	re3 = {}

	#ret = dao.insert_by_dict(re1)
	#ret=dao.get_by_readerid(1)
	ret=dao.update_renew(1)
	#ret=dao.update_returndate(150803,1)
	#ret=dao.select_overdate(150730)
	#ret=dao.del_by_bookid(3)
	#ret=dao.del_by_returndate(150830)
	#print 'insert list : %s, ret: %s' % (str(re1),str(ret))

	#h = dao.get_by_rname('dw')
	#print 'get by reader_name, ret: %s'% str(h)
    #ret = dao.get_by_title('python')
	#print 'get by title ,ret: %s' % str(ret)

	#ret = dao.del_by_rid(2)
	#ret=dao.update_by_rid('2',re3)
	print ret
Esempio n. 2
0
def test_dao(db):
    dao = BorrowDao(db)
    re1 = {}
    re1['bookid'] = '3'
    re1['readerid'] = 3
    re1['borrowdate'] = '150712'
    re1['returndate'] = '150812'
    re2 = {}
    re3 = {}

    #ret = dao.insert_by_dict(re1)
    #ret=dao.get_by_readerid(1)
    ret = dao.update_renew(1)
    #ret=dao.update_returndate(150803,1)
    #ret=dao.select_overdate(150730)
    #ret=dao.del_by_bookid(3)
    #ret=dao.del_by_returndate(150830)
    #print 'insert list : %s, ret: %s' % (str(re1),str(ret))

    #h = dao.get_by_rname('dw')
    #print 'get by reader_name, ret: %s'% str(h)
    #ret = dao.get_by_title('python')
    #print 'get by title ,ret: %s' % str(ret)

    #ret = dao.del_by_rid(2)
    #ret=dao.update_by_rid('2',re3)
    print ret
Esempio n. 3
0
 def initialize(self):
     self.db = self.application.db
     self.borrowdao = BorrowDao(self.db)
     self.Resp = Resp()
Esempio n. 4
0
class BorrowHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.db = self.application.db
        self.borrowdao = BorrowDao(self.db)
        self.Resp = Resp()

    def get(self):
        bookid = self.get_argument('bookid', None)
        readerid = self.get_argument('readerid', None)
        bid = tools.strip_string(bookid)
        rid = tools.strip_string(readerid)

        resp = None
        if bid == None and rid == None:
            logging.error("there is no parament bookid or readerid!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           para='id')
            self.write(resp)
            return

        if bid != None:
            logging.info("borrow detail! bookid:'%s'", str(bid))
            resp = self.borrowdao.get_by_bookid(bid)
            logging.info('query result: %s', str(resp))
        elif rid != None:
            logging.info("borrow detail! readerid:'%s'", str(rid))
            resp = self.borrowdao.get_by_readerid(rid)
            logging.info('query result: %s', str(resp))
        else:
            return

#		bo = tools.to_int(borrow['borrowdate'])
#		re = tools.to_int(borrow['returndate'])
#		bo=datetime.datetime.utcfromstamp(bo)
#		re=	datetime.datetime.utcfromstamp(re)
#		borrow['borrowdate'] = str(bo)
#		borrow['returndate'] = str(re)

        if resp == None or len(resp) == 0:
            logging.error('there is no record!')
            resp = self.Resp.make_response(code=RespCode.NO_RECORD)
            self.write(resp)

        resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
        self.write(resp)

#		_method = self.get_argument('_method', None)
#		if method == 'lost':
#			self.lost()
#
#	def clear(self):
#		pass
#

    def post(self):

        data = self.request.body
        h = json.loads(data)

        logging.info("in  post method. receive data:%s", str(data))
        bookid = h.get('bookid', None)
        bookid = tools.strip_string(bookid)
        readerid = h.get('readerid', None)
        readerid = tools.strip_string(readerid)

        resp = None
        if bookid == None or readerid == None:
            logging.error("there is no parament bookid or readerid!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           para='id')
            self.write(resp)
            return

        borrow = {}
        borrow['bookid'] = bookid
        borrow['readerid'] = readerid

        nowstamp = int(time.time())
        datearray = datetime.datetime.utcfromtimestamp(nowstamp)
        re = datearray + datetime.timedelta(days=31)
        restamp = int(time.mktime(re.timetuple()))

        borrow['borrowdate'] = nowstamp
        borrow['returndate'] = restamp

        ret = self.borrowdao.insert_by_dict(borrow)

        if ret == None:
            logging.error("error oucurred when insert into table 'borrow'")
            resp = self.Resp.make_response(code=RespCode.DB_ERROR)
            self.write(resp)
            return

        logging.info("borrow successed! The book: %s", str(bookid))
        borrow['brw_id'] = ret
        resp = self.Resp.make_response(code=RespCode.SUCCESS,
                                       content=borrow,
                                       para="borrow")
        self.write(resp)

    def delete(self):
        bookid = self.get_argument('bookid', None)
        bookid = tools.strip_string(bookid)

        resp = None
        if bookid == None:
            logging.error("there is no parament bookid!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           para='id')
            self.write(resp)
            return

        now = datetime.datetime.now()
        borrow = self.borrowdao.get_by_bookid(bookid)
        #		re=datetime.datetime.utcfromtimestamp(borrow['returndate'])
        #		delta=re-now
        #		days=getattr(delta,'days')
        #		if days < 0:
        #			logging.error("this book is delay for %s days",str(abs(days)))
        #			resp = self.Resp.make_response(code=Resp.DELAY,para=days)
        #			self.write(resp)

        logging.info("delete borrow book %s", str(bookid))
        ret = self.borrowdao.del_by_bookid(bookid)

        logging.info("delete successed!")

        resp = self.Resp.make_response(code=RespCode.SUCCESS, para="return")
        self.write(resp)

    def put(self):
        data = self.request.body
        h = json.loads(data)

        bookid = h.get('bookid', None)

        if bookid == None:
            logging.error("there is no input!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           pare='bookid')
            self.write(resp)

            return
#sql = "SELECT renew FROM borrow WHERE bookid='%s'"%str(bookid)
#		ret=self.db.get(sql)
#		if ret['renew'] == 0:

#		logging.info('renew book id:%s',str(bookid))
#		ret = self.borrowdao.update_renew(bookid)

#####add a month###
        re = self.borrowdao.get_by_bookid(bookid)
        restamp = re['returndate']
        datearray = datetime.datetime.utcfromtimestamp(restamp)
        re1 = datearray + datetime.timedelta(days=31)
        re1stamp = int(time.mktime(re1.timetuple()))
        ret = self.borrowdao.update_returndate(re1stamp, bookid)

        logging.info("renew success! bookid:'%s'", str(bookid))
        resp = self.Resp.make_response(code=RespCode.SUCCESS, para="renew")
        self.write(resp)
Esempio n. 5
0
	def initialize(self):
		self.db = self.application.db
		self.bookdao=BookDao(self.db)
		self.readerdao=ReaderDao(self.db)
		self.borrowdao=BorrowDao(self.db)
		self.Resp=Resp()
Esempio n. 6
0
class BorrowHandler(tornado.web.RequestHandler):
	def initialize(self):
		self.db = self.application.db
		self.bookdao=BookDao(self.db)
		self.readerdao=ReaderDao(self.db)
		self.borrowdao=BorrowDao(self.db)
		self.Resp=Resp()

	def borrow(self):
		bookid=self.get_argument('bookid',None)
		readerid=self.get_argument('readerid',None)
		bookid=tools.strip_string(bookid)
		readerid=tools.strip_string(readerid)

		resp=None
		if bookid ==None or readerid ==None:
			logging.error("there is no parament bookid or readerid!")
			resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,para='id')
			self.write(resp)
			return
		
		'''check readerid bookid exist and borrow exist ...'''

		borrow={}
		borrow['bookid']=bookid
		borrow['readerid']=readerid
		
		nowstamp=int(time.time())
		datearray=datetime.datetime.utcfromtimestamp(nowstamp)
		re=datearray+datetime.timedelta(days=31)
		restamp=int(time.mktime(re.timetuple()))
		
		borrow['borrowdate']=nowstamp
		borrow['returndate']=restamp

		ret = self.borrowdao.insert_by_dict(borrow)
		
		if ret == None:
			logging.error("error oucurred when insert into table 'borrow'")
			resp =self.Resp.make_response(code=RespCode.DB_ERROE)
			self.write(resp)
			return

		else:
			logging.info("borrow successed! The book: %s", str(bookid))
        	borrow['brw_id'] = ret
        	resp = self.Resp.make_response(code=RespCode.SUCCESS, content=borrow)
        	self.write(resp)
			


	def returnbook(self):
		
		bookid=self.get_argument('bookid',None)
		bookid=tools.strip_string(bookid)

		resp=None
		if bookid ==None:
			logging.error("there is no parament bookid!")
			resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,para='id')
			self.write(resp)
			return

		now=datetime.datetime.now()
		borrow=self.borrowdao.get_by_bookid(bookid)
		re=datetime.datetime.utcfromtimestamp(borrow['returndate'])
		delta=re-now
		day=getattr(delta,'days')
		if day < 0:
			punish=0.5*abs(day)

			logging.error("this book is delay and pay for %s yuan!",str(punish))
			resp = self.Resp.make_response(code=RespCode.RETURN,para='punish')
			self.write(resp)

		logging.info("delete borrow book %s",str(bookid))
		ret=self.borrowdao.del_by_bookid(bookid)

		logging.info("delete successed!")

		resp = self.Resp.make_response(code=RespCode.SUCCESS)
		self.write(resp)


	def renew(self):
		bookid=self.get_argument('bookid',None)
		bookid=self.tools.strip_string(bookid)

		if bookid == None:
			logging.error("there is no input!")
			resp=self.Resp.make_response(code=RespCode.NO_PARAMETER,pare= 'input')
			self.write(resp)
			return
			


		logging.info('renew book id:%s',str(bookid))
		ret=self.borrowdao.update_renew(bookid)

#	if ret:
#			logging.info("renew success! bookid:'%s'",str(bookid)
#		else:
#			logging.error("Fail! already done before.")
#			resp = self.Resp.make_response(code=RespCode.HAS_EXISTED)
#			self.write(resp)
#
#add a month
		re=self.borrowdao.get_by_bookid(bookid)
		restamp=re['returndate']
		datearray=datetime.datetime.utcfromtimestamp(restamp)
		re1=datearray+datetime.timedelta(days=31)
		re1stamp=int(time.mktime(re1.timetuple()))
		ret=update_returndate(re1stamp,bookid)
		
			
	
		resp = self.Resp.make_response(code=RespCode.SUCCESS)
		self.write(resp)


	def getbybid(self):
		bid=self.get_argument('book_id',None)
		bid=tools.strip_string(bid)

		resp=None
		if bid != None:
			logging.info("borrowdetail! bookid:'%s'",str(bid))
			ret=self.borrowdao.get_by_bid(bid)
			resp=ret
			logging.info('query result: %s', str(resp))
		else:
			logging.error("there is no input!")
			resp=self.Resp.make_response(code=RespCode.NO_PARAMETER,pare= 'bid')
			self.write(resp)
			return



		if resp == None or len(resp) == 0:
			logging.error('there is no record!')
			resp = self.Resp.make_response(code=RespCode.No_RECORD)
			self.write(resp)

		resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
		self.write(resp)

		



	def lost(self):

		bid=self.get_argument('book_id',None)
		bid=tools.strip_string(bid)

		if bid != None:
			h=self.bookdao.get_by_bid(bid)
			price=h['price']
			logging.info("lost bookid:'%s',pay for $%s",str(bid),str(price))
			ret=self.bookdao.del_by_bid(bid)		
		else:
			logging.error("there is no input!")
			resp=self.Resp.make_response(code=RespCode.NO_PARAMETER,pare= 'bid')
			self.write(resp)
			return

		resp = self.Resp.make_response(code=RespCode.SUCCESS)
		self.write(resp)




	def clearlist(self):
		pass
Esempio n. 7
0
class UserHandler(tornado.web.RequestHandler):
	def initialize(self):
		self.db = self.application.db
		self.bookdao=BookDao(self.db)
		self.readerdao=ReaderDao(self.db)
		self.borrowdao=BorrowDao(self.db)
		self.Resp=Resp()
		
	def search(self):
		se=self.get_argument('book',None)
		se=tools.strip_string(se)
		
		resp = []
		if se != None:
			logging.info("in search method! get search input:'%s'",str(se))
			ret=self.bookdao.get_by_title(se)
			resp.extend(ret)
			ret=self.bookdao.get_by_auther(se)
			resp.extend(ret)
			ret=self.bookdao.get_by_publisher(se)
			resp.extend(ret)

			logging.info('query result: %s', str(resp))

		else:
			logging.error("there is no input!")
			resp=self.Resp.make_response(code=RespCode.NO_PARAMETER,pare= 'input')
			self.write(resp)
			return

		if resp == None or len(resp) == 0:
			logging.error('there is no record!')
			resp = self.Resp.make_response(code=RespCode.No_RECORD)
			self.write(resp)

		resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
		self.write(resp)

	
	def getbybid(self):
		bid=self.get_argument('book_id',None)
		bid=tools.strip_string(bid)

		resp=None
		if bid != None:
			logging.info("bookdetail! bookid:'%s'",str(bid))
			ret=self.bookdao.get_by_bid(bid)
			resp=ret
			h=self.borrowdao.if_exist(bid)
			if h==True:
				resp['onsheet']='no'
			else:
				resp['onsheet']='yes'

			logging.info('query result: %s', str(resp))
		else:
			logging.error("there is no input!")
			resp=self.Resp.make_response(code=RespCode.NO_PARAMETER,pare= 'bid')
			self.write(resp)
			return



		if resp == None or len(resp) == 0:
			logging.error('there is no record!')
			resp = self.Resp.make_response(code=RespCode.No_RECORD)
			self.write(resp)

		resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
		self.write(resp)


	def searchbyrid(self):
		rid = self.get_argument('readerid',None)
		rid = tools.strip_string(rid)
		

		resp=None
		if readerid != None:
			logging.info("in searchbyrid method! get reader by readerid:'%s'",str(rid))
			ret= self.readerdao.get_by_rid(rid)
			resp=ret
			books=self.borrowdao.get_by_readerid(rid)
			resp["books"]=books

			logging.info('query result: %s', str(resp))


			
		if resp == None or len(resp) == 0:
			logging.error('there is no record!')
			resp = self.Resp.make_response(code=RespCode.No_RECORD)
			self.write(resp)

		resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
		self.write(resp)

	def renew(self):
		bookid=self.get_argument('bookid',None)
		bookid=self.tools.strip_string(bookid)

		if bookid == None:
			logging.error("there is no input!")
			resp=self.Resp.make_response(code=RespCode.NO_PARAMETER,pare='bid')
			self.write(resp)
			return


		logging.info('renew book id:%s',str(bookid))
		ret=self.borrowdao.update_renew(bookid)

		if ret:
			#####add a month###
			re=self.borrowdao.get_by_bookid(bookid)
			restamp=re['returndate']
			datearray=datetime.datetime.utcfromtimestamp(restamp)
			re1=datearray+datetime.timedelta(days=31)
			re1stamp=int(time.mktime(re1.timetuple()))
			ret=update_returndate(re1stamp,bookid)
		
			logging.info("renew success! bookid:'%s'",str(bookid))
		else:
			logging.error("Fail! already done before.")
			resp = self.Resp.make_response(code=RespCode.HAS_EXISTED)
			self.write(resp)

		
			
	
		resp = self.Resp.make_response(code=RespCode.SUCCESS)
		self.write(resp)
Esempio n. 8
0
 def initialize(self):
     self.db = self.application.db
     self.bookdao = BookDao(self.db)
     self.readerdao = ReaderDao(self.db)
     self.borrowdao = BorrowDao(self.db)
     self.Resp = Resp()
Esempio n. 9
0
class BorrowHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.db = self.application.db
        self.bookdao = BookDao(self.db)
        self.readerdao = ReaderDao(self.db)
        self.borrowdao = BorrowDao(self.db)
        self.Resp = Resp()

    def borrow(self):
        bookid = self.get_argument('bookid', None)
        readerid = self.get_argument('readerid', None)
        bookid = tools.strip_string(bookid)
        readerid = tools.strip_string(readerid)

        resp = None
        if bookid == None or readerid == None:
            logging.error("there is no parament bookid or readerid!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           para='id')
            self.write(resp)
            return
        '''check readerid bookid exist and borrow exist ...'''

        borrow = {}
        borrow['bookid'] = bookid
        borrow['readerid'] = readerid

        nowstamp = int(time.time())
        datearray = datetime.datetime.utcfromtimestamp(nowstamp)
        re = datearray + datetime.timedelta(days=31)
        restamp = int(time.mktime(re.timetuple()))

        borrow['borrowdate'] = nowstamp
        borrow['returndate'] = restamp

        ret = self.borrowdao.insert_by_dict(borrow)

        if ret == None:
            logging.error("error oucurred when insert into table 'borrow'")
            resp = self.Resp.make_response(code=RespCode.DB_ERROE)
            self.write(resp)
            return

        else:
            logging.info("borrow successed! The book: %s", str(bookid))
        borrow['brw_id'] = ret
        resp = self.Resp.make_response(code=RespCode.SUCCESS, content=borrow)
        self.write(resp)

    def returnbook(self):

        bookid = self.get_argument('bookid', None)
        bookid = tools.strip_string(bookid)

        resp = None
        if bookid == None:
            logging.error("there is no parament bookid!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           para='id')
            self.write(resp)
            return

        now = datetime.datetime.now()
        borrow = self.borrowdao.get_by_bookid(bookid)
        re = datetime.datetime.utcfromtimestamp(borrow['returndate'])
        delta = re - now
        day = getattr(delta, 'days')
        if day < 0:
            punish = 0.5 * abs(day)

            logging.error("this book is delay and pay for %s yuan!",
                          str(punish))
            resp = self.Resp.make_response(code=RespCode.RETURN, para='punish')
            self.write(resp)

        logging.info("delete borrow book %s", str(bookid))
        ret = self.borrowdao.del_by_bookid(bookid)

        logging.info("delete successed!")

        resp = self.Resp.make_response(code=RespCode.SUCCESS)
        self.write(resp)

    def renew(self):
        bookid = self.get_argument('bookid', None)
        bookid = self.tools.strip_string(bookid)

        if bookid == None:
            logging.error("there is no input!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           pare='input')
            self.write(resp)
            return

        logging.info('renew book id:%s', str(bookid))
        ret = self.borrowdao.update_renew(bookid)

        #	if ret:
        #			logging.info("renew success! bookid:'%s'",str(bookid)
        #		else:
        #			logging.error("Fail! already done before.")
        #			resp = self.Resp.make_response(code=RespCode.HAS_EXISTED)
        #			self.write(resp)
        #
        #add a month
        re = self.borrowdao.get_by_bookid(bookid)
        restamp = re['returndate']
        datearray = datetime.datetime.utcfromtimestamp(restamp)
        re1 = datearray + datetime.timedelta(days=31)
        re1stamp = int(time.mktime(re1.timetuple()))
        ret = update_returndate(re1stamp, bookid)

        resp = self.Resp.make_response(code=RespCode.SUCCESS)
        self.write(resp)

    def getbybid(self):
        bid = self.get_argument('book_id', None)
        bid = tools.strip_string(bid)

        resp = None
        if bid != None:
            logging.info("borrowdetail! bookid:'%s'", str(bid))
            ret = self.borrowdao.get_by_bid(bid)
            resp = ret
            logging.info('query result: %s', str(resp))
        else:
            logging.error("there is no input!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           pare='bid')
            self.write(resp)
            return

        if resp == None or len(resp) == 0:
            logging.error('there is no record!')
            resp = self.Resp.make_response(code=RespCode.No_RECORD)
            self.write(resp)

        resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
        self.write(resp)

    def lost(self):

        bid = self.get_argument('book_id', None)
        bid = tools.strip_string(bid)

        if bid != None:
            h = self.bookdao.get_by_bid(bid)
            price = h['price']
            logging.info("lost bookid:'%s',pay for $%s", str(bid), str(price))
            ret = self.bookdao.del_by_bid(bid)
        else:
            logging.error("there is no input!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           pare='bid')
            self.write(resp)
            return

        resp = self.Resp.make_response(code=RespCode.SUCCESS)
        self.write(resp)

    def clearlist(self):
        pass
Esempio n. 10
0
class UserHandler(tornado.web.RequestHandler):
    def initialize(self):
        self.db = self.application.db
        self.bookdao = BookDao(self.db)
        self.readerdao = ReaderDao(self.db)
        self.borrowdao = BorrowDao(self.db)
        self.Resp = Resp()

    def search(self):
        se = self.get_argument('book', None)
        se = tools.strip_string(se)

        resp = []
        if se != None:
            logging.info("in search method! get search input:'%s'", str(se))
            ret = self.bookdao.get_by_title(se)
            resp.extend(ret)
            ret = self.bookdao.get_by_auther(se)
            resp.extend(ret)
            ret = self.bookdao.get_by_publisher(se)
            resp.extend(ret)

            logging.info('query result: %s', str(resp))

        else:
            logging.error("there is no input!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           pare='input')
            self.write(resp)
            return

        if resp == None or len(resp) == 0:
            logging.error('there is no record!')
            resp = self.Resp.make_response(code=RespCode.No_RECORD)
            self.write(resp)

        resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
        self.write(resp)

    def getbybid(self):
        bid = self.get_argument('book_id', None)
        bid = tools.strip_string(bid)

        resp = None
        if bid != None:
            logging.info("bookdetail! bookid:'%s'", str(bid))
            ret = self.bookdao.get_by_bid(bid)
            resp = ret
            h = self.borrowdao.if_exist(bid)
            if h == True:
                resp['onsheet'] = 'no'
            else:
                resp['onsheet'] = 'yes'

            logging.info('query result: %s', str(resp))
        else:
            logging.error("there is no input!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           pare='bid')
            self.write(resp)
            return

        if resp == None or len(resp) == 0:
            logging.error('there is no record!')
            resp = self.Resp.make_response(code=RespCode.No_RECORD)
            self.write(resp)

        resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
        self.write(resp)

    def searchbyrid(self):
        rid = self.get_argument('readerid', None)
        rid = tools.strip_string(rid)

        resp = None
        if readerid != None:
            logging.info("in searchbyrid method! get reader by readerid:'%s'",
                         str(rid))
            ret = self.readerdao.get_by_rid(rid)
            resp = ret
            books = self.borrowdao.get_by_readerid(rid)
            resp["books"] = books

            logging.info('query result: %s', str(resp))

        if resp == None or len(resp) == 0:
            logging.error('there is no record!')
            resp = self.Resp.make_response(code=RespCode.No_RECORD)
            self.write(resp)

        resp = self.Resp.make_response(code=RespCode.SUCCESS, content=resp)
        self.write(resp)

    def renew(self):
        bookid = self.get_argument('bookid', None)
        bookid = self.tools.strip_string(bookid)

        if bookid == None:
            logging.error("there is no input!")
            resp = self.Resp.make_response(code=RespCode.NO_PARAMETER,
                                           pare='bid')
            self.write(resp)
            return

        logging.info('renew book id:%s', str(bookid))
        ret = self.borrowdao.update_renew(bookid)

        if ret:
            #####add a month###
            re = self.borrowdao.get_by_bookid(bookid)
            restamp = re['returndate']
            datearray = datetime.datetime.utcfromtimestamp(restamp)
            re1 = datearray + datetime.timedelta(days=31)
            re1stamp = int(time.mktime(re1.timetuple()))
            ret = update_returndate(re1stamp, bookid)

            logging.info("renew success! bookid:'%s'", str(bookid))
        else:
            logging.error("Fail! already done before.")
            resp = self.Resp.make_response(code=RespCode.HAS_EXISTED)
            self.write(resp)

        resp = self.Resp.make_response(code=RespCode.SUCCESS)
        self.write(resp)