def get_rst_bankcard_list(rst_id): arg_spec = { 'status': Arg(int, allow_missing=True), 'type_code': Arg(int, allow_missing=True), 'page_size': Arg(int, allow_missing=True), 'page_no': Arg(int, allow_missing=True) } args = args_parser.parse(arg_spec) status = args.get('status') type_code = args.get('type_code') page_no, page_size = get_paging_params() offset = (page_no - 1) * page_size limit = page_size rst_bankcard_list = bankcard_base \ .query_bankcard(rst_id, status=status, limit=limit, offset=offset) rst_bankcard_list_new = [model2dict(m) for m in rst_bankcard_list] return { 'bankcard_list': rst_bankcard_list_new, 'total_num': bankcard_base.get_bankcard_count([ rst_id, ], status=status, type_code=type_code) }
def _diff_bankcard(walis_bankcard_dict, zeus_bankcard_dict, user_dict, user_profile_dict): add_num = 0 change_num = 0 same_num = 0 not_admin_num = 0 session = DBSession() for zb_rst_id, zb in zeus_bankcard_dict.iteritems(): wb = walis_bankcard_dict.get(zb_rst_id) rst_admin = user_profile_dict.get(zb.user_id) if rst_admin is None: not_admin_num += 1 continue if wb is not None: if zb.card_id.strip() == wb.card_id.strip(): same_num += 1 continue else: change_num += 1 print('walis_bankcard({}) is not same with zeus({}):{}=>{}'. format(wb.id, zb.id, model2dict(wb), ttype2dict(zb))) _current_to_history(wb) session.add(wb) new_wb = _force_add_rst_bankcard( rst_id=zb_rst_id, username=user_dict[zb.user_id]['username'], cardholder_name=zb.cardholder_name, card_id=zb.card_id, bank_id=zb.bank_id, mobile=rst_admin.mobile, status=RstBankCard.STATUS_VALID) session.add(new_wb) else: add_num += 1 print('zeus_bankcard({}) does not exist in walis:{}'.format( zb.id, ttype2dict(zb))) new_wb = _force_add_rst_bankcard( rst_id=zb_rst_id, username=user_dict[zb.user_id]['username'], cardholder_name=zb.cardholder_name, card_id=zb.card_id, bank_id=zb.bank_id, mobile=rst_admin.mobile, status=RstBankCard.STATUS_VALID) session.add(new_wb) print( '(add_num:{add_num}, change_num:{change_num}, same_num:{same_num}, not_admin_num:{not_admin_num})' .format(add_num=add_num, change_num=change_num, same_num=same_num, not_admin_num=not_admin_num))
def get_all_bankcard_list(): arg_spec = { 'search_text': Arg(), 'status': Arg(int, allow_missing=True), 'type_code': Arg(int, allow_missing=True), } args = args_parser.parse(arg_spec) search_text = args.pop('search_text') rst_ids = _filter_ids(search_text) args['rst_ids'] = rst_ids page_no, page_size = get_paging_params(paging_size=50) offset = (page_no - 1) * page_size limit = page_size args.update({"offset": offset, "limit": limit}) bankcard_list = bankcard_base.query_by_status(**args) if not bankcard_list: return { 'bankcard_list': [], 'total_num': 0, } bankcard_list_new = [] rst_set_ids = set() for bankcard in bankcard_list: bankcard_list_new.append(model2dict(bankcard)) rst_set_ids.add(bankcard.rst_id) rst_map = rst_base.get_map(rst_set_ids) for bankcard in bankcard_list_new: bankcard.update({ "restaurant_name": rst_map[bankcard['rst_id']].name, }) return { 'bankcard_list': bankcard_list_new, 'total_num': bankcard_base.get_bankcard_count( rst_ids=rst_ids, status=args.get("status"), type_code=args.get("type_code")), }
def get_all_bankcard_list(): arg_spec = { 'search_text': Arg(), 'status': Arg(int, allow_missing=True), 'type_code': Arg(int, allow_missing=True), } args = args_parser.parse(arg_spec) search_text = args.pop('search_text') rst_ids = _filter_ids(search_text) args['rst_ids'] = rst_ids page_no, page_size = get_paging_params(paging_size=50) offset = (page_no - 1) * page_size limit = page_size args.update({"offset": offset, "limit": limit}) bankcard_list = bankcard_base.query_by_status(**args) if not bankcard_list: return { 'bankcard_list': [], 'total_num': 0, } bankcard_list_new = [] rst_set_ids = set() for bankcard in bankcard_list: bankcard_list_new.append(model2dict(bankcard)) rst_set_ids.add(bankcard.rst_id) rst_map = rst_base.get_map(rst_set_ids) for bankcard in bankcard_list_new: bankcard.update({ "restaurant_name": rst_map[bankcard['rst_id']].name, }) return { 'bankcard_list': bankcard_list_new, 'total_num': bankcard_base.get_bankcard_count(rst_ids=rst_ids, status=args.get("status"), type_code=args.get("type_code")), }
def get_processing_record(rst_id, bankcard_id): arg_spec = { "limit": Arg(int, allow_missing=True), } args = args_parser.parse(arg_spec) limit = args.get("limit", DEFAULT_RECORD_LIMIT) processing_record_list = bankcard_base \ .query_processing_record(rst_id, bankcard_id, limit) if not processing_record_list: return [] process_user_ids = [] for m in processing_record_list: process_user_ids.append(m.process_user_id) process_user_list = user_base.mget_users(process_user_ids) process_user_dict = {user.id: user.username for user in process_user_list} processing_record_list_new = [] for processing_record in processing_record_list: pr_dict = model2dict(processing_record) pr_dict['process_user_username'] = \ process_user_dict.get(pr_dict['process_user_id']) processing_record_list_new.append(pr_dict) return processing_record_list_new
def get_processing_record(rst_id, bankcard_id): arg_spec = { "limit": Arg(int, allow_missing=True), } args = args_parser.parse(arg_spec) limit = args.get("limit", DEFAULT_RECORD_LIMIT) processing_record_list = bankcard_base \ .query_processing_record(rst_id, bankcard_id, limit) if not processing_record_list: return [] process_user_ids = [] for m in processing_record_list: process_user_ids.append(m.process_user_id) process_user_list = user_base.mget_users(process_user_ids) process_user_dict = {user.id: user.username for user in process_user_list} processing_record_list_new = [] for processing_record in processing_record_list: pr_dict = model2dict(processing_record) pr_dict['process_user_username'] = \ process_user_dict.get(pr_dict['process_user_id']) processing_record_list_new.append(pr_dict) return processing_record_list_new
def _diff_bankcard(walis_bankcard_dict, zeus_bankcard_dict, user_dict, user_profile_dict): add_num = 0 change_num = 0 same_num = 0 not_admin_num = 0 session = DBSession() for zb_rst_id, zb in zeus_bankcard_dict.iteritems(): wb = walis_bankcard_dict.get(zb_rst_id) rst_admin = user_profile_dict.get(zb.user_id) if rst_admin is None: not_admin_num += 1 continue if wb is not None: if zb.card_id.strip() == wb.card_id.strip(): same_num += 1 continue else: change_num += 1 print('walis_bankcard({}) is not same with zeus({}):{}=>{}' .format(wb.id, zb.id, model2dict(wb), ttype2dict(zb))) _current_to_history(wb) session.add(wb) new_wb = _force_add_rst_bankcard(rst_id=zb_rst_id, username=user_dict[zb.user_id]['username'], cardholder_name=zb.cardholder_name, card_id=zb.card_id, bank_id=zb.bank_id, mobile=rst_admin.mobile, status=RstBankCard.STATUS_VALID) session.add(new_wb) else: add_num += 1 print('zeus_bankcard({}) does not exist in walis:{}'.format(zb.id, ttype2dict(zb))) new_wb = _force_add_rst_bankcard(rst_id=zb_rst_id, username=user_dict[zb.user_id]['username'], cardholder_name=zb.cardholder_name, card_id=zb.card_id, bank_id=zb.bank_id, mobile=rst_admin.mobile, status=RstBankCard.STATUS_VALID) session.add(new_wb) print('(add_num:{add_num}, change_num:{change_num}, same_num:{same_num}, not_admin_num:{not_admin_num})' .format(add_num=add_num, change_num=change_num, same_num=same_num, not_admin_num=not_admin_num))
def get_rst_bankcard_list(rst_id): arg_spec = { 'status': Arg(int, allow_missing=True), 'type_code': Arg(int, allow_missing=True), 'page_size': Arg(int, allow_missing=True), 'page_no': Arg(int, allow_missing=True) } args = args_parser.parse(arg_spec) status = args.get('status') type_code = args.get('type_code') page_no, page_size = get_paging_params() offset = (page_no - 1) * page_size limit = page_size rst_bankcard_list = bankcard_base \ .query_bankcard(rst_id, status=status, limit=limit, offset=offset) rst_bankcard_list_new = [model2dict(m) for m in rst_bankcard_list] return { 'bankcard_list': rst_bankcard_list_new, 'total_num': bankcard_base.get_bankcard_count([rst_id, ], status=status, type_code=type_code) }
def get_rst_bankcard(rst_id, bankcard_id): rst_bankcard = bankcard_base.get_bankcard(rst_id, bankcard_id) if not rst_bankcard: return {} return model2dict(rst_bankcard)
def get_rst_bankcard(rst_id, bankcard_id): rst_bankcard = bankcard_base.get_bankcard(rst_id, bankcard_id) if not rst_bankcard: return {} return model2dict(rst_bankcard)