- Memperbarui pemrosesan parameter pada `ProcessDailyMigration`:
- Mengubah logika pengiriman parameter `process_parameter` ke `MigrasiController`:
- Sebelumnya mengirimkan parameter dalam bentuk array.
- Sekarang parameter dikirimkan langsung tanpa pembungkusan array.
- Memastikan parameter diterima dan diproses sesuai dengan perubahan pada controller.
- Memodifikasi fungsi `index` pada `MigrasiController`:
- Menambahkan parameter opsional `$processParameter` pada fungsi.
- Mengganti penggunaan `request('process_parameter')` dengan langsung memeriksa `$processParameter`.
- Menghilangkan dependensi langsung terhadap input request untuk meningkatkan fleksibilitas pemrosesan.
- Tujuan pembaruan ini:
- Menyederhanakan struktur parameter yang digunakan dalam pemrosesan migrasi harian.
- Mengurangi gangguan yang mungkin terjadi akibat ketergantungan terhadap input langsung dari request.
- Memastikan konsistensi dan kompatibilitas pengiriman parameter dari command ke controller.
Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
124 lines
4.5 KiB
PHP
124 lines
4.5 KiB
PHP
<?php
|
|
namespace Modules\Webstatement\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use BadMethodCallException;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Log;
|
|
use Modules\Webstatement\Jobs\{ProcessAccountDataJob,
|
|
ProcessArrangementDataJob,
|
|
ProcessAtmTransactionJob,
|
|
ProcessBillDetailDataJob,
|
|
ProcessCategoryDataJob,
|
|
ProcessCompanyDataJob,
|
|
ProcessCustomerDataJob,
|
|
ProcessDataCaptureDataJob,
|
|
ProcessFtTxnTypeConditionJob,
|
|
ProcessFundsTransferDataJob,
|
|
ProcessStmtEntryDataJob,
|
|
ProcessStmtNarrFormatDataJob,
|
|
ProcessStmtNarrParamDataJob,
|
|
ProcessTellerDataJob,
|
|
ProcessTransactionDataJob,
|
|
ProcessSectorDataJob};
|
|
|
|
class MigrasiController extends Controller
|
|
{
|
|
private const PROCESS_TYPES = [
|
|
'transaction' => ProcessTransactionDataJob::class,
|
|
'stmtNarrParam' => ProcessStmtNarrParamDataJob::class,
|
|
'stmtNarrFormat' => ProcessStmtNarrFormatDataJob::class,
|
|
'ftTxnTypeCondition' => ProcessFtTxnTypeConditionJob::class,
|
|
'category' => ProcessCategoryDataJob::class,
|
|
'company' => ProcessCompanyDataJob::class,
|
|
'customer' => ProcessCustomerDataJob::class,
|
|
'account' => ProcessAccountDataJob::class,
|
|
'stmtEntry' => ProcessStmtEntryDataJob::class,
|
|
'dataCapture' => ProcessDataCaptureDataJob::class,
|
|
'fundsTransfer' => ProcessFundsTransferDataJob::class,
|
|
'teller' => ProcessTellerDataJob::class,
|
|
'atmTransaction' => ProcessAtmTransactionJob::class,
|
|
'arrangement' => ProcessArrangementDataJob::class,
|
|
'billDetail' => ProcessBillDetailDataJob::class,
|
|
'sector' => ProcessSectorDataJob::class
|
|
];
|
|
|
|
private const PARAMETER_PROCESSES = [
|
|
'transaction',
|
|
'stmtNarrParam',
|
|
'stmtNarrFormat',
|
|
'ftTxnTypeCondition',
|
|
'sector'
|
|
];
|
|
|
|
private const DATA_PROCESSES = [
|
|
'category',
|
|
'company',
|
|
'customer',
|
|
'account',
|
|
'stmtEntry',
|
|
'dataCapture',
|
|
'fundsTransfer',
|
|
'teller',
|
|
'atmTransaction',
|
|
'arrangement',
|
|
'billDetail'
|
|
];
|
|
|
|
public function __call($method, $parameters)
|
|
{
|
|
if (strpos($method, 'process') === 0) {
|
|
$type = lcfirst(substr($method, 7));
|
|
if (isset(self::PROCESS_TYPES[$type])) {
|
|
return $this->processData($type, $parameters[0] ?? '');
|
|
}
|
|
}
|
|
throw new BadMethodCallException("Method {$method} does not exist.");
|
|
}
|
|
|
|
private function processData(string $type, string $period)
|
|
: JsonResponse
|
|
{
|
|
try {
|
|
$jobClass = self::PROCESS_TYPES[$type];
|
|
$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) {
|
|
Log::error(sprintf('Error in %s processing: %s', $type, $e->getMessage()));
|
|
return response()->json(['error' => $e->getMessage()], 500);
|
|
}
|
|
}
|
|
public function index($processParameter = false)
|
|
{
|
|
$disk = Storage::disk('sftpStatement');
|
|
|
|
if ($processParameter) {
|
|
foreach (self::PARAMETER_PROCESSES as $process) {
|
|
$this->processData($process, '_parameter');
|
|
}
|
|
return response()->json(['message' => 'Parameter processes completed successfully']);
|
|
}
|
|
|
|
$period = date('Ymd', strtotime('-1 day'));
|
|
if (!$disk->exists($period)) {
|
|
return response()->json([
|
|
"message" => "Period {$period} folder not found in SFTP storage"
|
|
], 404);
|
|
}
|
|
|
|
foreach (self::DATA_PROCESSES as $process) {
|
|
$this->processData($process, $period);
|
|
}
|
|
|
|
return response()->json([
|
|
'message' => "Data processing for period {$period} has been queued successfully"
|
|
]);
|
|
}
|
|
}
|