Compare commits

...

2 Commits

Author SHA1 Message Date
daengdeni
41ed7c1ed9 refactor(jobs): improve flexibility in periods parameter handling
- Mengubah tipe properti `periods` dari `protected $periods` menjadi `protected array $periods` untuk memastikan konsistensi tipe data.
- Memodifikasi konstruktor pada beberapa job class (`ProcessFtTxnTypeConditionJob`, `ProcessStmtNarrFormatDataJob`, `ProcessStmtNarrParamDataJob`, dan `ProcessTransactionDataJob`) agar mendukung parameter `periods` dalam bentuk array atau string.
- Menambahkan validasi dalam konstruktor untuk mengonversi string `periods` menjadi array jika diperlukan, memastikan fleksibilitas dan kompatibilitas yang lebih baik saat inisialisasi object.
- Refaktor ini meningkatkan kejelasan dalam codebase dan mengurangi potensi error akibat perbedaan format input.
2025-05-26 13:47:52 +07:00
daengdeni
1e1120d29b refactor(migrasi): simplify and centralize data processing logic
- Menghapus metode proses data individual untuk setiap tipe data dengan menggantinya menjadi metode `processData`.
- Mengintegrasikan semua tipe proses data ke dalam konstanta `PROCESS_TYPES` untuk mempermudah pengelolaan dan memperluas tipe proses.
- Menambahkan konstanta `PARAMETER_PROCESSES` dan `DATA_PROCESSES` untuk memisahkan proses data parameter dan data utama.
- Mengimplementasikan metode `__call` untuk mendukung pemanggilan metode dinamis berdasarkan tipe proses data.
- Memperbaiki metode `index` untuk mendukung pemrosesan otomatis data parameter dan data utama dalam urutan yang ditentukan.
- Menambahkan logging untuk setiap proses data agar memudahkan debugging dan monitoring.
- Memastikan pengembalian respons JSON seragam untuk keberhasilan dan kegagalan setiap proses data.
2025-05-26 13:40:37 +07:00
5 changed files with 89 additions and 247 deletions

View File

