Exemplo n.º 1
0
def get_pay_records(rst_id, activity_id=None, activity_category_id=None,
                    offset=None, limit=None):
    records_paging = query_paylog_by_rst(rst_id, activity_id,
                                         activity_category_id, offset, limit)
    total_num = count_paylog_by_rst(rst_id, activity_id, activity_category_id)

    record_process_ids = [r[9] for r in records_paging if r[9]]
    record_process_logs = query_process_records_by_ids(record_process_ids)
    process_log_map = {r.id: r for r in record_process_logs}

    records = []
    for record in records_paging:
        new_record = {
            'record_id': record[0],
            'first_date': record[4],
            'last_date': record[5],
            'quantity': to_int(record[6]),
            'audit_time': record[8],
            'total_subsidy': to_float(record[7]),
            'activity_id': record[1],
            'activity_category_id': record[2],
        }
        process_log = process_log_map.get(record[9], None)

        new_record['card_id'] = process_log.card_id \
            if process_log else None
        new_record['cardholder_name'] = process_log.cardholder_name \
            if process_log else None

        if process_log:
            new_record['status'] = process_log.status
        elif record[3] == ActivityStats.STATUS_PAY_RECORD_GENERATED:
            new_record['status'] = 1
        else:
            raise_user_exc(ACTIVITY_PAYMENT_PROC_ILL_ERR)

        if new_record['status'] == SubsidyProcessRecord.STATUS_SUBMITTED:
            new_record['submit_time'] = process_log.processed_at
        elif new_record['status'] in [3, 4]:
            new_record['success_time'] = process_log.processed_at

        records.append(new_record)

    for record in records:
        # set activity name
        try:
            record['activity_name'] = act_base.get_name(
                record['activity_id'], record['activity_category_id'])
        except:
            # Fix history problem
            record['activity_name'] = ''

    record_results = set_null(records,
                              ['card_id', 'cardholder_name',
                               'audit_time', 'submit_time', 'success_time'])

    return record_results, total_num
Exemplo n.º 2
0
def get_pay_records2(rst_id, activity_id=None, activity_category_id=None,
                     offset=None, limit=None):

    pay_records = query_pay_records(rst_id)
    pay_record_ids = [p.id for p in pay_records]
    pay_record_map = {p.id: p.created_at for p in pay_records}

    paylogs = query_paylog(pay_record_ids, activity_id, activity_category_id,
                           offset, limit)
    record_process_ids = get_max_subsidy_process_record_ids(pay_record_ids)

    total_num = count_paylog_by_rst(rst_id, activity_id, activity_category_id)

    record_process_logs = query_process_records_by_ids(
        [p[0] for p in record_process_ids])
    process_log_map = {r.pay_record_id: r for r in record_process_logs}

    records = []
    for record in paylogs:
        new_record = {
            'record_id': record[0],
            'first_date': record[4],
            'last_date': record[5],
            'quantity': to_int(record[6]),
            'audit_time': pay_record_map[record[0]],
            'total_subsidy': to_float(record[7]),
            'activity_id': record[1],
            'activity_category_id': record[2],
        }
        process_log = process_log_map.get(record[0], None)

        new_record['card_id'] = process_log.card_id \
            if process_log else None
        new_record['cardholder_name'] = process_log.cardholder_name \
            if process_log else None

        if process_log:
            new_record['status'] = process_log.status
        elif record[3] == ActivityStats.STATUS_PAY_RECORD_GENERATED:
            new_record['status'] = 1
        else:
            raise Exception('Invalid pay process record status.')

        if new_record['status'] == SubsidyProcessRecord.STATUS_SUBMITTED:
            new_record['submit_time'] = process_log.processed_at
        elif new_record['status'] in [3, 4]:
            new_record['success_time'] = process_log.processed_at

        records.append(new_record)

    for record in records:
        # set activity name
        try:
            record['activity_name'] = act_base.get_name(
                record['activity_id'], record['activity_category_id'])
        except:
            # Fix history problem
            record['activity_name'] = ''

    record_results = set_null(records,
                              ['card_id', 'cardholder_name',
                               'audit_time', 'submit_time', 'success_time'])

    return record_results, total_num