MT#9637 Extract reseller fields from admin fields

changes/08/1108/1
Andreas Granig 12 years ago
parent bcb750d7ff
commit d266163cba

@ -18,8 +18,8 @@ MAX_ROWS_PER_FILE=5000
EXPORT_INCOMING=no
ADMIN_EXPORT_FIELDS = 'accounting.cdr.id', 'accounting.cdr.update_time', 'accounting.cdr.source_user_id', 'accounting.cdr.source_provider_id', 'accounting.cdr.source_external_subscriber_id', 'source_voip_subscribers.id', 'accounting.cdr.source_external_contract_id', 'accounting.cdr.source_account_id', 'accounting.cdr.source_user', 'accounting.cdr.source_domain', 'accounting.cdr.source_cli', 'accounting.cdr.source_clir', 'accounting.cdr.source_ip', 'accounting.cdr.destination_user_id', 'accounting.cdr.destination_provider_id', 'accounting.cdr.destination_external_subscriber_id', 'destination_voip_subscribers.id', 'accounting.cdr.destination_external_contract_id', 'accounting.cdr.destination_account_id', 'accounting.cdr.destination_user', 'accounting.cdr.destination_domain', 'accounting.cdr.destination_user_in', 'accounting.cdr.destination_domain_in', 'accounting.cdr.destination_user_dialed', 'accounting.cdr.peer_auth_user', 'accounting.cdr.peer_auth_realm', 'accounting.cdr.call_type', 'accounting.cdr.call_status', 'accounting.cdr.call_code', 'FROM_UNIXTIME(accounting.cdr.init_time)', 'FROM_UNIXTIME(accounting.cdr.start_time)', 'accounting.cdr.duration', 'accounting.cdr.call_id', 'accounting.cdr.rating_status', 'accounting.cdr.rated_at', 'accounting.cdr.source_carrier_cost', 'accounting.cdr.source_customer_cost', 'source_carrier_bbz.zone', 'source_customer_bbz.zone', 'source_carrier_bbz.detail', 'source_customer_bbz.detail', 'accounting.cdr.source_carrier_free_time', 'accounting.cdr.source_customer_free_time', 'accounting.cdr.destination_carrier_cost', 'accounting.cdr.destination_customer_cost', 'destination_carrier_bbz.zone', 'destination_customer_bbz.zone', 'destination_carrier_bbz.detail', 'destination_customer_bbz.detail', 'accounting.cdr.destination_carrier_free_time', 'accounting.cdr.destination_customer_free_time', 'accounting.cdr.source_reseller_cost', 'source_reseller_bbz.zone', 'source_reseller_bbz.detail', 'accounting.cdr.source_reseller_free_time', 'accounting.cdr.destination_reseller_cost', 'destination_reseller_bbz.zone', 'destination_reseller_bbz.detail', 'accounting.cdr.destination_reseller_free_time'
RESELLER_EXPORT_FIELDS = 'accounting.cdr.id', 'accounting.cdr.update_time', 'accounting.cdr.source_user_id', 'accounting.cdr.source_provider_id', 'accounting.cdr.source_external_subscriber_id', 'source_voip_subscribers.id', 'accounting.cdr.source_external_contract_id', 'accounting.cdr.source_account_id', 'accounting.cdr.source_user', 'accounting.cdr.source_domain', 'accounting.cdr.source_cli', 'accounting.cdr.source_clir', 'accounting.cdr.source_ip', 'destination_voip_subscribers.id', 'accounting.cdr.destination_provider_id', 'accounting.cdr.destination_external_subscriber_id', 'destination_voip_subscriber.id', 'accounting.cdr.destination_external_contract_id', 'accounting.cdr.destination_account_id', 'accounting.cdr.destination_user', 'accounting.cdr.destination_domain', 'accounting.cdr.destination_user_in', 'accounting.cdr.destination_domain_in', 'accounting.cdr.destination_user_dialed', 'accounting.cdr.peer_auth_user', 'accounting.cdr.peer_auth_realm', 'accounting.cdr.call_type', 'accounting.cdr.call_status', 'accounting.cdr.call_code', 'FROM_UNIXTIME(accounting.cdr.init_time)', 'FROM_UNIXTIME(accounting.cdr.start_time)', 'accounting.cdr.duration', 'accounting.cdr.call_id', 'accounting.cdr.rating_status', 'accounting.cdr.rated_at', 'accounting.cdr.source_customer_cost', 'source_customer_bbz.zone', 'source_customer_bbz.detail', 'accounting.cdr.source_customer_free_time', 'accounting.cdr.destination_customer_cost', 'destination_customer_bbz.zone', 'destination_customer_bbz.detail', 'accounting.cdr.destination_customer_free_time'
ADMIN_EXPORT_FIELDS = 'accounting.cdr.id', 'accounting.cdr.update_time', 'accounting.cdr.source_user_id', 'accounting.cdr.source_provider_id', 'accounting.cdr.source_external_subscriber_id', 'source_voip_subscribers.id', 'accounting.cdr.source_external_contract_id', 'accounting.cdr.source_account_id', 'accounting.cdr.source_user', 'accounting.cdr.source_domain', 'accounting.cdr.source_cli', 'accounting.cdr.source_clir', 'accounting.cdr.source_ip', 'accounting.cdr.destination_user_id', 'accounting.cdr.destination_provider_id', 'accounting.cdr.destination_external_subscriber_id', 'destination_voip_subscribers.id', 'accounting.cdr.destination_external_contract_id', 'accounting.cdr.destination_account_id', 'accounting.cdr.destination_user', 'accounting.cdr.destination_domain', 'accounting.cdr.destination_user_in', 'accounting.cdr.destination_domain_in', 'accounting.cdr.destination_user_dialed', 'accounting.cdr.peer_auth_user', 'accounting.cdr.peer_auth_realm', 'accounting.cdr.call_type', 'accounting.cdr.call_status', 'accounting.cdr.call_code', 'CONCAT(FROM_UNIXTIME(accounting.cdr.init_time), ".", SUBSTRING_INDEX(accounting.cdr.init_time, ".", -1))', 'CONCAT(FROM_UNIXTIME(accounting.cdr.start_time), ".", SUBSTRING_INDEX(accounting.cdr.start_time, ".", -1))', 'accounting.cdr.duration', 'accounting.cdr.call_id', 'accounting.cdr.rating_status', 'accounting.cdr.rated_at', 'accounting.cdr.source_carrier_cost', 'accounting.cdr.source_customer_cost', 'COALESCE(source_carrier_bbz.zone, "onnet")', 'source_customer_bbz.zone', 'COALESCE(source_carrier_bbz.detail, "platform internal")', 'source_customer_bbz.detail', 'accounting.cdr.source_carrier_free_time', 'accounting.cdr.source_customer_free_time', 'accounting.cdr.destination_carrier_cost', 'accounting.cdr.destination_customer_cost', 'destination_carrier_bbz.zone', 'destination_customer_bbz.zone', 'destination_carrier_bbz.detail', 'destination_customer_bbz.detail', 'accounting.cdr.destination_carrier_free_time', 'accounting.cdr.destination_customer_free_time', 'accounting.cdr.source_reseller_cost', 'source_reseller_bbz.zone', 'source_reseller_bbz.detail', 'accounting.cdr.source_reseller_free_time', 'accounting.cdr.destination_reseller_cost', 'destination_reseller_bbz.zone', 'destination_reseller_bbz.detail', 'accounting.cdr.destination_reseller_free_time'
RESELLER_EXPORT_FIELDS = 'accounting.cdr.id', 'accounting.cdr.update_time', 'accounting.cdr.source_user_id', 'accounting.cdr.source_provider_id', 'accounting.cdr.source_external_subscriber_id', 'source_voip_subscribers.id', 'accounting.cdr.source_external_contract_id', 'accounting.cdr.source_account_id', 'accounting.cdr.source_user', 'accounting.cdr.source_domain', 'accounting.cdr.source_cli', 'accounting.cdr.source_clir', 'accounting.cdr.source_ip', 'accounting.cdr.destination_user_id', 'accounting.cdr.destination_provider_id', 'accounting.cdr.destination_external_subscriber_id', 'destination_voip_subscribers.id', 'accounting.cdr.destination_external_contract_id', 'accounting.cdr.destination_account_id', 'accounting.cdr.destination_user', 'accounting.cdr.destination_domain', 'accounting.cdr.destination_user_in', 'accounting.cdr.destination_domain_in', 'accounting.cdr.destination_user_dialed', 'accounting.cdr.peer_auth_user', 'accounting.cdr.peer_auth_realm', 'accounting.cdr.call_type', 'accounting.cdr.call_status', 'accounting.cdr.call_code', 'CONCAT(FROM_UNIXTIME(accounting.cdr.init_time), ".", SUBSTRING_INDEX(accounting.cdr.init_time, ".", -1))', 'CONCAT(FROM_UNIXTIME(accounting.cdr.start_time), ".", SUBSTRING_INDEX(accounting.cdr.start_time, ".", -1))', 'accounting.cdr.duration', 'accounting.cdr.call_id', 'accounting.cdr.rating_status', 'accounting.cdr.rated_at', 'accounting.cdr.source_customer_cost', 'source_customer_bbz.zone', 'source_customer_bbz.detail', 'accounting.cdr.source_customer_free_time', 'accounting.cdr.destination_customer_cost', 'destination_customer_bbz.zone', 'destination_customer_bbz.detail', 'accounting.cdr.destination_customer_free_time'
EXPORT_JOINS = { 'billing.voip_subscribers source_voip_subscribers' => { 'source_voip_subscribers.uuid' => 'accounting.cdr.source_user_id' } }, { 'billing.voip_subscribers destination_voip_subscribers' => { 'destination_voip_subscribers.uuid' => 'accounting.cdr.destination_user_id' } }, { 'billing.billing_zones_history source_carrier_bbz' => { 'source_carrier_bbz.id' => 'accounting.cdr.source_carrier_billing_zone_id' } }, { 'billing.billing_zones_history source_reseller_bbz' => { 'source_reseller_bbz.id' => 'accounting.cdr.source_reseller_billing_zone_id' } }, { 'billing.billing_zones_history source_customer_bbz' => { 'source_customer_bbz.id' => 'accounting.cdr.source_customer_billing_zone_id' } }, { 'billing.billing_zones_history destination_carrier_bbz' => { 'destination_carrier_bbz.id' => 'accounting.cdr.destination_carrier_billing_zone_id' } }, { 'billing.billing_zones_history destination_reseller_bbz' => { 'destination_reseller_bbz.id' => 'accounting.cdr.destination_reseller_billing_zone_id' } }, { 'billing.billing_zones_history destination_customer_bbz' => { 'destination_customer_bbz.id' => 'accounting.cdr.destination_customer_billing_zone_id' } }

