def search_list(cls, _user_id=None): total, item_list = cls.search_item_list(_user_id=_user_id) if total <= 0 or item_list is None: return success(package_result(0, [])) return success( package_result(total, [item.to_dict() for item in item_list]))
def get_device_deploy_list(device_id, page, size): # 获取数据总数目 total = 0 result_list = list() # 根据设备ID过滤 query = Deploy.query.filter(Deploy.device_id == device_id) # 获取部署信息列表 item_paginate = query.paginate(page=page, per_page=size, error_out=False) if item_paginate is None: log.warn("获取部署信息翻页查询失败: device_id = {} page = {} size = {}".format( device_id, page, size)) return package_result(total, result_list) item_list = item_paginate.items if item_list is None: log.warn("部署信息分页查询失败: device_id = {} page = {} size = {}".format( device_id, page, size)) return package_result(total, result_list) return package_result(item_paginate.total, [item.to_dict() for item in item_list])
def search_list(): log.info("获取维护人员列表信息...") total, item_list = Maintain.search_item_list() if total <= 0 or item_list is None: return success(package_result(0, [])) result_list = [] for item in item_list: # item_dict = item.to_dict() # while True: # # # 判断是否所有大厅 # if item.address_id == Maintain.ALL_ADDRESS_ID: # full_address = Maintain.ALL_ADDRESS_STR # break # # # 获取地址信息 # address = Address.get(item.address_id) # if address is None: # log.warn("当前地址不存在: maintain_id = {} address_id = {}".format(item.id, item.address_id)) # full_address = '当前地址不存在!' # break # # full_address = address.get_full_address() # break # # item_dict['address'] = full_address result_list.append(MaintainService.to_address_dict(item)) return success(package_result(total, result_list))
def find_role_list(cls, page, size=10): # 获取数据总数目 total = 0 result_list = [] item_paginate = cls.query.paginate(page=page, per_page=size, error_out=False) if item_paginate is None: log.warn("角色信息分页查询失败: page = {} size = {}".format(page, size)) return package_result(total, result_list) item_list = item_paginate.items if item_list is None: log.warn("角色信息分页查询失败: page = {} size = {}".format(page, size)) return package_result(total, result_list) return package_result(item_paginate.total, [item.to_dict() for item in item_list])
def search_by_keyword(page, size, keyword): # 请求参数必须为正数 if page <= 0 or size <= 0: msg = "请求参数错误: page = {} size = {}".format(page, size) log.error(msg) return fail(HTTP_OK, msg) if size > 50: log.info("翻页最大数目只支持50个, 当前size超过50 size = {}!".format(size)) size = 50 total, item_list = MaintainService.find_list_by_keyword( page, size, keyword) if total <= 0 or not isinstance(item_list, list): return success(package_result(0, [])) return success( package_result( total, [MaintainService.to_address_dict(item) for item in item_list]))
def get_device_game_list(device_id, page=0, size=0): # 如果page 和 size为0 则返回全部游戏数据 if page <= 0 or size <= 0: item_list = DeviceGame.query.filter( DeviceGame.device_id == device_id).all() return success( package_result(len(item_list), [item.to_full_dict() for item in item_list])) query = DeviceGame.query # 再通过用户名查找 pagination = query.filter(DeviceGame.device_id == device_id).paginate( page=page, per_page=size, error_out=False) if pagination is None or pagination.total <= 0: return success(package_result(0, [])) # return pagination.total, pagination.items return success( package_result(pagination.total, [item.to_full_dict() for item in pagination.items]))
def search_list(): if not has_request_context(): log.warn("上下文异常") return fail(HTTP_OK, u"服务器未知!") if not request.is_json: log.warn("参数错误...") return fail(HTTP_OK, u"need application/json!!") filters = list() page = request.json.get('page') size = request.json.get('size') province = request.json.get('province') city = request.json.get('city') area = request.json.get('area') start_time_str = request.json.get('start_time') end_time_str = request.json.get('end_time') state = request.json.get('state') alive = request.json.get('alive') order_by = request.json.get('order_by') # 如果存在状态信息,但是状态错误,则返回错误 if state is not None: if state not in Device.STATUS_VALUES: return fail(HTTP_OK, u'状态信息错误!') # 判断是否有检测设备状态 if alive is not None: if alive not in Device.ALIVE_VALUES: return fail(HTTP_OK, u'存活状态信息错误!') if isinstance(start_time_str, basestring) and isinstance( end_time_str, basestring): if end_time_str < start_time_str: return fail( HTTP_OK, u"时间区间错误: start_time = {} > end_time = {}".format( start_time_str, end_time_str)) try: # 转换为 datetime 类型 start_time = None if isinstance(start_time_str, basestring): start_time = datetime.strptime(start_time_str, '%Y-%m-%d %H:%M:%S') log.info("转换后时间: start_time = {} type = {}".format( start_time, type(start_time))) else: log.info("start_time 不是字符串: {}".format(start_time_str)) end_time = None if isinstance(end_time_str, basestring): end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S') log.info("转换后时间: end_time = {} type = {}".format( end_time, type(end_time))) else: log.info("end_time 不是字符串: {}".format(end_time_str)) except Exception as e: log.error("时间格式转换错误: start_time_str = {} end_time_str = {}".format( start_time_str, end_time_str)) log.exception(e) return fail(HTTP_OK, u"时间格式转换错误!") if not isinstance(page, int) or \ not isinstance(size, int): log.warn("请求参数错误: page = {} size = {}".format(page, size)) return fail(HTTP_OK, u"请求参数错误") # 请求参数必须为正数 if page <= 0 or size <= 0: msg = "请求参数错误: page = {} size = {}".format(page, size) log.error(msg) return fail(HTTP_OK, msg) if size > 50: log.info("翻页最大数目只支持50个, 当前size超过50 size = {}!".format(size)) size = 50 total, item_list = DeviceService.find_list(province, city, area, start_time, end_time, state, alive, page, size, filters=filters, order_by=order_by) if total <= 0 or item_list is None: return success(package_result(0, [])) return success( package_result(total, [item.to_dict() for item in item_list]))