@@ -4,6 +4,7 @@
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Exception; use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Log; use Log;
use Modules\Webstatement\Jobs\ProcessAccountDataJob; use Modules\Webstatement\Jobs\ProcessAccountDataJob;
@@ -24,259 +25,97 @@
class MigrasiController extends Controller class MigrasiController extends Controller
{ {
private const PROCESS_TYPES = [
public function processTransactionData($period) 'transaction' => ProcessTransactionDataJob::class,
{ 'stmtNarrParam' => ProcessStmtNarrParamDataJob::class,
try { 'stmtNarrFormat' => ProcessStmtNarrFormatDataJob::class,
ProcessTransactionDataJob::dispatch($period); 'ftTxnTypeCondition' => ProcessFtTxnTypeConditionJob::class,
Log::info('Data Transaction processing job has been successfully'); 'category' => ProcessCategoryDataJob::class,
return response()->json(['message' => 'Data Transaction processing job has been successfully']); 'company' => ProcessCompanyDataJob::class,
} catch (Exception $e) { 'customer' => ProcessCustomerDataJob::class,
return response()->json(['error' => $e->getMessage()], 500); 'account' => ProcessAccountDataJob::class,
} 'stmtEntry' => ProcessStmtEntryDataJob::class,
} 'dataCapture' => ProcessDataCaptureDataJob::class,
'fundsTransfer' => ProcessFundsTransferDataJob::class,
public function processStmtNarrParamData($period) 'teller' => ProcessTellerDataJob::class,
{ 'atmTransaction' => ProcessAtmTransactionJob::class,
try { 'arrangement' => ProcessArrangementDataJob::class,
ProcessStmtNarrParamDataJob::dispatch($period); 'billDetail' => ProcessBillDetailDataJob::class
return response()->json(['message' => 'Data TempStmtNarrParam processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processStmtNarrFormatData($period)
{
try {
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($period)
{
try {
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 index_manual()
{
//$disk = Storage::disk('sftpStatement');
// Get all directories (periods) in the SFTP disk
//$allDirectories = $disk->directories();
//$this->processTransactionData('_parameter');
//$this->processStmtNarrParamData('_parameter');
//$this->processStmtNarrFormatData('_parameter');
//$this->ProcessFtTxnTypeConditioData('_parameter');
// Filter out the _parameter folder
/*$periods = array_filter($allDirectories, function($dir) {
return $dir !== '_parameter';
});*/
$periods = [
/*'20250510',
'20250512',
'20250513',
'20250514',
'20250515',
'20250516',
'20250517',
'20250518',
'20250519',*/
'20250520',
'20250521',
'20250522'
]; ];
// Sort periods by date (descending) private const PARAMETER_PROCESSES = [
usort($periods, function ($a, $b) { 'transaction',
return strcmp($b, $a); // Reverse comparison for descending order 'stmtNarrParam',
}); 'stmtNarrFormat',
'ftTxnTypeCondition'
];
if (empty($periods)) { private const DATA_PROCESSES = [
return response()->json(['message' => 'No valid period folders found in SFTP storage'], 404); 'category',
} 'company',
'customer',
'account',
'stmtEntry',
'dataCapture',
'fundsTransfer',
'teller',
'atmTransaction',
'arrangement',
'billDetail'
];
foreach ($periods as $period) { private function processData(string $type, string $period)
$this->ProcessCategoryData($period); : JsonResponse
$this->ProcessCompanyData($period);
$this->processCustomerData($period);
$this->processAccountData($period);
$this->processStmtEntryData($period);
$this->ProcessDataCaptureData($period);
$this->processFundsTransferData($period);
$this->ProcessTellerData($period);
$this->ProcessAtmTransaction($period);
$this->processArrangementData($period);
$this->processBillDetailData($period);
}
return response()->json(['message' => 'Data processing job has been successfully']);
}
public function ProcessCategoryData($period)
{ {
try { try {
ProcessCategoryDataJob::dispatch($period); $jobClass = self::PROCESS_TYPES[$type];
return response()->json(['message' => 'Category processing job has been successfully']); $jobClass::dispatch($period);
$message = sprintf('%s data processing job has been queued successfully', ucfirst($type));
Log::info($message);
return response()->json(['message' => $message]);
} catch (Exception $e) { } catch (Exception $e) {
Log::error(sprintf('Error in %s processing: %s', $type, $e->getMessage()));
return response()->json(['error' => $e->getMessage()], 500); return response()->json(['error' => $e->getMessage()], 500);
} }
} }
public function ProcessCompanyData($period) public function __call($method, $parameters)
{ {
try { if (strpos($method, 'process') === 0) {
ProcessCompanyDataJob::dispatch($period); $type = lcfirst(substr($method, 7));
return response()->json(['message' => 'Company processing job has been successfully']); if (isset(self::PROCESS_TYPES[$type])) {
} catch (Exception $e) { return $this->processData($type, $parameters[0] ?? '');
return response()->json(['error' => $e->getMessage()], 500);
} }
} }
throw new BadMethodCallException("Method {$method} does not exist.");
}
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.
*
* This method automatically determines the period based on yesterday's date,
* checks if the corresponding folder exists in SFTP storage, and then
* processes all required data types in the correct sequence.
*
* @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'); $disk = Storage::disk('sftpStatement');
if (request('process_parameter')) {
foreach (self::PARAMETER_PROCESSES as $process) {
$this->processData($process, '_parameter');
}
return response()->json(['message' => 'Parameter processes completed successfully']);
}
$period = date('Ymd', strtotime('-1 day')); $period = date('Ymd', strtotime('-1 day'));
if (!$disk->exists($period)) { if (!$disk->exists($period)) {
return response()->json(["message" => "Period {$period} folder not found in SFTP storage"], 404); return response()->json([
"message" => "Period {$period} folder not found in SFTP storage"
], 404);
} }
$this->ProcessCategoryData($period); foreach (self::DATA_PROCESSES as $process) {
$this->ProcessCompanyData($period); $this->processData($process, $period);
}
$this->processCustomerData($period); return response()->json([
$this->processAccountData($period); 'message' => "Data processing for period {$period} has been queued successfully"
]);
$this->processStmtEntryData($period);
$this->ProcessDataCaptureData($period);
$this->processFundsTransferData($period);
$this->ProcessTellerData($period);
$this->ProcessAtmTransaction($period);
$this->processArrangementData($period);
$this->processBillDetailData($period);
return response()->json(['message' => "Data processing {$period} job has been successfully"]);
} }
} }

View File

@@ -16,18 +16,18 @@ class ProcessFtTxnTypeConditionJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods;
protected $filename; protected $filename;
protected array $periods;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = [], string $filename = "ST.FT.TXN.TYPE.CONDITION.csv") public function __construct(array|string $periods = [])
{ {
$this->periods = $periods; $this->periods = is_string($periods) ? [$periods] : $periods;
$this->filename = $filename;
} }
/** /**
* Execute the job. * Execute the job.
*/ */

View File

@@ -16,16 +16,17 @@ class ProcessStmtNarrFormatDataJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected array $periods;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(array|string $periods = [])
{ {
$this->periods = $periods; $this->periods = is_string($periods) ? [$periods] : $periods;
} }
/** /**
* Execute the job. * Execute the job.
*/ */

View File

@@ -16,16 +16,17 @@
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected array $periods;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(array|string $periods = [])
{ {
$this->periods = $periods; $this->periods = is_string($periods) ? [$periods] : $periods;
} }
/** /**
* Execute the job. * Execute the job.
*/ */

View File

@@ -16,16 +16,17 @@ class ProcessTransactionDataJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected array $periods;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(array|string $periods = [])
{ {
$this->periods = $periods; $this->periods = is_string($periods) ? [$periods] : $periods;
} }
/** /**
* Execute the job. * Execute the job.
*/ */