Преобразуй perl в java
#!/bin/env perl
use DateTime;
use strict;

my ($months, $startDate) = $self->_defaultMonthsStartDate($months, $startDate);
my @cmpkey=('BC02','BC03','BC04','BC05','BC06','BC07','BC08','BC09');
my (undef, $prebill_offset) = $self->getBOPARAMS('BillingPreBillOffsetDays');
my ($sch_defaults,undef) = $self->getBOPARAMS('BillingScheduleOverrideDefaults');
my ($cust_categories,undef) = $self->getBOPARAMS('CustomerCategories');
my ($thresholds,undef) = $self->getBOPARAMS('BillingThresholdCheckDefaults');
my ($custbill_sch)= $self->getBOPARAMS('CustomerBillingScheduleDefaults');
my %bill_days;
my $keyid;
my $cust_type;
my %custbillsch;
my %custsch;
#Modification for Nuuday
my %holiday;
my $dayNo;
my $dbh;
&DBILogin;
$dbh->{PrintError} = 0;
$dbh->{RaiseError} = 0;

my $selectHD = $dbh->prepare(q{select TO_CHAR(HOLIDAY_DAT,'YYYYMMDD')  FROM HOLIDAYDATE ORDER BY 1}) or die $DBI::Errstr;
while (my ($HD) = $selectHD->fetchrow_array() ) {
$holiday{$HD} = 1;
$rows++;
}
$selectHD->finish();
print "Loaded $rows in holiday hash\n";
#Extract Schedule day as per Customer Category/Type
 foreach my $item (split(/\|/,$custbill_sch)) {
 my ($billsch_day,$ctyp) = split(/,/,$item);
 $custbillsch{$billsch_day}=$ctyp;
 $custsch{$ctyp}=sprintf("%02d",$billsch_day);
 }
