class CataloguedPage: def __init__(self, loginName, loginPwd): self.rp = RequestsPage() self.ep = ElibPage(loginName, loginPwd) def CataloguedForQuery(self): """ 编目管理书目列表功能验证 :return: None """ res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/catalog/catalogue/list', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 15, 'userType': 1, 'dateType': 1 }).json() print(res) if 'message' in res: if res['message'] == '操作成功': print("编目管理书目列表查询成功") # pass else: print("编目管理书目列表查询出错") else: print("编目管理书目列表查询出错", res) def CataloguedForAdd(self): """ 新增编目功能验证 :return: marctyid 书目编号,定位要编目的书目记录 """ data = {"userToken": self.ep.getUserToken(), "marcfbid": self.ep.getFblxid(isMore=False), "simpleList": [ {"fieldName": "分类号", "marcField": "690a", "content": "EC-7", "isEmpty": 1, "sort": 1}, {"fieldName": "并列正题名", "marcField": "510a", "content": "", "isEmpty": 1, "sort": 2}, {"fieldName": "正题名拼音", "marcField": "2009", "content": "", "isEmpty": 1, "sort": 3}, {"fieldName": "国内订购号", "marcField": "092b", "content": "", "isEmpty": 1, "sort": 4}, {"fieldName": "语种", "marcField": "101a", "content": "", "isEmpty": 1, "sort": 5}, {"fieldName": "期刊价格", "marcField": "011d", "content": "", "isEmpty": 1, "sort": 6}, {"fieldName": "ISBN", "marcField": "010a", "content": "508", "isEmpty": 0, "sort": 7}, {"fieldName": "责任者拼音", "marcField": "7019", "content": "", "isEmpty": 1, "sort": 8}, {"fieldName": "副题名", "marcField": "200e", "content": "", "isEmpty": 1, "sort": 9}, {"fieldName": "价格", "marcField": "010d", "content": "", "isEmpty": 1, "sort": 10}, {"fieldName": "版次", "marcField": "205a", "content": "", "isEmpty": 1, "sort": 11}, {"fieldName": "正题名", "marcField": "200a", "content": "这是正题名", "isEmpty": 0, "sort": 12}, {"fieldName": "出版地", "marcField": "210a", "content": "", "isEmpty": 1, "sort": 13}, {"fieldName": "其他责任者", "marcField": "200g", "content": "", "isEmpty": 1, "sort": 14}, {"fieldName": "页码", "marcField": "215a", "content": "", "isEmpty": 1, "sort": 15}, {"fieldName": "统一书刊号", "marcField": "091a", "content": "", "isEmpty": 1, "sort": 16}, {"fieldName": "分辑名", "marcField": "200i", "content": "", "isEmpty": 1, "sort": 17}, {"fieldName": "版本与书目史附注", "marcField": "305a", "content": "", "isEmpty": 1, "sort": 18}, {"fieldName": "内容附注", "marcField": "327a", "content": "", "isEmpty": 1, "sort": 19}, {"fieldName": "一般性附注", "marcField": "300a", "content": "", "isEmpty": 1, "sort": 20}, {"fieldName": "丛编题名", "marcField": "225a", "content": "", "isEmpty": 1, "sort": 21}, {"fieldName": "国外订购号", "marcField": "092c", "content": "", "isEmpty": 1, "sort": 22}, {"fieldName": "摘要", "marcField": "330a", "content": "", "isEmpty": 1, "sort": 23}, {"fieldName": "尺寸", "marcField": "215e", "content": "", "isEmpty": 1, "sort": 24}, {"fieldName": "责任者", "marcField": "200f", "content": "", "isEmpty": 1, "sort": 25}, {"fieldName": "相关题名附注", "marcField": "312a", "content": "", "isEmpty": 1, "sort": 26}, {"fieldName": "出版社", "marcField": "210c", "content": "", "isEmpty": 1, "sort": 27}, {"fieldName": "附件", "marcField": "215b", "content": "", "isEmpty": 1, "sort": 28}, {"fieldName": "分辑号", "marcField": "200h", "content": "", "isEmpty": 1, "sort": 29}, {"fieldName": "文献类型", "marcField": "200b", "content": "", "isEmpty": 1, "sort": 30}, {"fieldName": "丛编责任者", "marcField": "225f", "content": "", "isEmpty": 1, "sort": 31}, {"fieldName": "书目控制号", "marcField": "001", "content": "012020", "isEmpty": 1, "sort": 32}, {"fieldName": "出版日期", "marcField": "210d", "content": "", "isEmpty": 1, "sort": 33}, {"fieldName": "ISRC", "marcField": "016a", "content": "", "isEmpty": 1, "sort": 34}, {"fieldName": "主题词", "marcField": "606a", "content": "", "isEmpty": 1, "sort": 35}, {"fieldName": "ISSN", "marcField": "011a", "content": "", "isEmpty": 1, "sort": 36}, {"fieldName": "出版周期", "marcField": "326a", "content": "", "isEmpty": 1, "sort": 37}, {"fieldName": "封面题名", "marcField": "512a", "content": "", "isEmpty": 1, "sort": 38}, {"fieldName": "并列题名", "marcField": "200d", "content": "", "isEmpty": 1, "sort": 39}] } res = self.rp.sendRequest('JSON', self.ep.getUrl() + '/service/api/e/catalog/catalogue/simple/save', json.dumps(data)).json() if 'message' in res: if res['message'] == '操作成功!': print("新增编目成功") return res['data']['marctyid'] else: print("新增编目出错") else: print("新增编目出错", res) def CataloguedForMod(self, cata): """ 修改编目功能验证 marctyid:书目编号,定位要编目的书目记录 :return: None """ data = {"userToken": self.ep.getUserToken(), "marcfbid": self.ep.getFblxid(isMore=False), "marctyid": cata, "simpleList": [ {"fieldName": "分类号", "marcField": "690a", "content": "EC-7", "isEmpty": 1, "sort": 1}, {"fieldName": "并列正题名", "marcField": "510a", "content": "", "isEmpty": 1, "sort": 2}, {"fieldName": "正题名拼音", "marcField": "2009", "content": "", "isEmpty": 1, "sort": 3}, {"fieldName": "国内订购号", "marcField": "092b", "content": "", "isEmpty": 1, "sort": 4}, {"fieldName": "语种", "marcField": "101a", "content": "", "isEmpty": 1, "sort": 5}, {"fieldName": "期刊价格", "marcField": "011d", "content": "", "isEmpty": 1, "sort": 6}, {"fieldName": "ISBN", "marcField": "010a", "content": "5021", "isEmpty": 0, "sort": 7}, {"fieldName": "责任者拼音", "marcField": "7019", "content": "", "isEmpty": 1, "sort": 8}, {"fieldName": "副题名", "marcField": "200e", "content": "", "isEmpty": 1, "sort": 9}, {"fieldName": "价格", "marcField": "010d", "content": "", "isEmpty": 1, "sort": 10}, {"fieldName": "版次", "marcField": "205a", "content": "", "isEmpty": 1, "sort": 11}, {"fieldName": "正题名", "marcField": "200a", "content": "5021", "isEmpty": 0, "sort": 12}, {"fieldName": "出版地", "marcField": "210a", "content": "", "isEmpty": 1, "sort": 13}, {"fieldName": "其他责任者", "marcField": "200g", "content": "", "isEmpty": 1, "sort": 14}, {"fieldName": "页码", "marcField": "215a", "content": "", "isEmpty": 1, "sort": 15}, {"fieldName": "统一书刊号", "marcField": "091a", "content": "", "isEmpty": 1, "sort": 16}, {"fieldName": "分辑名", "marcField": "200i", "content": "", "isEmpty": 1, "sort": 17}, {"fieldName": "版本与书目史附注", "marcField": "305a", "content": "", "isEmpty": 1, "sort": 18}, {"fieldName": "内容附注", "marcField": "327a", "content": "", "isEmpty": 1, "sort": 19}, {"fieldName": "一般性附注", "marcField": "300a", "content": "", "isEmpty": 1, "sort": 20}, {"fieldName": "丛编题名", "marcField": "225a", "content": "", "isEmpty": 1, "sort": 21}, {"fieldName": "国外订购号", "marcField": "092c", "content": "", "isEmpty": 1, "sort": 22}, {"fieldName": "摘要", "marcField": "330a", "content": "", "isEmpty": 1, "sort": 23}, {"fieldName": "尺寸", "marcField": "215e", "content": "", "isEmpty": 1, "sort": 24}, {"fieldName": "责任者", "marcField": "200f", "content": "", "isEmpty": 1, "sort": 25}, {"fieldName": "相关题名附注", "marcField": "312a", "content": "", "isEmpty": 1, "sort": 26}, {"fieldName": "出版社", "marcField": "210c", "content": "", "isEmpty": 1, "sort": 27}, {"fieldName": "附件", "marcField": "215b", "content": "", "isEmpty": 1, "sort": 28}, {"fieldName": "分辑号", "marcField": "200h", "content": "", "isEmpty": 1, "sort": 29}, {"fieldName": "文献类型", "marcField": "200b", "content": "", "isEmpty": 1, "sort": 30}, {"fieldName": "丛编责任者", "marcField": "225f", "content": "", "isEmpty": 1, "sort": 31}, {"fieldName": "书目控制号", "marcField": "001", "content": "012020", "isEmpty": 1, "sort": 32}, {"fieldName": "出版日期", "marcField": "210d", "content": "", "isEmpty": 1, "sort": 33}, {"fieldName": "ISRC", "marcField": "016a", "content": "", "isEmpty": 1, "sort": 34}, {"fieldName": "主题词", "marcField": "606a", "content": "", "isEmpty": 1, "sort": 35}, {"fieldName": "ISSN", "marcField": "011a", "content": "", "isEmpty": 1, "sort": 36}, {"fieldName": "出版周期", "marcField": "326a", "content": "", "isEmpty": 1, "sort": 37}, {"fieldName": "封面题名", "marcField": "512a", "content": "", "isEmpty": 1, "sort": 38}, {"fieldName": "并列题名", "marcField": "200d", "content": "", "isEmpty": 1, "sort": 39}] } res = self.rp.sendRequest('JSON', self.ep.getUrl() + '/service/api/e/catalog/catalogue/simple/save', json.dumps(data)).json() if 'message' in res: if res['message'] == '操作成功!': print("修改编目成功") else: print("修改编目出错") else: print("修改编目出错", res) def CataloguedForDel(self, cata): """ 删除编目功能验证 marctyid:书目编号,定位要编目的书目记录 :return: None """ res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/catalog/catalogue/delete', { 'userToken': self.ep.getUserToken(), 'marctyIds': cata }).json() if 'message' in res: if res['message'] == '操作成功!': print("删除编目成功") else: print("删除编目出错") else: print("删除编目出错", res)
class CirculationPage: def __init__(self, loginName, loginPwd): self.rp = RequestsPage() self.ep = ElibPage(loginName, loginPwd) def BRRManage(self): """ 借还续功能验证 :return: None """ for r2 in self.getReaderForAdd(): print(self.operateBook(r2, '借')) print(self.operateBook(r2, '续')) print(self.operateBook(r2, '还')) for r1 in self.getReader(): print(self.operateBook(r1, '借')) print(self.operateBook(r1, '续')) print(self.operateBook(r1, '还')) def getReader(self): readerList = list() # for i in self.ep.getDzlxid('more'): for data in self.ep.getReaderList()['data']['dataList']: # isOverTime = False # 判断是否超借 r = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/doclx/curBro', { 'userToken': self.ep.getUserToken(), 'readerBarcode': data['dzzhao'] }).json() if len(r['data']) == 0: readerList.append(data['dzzhao']) break # for d in r['data']: # if d['jyztai'] == '超期': # isOverTime = True # break # if isOverTime is False: return tuple(readerList) def getReaderForAdd(self): """ 创建读者 :return: Tuple """ readerList = list() for n in self.rp.getRandomReaderID(): # 发送添加读者的请求 res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/readerManager/readerManagerSave', { "userToken": self.ep.getUserToken(), "dzzhao": n, # 读者证号 "xming": n, # 姓名 "ztai": "正常", # 状态 "mima": "123456", # 密码 "dzlxid": self.ep.getDzlxid(isMore=False), # 读者类型 "jzrqi": "2020-10-31", # 截止日期 "qyrqi": "2020-08-01", # 启用日期 "libid": self.ep.getLibid(), # 馆id "smrz": "0", "zhuanye": "其他", "zhiwu": "无", "zcheng": "无", "xueli": "其他", "xingbie": self.ep.getXingbie(), "yajin": "100", "zhiye": "其他", "jycshu": "0", "yycshu": "0", "xjcshu": "0", "wzcshu": "0", "gjhjcshu": "0", "qkuan": "0", "dzdw": self.rp.randomValue(self.ep.getDzdw()) # "registerPlaceId": self.rp.randomValue(self.ep.getRegisterPlaceId()) # 办证地点 }).json() if res['message'] == '操作成功!': readerList.append(n) return tuple(readerList) def operateBook(self, reader, state): """ 借书、还书、续借功能 :param reader: 读者 :param state: 借 / 续 / 还 :return: String """ res_sm = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/catalog/catalogue/list', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 1000, 'userType': 1, 'dateType': 1 }).json() for data in res_sm['data']['dataList']: res_gc = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/book/listByCatalogue', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 1000, 'marctyId': data['marctyid'], 'isShow': 0 }).json() # 书目馆藏数量不等于0 if res_gc['data']['count'] != 0: for d in res_gc['data']['page']['dataList']: if d['ztai'] == '在馆' and state == '借': broResult = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/doclx/bro', { 'userToken': self.ep.getUserToken(), 'readerBarcode': reader, 'bookBarcode': d['tiaoma'] }).json() return broResult['message'] # message=借阅成功 elif d['ztai'] == '借出' and state == '续': renResult = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/doclx/ren', { 'userToken': self.ep.getUserToken(), 'readerBarcode': reader, 'bookBarcode': d['tiaoma'] }).json() return renResult['message'] # message=续借成功! elif d['ztai'] == '借出' and state == '还': retResult = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/doclx/ret', { 'userToken': self.ep.getUserToken(), 'isSameCz': 1, 'bookBarcode': d['tiaoma'] }).json() return retResult['message'] # message=还书成功! else: # print('数据错误') pass
class SetzhingPage: def __init__(self, loginName, loginPwd): self.rp = RequestsPage() self.ep = ElibPage(loginName, loginPwd) def BookmanForQuery(self): """ 书商管理列表功能验证 :return: None """ res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/sys/setup/param/gysFind', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 15, 'flag': 1 }).json() if 'message' in res: if res['message'] == '操作成功': print("书商管理书目列表查询成功") # pass else: print(self.ep.getUsercode(), "书商管理书目列表查询出错") else: print(self.ep.getUsercode(), "书商管理书目列表查询出错", res) def BookmanForFoundgysId(self): """ 书商管理列表功能验证 :return: gysId """ res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/sys/setup/param/gysFind', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 15, 'flag': 1 }).json() if 'message' in res: if res['message'] == '操作成功': # print(res['data']['dataList'][0]) return res['data']['dataList'][0]['gysId'] else: print(self.ep.getUsercode(), "获取书商列表第一条数据书商ID出错") else: print(self.ep.getUsercode(), "获取书商列表第一条数据书商ID出错", res) def BookmanForFoundcygname(self): """ 书商管理列表功能验证 :return: cygname """ res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/sys/setup/param/gysFind', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 15, 'flag': 1 }).json() if 'message' in res: if res['message'] == '操作成功': return res['data']['dataList'][0]['cygName'] else: print(self.ep.getUsercode(), "获取书商列表第一条数据成员馆出错") else: print(self.ep.getUsercode(), "获取书商列表第一条数据成员馆出错", res) def BookmanForAdd(self): """ 新增书商功能验证 :return: None """ res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/sys/setup/param/gysSave', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'gysCode': '12345', 'gysName': '12345', 'gysStat': '正常', 'gysCred': '0' }).json() if 'message' in res: if res['message'] == '操作成功!': print("新增书商成功") else: print(self.ep.getUsercode(), "新增书商出错") else: print(self.ep.getUsercode(), "新增书商出错", res) def BookmanForMod(self, g_data, c_data): """ 修改书商功能验证 :return: None """ res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/sys/setup/param/gysSave', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'gysId': g_data, 'gysCode': 'SSDM-02', 'gysName': '南方书店', 'gysStat': '正常', 'gysCred': 0, 'cygName': c_data }).json() if 'message' in res: if res['message'] == '操作成功!': print("修改书商成功") else: print(res) print(self.ep.getUsercode(), "修改书商出错") else: print(self.ep.getUsercode(), "修改书商出错", res) def BookmanForDel(self, g_data): """ 删除书商功能验证 :return: None """ res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/sys/setup/param/gysDel', { 'userToken': self.ep.getUserToken(), 'gysId': g_data }).json() if 'message' in res: if res['message'] == '操作成功!': print("删除书商成功") else: print(res) print(self.ep.getUsercode(), "删除书商出错") else: print(self.ep.getUsercode(), "删除书商出错", res)
class Reader: def __init__(self): self.rp = RequestsPage() # self.rpp = ReadPage() self.ep = ElibPage('YZ', 'Td123456') self.slp = DBPage('book') def addReader(self): """ 创建读者 :return: 无返回 """ l = list() # 获取随机值,插如 tb_reader 中 # self.slp.addReader(self.ep.getRandomReaderID()) for n in self.rp.getRandomReaderID(): sex = self.ep.getXingbie() dzdw = self.rp.randomValue(self.ep.getDzdw()) if sex == 1: l.append((n, '男', dzdw, '', '', 0, 0, 0, 0)) else: l.append((n, '女', dzdw, '', '', 0, 0, 0, 0)) # 发送添加读者的请求 self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/readerManager/readerManagerSave', { "userToken": self.ep.getUserToken(), "dzzhao": n, # 读者证号 "xming": n, # 姓名 "ztai": "正常", # 状态 "mima": "123456", # 密码 "dzlxid": self.ep.getDzlxid(isMore=False), # 读者类型 "jzrqi": self.rp.nowTime(ty='end'), # 截止日期 "qyrqi": self.rp.nowTime(ty='now'), # 启用日期 "libid": self.ep.getLibid(), # 馆id "smrz": "0", "zhuanye": "其他", "zhiwu": "无", "zcheng": "无", "xueli": "其他", "xingbie": sex, "yajin": "0", "zhiye": "其他", "jycshu": "0", "yycshu": "0", "xjcshu": "0", "wzcshu": "0", "gjhjcshu": "0", "qkuan": "0", "dzdw": dzdw, "registerPlaceId": self.rp.randomValue(self.ep.getRegisterPlaceId()) # 办证地点 }) # 添加到数据库中 self.slp.addReader(l) self.slp.addTotal([(len(l), 0, 0, 0, str(self.rp.nowTime()))]) def deleteReader(self): """ 删除读者 :return: 无返回 """ l = list() # requests 模拟接口必要参数 res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/readerManager/readerManagerList', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 50 }).json() for dataList in res['data']['dataList']: # 获取所有读者id,添加到列表中 l.append(dataList['dzid']) # 发送请求删除所有读者 self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/readerManager/readerManagerDel', { 'userToken': self.ep.getUserToken(), 'dzid': ','.join(l) }) # 清空数据库 self.slp.deleteReader()
class Book: def __init__(self): self.rp = RequestsPage() self.ep = ElibPage('YZ', 'Td123456') self.slp = DBPage('book') def copyBooks(self, num): """ 编目-回溯建库 此方法用于给每书目添加馆藏 :param num: 每个书目添加多少馆藏(填写100那么每本书添加100条馆藏数据) :return: 无返回 """ # 保存图书信息的 list l = list() # 馆藏信息中的条码号,用于循环递增 count = 0 # 发送 requests 请求,获取书目信息(这是一个 json 值) res_1 = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/catalog/catalogue/list', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'libId': self.ep.getLibid(), 'userType': 1, 'dateType': 1 }).json() # 循环 requests 返回的书目信息,处理数据 for dataList in res_1['data']['dataList']: bookDefault = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/book/bookDefault', { 'userToken': self.ep.getUserToken(), 'marctyId': dataList['marctyid'] }).json() # print(bookDefault) # # 处理返回值,获取 著者 字段 # fl = self.rp.matchString(dataList['fieldList']) # # 处理没有 著者 字段的图书,返回一个空值 # if len(fl) == 0: # fl = [''] # 添加信息到 list 中 l.append( (dataList['ztming'], dataList['zrsming'], dataList['isbn'], dataList['cbzhe'], bookDefault['data']['author'], dataList['flhao'], 0, 0, 0)) # 循环值,判断什么时候跳出while循环 loopValue = 0 while True: # 循环次数递增 loopValue += 1 # 条码递增 count += 1 # 发送 requests 请求,给每本书一条条添加馆藏 self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/book/save', { 'userToken': self.ep.getUserToken(), 'ztai': bookDefault['data']['bookDeault']['ztai'], 'tiaoma': 'YZ' + str(count).zfill(5), 'bookCodes': 'YZ' + str(count).zfill(5), 'sshao': bookDefault['data']['sshao'], 'gysid': self.ep.getGysid(isMore=False), 'batchid': self.rp.randomValue(self.ep.getBatchid()), 'ltlxid': self.ep.getLtlxid(isMore=False), 'cygid1': bookDefault['data']['bookDeault']['cygid1'], 'cygid0': bookDefault['data']['bookDeault']['cygid0'], 'ysuanid': self.ep.getYsid(isMore=False), 'marctyId': dataList['marctyid'], 'cejia': bookDefault['data']['bookDeault']['cejia'], 'taojia': bookDefault['data']['bookDeault']['taojia'], 'czid0': self.ep.getCzid(isMore=False), 'czid1': self.ep.getCzid(isMore=False), 'bookNum': 1, 'flhao': bookDefault['data']['fzqfhDTO']['flhao'], 'zchao': bookDefault['data']['fzqfhDTO']['zchao'], 'ljf': bookDefault['data']['fzqfhDTO']['ljf'], 'fzqfh': bookDefault['data']['fzqfhDTO']['fzqfh'], 'purchasePrice': '', 'purchaseDiscount': '', 'jcmshu': '', 'beizhu': '', 'sellPrice': '', 'wxlyuan': '', 'jzleixing': '', 'zdfangshi': '', 'sellDiscount': '' }).json() # 控制什么时候跳出死循环,每本书目添加 num 本馆藏后跳出,添加下一本 if loopValue >= num: break # 更新数据,将图书信息添加到 tb_book 数据库中 self.slp.addBook(l) def borrowBooks(self): """ 流通-借还管理-借出 此方法用于给读者随机借书 :return:无返回 """ # 将所有图书条码添加到集合中,检查所有添加的条码是否重复 checkDoubleValue = set() # 将每个用户借的图书条码添加到集合中,获取单个用户接了哪几本书 temp_bro = set() # 获取 tb_total 表的数据 tb = self.slp.selectTotal() # 获取 tb_reader 表的数据 selectData = self.slp.selectReader() for tup_1 in selectData: # 将数据库中所有用户的条码添加到集合中查重,防止多次运行借书数据库数据与业务系统对不上 checkDoubleValue = checkDoubleValue | self.rp.modifyTuples(tup_1) for tup_2 in selectData: # 循环值,判断什么时候跳出while循环 loopValue = 0 # 获取随机借书数量(每个人借多少本) a = random.randint(1, 20) # 将个人之前借的书添加到集合中 temp_bro = temp_bro | self.rp.modifyTuples(tup_2) while True: # 获取随机图书条码 randomValue = 'YZ' + str(random.randint(1, 1000)).zfill(5) # 对比图书条码是否已在数据库中存在,存在就不发送借书请求 if randomValue in checkDoubleValue: print('获取随机图书已重复') else: # 发送借书请求 self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/doclx/bro', { 'userToken': self.ep.getUserToken(), 'readerBarcode': tup_2[1], 'bookBarcode': randomValue }) # 所有图书集合 / 个人图书集合添加图书 checkDoubleValue.add(randomValue) temp_bro.add(randomValue) # 循环次数自增 loopValue += 1 # 当循环次数大于等于个人借书随机数,跳出循环 if loopValue >= a: # 更新数据,将读者信息更新到 tb_reader 数据库中 self.slp.updateReader((tup_2[1], tup_2[2], tup_2[3], str(temp_bro), tup_2[5], int(tup_2[6] + len(temp_bro)), int(tup_2[7] + len(temp_bro)), tup_2[8], tup_2[9], tup_2[0])) # 清空个人借书集合,防止插入数据库值错误 temp_bro.clear() break # 处理数据获取借阅数量,返回值是一个 list t = self.rp.modifyNum(checkDoubleValue) # 用于 list 下标递增 lv = 0 for tup_3 in self.slp.selectBook(): # 更新数据,将图书信息更新到 tb_book 数据库中 self.slp.updateBook( (tup_3[1], tup_3[2], tup_3[3], tup_3[4], tup_3[5], tup_3[6], t[lv], tup_3[8], tup_3[9], tup_3[0])) # 下标递增 lv += 1 # 更新数据,将统计信息更新到 tb_total 数据库中 self.slp.updateTotal( (tb[0], int(tb[1]) + len(checkDoubleValue), tb[2], tb[3], str(self.rp.nowTime()))) def returnBooks(self): """ 流通-借还管理-归还 此方法用于给读者随机还书 :return:无返回 """ # 获取 tb_total 表的数据 tb = self.slp.selectTotal() # 好像没用,但是懒得删,怕爆炸 :) count = 0 # temp_bro 用于存放借出图书;temp_ret 用于存放还回图书,循环一次会清空 temp_bro = set() temp_ret = set() # temp_bro_all 用于存放借出图书;temp_ret_all 用于存放还回图书,不会清空 temp_bro_all = set() temp_ret_all = set() # 循环从数据库中取出的 tb_reader 表信息 for tup in self.slp.selectReader(): # 获取数据库中用户借的图书条码,添加到集合中 temp_bro = temp_bro | self.rp.modifyTuples(tup) # 如果借出是空的,就不发送借书请求,更新 tb_reader 数据库 if len(temp_bro) == 0: self.slp.updateReader( (tup[1], tup[2], tup[3], "", tup[5], len(temp_bro), tup[7], int(tup[8]) - len(temp_bro), tup[9], tup[0])) else: # 获取还书随机值 loopValue = random.randint(1, len(temp_bro)) while loopValue > 0: # 好像没软用,不敢删 :) count += 1 # 获取集合中的任意一个条码 temp = temp_bro.pop() # 将还回条码添加到还回集合中 temp_ret.add(temp) # 发送 requests 请求,用户还书 self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/doclx/ret', { 'userToken': self.ep.getUserToken(), 'isSameCz': '1', 'bookBarcode': temp }) # 递减到0退出循环 loopValue -= 1 # 数据库中借书为空时运行程序容易把set()插入数据库中,做下处理 # 如果借书为空,传空字符串 if str(temp_bro) == 'set()': self.slp.updateReader( (tup[1], tup[2], tup[3], '', str(temp_ret), len(temp_bro), tup[7], int(tup[7]) - len(temp_bro), tup[9], tup[0])) # 借书不为空,就把信息更新到 tb_reader 数据库中 else: self.slp.updateReader( (tup[1], tup[2], tup[3], str(temp_bro), str(temp_ret), len(temp_bro), tup[7], int(tup[7]) - len(temp_bro), tup[9], tup[0])) # 将每个人的借/还书添加到一个集合中 temp_bro_all = temp_bro_all | temp_bro temp_ret_all = temp_ret_all | temp_ret # 清空集合,防止程序错误 temp_bro.clear() temp_ret.clear() # 处理数据,获取各图书的还数量 tba = self.rp.modifyNum(temp_bro_all) tra = self.rp.modifyNum(temp_ret_all) # 用于 list 下标递增 lv = 0 # 更新数据,将图书信息更新到 tb_book 数据库中 for tup_3 in self.slp.selectBook(): self.slp.updateBook( (tup_3[1], tup_3[2], tup_3[3], tup_3[4], tup_3[5], tup_3[6], tba[lv], tra[lv], tup_3[9], tup_3[0])) # 下标递增 lv += 1 # 更新数据,将统计信息更新到 tb_total 数据库中 self.slp.updateTotal( (tb[0], tb[1], tb[2] + count, tb[3], str(self.rp.nowTime()))) def renewBooks(self): """ 流通-借还管理-续借 此方法用于给读者随机续借 :return:无返回 """ # 保存每个用户借阅的图书 temp = set() # 所有用户借阅的图书 tenp_all = set() # 统计数据用 count = 0 # 获取 tb_total 表的数据 tb = self.slp.selectTotal() # 循环从数据库中取出的 tb_reader 表信息 for tup in self.slp.selectReader(): # 循环值,判断什么时候跳出while循环 loopValue = 1 # 获取数据库中用户借的图书条码,添加到集合中 temp = temp | self.rp.modifyTuples(tup) # print(temp) # 空的不处理 if len(temp) != 0: # 获取续借随机值(每个用户续借多少本) a = random.randint(1, len(temp)) while a >= loopValue: # 获取set中的任意值 t = temp.pop() # 将所有续借条码添加到集合中 tenp_all.add(t) count += 1 # 发送 requests 请求,用户续借 self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/doclx/ren', { 'userToken': self.ep.getUserToken(), 'readerBarcode': tup[1], 'bookBarcode': t }) loopValue += 1 # 更新数据,将统计信息更新到 tb_reader 数据库中 self.slp.updateReader((tup[1], tup[2], tup[3], tup[4], tup[5], tup[6], tup[7], tup[8], a, tup[0])) temp.clear() # 处理数据,获取各图书的续借数量 t = self.rp.modifyNum(tenp_all) # 用于 list 下标递增 lv = 0 # 更新数据,将图书信息更新到 tb_book 数据库中 for tup_3 in self.slp.selectBook(): self.slp.updateBook( (tup_3[1], tup_3[2], tup_3[3], tup_3[4], tup_3[5], tup_3[6], tup_3[7], tup_3[8], t[lv], tup_3[0])) # 下标递增 lv += 1 # 更新数据,将统计信息更新到 tb_total 数据库中 self.slp.updateTotal( (tb[0], tb[1], tb[2], tb[3] + count, str(self.rp.nowTime()))) def allReturnBooks(self): """ 流通-借还管理-归还 此方法用于给读者全部归还 :return:无返回 """ # 发送 requests 请求,用户归还条码1~1000的图书 for n in range(1, 1001): self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/doclx/ret', { 'userToken': self.ep.getUserToken(), 'isSameCz': '1', 'bookBarcode': 'YZ' + str(n).zfill(5) }) def clearBooks(self): """ 流通-借还管理-归还 此方法用于清除所有馆藏图书 :return:无返回 """ # 用于存储馆藏书目的id l = list() # 清空前先把书都还了 self.allReturnBooks() # 发送 requests 请求,获取书目信息,返回 json 值 res_1 = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/catalog/catalogue/list', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'libId': self.ep.getLibid(), 'userType': 1, 'dateType': 1 }).json() # 处理数据 for dataList in res_1['data']['dataList']: # 发送 requests 请求,获取馆藏信息,返回 json 值 res_2 = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/book/listByCatalogue', { 'userToken': self.ep.getUserToken(), 'marctyId': dataList['marctyid'], 'pageSize': 1000, 'pageNumber': 1, 'isShow': 0 }).json() for r in res_2['data']['page']['dataList']: # 将要删除的馆藏 id 添加到列表中 l.append(r['shuceid']) # 发送 requests 请求,删除馆藏信息,返回 json 值 self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/book/delete', { 'userToken': self.ep.getUserToken(), 'shuceIds': ','.join(l) }).json() self.slp.deleteTotal() self.slp.deleteBook()
class LTTest(unittest.TestCase): def __init__(self, *args, **kwargs): super(LTTest, self).__init__(*args, **kwargs) self.book = Book() self.reader = Reader() self.db = DBPage('book') self.rp = RequestsPage() self.ep = ElibPage('YZ', 'Td123456') def test_lttj_default(self): """ 流通-流通统计 获取总计数据 与 tb_total的借/还数 进行比较 :return: """ # TODO: 1. 增加每本图书藏址到数据库中 2. 增加对藏址图书统计的测试 res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/lttjList', { 'userToken': self.ep.getUserToken(), 'type': 1, 'cygid0': self.ep.getLibid(), 'cygid1': self.ep.getLibid(), 'timeType': 1, 'pageSize': 50, 'pageNumber': 1 }).json() self.assertEqual(res['data']['dataList'][0]['list2'][0]['jccs'], str(self.db.selectTotal()[1])) self.assertEqual(res['data']['dataList'][0]['list2'][0]['ghcs'], str(self.db.selectTotal()[2])) def test_ltxd_default(self): """ 流通-流通详单 获取总的数据数量 与 tb_total的借/还/续相加 进行比较 :return: """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/ltxd', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'libId': self.ep.getLibid() }).json() result = self.db.selectTotal()[1] + self.db.selectTotal( )[2] + self.db.selectTotal()[3] self.assertEqual(res['data']['totalElements'], str(result)) def test_ltxd_search_readerId(self): """ 流通-流通详单 查询每个读者的借/还/续总量 与 tb_reader的读者借/还/续相加 进行比较 :return: """ for data in self.db.selectReader(): res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/ltxd', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'libId': self.ep.getLibid(), 'dzzhao': data[1] }).json() self.assertEqual(res['data']['totalElements'], str(data[7] + data[8] + data[9])) def test_ltxd_search_title(self): """ 流通-流通详单 查询每本书的借/还/续总量 与 tb_book的图书借/还/续相加 进行比较 PS:由于tb_book中的借数量是减掉了还的数量,所以统计时还的数量应该为2倍 :return: """ for data in self.db.selectBook(): res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/ltxd', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'libId': self.ep.getLibid(), 'ztming': data[1] }).json() self.assertEqual(res['data']['totalElements'], str(data[7] + data[8] * 2 + data[9])) def test_dzjyphb_default(self): """ 流通-读者借阅排行榜 查询每个读者的总借阅册次 与 tb_reader的读者总借阅册次 进行比较 :return: """ for data in self.db.selectReader(): res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/dzjyphb', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'renshu': 100, 'pageNumber': 1, 'pageSize': 50, 'jycs': 1, 'dzzhao': data[1] }).json() self.assertEqual(res['data']['dataList'][0]['jieyuecs'], data[7] + data[9]) def test_dzjhtj_default(self): """ 流通-读者借还统计 查询每个读者的借/还/续次数 与 tb_reader的借/还/续次数 进行比较 :return: """ for data in self.db.selectReader(): res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/dzjhtj', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 50, 'dzzhao': data[1] }).json() self.assertEqual(res['data']['page']['dataList'][0]['jieyuecs'], data[7] + data[9]) self.assertEqual(res['data']['page']['dataList'][0]['guihuancs'], data[8]) self.assertEqual(res['data']['page']['dataList'][0]['xujiecs'], data[9]) def test_wxjyphb_default(self): """ 流通-文献借阅排行榜 查询每本书的总借阅册次 与 tb_book的读者总借阅册次 进行比较 :return: """ for data in self.db.selectBook(): res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/wxjyphb', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'renshu': 100, 'pageNumber': 1, 'pageSize': 50, 'jycs': 1, 'ztming': data[1] }).json() print(data) print(res['data']['dataList'][0]) for r in res['data']['dataList']: if r['ztming'] == data[1]: self.assertEqual(res['data']['dataList'][0]['jieyuecs'], data[7] + data[8]) def test_wxjhtj_default(self): """ 流通-文献借还统计 查询每个大类的借阅册次 与 tb_book的每个书目挑选相关类型相加 进行比较 :return: """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/wxjhtj', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid() }).json() for data in res['data']: val = 0 for d in self.db.selectBookFlh(data['wxlx']): val = val + d[0] + d[1] + d[2] self.assertEqual(data['jycs'], str(val)) def test_dzlxjhtj_default(self): """ 流通-读者类型借还统计 因为只有一个读者类型,所以直接和 tb_total 的借阅数/归还数进行比较 :return: """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/dzlxjhtj', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 15 }).json() for data in res['data']['dataList']: self.assertEqual( data['jieyuecs'], self.db.selectTotal()[1] + self.db.selectTotal()[3]) self.assertEqual(data['guihuancs'], self.db.selectTotal()[2]) def test_dzdwjhtj_default(self): """ 流通-读者单位借还统计 根据数据库中读者的读者单位全部相加 进行比较 :return: """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/dzdwjhtj', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 15 }).json() for data in res['data']['dataList']: val_bro, val_ret = 0, 0 for d in self.db.selectReaderDzdw(data['dzdw']): val_bro = val_bro + d[0] + d[3] val_ret = val_ret + d[1] self.assertEqual(data['jieyuecs'], val_bro) self.assertEqual(data['guihuancs'], val_ret) def test_zzph_default(self): """ 流通-著者排行 根据数据库中书目的著者比较借阅次数 PS:借阅次数在还书方法中减掉了还书次数,所以完整的借阅次数应该为借阅次数+归还次数 :return: """ for data in self.db.selectBook(): if data[5] == '': break else: res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/authorRank', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 50, 'equalType': 1, 'brwNum': 1, 'rankNum': 100, 'author': data[5] }).json() self.assertEqual(res['data']['dataList'][0]['brwNum'], str(data[7] + data[8])) def test_dzbqjhtj_defaul(self): """ 流通-读者标签借还统计 根据 selectReaderDzdw 方法,会返回读者借/还/性别的元祖,根据性别将借/还相添加比较 :return: """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/readerLabelCir', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 50 }).json() for data in res['data']['dataList']: bro_num, ret_num = 0, 0 for d in self.db.selectReaderDzdw(data['readerUnit']): if d[2] == data['readerGenderName']: bro_num = bro_num + d[0] + d[3] ret_num = ret_num + d[1] self.assertEqual(data['brwNum'], bro_num) self.assertEqual(data['returnNum'], ret_num) def test_dzxbjytj_defaul(self): """ 流通-读者性别借阅统计 根据 selectReaderSex 方法,会返回读者借/续的元祖,将借/续相添加比较 :return: """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/readerGenderBorrowList', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'statisticalPeriod': 0, 'pageNumber': 1, 'pageSize': 50 }).json() num_1, num_2, man_num, famale_num = 0, 0, 0, 0 for data in res['data']['dataList']: man_num = man_num + int(data['manBorrwoNumber']) famale_num = famale_num + int(data['femaleBorrowNumber']) for mNum in self.db.selectReaderSex('男'): num_1 = num_1 + mNum[0] + mNum[1] for fNum in self.db.selectReaderSex('女'): num_2 = num_2 + fNum[0] + fNum[1] self.assertEqual(num_1, man_num) self.assertEqual(num_2, famale_num) def test_dzxbjytj_total(self): """ 流通-读者性别借阅统计 由于测试时合计小于月数量,故将月数量循环相加与合计相比较 :return: """ res_1 = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/readerGenderBorrowList', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'statisticalPeriod': 0, 'pageNumber': 1, 'pageSize': 50 }).json() res_2 = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/totalGenderBorrow', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 50 }).json() man_num, famale_num = 0, 0 for data in res_1['data']['dataList']: print(data) man_num = man_num + int(data['manBorrwoNumber']) famale_num = famale_num + int(data['femaleBorrowNumber']) print(res_2['data']) self.assertEqual(man_num, res_2['data']['manBorrow']) self.assertEqual(famale_num, res_2['data']['femaleBorrow']) def test_jysktj_default(self): """ 流通-借阅时刻统计 获取合计数量和数据库 tb_book 借阅/续借相比较 :return: """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/timeBorrowList', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'date1': self.rp.nowTime('start'), 'date2': self.rp.nowTime('end'), 'time1': '00', 'time2': '00' }).json() data = self.db.selectTotal() self.assertEqual(res['data']['totalBorrow'][0], data[1] + data[3]) def test_jysktj_total(self): """ 流通-借阅时刻统计 获取合计数量和各个时间段 相比较 :return: """ num = 0 res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/lttj/timeBorrowList', { 'userToken': self.ep.getUserToken(), 'libId': self.ep.getLibid(), 'date1': self.rp.nowTime('start'), 'date2': self.rp.nowTime('end'), 'time1': '00', 'time2': '00' }).json() for data in res['data']['hourList']: num = num + int(data['borrowNumber']) self.assertEqual(res['data']['totalBorrow'][0], num) def test_dzdqjycx_default(self): """ 流通-读者当前借阅查询 每本书进行搜索,搜索的到就ok :return: """ for data in self.db.selectReader(): res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/ltcx/dzjycx', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'dzzhao': data[1], 'pageNumber': 1, 'pageSize': 50 }).json() num = 0 for d in res['data']['dataList']: num += 1 if d['tiaoma'] in data[4]: self.assertTrue(True) else: self.assertTrue(False) self.assertEqual(num, len(self.rp.modifyTuples(data))) def test_dzdqjycx_total(self): """ 流通-读者当前借阅查询 计算每个用户图书的数量,和总量进行比较 :return: """ num = 0 res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/ltcx/dzjycx', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 50 }).json() for data in self.db.selectReader(): num = num + len(self.rp.modifyTuples(data)) self.assertEqual(num, int(res['data']['totalElements'])) def test_dzlsjycx_default(self): """ 流通-读者历史借阅查询 每本书进行搜索,搜索的到就ok :return: """ for data in self.db.selectReader(): res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/ltcx/dzjylscx', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'dzzhao': data[1], 'pageNumber': 1, 'pageSize': 50 }).json() print(res) num = 0 for d in res['data']['dataList']: num += 1 if d['tiaoma'] in data[5]: self.assertTrue(True) else: self.assertTrue(False) self.assertEqual(num, len(self.rp.modifyTuples(data, value=5))) def test_dzlsjycx_total(self): """ 流通-读者历史借阅查询 计算每个用户图书的数量,和总量进行比较 :return: """ num = 0 res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/e/flow/ltcx/dzjylscx', { 'userToken': self.ep.getUserToken(), 'libid': self.ep.getLibid(), 'pageNumber': 1, 'pageSize': 50 }).json() for data in self.db.selectReader(): num = num + len(self.rp.modifyTuples(data, value=5)) self.assertEqual(num, int(res['data']['totalElements']))
class InterviewPage: def __init__(self, loginName, loginPwd): self.rp = RequestsPage() self.ep = ElibPage(loginName, loginPwd) def ZDManage(self): print(self.subscriptionBooksImport()) print(self.subscriptionBooks()) print(self.directSubscription()) print(self.subscriptionVerify()) print(self.directVerify()) def subscriptionBooksImport(self): """ 征订书目导入功能 :return: """ with open('D:\Cache\Project\TJProject\list.xls', mode="rb+") as f: # 打开文件 file = { "excel": ('list.xls', f.read()), # 引号的file是接口的字段,后面的是文件的名称、文件的内容 "userToken": self.ep.getUserToken(), # 如果接口中有其他字段也可以加上 } res = self.rp.sendRequest('FILE', self.ep.getUrl() + '/service/api/e/interview/file/zdsmI', file).json() r = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/zdsm/import/main', { 'userToken': self.ep.getUserToken(), 'path': res['data']['path'], 'marcfbid': self.ep.getFblxid(isMore=False), 'zdpcid': self.ep.getZdpcid(isMore=False), 'isbn': 'ISBN,0', 'ztming': '正题名,0', 'zrsming': '责任者, 1', 'cbzhe': '出版社, 1', 'cbrqi': '出版日期, 1', 'cbdi': '出版社, 1', 'flhao': '分类号, 1', 'jge': '价格, 1' }).json() return r['message'] def subscriptionBooks(self): """ 征订书目预订功能 :return: """ # 先在 预订单管理 设置第一个为工作预定单 self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/work/save', { 'userToken': self.ep.getUserToken(), 'ydpcid': self.ep.getYdd()[0] }) # 获取征订目录列表 res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/zdpc/search', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50 }).json() # 获取图书信息 r = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/zdsm/search', { 'userToken': self.ep.getUserToken(), 'zdpcid': res['data']['dataList'][0]['zdpcid'], 'pageNumber': 1, 'pageSize': 50 }).json() # 判断图书信息中价格是否存在 price = 0 if 'jge' in dict(r): price = int(self.rp.matchNumber(r['data']['page']['dataList'][0]['jge'])) # 获取预订单信息 yd = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/yd/pcList', { 'userToken': self.ep.getUserToken() }).json() # 预订 result = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/yd/smSave', { 'userToken': self.ep.getUserToken(), 'cygName': yd['data'][0]['cygName'], 'ysName': yd['data'][0]['ysName'], 'marcid': r['data']['page']['dataList'][0]['marcid'], 'gysName': yd['data'][0]['gysName'], 'ydbhao': '', 'ydpcid': yd['data'][0]['ydpcid'], 'ceshu': 1, 'ydlaiyuan': '订购', 'yjhbid': self.ep.getHbList(isMore='NO'), 'jzleixing': '纸张', 'yuanjia': price, 'zdfangshi': '平装', 'ydhbid': self.ep.getHbList(isMore='NO'), 'juance': 1, 'jiage': price, 'fuzhu': '', 'zdpcdm': res['data']['dataList'][0]['zdpcdm'], 'ydpcdm': self.ep.getZdsmReserve(zdpcid=res['data']['dataList'][0]['zdpcid'], zdsmid=r['data']['page']['dataList'][0]['zdsmid']), 'ysCode': yd['data'][0]['ysCode'], 'zdpcid': self.ep.getZdpcid(isMore='NO'), 'gysCode': yd['data'][0]['gysCode'], 'ydleixing': '征订预订' }).json() print(result['message']) # 操作成功! def directSubscription(self): """ 直接预订功能 :return: """ # 先在 预订单管理 设置第一个为工作预定单 self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/work/save', { 'userToken': self.ep.getUserToken(), 'ydpcid': self.ep.getYdd()[0] }) # 获取图书信息 res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/yd/searchBook', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'flag': 1 }).json() # 征订书目-直接预订 r = self.ep.getZdsmReserve(marcid=res['data']['dataList'][0]['marcid']) # 预定 result = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/yd/smSave', { 'userToken': self.ep.getUserToken(), 'cygName': r['data']['cygName'], 'ysName': r['data']['ysName'], 'marcid': r['data']['marcid'], 'gysName': r['data']['gysName'], 'ydbhao': '', 'ydpcid': r['data']['ydpcid'], 'ceshu': 1, 'ydlaiyuan': '订购', 'yjhbid': self.ep.getHbList(isMore='NO'), 'jzleixing': '纸张', 'yuanjia': 0, 'zdfangshi': '平装', 'ydhbid': self.ep.getHbList(isMore='NO'), 'juance': 1, 'jiage': 0, 'fuzhu': '', 'ydpcdm': 1, 'ysCode': r['data']['ysCode'], 'gysCode': r['data']['gysCode'], 'ydleixing': '直接预订' }).json() print(result['message']) # 操作成功! 已超出预算金额,不能预订! def subscriptionVerify(self): """ 预订验收功能 :return: """ # 先在 验收单管理 设置第一个为工作验收单 self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/work/save', { 'userToken': self.ep.getUserToken(), 'yspcid': self.ep.getYsd()[0] }) # 获取图书信息 res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/yd/smSearch', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'from': 1, 'flag': 1 }).json() # 获取索书号 r = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/ys/curSshao', { 'userToken': self.ep.getUserToken(), 'marcid': res['data']['dataList'][0]['marcid'] }).json() # 验收 numList = list() for i in range(res['data']['dataList'][0]['ceshu']): numDict = dict() numDict['barcode'] = "TS" + str(random.randint(1, 10000)).zfill(5) numDict['libId'] = self.ep.getLibid() numDict['czId'] = self.ep.getCzid(isMore='NO') numDict['ltlxId'] = self.ep.getLtlxid(isMore='NO') numList.append(numDict) # '[' # '{"barcode": "test100", "libId": "2", "czId": "ebd840b69bc04948859cd05a4da638b3", "ltlxId": "1"},' # '{"barcode": "test101", "libId": "2", "czId": "ebd840b69bc04948859cd05a4da638b3", "ltlxId": "1"}' # ']', result = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/ys/smSave', { 'userToken': self.ep.getUserToken(), 'marcid': res['data']['dataList'][0]['marcid'], 'yslxing': '预订验收', 'yspcid': self.ep.getYsd()[0], 'collectionDtos': json.dumps(numList), 'yjhbid': self.ep.getHbList(isMore='NO'), 'yuanjia': res['data']['dataList'][0]['jiage'], 'cejia': res['data']['dataList'][0]['jiage'], 'ydlaiyuan': '订购', 'ydhbid': self.ep.getHbList(isMore='NO'), 'jiage': res['data']['dataList'][0]['jiage'], 'taojia': res['data']['dataList'][0]['jiage'], 'jzleixing': '纸张', 'zdfangshi': '平装', 'juance': 1, 'fuben': res['data']['dataList'][0]['ceshu'], 'sshao': r['data']['sshao'], 'ydRecord': res['data']['dataList'][0]['ydRecord'], 'ydsmid': res['data']['dataList'][0]['ydsmid'], 'ydjge': res['data']['dataList'][0]['jiage'] }).json() print(result['message']) def directVerify(self): """ 快捷验收功能 :return: """ # 先在 验收单管理 设置第一个为工作验收单 self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/work/save', { 'userToken': self.ep.getUserToken(), 'yspcid': self.ep.getYsd()[0] }) # 获取图书信息 res = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/yd/searchBook', { 'userToken': self.ep.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'flag': 1 }).json() # 获取索书号 r = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/yd/searchBookByMarcid', { 'userToken': self.ep.getUserToken(), 'marcid': res['data']['dataList'][0]['marcid'] }).json() print(r['data']['sshao']) # 验收 numList = list() for i in range(res['data']['dataList'][0]['fuben']+1): numDict = dict() numDict['barcode'] = "TS" + str(random.randint(1, 10000)).zfill(5) numDict['libId'] = self.ep.getLibid() numDict['czId'] = self.ep.getCzid(isMore='NO') numDict['ltlxId'] = self.ep.getLtlxid(isMore='NO') numList.append(numDict) result = self.rp.sendRequest('POST', self.ep.getUrl() + '/service/api/e/interview/ys/smSave', { 'userToken': self.ep.getUserToken(), 'marcid': res['data']['dataList'][0]['marcid'], 'yslxing': '直接验收', 'yspcid': self.ep.getYsd()[0], 'collectionDtos': json.dumps(numList), 'yjhbid': self.ep.getHbList(isMore='NO'), 'yuanjia': r['data']['jge'], 'cejia': r['data']['jge'], 'ydlaiyuan': '订购', 'ydhbid': self.ep.getHbList(isMore='NO'), 'jiage': r['data']['jge'], 'taojia': r['data']['jge'], 'jzleixing': '纸张', 'zdfangshi': '平装', 'juance': 1, 'fuben': res['data']['dataList'][0]['fuben']+1, 'sshao': r['data']['sshao'], }).json() print(result['message'])
class WebopacPage: def __init__(self, loginName, loginPwd): self.rp = RequestsPage() self.ep = ElibPage(loginName, loginPwd) def opacManage(self): print(self.simpleSearch()) print(self.advanceSearch()) print(self.opacReaderLogin()) def simpleSearch(self, searchValue=None, searchItem='ztming', size=10, current=1, sortValue=0, isBrwNum=0, haveCollection=1, sortField='cbYear', cbYear=None, cbYear2=None, leixing=None, classify=None, category=None, subCategory=None): """ 检索首页 :param searchValue: 搜索值 :param searchItem: 搜索项,比如: 任意词keyWord、题名ztming、ISBN/ISSNisbn、责任者zrsming、主题词zti、分类号flhao、 订购号dghao、出版地cbdi、出版社cbzhe、从编seriesStatement、索书号sshao、统一书刊号unifyNumber :param size: 每页多少条数据,比如(10) :param current: 现在第几页,比如(1) :param sortValue: 排序,升序为0,降序为1 :param isBrwNum: 借阅最多,1为勾选,0为未勾选 :param haveCollection: 只显示在馆记录,1为勾选,0为未勾选 :param sortField: 排序选项,比如: 匹配度score、题名ztming、责任者zrsming、索书号sshao、出版社cbzhe、出版日期cbYear、馆藏数bookNum :param cbYear: 出版日期开始年,比如(2010) :param cbYear2: 出版日期结束年,比如(2011) :param leixing: 文献类型,比如:图书aa、期刊bb、其他other :param classify: 分类 第一层,比如(A) :param category: 分类 第二层,比如(A1) :param subCategory: 分类 第三层,比如(A12) :return: String 操作成功 """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/p/search/advanceSearch', { 'size': size, 'current': current, searchItem: searchValue, 'sortValue': sortValue, 'isBrwNum': isBrwNum, 'haveCollection': haveCollection, 'sortField': sortField, 'yzhong': '', # 语种,但是中英文都是空值 'libIds': self.ep.getLibid(), # 馆id 'cbYear': cbYear, 'cbYear2': cbYear2, 'leixing': leixing, 'classify': classify, 'category': category, 'subCategory': subCategory }).json() if res['message'] == '操作成功': print(res['data']['page']['dataList']) else: print('查询失败') def advanceSearch(self, size=10, current=1, sortValue=0, isBrwNum=0, haveCollection=1, sortField='cbYear', cbYear=None, cbYear2=None, leixing=None, classify=None, category=None, subCategory=None, searchField1='ztming', searchField2='ztming', searchField3='ztming', searchValue1=None, searchValue2=None, searchValue3=None, assemblyType1='or', assemblyType2='or'): """ 高级检索 :param size: 每页多少条数据,比如(10) :param current: 现在第几页,比如(1) :param sortValue: 排序,升序为0,降序为1 :param isBrwNum: 借阅最多,1为勾选,0为未勾选 :param haveCollection: 只显示在馆记录,1为勾选,0为未勾选 :param sortField: 排序选项,比如: 匹配度score、题名ztming、责任者zrsming、索书号sshao、出版社cbzhe、出版日期cbYear、馆藏数bookNum :param cbYear: 出版日期开始年,比如(2010) :param cbYear2: 出版日期结束年,比如(2011) :param leixing: 文献类型,比如:图书aa、期刊bb、其他other :param classify: 分类 第一层,比如(A) :param category: 分类 第二层,比如(A1) :param subCategory: 分类 第三层,比如(A12) :param searchField1: 搜索项 :param searchField2: 搜索项 :param searchField3: 搜索项 任意词keyWord、题名ztming、ISBN/ISSNisbn、责任者zrsming、主题词zti、分类号flhao、 订购号dghao、出版地cbdi、出版社cbzhe、从编seriesStatement、索书号sshao、统一书刊号unifyNumber :param searchValue1: 搜索值 :param searchValue2: 搜索值 :param searchValue3: 搜索值 :param assemblyType1: or / and :param assemblyType2: or / and :return: String """ res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/p/search/advanceSearch', { 'size': size, 'current': current, 'classify': classify, 'category': category, 'subCategory': subCategory, 'sortValue': sortValue, 'isBrwNum': isBrwNum, 'haveCollection': haveCollection, 'sortField': sortField, 'yzhong': '', # 语种 'libIds': self.ep.getLibid(), 'cbYear': cbYear, 'cbYear2': cbYear2, 'leixing': leixing, 'searchField1': searchField1, 'searchField2': searchField2, 'searchField3': searchField3, 'searchValue1': searchValue1, 'searchValue2': searchValue2, 'searchValue3': searchValue3, 'assemblyType1': assemblyType1, 'assemblyType2': assemblyType2 }).json() if res['message'] == '操作成功': print(res['data']['page']['dataList']) else: print('查询失败') def opacReaderLogin(self): # 获取读者token res = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/p/login/readerLogin', { 'loginName': self.ep.getReaderList()['data']['dataList'][0]['dzzhao'], 'loginPwd': self.ep.getReaderList()['data']['dataList'][0]['mima'] }).json() # 获取读者信息 r1 = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/opac/reader/barcode', { 'readerToken': res['data']['readerToken'] }).json() r2 = self.rp.sendRequest( 'POST', self.ep.getUrl() + '/service/api/opac/book/list/nowcheckout', { 'readerToken': res['data']['readerToken'] }).json() print(r1)
class ElibPage(object): # __instance = None # python3 单例模式 # def __new__(cls, *args, **kwargs): # if cls.__instance is None: # cls.__instance = super(ElibPage, cls).__new__(cls) # return cls.__instance def __init__(self, loginName, loginPwd, isAes='yes'): self.rp = RequestsPage() self.baseUrl = 'http://192.168.1.47:8081' # self.baseUrl = 'http://tsgl.geiec.cn' self.msg = self.getLoginMsg(loginName, loginPwd, isAes) def getUrl(self): """ 获取 baseUrl :return: String """ return self.baseUrl def getUsercode(self): """ 获取 管理员用户名 :return: String """ return self.msg['data']['user']['usercode'] def getUserToken(self): """ 获取 token :return: String """ # print(self.msg) return self.msg['data']['userToken'] def getLibid(self): """ 获取馆ID :return: String """ return self.msg['data']['user']['libId'] def getLoginMsg(self, loginName, loginPwd, isAes='yes'): """ 获取登录用户信息 :return: """ if isAes == 'yes': # yes为密码加密 loginMsg = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/p/login/userLogin', { 'loginName': loginName, 'loginPwd': AesPage().AES_encrypt(loginPwd) }).json() else: loginMsg = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/p/login/userLogin', { 'loginName': loginName, 'loginPwd': loginPwd }).json() return loginMsg def getGysid(self, isMore=True): """ 获取供应商ID (暂时先只取第一个供应商) :return: String / Tuple """ try: gysId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/sys/setup/param/gysFind', { 'userToken': self.getUserToken(), 'flag': 1, 'pageSize': 1000, 'pageNumber': 1, 'libId': self.getLibid() }).json() return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, gysId['message']).ErrorTemplate( gysId, 'gysId', isMore) except Exception as e: print(e) def getLtlxid(self, isMore=True): """ 获取流通类型ID :return: String / Tuple """ try: ltlxId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/sys/flowParameters/flowTypeList', { 'userToken': self.getUserToken(), 'pageSize': 1000, 'pageNumber': 1, 'libId': self.getLibid() }).json() return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, ltlxId['message']).ErrorTemplate( ltlxId, 'ltlxid', isMore) except Exception as e: print(e) def getCzid(self, isMore=True): """ 获取藏址ID :return: String / Tuple """ try: czId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/sys/setup/param/czFind', { 'userToken': self.getUserToken(), 'state': -1, 'pageSize': 1000, 'pageNumber': 1, 'libId': self.getLibid() }).json() return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, czId['message']).ErrorTemplate( czId, 'czid', isMore) except Exception as e: print(e) def getYslxid(self, isMore=True): """ 设置 -> 预算类型 获取预算类型ID (暂时先只取第一个预算) :return: String / Tuple """ try: yslxId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/sys/setup/param/yslxFind', { 'userToken': self.getUserToken(), 'flag': 0, 'pageSize': 1000, 'pageNumber': 1, 'libId': self.getLibid() }).json() return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, yslxId['message']).ErrorTemplate( yslxId, 'yslxid', isMore) except Exception as e: print(e) def getYsid(self, isMore=True): """ 设置 -> 预算管理 获取预算管理ID :return: String / Tuple """ ysId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/sys/setup/param/ysFind', { 'userToken': self.getUserToken(), 'flag': 0, 'pageSize': 1000, 'pageNumber': 1, 'libId': self.getLibid() }).json() try: return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, ysId['message']).ErrorTemplate( ysId, 'ysid', isMore) except Exception as e: print(e) def getBatchid(self, isMore=True): """ 获取编目批次ID :return: Tuple """ batchId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/catalog/other/searchBatch', { 'userToken': self.getUserToken(), 'flag': 1, 'pageSize': 1000, 'pageNumber': 1, 'batchStatus': '正常', 'libId': self.getLibid() }).json() try: return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, batchId['message']).ErrorTemplate( batchId, 'batchId', isMore) except Exception as e: print(e) def getRegisterPlaceId(self, isMore=True): """ 获取办证地点ID :return: Tuple / String """ registerPlaceId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/sys/setup/param/registerPlace/list', { 'userToken': self.getUserToken(), 'pageSize': 1000, 'pageNumber': 1, 'libId': self.getLibid() }).json() try: return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, registerPlaceId['message']).ErrorTemplate( registerPlaceId, 'registerPlaceId', isMore) except Exception as e: print(e) def getDzlxid(self, isMore=True): """ 获取读者类型 :return: Tuple / String """ dzlxId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/sys/flowParameters/readerTypeList', { 'userToken': self.getUserToken(), 'pageSize': 1000, 'pageNumber': 1, 'libId': self.getLibid() }).json() try: return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, dzlxId['message']).ErrorTemplate( dzlxId, 'dzlxid', isMore) except Exception as e: print(e) def getFblxid(self, isMore=True): """ 获取分编类型 :return: Tuple / String """ marcFBId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/parameter/marcFb', { 'userToken': self.getUserToken(), 'libId': self.getLibid() }).json() marcFBList = list() try: if marcFBId['code'] == 0: # data 存在于 response 中 if 'data' in marcFBId: for data in marcFBId['data']['list']: marcFBList.append(data['marcfbid']) if isMore is True: return marcFBList else: return marcFBList[0] # return ExceptionPage( # _getframe().f_code.co_filename, # _getframe().f_code.co_name, # marcFBId['message'] # ).ErrorTemplate(marcFBId, 'marcfbid', isMore) except Exception as e: print(e) def getZdpcid(self, isMore=True): """ 获取征订目录 :return: Tuple / String """ zdpcId = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/parameter/zdpcList', { 'userToken': self.getUserToken() }).json() try: return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, zdpcId['message']).ErrorTemplate( zdpcId, 'zdpcid', isMore) except Exception as e: print(e) def getYdd(self, yddDaima='daimaCs', yddIsWork=True): """ 采访 -> 预订单管理 获取预定单 :param yddDaima: 添加预订单时添加的预订单名称 :param yddIsWork: 添加预订单时是否设置为工作预订单 :return: Tuple """ # 查询 ydd = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/interview/yd/pcSearch', { 'userToken': self.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'flag': 1 }).json() yddList = list() try: # code 为 0,返回正确 if ydd['code'] == 0: # data 存在于 response 中 if 'data' in ydd: # 如果 dataList 为空,则添加并更新数据 if len(ydd['data']['dataList']) == 0: self.addYdd(yddDaima, yddIsWork) ydd = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/interview/yd/pcSearch', { 'userToken': self.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'flag': 1 }).json() # 循环 dataList, 获取所有 ydpcid, 并返回一个元祖 for i in ydd['data']['dataList']: yddList.append(i['ydpcid']) return tuple(yddList) else: raise ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, 'data 字段找不到') else: raise ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, ydd['message']) except Exception as e: print(e) def addYdd(self, daima='daimaCs', isWork=True): """ 采访 -> 预订单管理 新增预订单 :param daima: 添加预订单时添加的预订单名称 :param isWork: 添加预订单时是否设置为工作预订单 :return: <[Response 200]> """ return self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/interview/yd/pcAdd', { 'userToken': self.getUserToken(), 'daima': daima, 'libid': self.getLibid(), 'gysid': self.getGysid(isMore=False), 'ysid': self.getYsid(isMore=False), 'isWork': isWork }).json() def getYsd(self, ysdDaima='daimaCs', ysdIsWork=True): """ 采访 -> 验收单管理 获取验收单 :param ysdDaima: 添加预订单时添加的验收单名称 :param ysdIsWork: 添加预订单时是否设置为工作验收单 :return: Tuple """ # 查询 ysd = self.rp.sendRequest( 'POST', self.baseUrl + '/service/api/e/interview/ys/pcSearch', { 'userToken': self.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'flag': 1 }).json() ysdList = list() try: # code 为 0,返回正确 if ysd['code'] == 0: # data 存在于 response 中 if 'data' in ysd: # 如果 dataList 为空,则添加并更新数据 if len(ysd['data']['dataList']) == 0: self.addYsd(ysdDaima, ysdIsWork) ysd = self.rp.sendRequest( 'POST', self.baseUrl + '/service/api/e/interview/ys/pcSearch', { 'userToken': self.getUserToken(), 'pageNumber': 1, 'pageSize': 50, 'flag': 1 }).json() # 循环 dataList, 获取所有 yspcid, 并返回一个元祖 for i in ysd['data']['dataList']: ysdList.append(i['yspcid']) return tuple(ysdList) else: raise ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, 'data 字段找不到') else: raise ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, ysd['message']) except Exception as e: print(e) def addYsd(self, daima='daimaCs', isWork=True): """ 采访 -> 验收单管理 新增验收单 :param daima: 添加预订单时添加的验收单名称 :param isWork: 添加预订单时是否设置为工作验收单 :return: <[Response 200]> """ return self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/interview/ys/pcSave', { 'userToken': self.getUserToken(), 'daima': daima, 'libid': self.getLibid(), 'gysid': self.getGysid(isMore='NO'), 'ysid': self.getYsid(isMore='NO'), 'isWork': isWork }).json() def getZdsmReserve(self, marcid=None, zdpcid=None, zdsmid=None): """ 征订书目-跳转预订 参数传递: 征订批次->预订(zdpcid,zdsmid)。直接预订(marcid) :param zdsmid: 征订书目id :param zdpcid: 征订批次id :param marcid: marcid :return: req(<Response [200]>) """ if zdpcid is None and zdsmid is None and marcid is not None: return self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/interview/zdsm/reserve', { 'userToken': self.getUserToken(), 'marcid': marcid }).json() if zdpcid is not None and zdsmid is not None and marcid is None: return self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/interview/zdsm/reserve', { 'userToken': self.getUserToken(), 'zdpcid': zdpcid, 'zdsmid': zdsmid }).json() def getHbList(self, isMore=True): """ 货币列表 CNY :param isMore: YES输出元祖,NO输出字符串 :return: String """ hb = self.rp.sendRequest( "POST", self.baseUrl + '/service/api/e/parameter/hbList', { 'userToken': self.getUserToken(), 'libId': self.getLibid() }).json() try: return ExceptionPage(_getframe().f_code.co_filename, _getframe().f_code.co_name, hb['message']).ErrorTemplate( hb, 'hbid', isMore) except Exception as e: print(e) def getReaderList(self, ztai='正常', qkuan=0): if qkuan == 0 and qkuan == 1: res = self.rp.sendRequest( 'POST', self.getUrl() + '/service/api/e/flow/readerManager/readerManagerList', { 'userToken': self.getUserToken(), 'libid': self.getLibid(), 'pageNumber': 1, 'pageSize': 50, 'ztai': ztai, 'qkuan': qkuan }).json() else: res = self.rp.sendRequest( 'POST', self.getUrl() + '/service/api/e/flow/readerManager/readerManagerList', { 'userToken': self.getUserToken(), 'libid': self.getLibid(), 'pageNumber': 1, 'pageSize': 50, 'ztai': ztai }).json() return res def getXingbie(self): """ 获取性别 :return: Int """ return random.randint(0, 1) def getDzdw(self): """ 获取工作单位 :return: Tuple """ dzdw = ("asd1", "asd2", "asd3") return dzdw