def query_user(): current_page, page_size = utils.get_page_info(request) form = QueryUserForm(request.form) if not form.validate(): return param_error(form.errors) user_query = dict() if form.id.data: user_query['id'] = form.id.data if form.user_name.data: user_query['user_name'] = form.user_name.data if form.user_alias.data: user_query['user_alias'] = form.user_alias.data if form.user_number.data: user_query['user_number'] = form.user_number.data if form.dept_id.data: user_query['dept_id'] = form.dept_id.data users = UserInfo.query.filter_by() if user_query: user_query['record_status'] = const.record_normal users = users.filter_by(**user_query) total_count = users.count() users = users.paginate(current_page, page_size, False).items data = map(lambda x: transform(x), users) data = list(data) return query_reply(success=True, data=data, paging={ 'current': current_page, 'pages': int(total_count / page_size + 1), 'records': total_count, }, message='done', error_code=const.code_success)
def query_member(): page_info = utils.get_page_info(request) current_page = page_info[0] page_size = page_info[1] valid, form = parsing_form('queryMemberForm') if not valid: return reply(success=False, message='参数错误', error_code=const.PARAM_ERR) members = Member.query.filter_by() query_dict = dict() if form['id']: query_dict['id'] = form['id'] if form['code']: query_dict['code'] = form.code.data if form['name']: query_dict['name'] = form.name.data if query_dict: members = members.filter_by(**query_dict) members = members.filter_by(record_status=const.RECORD_NORMAL) total_count = members.count() members = members.paginate(current_page, page_size, False).items data = [] for member in members: data.append(member.to_json()) return query_reply(success=True, data=data, paging={ 'current': current_page, 'pages': int(total_count / page_size + 1), 'records': total_count, }, message='done', error_code=const.CODE_SUCCESS)
def query_achievement(): page_info = utils.get_page_info(request) current_page = page_info[0] page_size = page_info[1] valid, form = parsing_form('queryAchievementForm') if not valid: return reply(success=False, message='参数错误', error_code=const.PARAM_ERR) achievement_query = dict() if form['device_code']: achievement_query['device_code'] = form['device_code'] if form['member_code']: achievement_query['member_code'] = form['member_code'] if form['department_id']: achievement_query['department_id'] = form['department_id'] achievements = Achievement.query.filter_by() if achievement_query: achievements = achievements.filter_by(**achievement_query) device_query = dict() if form['device_code']: device_query['code'] = form['device_code'] if form['device_name']: device_query['name'] = form['device_name'] if form['model']: device_query['model'] = form['model'] if form['brand']: device_query['brand'] = form['brand'] if form['tag_code']: device_query['tag_code'] = form['tag_code'] devices = Device.query.filter_by() if device_query: devices = devices.filter_by(**device_query) achievements = achievements.filter( Achievement.device_code.in_(map(lambda x: x.code, devices))) if form['manufacturer_date']: achievements = achievements.filter( db.cast(Achievement.manufacturer_date, db.DATE) == form['manufacturer_date']) total_count = achievements.count() achievements = achievements.paginate(current_page, page_size, False).items data = map(lambda x: transform(x), achievements) data = list(data) return query_reply(success=True, data=data, paging={ 'current': current_page, 'pages': int(total_count / page_size + 1), 'records': total_count, }, message='done', error_code=const.CODE_SUCCESS)
def account_user_query(): current_page, page_size = utils.get_page_info(request) accounts = Account.query.filter(Account.user_id == current_user.id) total_count = accounts.count() accounts = accounts.paginate(current_page, page_size, False).items accounts = map(lambda account: get_user_account(account), accounts) accounts = list(accounts) return query_reply(success=True, data={'accounts': accounts}, paging={ 'current': current_page, 'pages': int((total_count - 1) / page_size + 1), 'records': total_count, }, message='done', error_code=const.code_success)
def query_device(): page_info = utils.get_page_info(request) current_page = page_info[0] page_size = page_info[1] valid, form = parsing_form('queryDeviceForm') if not valid: return reply(success=False, message='参数错误', error_code=const.PARAM_ERR) device_query = dict() if form['code']: device_query['code'] = form['code'] if form['name']: device_query['name'] = form['name'] if form['model']: device_query['model'] = form['model'] if form['brand']: device_query['brand'] = form['brand'] if form['tag_code']: device_query['tag_code'] = form['tag_code'] if form['status']: device_query['status'] = form['status'] if form['manufacturer_id']: device_query['manufacturer_id'] = form['manufacturer_id'] if form['department_id']: device_query['department_id'] = form['department_id'] devices = Device.query.filter_by() if device_query: device_query['record_status'] = const.RECORD_NORMAL devices = devices.filter_by(**device_query) if form['manufacturer_date']: devices = devices.filter( db.cast(Device.manufacturer_date, db.DATE) == form['manufacturer_date']) total_count = devices.count() devices = devices.paginate(current_page, page_size, False).items data = map(lambda x: transform(x), devices) data = list(data) return query_reply(success=True, data=data, paging={ 'current': current_page, 'pages': int(total_count / page_size + 1), 'records': total_count, }, message='done', error_code=const.CODE_SUCCESS)
def order_user_query(): current_page, page_size = utils.get_page_info(request) orders = db.session.query(CourtOrder).filter(CourtOrder.user_id == current_user.id) total_count = orders.count() orders = orders.paginate(current_page, page_size, False).items print(orders) orders = map(lambda order: get_user_order(order), orders) orders = list(orders) return query_reply(success=True, data={'orders': orders}, paging={ 'current': current_page, 'pages': int((total_count - 1) / page_size + 1), 'records': total_count, }, message='done', error_code=const.code_success)
def query_manufacturer(): page_info = utils.get_page_info(request) current_page = page_info[0] page_size = page_info[1] manufacturer = Manufacturer.query.order_by( Manufacturer.name ).filter_by( record_status=const.RECORD_NORMAL ) total_count = manufacturer.count() members = manufacturer.paginate(current_page, page_size, False).items data = map(lambda x: tran_to_json(x), members) data = list(data) return query_reply(success=True, data=data, paging={ 'current': current_page, 'pages': int(total_count / page_size + 1), 'records': total_count, }, message='done', error_code=const.CODE_SUCCESS)
def account_manager_query(): if current_user.user_type != const.user_type_manage: return reply(success=False, message='无权限', error_code=const.code_not_permit) current_page, page_size = utils.get_page_info(request) accounts = Account.query.order_by(Account.account_time) total_count = accounts.count() accounts = accounts.paginate(current_page, page_size, False).items accounts = map(lambda account: get_manager_account(account), accounts) accounts = list(accounts) return query_reply(success=True, data={'accounts': accounts}, paging={ 'current': current_page, 'pages': int((total_count - 1) / page_size + 1), 'records': total_count, }, message='done', error_code=const.code_success)
def query_rent_device(): page_info = utils.get_page_info(request) current_page = page_info[0] page_size = page_info[1] valid, form = parsing_form('queryDeviceLendForm') if not valid: return reply(success=False, message='参数错误', error_code=const.PARAM_ERR) rent_query = dict() if form['device_code']: rent_query['device_code'] = form['device_code'] if form['status']: rent_query['status'] = form['status'] if form['department_id']: rent_query['device_department_id'] = form['department_id'] if form['borrower_member_code']: rent_query['borrower_member_code'] = form['borrower_member_code'] if form['borrower_department_id']: rent_query['borrower_department_id'] = form['borrower_department_id'] if form['returner_member_code']: rent_query['returner_member_code'] = form['returner_member_code'] if form['returner_department_id']: rent_query['returner_department_id'] = form['returner_department_id'] device_rents = DeviceRent.query.filter_by() if rent_query: device_rents = device_rents.filter_by( **rent_query ) device_query = dict() if form['device_name']: device_query['device_name'] = form['device_name'] if form['model']: device_query['model'] = form['model'] if form['brand']: device_query['brand'] = form['brand'] if form['tag_code']: device_query['tag_code'] = form['tag_code'] if device_query: devices = Device.filter_by( **device_query ) device_rents = device_rents.filter( DeviceRent.device_code.in_( map(lambda x: x.device_code, devices) ) ) if form['borrow_date']: device_rents = device_rents.filter( db.cast(DeviceRent.borrow_date, db.DATE) == form['borrow_date']) if form['real_return_date']: device_rents = device_rents.filter( db.cast(DeviceRent.return_date, db.DATE) == form['real_return_date']) if form['expect_return_date']: device_rents = device_rents.filter( db.cast(DeviceRent.expect_return_date, db.DATE) == form['expect_return_date']) total_count = device_rents.count() device_rents = device_rents.paginate(current_page, page_size, False).items data = map(lambda x: transform(x), device_rents) data = list(data) return query_reply(success=True, data=data, paging={ 'current': current_page, 'pages': int(total_count / page_size + 1), 'records': total_count, }, message='done', error_code=const.CODE_SUCCESS)