@ -130,6 +130,20 @@ print("+++ Start run with DB " . ($config->{'default.DBUSER'} || "(undef)") .
my $file_ts = NGCP::CDR::Export::get_ts_for_filename;
# extract positions of reseller fields from admin fields
my @reseller_positions = ();
my %reseller_index;
@reseller_index{@admin_fields} = (0..$#admin_fields);
for(my $i = 0; $i < @reseller_fields; $i++) {
my $name = $reseller_fields[$i];
unless(exists $reseller_index{$name}) {
die "Invalid RESELLER_EXPORT_FIELDS element '$name', not available in ADMIN_EXPORT_FIELDS!";
}
push @reseller_positions, $reseller_index{$name};
}
# add fields we definitely need, will be removed during processing
unshift @admin_fields, qw/
accounting.cdr.id
@ -163,12 +177,13 @@ my $reseller_lines = {};
while(my $row = $sth->fetchrow_arrayref) {
# agranig: no quoting of fields
# my @fields = map { defined $_ ? "\"$_\"" : '""' } (@{ $row });
my @fields = map { defined $_ ? $_ : '' } (@{ $row });
my @fields = @{ $row };
my $id = shift @fields;
my $src_uuid = shift @fields;
my $dst_uuid = shift @fields;
my $src_provid = shift @fields;
my $dst_provid = shift @fields;
@fields = map { defined $_ ? "'$_'" : "''" } (@fields);
if($config->{'default.EXPORT_INCOMING'} eq "no" && $src_uuid eq "0") {
push @ignored_ids, $id;
@ -178,12 +193,15 @@ while(my $row = $sth->fetchrow_arrayref) {
my $line = join ",", @fields;
$reseller_lines->{'system'}->{$id} = $line;
my @reseller_fields = @fields[@reseller_positions];
my $reseller_line = join ",", @reseller_fields;
if($src_uuid ne "0") {
if(!exists $reseller_names->{$src_provid}) {
$reseller_names->{$src_provid} = NGCP::CDR::Export::get_reseller_name($dbh, $src_provid);
$reseller_ids->{$reseller_names->{$src_provid}} = $src_provid;
}
$reseller_lines->{$reseller_names->{$src_provid}}->{$id} = $line;
$reseller_lines->{$reseller_names->{$src_provid}}->{$id} = $reseller_line;
}
if($dst_uuid ne "0") {
if($config->{'default.EXPORT_INCOMING'} eq "no" && $src_provid ne $dst_provid) {
@ -193,7 +211,7 @@ while(my $row = $sth->fetchrow_arrayref) {
$reseller_names->{$dst_provid} = NGCP::CDR::Export::get_reseller_name($dbh, $dst_provid);
$reseller_ids->{$reseller_names->{$dst_provid}} = $dst_provid;
}
$reseller_lines->{$reseller_names->{$dst_provid}}->{$id} = $line;
$reseller_lines->{$reseller_names->{$dst_provid}}->{$id} = $reseller_line;
}
}
}

Loading…
Cancel
Save