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:
@@ -1,272 +1,282 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Http\Controllers;
|
||||
namespace Modules\Webstatement\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Log;
|
||||
use Modules\Webstatement\Jobs\ProcessAccountDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessArrangementDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessAtmTransactionJob;
|
||||
use Modules\Webstatement\Jobs\ProcessBillDetailDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessCategoryDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessCompanyDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessCustomerDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessDataCaptureDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessFtTxnTypeConditionJob;
|
||||
use Modules\Webstatement\Jobs\ProcessFundsTransferDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessStmtEntryDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessStmtNarrFormatDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessStmtNarrParamDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessTellerDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessTransactionDataJob;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Log;
|
||||
use Modules\Webstatement\Jobs\ProcessAccountDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessArrangementDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessAtmTransactionJob;
|
||||
use Modules\Webstatement\Jobs\ProcessBillDetailDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessCategoryDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessCompanyDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessCustomerDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessDataCaptureDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessFtTxnTypeConditionJob;
|
||||
use Modules\Webstatement\Jobs\ProcessFundsTransferDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessStmtEntryDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessStmtNarrFormatDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessStmtNarrParamDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessTellerDataJob;
|
||||
use Modules\Webstatement\Jobs\ProcessTransactionDataJob;
|
||||
|
||||
class MigrasiController extends Controller
|
||||
{
|
||||
|
||||
public function processArrangementData($periods)
|
||||
class MigrasiController extends Controller
|
||||
{
|
||||
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 processTransactionData($period)
|
||||
{
|
||||
try {
|
||||
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) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function processStmtNarrParamData($period)
|
||||
{
|
||||
try {
|
||||
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($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)
|
||||
usort($periods, function ($a, $b) {
|
||||
return strcmp($b, $a); // Reverse comparison for descending order
|
||||
});
|
||||
|
||||
if (empty($periods)) {
|
||||
return response()->json(['message' => 'No valid period folders found in SFTP storage'], 404);
|
||||
}
|
||||
|
||||
foreach ($periods as $period) {
|
||||
$this->ProcessCategoryData($period);
|
||||
$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 {
|
||||
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.
|
||||
*
|
||||
* 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()
|
||||
{
|
||||
$disk = Storage::disk('sftpStatement');
|
||||
|
||||
$period = date('Ymd', strtotime('-1 day'));
|
||||
if (!$disk->exists($period)) {
|
||||
return response()->json(["message" => "Period {$period} folder not found in SFTP storage"], 404);
|
||||
}
|
||||
|
||||
$this->ProcessCategoryData($period);
|
||||
$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 {$period} job has been successfully"]);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
Log::info('Data Transaction processing job has been successfully');
|
||||
return response()->json(['message' => 'Data Transaction processing job has been successfully']);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
try {
|
||||
ProcessStmtNarrParamDataJob::dispatch($periods);
|
||||
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){
|
||||
try {
|
||||
ProcessStmtNarrFormatDataJob::dispatch($periods);
|
||||
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){
|
||||
try {
|
||||
ProcessFtTxnTypeConditionJob::dispatch($periods);
|
||||
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');
|
||||
|
||||
// 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)
|
||||
usort($periods, function($a, $b) {
|
||||
return strcmp($b, $a); // Reverse comparison for descending order
|
||||
});
|
||||
|
||||
if (empty($periods)) {
|
||||
return response()->json(['message' => 'No valid period folders found in SFTP storage'], 404);
|
||||
}
|
||||
|
||||
foreach($periods as $period){
|
||||
$this->ProcessCategoryData([$period]);
|
||||
$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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(){
|
||||
$disk = Storage::disk('sftpStatement');
|
||||
|
||||
$period = date('Ymd', strtotime('-1 day'));
|
||||
if (!$disk->exists($period)) {
|
||||
return response()->json(["message" => "Period {$period} folder not found in SFTP storage"], 404);
|
||||
}
|
||||
|
||||
$this->ProcessCategoryData($period);
|
||||
$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 {$period} job has been successfully"]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user