refactor(jobs): simplify jobs and controllers by replacing period array with single period parameter
- Mengganti parameter `$periods` (array) menjadi `$period` (string) pada semua Job terkait: `ProcessCustomerDataJob`, `ProcessFundsTransferDataJob, etc`. - Menyederhanakan operasi loop dalam proses data dengan hanya memproses satu periode per eksekusi Job. - Memodifikasi fungsi controller di `MigrasiController` agar sesuai dengan perubahan parameter dari array ke string. - Menambahkan pengamanan jika `$period` kosong atau bernilai '_parameter' untuk mencegah proses yang tidak diperlukan. - Mengurangi duplikasi kode dengan mengeliminasi metode yang mengelola array periode dan menggantinya dengan pendekatan tunggal. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -19,10 +19,10 @@
|
||||
private const PARAMETER_FOLDER = '_parameter';
|
||||
|
||||
// Konstanta untuk nilai-nilai statis
|
||||
private const FILE_EXTENSION = '.ST.ATM.TRANSACTION.csv';
|
||||
private const CSV_DELIMITER = '~';
|
||||
private const DISK_NAME = 'sftpStatement';
|
||||
private const HEADER_MAP = [
|
||||
private const FILE_EXTENSION = '.ST.ATM.TRANSACTION.csv';
|
||||
private const CSV_DELIMITER = '~';
|
||||
private const DISK_NAME = 'sftpStatement';
|
||||
private const HEADER_MAP = [
|
||||
'id' => 'transaction_id',
|
||||
'card_acc_id' => 'card_acc_id',
|
||||
'pan_number' => 'pan_number',
|
||||
@@ -43,30 +43,37 @@
|
||||
];
|
||||
|
||||
// Pemetaan bidang header ke kolom model
|
||||
protected array $periods;
|
||||
protected string $period;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(array $periods = [])
|
||||
public function __construct(string $period = '')
|
||||
{
|
||||
$this->periods = $periods;
|
||||
$this->period = $period;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
public function handle()
|
||||
: void
|
||||
{
|
||||
try {
|
||||
set_time_limit(24 * 60 * 60);
|
||||
|
||||
if (empty($this->periods)) {
|
||||
Log::warning('No periods provided for ATM transaction data processing');
|
||||
if (empty($this->period)) {
|
||||
Log::warning('No period provided for ATM transaction data processing');
|
||||
return;
|
||||
}
|
||||
|
||||
$stats = $this->processPeriods();
|
||||
// Skip the parameter folder
|
||||
if ($this->period === self::PARAMETER_FOLDER) {
|
||||
Log::info("Skipping " . self::PARAMETER_FOLDER . " folder");
|
||||
return;
|
||||
}
|
||||
|
||||
$stats = $this->processPeriodFile();
|
||||
|
||||
Log::info("ProcessAtmTransactionJob completed. Total processed: {$stats['processed']}, Total errors: {$stats['errors']}");
|
||||
} catch (Exception $e) {
|
||||
@@ -75,40 +82,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process all periods and return statistics
|
||||
*/
|
||||
private function processPeriods(): array
|
||||
{
|
||||
$disk = Storage::disk(self::DISK_NAME);
|
||||
$processedCount = 0;
|
||||
$errorCount = 0;
|
||||
|
||||
foreach ($this->periods as $period) {
|
||||
// Skip the parameter folder
|
||||
if ($period === self::PARAMETER_FOLDER) {
|
||||
Log::info("Skipping " . self::PARAMETER_FOLDER . " folder");
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = $this->processPeriodFile($disk, $period);
|
||||
$processedCount += $result['processed'];
|
||||
$errorCount += $result['errors'];
|
||||
}
|
||||
|
||||
return [
|
||||
'processed' => $processedCount,
|
||||
'errors' => $errorCount
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a single period file
|
||||
*/
|
||||
private function processPeriodFile($disk, string $period): array
|
||||
private function processPeriodFile()
|
||||
: array
|
||||
{
|
||||
$filename = $period . self::FILE_EXTENSION;
|
||||
$filePath = "$period/$filename";
|
||||
$disk = Storage::disk(self::DISK_NAME);
|
||||
$filename = $this->period . self::FILE_EXTENSION;
|
||||
$filePath = "{$this->period}/$filename";
|
||||
$processedCount = 0;
|
||||
$errorCount = 0;
|
||||
|
||||
@@ -141,7 +123,8 @@
|
||||
/**
|
||||
* Create a temporary file for processing
|
||||
*/
|
||||
private function createTempFile($disk, string $filePath, string $filename): string
|
||||
private function createTempFile($disk, string $filePath, string $filename)
|
||||
: string
|
||||
{
|
||||
$tempFilePath = storage_path("app/temp_$filename");
|
||||
file_put_contents($tempFilePath, $disk->get($filePath));
|
||||
@@ -151,7 +134,8 @@
|
||||
/**
|
||||
* Process a CSV file and import data
|
||||
*/
|
||||
private function processCSVFile(string $tempFilePath, string $originalFilePath): array
|
||||
private function processCSVFile(string $tempFilePath, string $originalFilePath)
|
||||
: array
|
||||
{
|
||||
$processedCount = 0;
|
||||
$errorCount = 0;
|
||||
@@ -194,7 +178,8 @@
|
||||
/**
|
||||
* Process a single row from the CSV file
|
||||
*/
|
||||
private function processRow(array $headerRow, array $row, int $rowCount, string $filePath): array
|
||||
private function processRow(array $headerRow, array $row, int $rowCount, string $filePath)
|
||||
: array
|
||||
{
|
||||
// Combine the header row with the data row
|
||||
$rawData = array_combine($headerRow, $row);
|
||||
|
||||
Reference in New Issue
Block a user