foreach my $item (split(/\|/,$sch_defaults)) {
    #Modification for Nuuday
my ($bill_day, $sch_day,$bill_cycle) = split(/,/,$item);
if ($bill_day < 1 || $bill_day > 28) {
print "Invalid bill day of $bill_day with schedule day of $sch_day\n";
return(1);
}
if ($sch_day < 1 || $sch_day > 28) {
print "Invalid schedule day of $sch_day with bill day of $bill_day\n";
return(1);
}
if ($bill_day > $sch_day && $sch_day > 4) {
print "Invalid combination of schedule day of $sch_day with bill day of $bill_day\n";
return(1);
}
if ($bill_day > $sch_day && $bill_day < 25) {
print "Invalid combination of schedule day of $sch_day with bill day of $bill_day\n";
return(1);
}
# set bogey that schedule_dat can't be more than 5 days later than NBD day
if ($bill_day < $sch_day && $bill_day + 5 < $sch_day) {
print "Invalid combination of schedule day of $sch_day with bill day of $bill_day\n";
return(1);
}
#Modification for Nuuday
if (($bill_cycle ne 'BC02') || ($bill_cycle ne 'BC03') || ($bill_cycle ne 'BC04') || ($bill_cycle ne 'BC05') || ($bill_cycle ne 'BC06') || ($bill_cycle ne 'BC07') || ($bill_cycle ne 'BC08') || ($bill_cycle ne 'BC09')   {
 print "Invalid bill cycle $bill_cycle assigned to schedule day of $sch_day with bill day of $bill_day \n";
}
#$cust_type = $custbillsch{$sch_day};
     $keyid = sprintf("%02d",$bill_day).'|'.$bill_cycle;
 $bill_days{$keyid} = $sch_day;
}
my %categories;
foreach my $item (split(/\|/,$cust_categories)) {
my ($id, $category) = split(/,/,$item);
$categories{$id} = $category;
}
my %threshold_percent;
my %threshold_quantity;
foreach my $item (split(/\|/,$thresholds)) {
my ($id, $percent, $quantity) = split(/,/,$item);
$threshold_percent{$id} = $percent;
$threshold_quantity{$id} = $quantity;
}

# set bogey of 1-9 days to do pre-bill BEFORE real billing
if ($prebill_offset < 1 || $prebill_offset > 9 || $prebill_offset eq '') {
print "Invalid BillingPreBillOffsetDays setting of $prebill_offset - must be 1 to 9 days\n";
return(1);
}
foreach my $key (sort keys(%categories)) {
if (!defined $threshold_percent{$key}) {
print "Can't find BillingThresholdCheckDefaults details for id $key category $categories{$key}\n";
return(1);
}
}
foreach my $key (sort keys(%threshold_percent)) {
if (!defined $categories{$key}) {
print "Can't find CustomerCategories details for id $key\n";
return(1);
}
}

my $deleteBS = $dbh->prepare(q{delete from BO_BILLINGSCHEDULE
                where BILL_CYCLE = ? and NEXT_BILL_DAT between ? and ?}) or die $DBI::Errstr;
my $deleteBSC = $dbh->prepare(q{delete from BO_BILLINGSCHEDULECATEGORY
                where BILL_CYCLE = ? and BILLING_SCHEDULE_DAT=?}) or die $DBI::Errstr;
my $insertBS = $dbh->prepare(q{insert into BO_BILLINGSCHEDULE
                (BILL_CYCLE,NEXT_BILL_DAT,BILLING_SCHEDULE_DAT,PREBILL_DAT,CUSTOMER_TYPE) values (?,?,?,?) }) or die $DBI::Errstr;
my $insertBSC = $dbh->prepare(q{insert into BILLINGSCHEDULECATEGORY
                (BILL_CYCLE,BILLING_SCHEDULE_DAT,CUSTOMER_TYPE,THRESHOLD_QUANTITY,THRESHOLD_PERCENT) values (?,?,?,?) }) or die $DBI::Errstr;
my $total_deletes_BS = 0;
my $total_inserts_BS = 0;
my $total_deletes_BSC = 0;
my $total_inserts_BSC = 0;

my ($monthMaxDayRef, @date_range) = $self->dateRange($startDate,$months);
my $date_qty = @date_range;
my $endDate = $date_range[$date_qty - 1];
#print "range is $date_range[0] / $startDate to $endDate\n";
my %sch_days;
my $prebilldate;
my $rv;
my $work_failed = 0;
my $cust_type;

$rv = $deleteBS->execute($startDate, $endDate);
if ($@ || $DBI::errstr || $rv eq '') {
print "Failed to delete rows in BILLINGSCHEDULE: $DBI::errstr\n";
$work_failed++;
} else {
#print "deleted BS rows = $DBI::rows\n";
$total_deletes_BS += $DBI::rows;
}

my $finalkey;
#my $cmpstr;
my $bsc_done='F';
foreach  $cmpstr (@cmpkey) {
 foreach my $date (@date_range) {
my $day = substr($date,6,2);
$finalkey=$day."|".$cmpstr;
if ($bill_days{$finalkey}) {
#my $sch_date = sprintf("%06d%02d", substr($date,0,6), $bill_days{$day});
my $sch_date = sprintf("%06d%02d", substr($date,0,6), $bill_days{$finalkey});
# handle crossing into next month and/or year
#if ($day > $bill_days{$day}) {
#Modification for Nuuday
$dayNo = $self->_dayNumber($sch_date)
#Validate if schedule date is a holiday .Advance by a day if it's a holiday
while  (defined $holiday{$sch_date} || $dayNo eq 0 || $dayNo eq 6)  {
   print "$sch_date is a schedule holiday/weekend \n";
   $bill_days{$finalkey} = substr($sch_date,6,2)+1;
   $sch_date = $sch_date + 1;
   $dayNo = $self->_dayNumber($sch_date)
}
if ($day > $bill_days{$finalkey}) {
my $sch_year = substr($date,0,4);
my $sch_month = substr($date,4,2) + 1;
if ($sch_month == 13) {
$sch_month = 1;
$sch_year++;
}
$sch_date = sprintf("%04d%02d%02d", $sch_year, $sch_month, substr($date,6,2));
}
$sch_days{$sch_date} += 1;
$prebilldate = $self->_dateOffset($date, $prebill_offset);
# fix - need smarter BSC delete to avoid overlap outside range sharing same BS date
$rv = $deleteBSC->execute($bill_cycle,$sch_date);
if ($@ || $DBI::errstr || $rv eq '') {
print "Failed to delete rows in BILLINGSCHEDULECATEGORY: $DBI::errstr\n";
$work_failed++;
} else {
#print "deleted BSC rows for $sch_date = $DBI::rows\n";
$total_deletes_BSC += $DBI::rows;
}
#$rv = $insertBS->execute($date, $sch_date, $prebilldate);
my ($tmpday,$tmpcusttype)=split(/\|/,$finalkey);
$rv = $insertBS->execute($bill_cycle,$date, $sch_date, $prebilldate,$tmpcusttype);
if ($@ || $DBI::errstr || $DBI::rows == 0 || $rv eq '') {
print "Failed to insert row $date into BILLINGSCHEDULE: $DBI::errstr \n";
$work_failed++;
} else {
$total_inserts_BS++;
}
foreach my $key (sort keys(%categories)) {
my $tmpsch_day = $custsch{$categories{$key}};
my $tmp_day = substr($sch_date,6,2);
print "tmpsch_day,tmp_day - $tmpsch_day,$tmp_day \n");
if ($tmpsch_day eq $tmp_day) { 
$rv = $insertBSC->execute($bill_cycle,$sch_date, $categories{$key}, $threshold_quantity{$key}, $threshold_percent{$key});
if ($@ || $DBI::errstr || $DBI::rows == 0 || $rv eq '') {
    print "Failed to insert row $sch_date/$categories{$key} into BILLINGSCHEDULECATEGORY: $DBI::errstr\n";
    $work_failed++;
        } else {
    $total_inserts_BSC++;
        }
}
                        }   
#print "DATE $date ; PREBILL = $prebilldate ; SCH = $sch_date\n\n";
} else {
#print "DATE $date ; no billing\n";
}
}



print "Work Failed       = " . $self->_fancy_num($work_failed)." \n";
print "Total deletes BS  = " . $self->_fancy_num($total_deletes_BS)." \n";
print "Total deletes BSC = " . $self->_fancy_num($total_deletes_BSC)." \n";
print "Total inserts BS  = " . $self->_fancy_num($total_inserts_BS)." \n";
print "Total inserts BSC = " . $self->_fancy_num($total_inserts_BSC)." \n";
if ($work_failed) {
print "Rolling back entire change set due to $work_failed DB errors\n";
$dbh->rollback;
} else {
print "Committing entire change set of BS & BSC to database\n";
$self->{rba}->db->commit;
}
$deleteBS->finish;
$insertBS->finish;
$deleteBSC->finish;
$insertBSC->finish;
if ($work_failed) {
return(1);
} else {
return(0);
}
}
&DBILogout;
print("Processing completed.Exiting out of the program \n");