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:
Daeng Deni Mardaeni
2025-05-24 19:40:40 +07:00
parent 85b8bfa07b
commit cd447eb019
9 changed files with 761 additions and 799 deletions

View File

@@ -25,54 +25,10 @@ use Modules\Webstatement\Jobs\ProcessTransactionDataJob;
class MigrasiController extends Controller
{
public function processArrangementData($periods)
public function processTransactionData($period)
{
try {
ProcessArrangementDataJob::dispatch($periods);
return response()->json(['message' => 'Data Arrangement processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processCustomerData($periods)
{
try {
// Pass the periods to the job for processing
ProcessCustomerDataJob::dispatch($periods);
return response()->json([
'message' => 'Data Customer processing job has been successfully queued',
'periods' => $periods
]);
} catch (Exception $e) {
Log::error('Error in processCustomerData: ' . $e->getMessage());
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processBillDetailData($periods)
{
try {
ProcessBillDetailDataJob::dispatch($periods);
return response()->json(['message' => 'Data Bill Details processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processAccountData($periods){
try{
ProcessAccountDataJob::dispatch($periods);
return response()->json(['message' => 'Data Account processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processTransactionData($periods){
try{
ProcessTransactionDataJob::dispatch($periods);
ProcessTransactionDataJob::dispatch($period);
Log::info('Data Transaction processing job has been successfully');
return response()->json(['message' => 'Data Transaction processing job has been successfully']);
} catch (Exception $e) {
@@ -80,99 +36,36 @@ class MigrasiController extends Controller
}
}
public function processFundsTransferData($periods){
try{
ProcessFundsTransferDataJob::dispatch($periods);
return response()->json(['message' => 'Data Funds Transfer processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processStmtNarrParamData($periods)
public function processStmtNarrParamData($period)
{
try {
ProcessStmtNarrParamDataJob::dispatch($periods);
ProcessStmtNarrParamDataJob::dispatch($period);
return response()->json(['message' => 'Data TempStmtNarrParam processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processStmtNarrFormatData($periods){
public function processStmtNarrFormatData($period)
{
try {
ProcessStmtNarrFormatDataJob::dispatch($periods);
ProcessStmtNarrFormatDataJob::dispatch($period);
return response()->json(['message' => 'Data TempStmtNarrFormat processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessFtTxnTypeConditioData($periods){
public function ProcessFtTxnTypeConditioData($period)
{
try {
ProcessFtTxnTypeConditionJob::dispatch($periods);
ProcessFtTxnTypeConditionJob::dispatch($period);
return response()->json(['message' => 'FtTxnTypeCondition processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processStmtEntryData($periods){
try {
ProcessStmtEntryDataJob::dispatch($periods);
return response()->json(['message' => 'Stmt Entry processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessCompanyData($periods){
try {
ProcessCompanyDataJob::dispatch($periods);
return response()->json(['message' => 'Company processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessDataCaptureData($periods){
try {
ProcessDataCaptureDataJob::dispatch($periods);
return response()->json(['message' => 'Data Capture processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessCategoryData($periods){
try {
ProcessCategoryDataJob::dispatch($periods);
return response()->json(['message' => 'Category processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessTellerData($periods){
try {
ProcessTellerDataJob::dispatch($periods);
return response()->json(['message' => 'Teller processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessAtmTransaction($periods){
try {
ProcessAtmTransactionJob::dispatch($periods);
return response()->json(['message' => 'AtmTransaction processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function index_manual()
{
//$disk = Storage::disk('sftpStatement');
@@ -180,10 +73,10 @@ class MigrasiController extends Controller
// Get all directories (periods) in the SFTP disk
//$allDirectories = $disk->directories();
//$this->processTransactionData(['_parameter']);
//$this->processStmtNarrParamData(['_parameter']);
//$this->processStmtNarrFormatData(['_parameter']);
//$this->ProcessFtTxnTypeConditioData(['_parameter']);
//$this->processTransactionData('_parameter');
//$this->processStmtNarrParamData('_parameter');
//$this->processStmtNarrFormatData('_parameter');
//$this->ProcessFtTxnTypeConditioData('_parameter');
// Filter out the _parameter folder
/*$periods = array_filter($allDirectories, function($dir) {
@@ -215,25 +108,141 @@ class MigrasiController extends Controller
}
foreach ($periods as $period) {
$this->ProcessCategoryData([$period]);
$this->ProcessCompanyData([$period]);
$this->ProcessCategoryData($period);
$this->ProcessCompanyData($period);
$this->processCustomerData([$period]);
$this->processAccountData([$period]);
$this->processCustomerData($period);
$this->processAccountData($period);
$this->processStmtEntryData([$period]);
$this->ProcessDataCaptureData([$period]);
$this->processFundsTransferData([$period]);
$this->ProcessTellerData([$period]);
$this->ProcessAtmTransaction([$period]);
$this->processStmtEntryData($period);
$this->ProcessDataCaptureData($period);
$this->processFundsTransferData($period);
$this->ProcessTellerData($period);
$this->ProcessAtmTransaction($period);
$this->processArrangementData([$period]);
$this->processBillDetailData([$period]);
$this->processArrangementData($period);
$this->processBillDetailData($period);
}
return response()->json(['message' => 'Data processing job has been successfully']);
}
public function ProcessCategoryData($period)
{
try {
ProcessCategoryDataJob::dispatch($period);
return response()->json(['message' => 'Category processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessCompanyData($period)
{
try {
ProcessCompanyDataJob::dispatch($period);
return response()->json(['message' => 'Company processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processCustomerData($period)
{
try {
// Pass the period to the job for processing
ProcessCustomerDataJob::dispatch($period);
return response()->json([
'message' => 'Data Customer processing job has been successfully queued',
'period' => $period
]);
} catch (Exception $e) {
Log::error('Error in processCustomerData: ' . $e->getMessage());
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processAccountData($period)
{
try {
ProcessAccountDataJob::dispatch($period);
return response()->json(['message' => 'Data Account processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processStmtEntryData($period)
{
try {
ProcessStmtEntryDataJob::dispatch($period);
return response()->json(['message' => 'Stmt Entry processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessDataCaptureData($period)
{
try {
ProcessDataCaptureDataJob::dispatch($period);
return response()->json(['message' => 'Data Capture processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processFundsTransferData($period)
{
try {
ProcessFundsTransferDataJob::dispatch($period);
return response()->json(['message' => 'Data Funds Transfer processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessTellerData($period)
{
try {
ProcessTellerDataJob::dispatch($period);
return response()->json(['message' => 'Teller processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessAtmTransaction($period)
{
try {
ProcessAtmTransactionJob::dispatch($period);
return response()->json(['message' => 'AtmTransaction processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processArrangementData($period)
{
try {
ProcessArrangementDataJob::dispatch($period);
return response()->json(['message' => 'Data Arrangement processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processBillDetailData($period)
{
try {
ProcessBillDetailDataJob::dispatch($period);
return response()->json(['message' => 'Data Bill Details processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
/**
* Process data migration for the previous day's period.
*
@@ -244,7 +253,8 @@ class MigrasiController extends Controller
* @return \Illuminate\Http\JsonResponse A JSON response indicating success or failure
* @throws \Exception If the period folder doesn't exist or if any processing job fails
*/
public function index(){
public function index()
{
$disk = Storage::disk('sftpStatement');
$period = date('Ymd', strtotime('-1 day'));
@@ -255,17 +265,17 @@ class MigrasiController extends Controller
$this->ProcessCategoryData($period);
$this->ProcessCompanyData($period);
$this->processCustomerData([$period]);
$this->processAccountData([$period]);
$this->processCustomerData($period);
$this->processAccountData($period);
$this->processStmtEntryData([$period]);
$this->ProcessDataCaptureData([$period]);
$this->processFundsTransferData([$period]);
$this->ProcessTellerData([$period]);
$this->ProcessAtmTransaction([$period]);
$this->processStmtEntryData($period);
$this->ProcessDataCaptureData($period);
$this->processFundsTransferData($period);
$this->ProcessTellerData($period);
$this->ProcessAtmTransaction($period);
$this->processArrangementData([$period]);
$this->processBillDetailData([$period]);
$this->processArrangementData($period);
$this->processBillDetailData($period);
return response()->json(['message' => "Data processing {$period} job has been successfully"]);
}

View File

@@ -17,20 +17,21 @@
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods;
protected $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);
@@ -38,27 +39,26 @@
$processedCount = 0;
$errorCount = 0;
if (empty($this->periods)) {
Log::warning('No periods provided for account data processing');
if (empty($this->period)) {
Log::warning('No period provided for account data processing');
return;
}
foreach ($this->periods as $period) {
// Skip the _parameter folder
if ($period === '_parameter') {
if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder");
continue;
return;
}
// Construct the filename based on the period folder name
$filename = "$period.ST.ACCOUNT.csv";
$filePath = "$period/$filename";
$filename = "{$this->period}.ST.ACCOUNT.csv";
$filePath = "{$this->period}/$filename";
Log::info("Processing account file: $filePath");
if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath");
continue;
return;
}
// Create a temporary local copy of the file
@@ -98,7 +98,7 @@
if (isset($data['open_actual_bal']) || isset($data['open_cleared_bal'])) {
$accountBalance = AccountBalance::firstOrNew([
'account_number' => $data['account_number'],
'period' => $period
'period' => $this->period
]);
// Set the balances
@@ -106,7 +106,7 @@
$accountBalance->cleared_balance = $data['open_cleared_bal'] ?? 0;
$accountBalance->save();
Log::info("Saved balance for account {$data['account_number']} for period $period");
Log::info("Saved balance for account {$data['account_number']} for period {$this->period}");
}
$processedCount++;
@@ -128,7 +128,6 @@
} else {
Log::error("Unable to open file: $filePath");
}
}
Log::info("Account data processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -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);

View File

@@ -2,28 +2,28 @@
namespace Modules\Webstatement\Jobs;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Modules\Webstatement\Models\TempBillDetail;
use Exception;
class ProcessBillDetailDataJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $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;
}
/**
@@ -37,27 +37,26 @@ class ProcessBillDetailDataJob implements ShouldQueue
$processedCount = 0;
$errorCount = 0;
if (empty($this->periods)) {
Log::warning('No periods provided for bill detail data processing');
if (empty($this->period)) {
Log::warning('No period provided for bill detail data processing');
return;
}
foreach ($this->periods as $period) {
// Skip the _parameter folder
if ($period === '_parameter') {
if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder");
continue;
return;
}
// Construct the filename based on the period folder name
$filename = "$period.ST.AA.BILL.DETAILS.csv";
$filePath = "$period/$filename";
$filename = "{$this->period}.ST.AA.BILL.DETAILS.csv";
$filePath = "{$this->period}/$filename";
Log::info("Processing bill detail file: $filePath");
if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath");
continue;
return;
}
// Create a temporary local copy of the file
@@ -78,7 +77,7 @@ class ProcessBillDetailDataJob implements ShouldQueue
try {
if (isset($data['_id']) && $data['_id'] !== '_id') {
TempBillDetail::updateOrCreate(
['_id' => $data['_id']], // Fixed the syntax error here
['_id' => $data['_id']],
$data
);
$processedCount++;
@@ -100,7 +99,6 @@ class ProcessBillDetailDataJob implements ShouldQueue
} else {
Log::error("Unable to open file: $filePath");
}
}
Log::info("Bill Detail data processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -8,19 +8,19 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Modules\Webstatement\Models\Customer;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Modules\Webstatement\Models\Customer;
class ProcessCustomerDataJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods;
protected $period;
public function __construct(array $periods = [])
public function __construct(string $period = '')
{
$this->periods = $periods;
$this->period = $period;
}
public function handle()
@@ -31,28 +31,26 @@ class ProcessCustomerDataJob implements ShouldQueue
$processedCount = 0;
$errorCount = 0;
if (empty($this->periods)) {
Log::warning('No periods provided for customer data processing');
if (empty($this->period)) {
Log::warning('No period provided for customer data processing');
return;
}
foreach ($this->periods as $period) {
// Skip the _parameter folder
if ($period === '_parameter') {
if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder");
continue;
return;
}
// Construct the filename based on the period folder name
$filename = "$period.ST.CUSTOMER.csv";
$filePath = "$period/$filename";
$filename = "{$this->period}.ST.CUSTOMER.csv";
$filePath = "{$this->period}/$filename";
Log::info("Processing customer file: $filePath");
if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath");
continue;
return;
}
// Create a temporary local copy of the file
@@ -95,8 +93,6 @@ class ProcessCustomerDataJob implements ShouldQueue
Log::error("Unable to open file: $filePath");
}
}
Log::info("Customer data processing completed. Total processed: $processedCount, Total errors: $errorCount");
} catch (Exception $e) {

View File

@@ -16,15 +16,15 @@
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods;
protected $period;
protected $filename;
/**
* Create a new job instance.
*/
public function __construct(array $periods = [], string $filename = "ST.DATA.CAPTURE.csv")
public function __construct(string $period = '', string $filename = "ST.DATA.CAPTURE.csv")
{
$this->periods = $periods;
$this->period = $period;
$this->filename = $filename;
}
@@ -40,27 +40,26 @@
$processedCount = 0;
$errorCount = 0;
if (empty($this->periods)) {
Log::warning('No periods provided for data capture processing');
if (empty($this->period)) {
Log::warning('No period provided for data capture processing');
return;
}
foreach ($this->periods as $period) {
// Skip the _parameter folder
if ($period === '_parameter') {
if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder");
continue;
return;
}
// Construct the filepath based on the period folder name
$fileName = "$period.$this->filename";
$filePath = "$period/$fileName";
$fileName = "{$this->period}.{$this->filename}";
$filePath = "{$this->period}/$fileName";
Log::info("Processing data capture file: $filePath");
if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath");
continue;
return;
}
// Create a temporary local copy of the file
@@ -173,7 +172,6 @@
} else {
Log::error("Unable to open file: $filePath");
}
}
Log::info("Data capture processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -16,20 +16,21 @@
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods;
protected $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);
@@ -37,27 +38,26 @@
$processedCount = 0;
$errorCount = 0;
if (empty($this->periods)) {
Log::warning('No periods provided for funds transfer data processing');
if (empty($this->period)) {
Log::warning('No period provided for funds transfer data processing');
return;
}
foreach ($this->periods as $period) {
// Skip the _parameter folder
if ($period === '_parameter') {
if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder");
continue;
return;
}
// Construct the filename based on the period folder name
$filename = "$period.ST.FUNDS.TRANSFER.csv";
$filePath = "$period/$filename";
$filename = "{$this->period}.ST.FUNDS.TRANSFER.csv";
$filePath = "{$this->period}/$filename";
Log::info("Processing funds transfer file: $filePath");
if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath");
continue;
return;
}
// Create a temporary local copy of the file
@@ -105,7 +105,6 @@
} else {
Log::error("Unable to open file: $filePath");
}
}
Log::info("Funds Transfer data processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -11,26 +11,26 @@
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Modules\Webstatement\Models\StmtEntry;
use Modules\Webstatement\Models\TempStmtEntry;
class ProcessStmtEntryDataJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods;
protected $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);
@@ -38,27 +38,26 @@
$processedCount = 0;
$errorCount = 0;
if (empty($this->periods)) {
Log::warning('No periods provided for statement entry data processing');
if (empty($this->period)) {
Log::warning('No period provided for statement entry data processing');
return;
}
foreach ($this->periods as $period) {
// Skip the _parameter folder
if ($period === '_parameter') {
if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder");
continue;
return;
}
// Construct the filename based on the period folder name
$filename = "$period.ST.STMT.ENTRY.csv";
$filePath = "$period/$filename";
$filename = "{$this->period}.ST.STMT.ENTRY.csv";
$filePath = "{$this->period}/$filename";
Log::info("Processing statement entry file: $filePath");
if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath");
continue;
return;
}
// Create a temporary local copy of the file
@@ -106,7 +105,6 @@
} else {
Log::error("Unable to open file: $filePath");
}
}
Log::info("Statement Entry data processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -129,14 +129,14 @@
];
// 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;
}
/**
@@ -148,12 +148,18 @@
try {
set_time_limit(24 * 60 * 60);
if (empty($this->periods)) {
Log::warning('No periods provided for teller data processing');
if (empty($this->period)) {
Log::warning('No period provided for teller 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("ProcessTellerDataJob completed. Total processed: {$stats['processed']}, Total errors: {$stats['errors']}");
} catch (Exception $e) {
@@ -163,41 +169,14 @@
}
/**
* Process all periods and return statistics
* Process a single period file
*/
private function processPeriods()
private function processPeriodFile()
: 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
{
$filename = $period . self::FILE_EXTENSION;
$filePath = "$period/$filename";
$filename = $this->period . self::FILE_EXTENSION;
$filePath = "{$this->period}/$filename";
$processedCount = 0;
$errorCount = 0;