feat(webstatement): tambahkan proses pengolahan data FtTxnTypeCondition
- Menambahkan method `ProcessFtTxnTypeConditioData` pada `MigrasiController` untuk memproses data FtTxnTypeCondition melalui dispatching job baru. - Menambahkan job baru `ProcessFtTxnTypeConditionJob` untuk mengelola dan memproses data TxnTypeCondition dari file `TXN_TYPE_CONDITION.csv`: - Membaca file CSV melalui SFTP dengan validasi header dan struktur kolom. - Menggunakan model `FtTxnTypeCondition` untuk menyimpan atau memperbarui data ke database. - Menambahkan logging untuk memberikan informasi dan menangani pengecualian/error selama proses. - Menambahkan model `FtTxnTypeCondition` untuk representasi data `ft_txn_type_condition` di database: - Tabel memiliki atribut seperti `id`, `date_time`, `transaction_type`, `short_descr`, `txn_code_cr`, dan `txn_code_dr`. - Mengatur primary key pada atribut `id` dengan tipe string dan non-incremental. - Menambahkan migrasi untuk tabel `ft_txn_type_condition`: - Menyediakan kolom utama yang diperlukan dengan tipe data sesuai kebutuhan, termasuk `softDelete`. - Kolom primary key `id` dengan tipe `string`. - Memodifikasi proses migrasi utama untuk memanggil method `ProcessFtTxnTypeConditioData`. - Menangani folder `_parameter` sebagai folder yang diabaikan dalam proses. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -10,6 +10,7 @@ use Modules\Webstatement\Jobs\ProcessAccountDataJob;
|
|||||||
use Modules\Webstatement\Jobs\ProcessArrangementDataJob;
|
use Modules\Webstatement\Jobs\ProcessArrangementDataJob;
|
||||||
use Modules\Webstatement\Jobs\ProcessBillDetailDataJob;
|
use Modules\Webstatement\Jobs\ProcessBillDetailDataJob;
|
||||||
use Modules\Webstatement\Jobs\ProcessCustomerDataJob;
|
use Modules\Webstatement\Jobs\ProcessCustomerDataJob;
|
||||||
|
use Modules\Webstatement\Jobs\ProcessFtTxnTypeConditionJob;
|
||||||
use Modules\Webstatement\Jobs\ProcessFundsTransferDataJob;
|
use Modules\Webstatement\Jobs\ProcessFundsTransferDataJob;
|
||||||
use Modules\Webstatement\Jobs\ProcessStmtEntryDataJob;
|
use Modules\Webstatement\Jobs\ProcessStmtEntryDataJob;
|
||||||
use Modules\Webstatement\Jobs\ProcessStmtNarrFormatDataJob;
|
use Modules\Webstatement\Jobs\ProcessStmtNarrFormatDataJob;
|
||||||
@@ -102,6 +103,15 @@ class MigrasiController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ProcessFtTxnTypeConditioData($periods){
|
||||||
|
try {
|
||||||
|
ProcessFtTxnTypeConditionJob::dispatch($periods);
|
||||||
|
return response()->json(['message' => 'Data FtTxnTypeCondition processing job has been successfully']);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return response()->json(['error' => $e->getMessage()], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function processStmtEntryData($periods){
|
public function processStmtEntryData($periods){
|
||||||
try {
|
try {
|
||||||
ProcessStmtEntryDataJob::dispatch($periods);
|
ProcessStmtEntryDataJob::dispatch($periods);
|
||||||
@@ -123,6 +133,7 @@ class MigrasiController extends Controller
|
|||||||
$this->processStmtNarrParamData(['_parameter']);
|
$this->processStmtNarrParamData(['_parameter']);
|
||||||
$this->processStmtNarrFormatData(['_parameter']);
|
$this->processStmtNarrFormatData(['_parameter']);
|
||||||
|
|
||||||
|
$this->ProcessFtTxnTypeConditioData(['_parameter']);
|
||||||
|
|
||||||
// Filter out the _parameter folder
|
// Filter out the _parameter folder
|
||||||
$periods = array_filter($allDirectories, function($dir) {
|
$periods = array_filter($allDirectories, function($dir) {
|
||||||
|
|||||||
118
app/Jobs/ProcessFtTxnTypeConditionJob.php
Normal file
118
app/Jobs/ProcessFtTxnTypeConditionJob.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Webstatement\Jobs;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
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\FtTxnTypeCondition;
|
||||||
|
|
||||||
|
class ProcessFtTxnTypeConditionJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
protected $periods;
|
||||||
|
protected $filename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct(array $periods = [], string $filename = "TXN_TYPE_CONDITION.csv")
|
||||||
|
{
|
||||||
|
$this->periods = $periods;
|
||||||
|
$this->filename = $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
set_time_limit(24 * 60 * 60);
|
||||||
|
$disk = Storage::disk('sftpStatement');
|
||||||
|
$processedCount = 0;
|
||||||
|
$errorCount = 0;
|
||||||
|
|
||||||
|
if (empty($this->periods)) {
|
||||||
|
Log::warning('No periods provided for transaction type condition data processing');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->periods as $period) {
|
||||||
|
// Skip the _parameter folder
|
||||||
|
if ($period === '_parameter') {
|
||||||
|
Log::info("Skipping _parameter folder");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct the filepath based on the period folder name
|
||||||
|
$filePath = "$period/{$this->filename}";
|
||||||
|
|
||||||
|
Log::info("Processing transaction type condition file: $filePath");
|
||||||
|
|
||||||
|
if (!$disk->exists($filePath)) {
|
||||||
|
Log::warning("File not found: $filePath");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temporary local copy of the file
|
||||||
|
$tempFilePath = storage_path("app/temp_{$this->filename}");
|
||||||
|
file_put_contents($tempFilePath, $disk->get($filePath));
|
||||||
|
|
||||||
|
$handle = fopen($tempFilePath, "r");
|
||||||
|
|
||||||
|
if ($handle !== false) {
|
||||||
|
$headers = ['id', 'date_time', 'transaction_type', 'short_descr', 'txn_code_cr', 'txn_code_dr'];
|
||||||
|
$rowCount = 0;
|
||||||
|
|
||||||
|
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||||
|
$rowCount++;
|
||||||
|
|
||||||
|
// Skip header row if it exists
|
||||||
|
if ($rowCount === 1 && strtolower($row[0]) === 'id') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($headers) === count($row)) {
|
||||||
|
$data = array_combine($headers, $row);
|
||||||
|
try {
|
||||||
|
if (!empty($data['id'])) {
|
||||||
|
FtTxnTypeCondition::updateOrCreate(
|
||||||
|
['id' => $data['id']],
|
||||||
|
$data
|
||||||
|
);
|
||||||
|
$processedCount++;
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$errorCount++;
|
||||||
|
Log::error("Error processing Transaction Type Condition at row $rowCount in $filePath: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log::warning("Row $rowCount in $filePath has incorrect column count. Expected: " . count($headers) . ", Got: " . count($row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($handle);
|
||||||
|
Log::info("Completed processing $filePath. Processed $processedCount records with $errorCount errors.");
|
||||||
|
|
||||||
|
// Clean up the temporary file
|
||||||
|
unlink($tempFilePath);
|
||||||
|
} else {
|
||||||
|
Log::error("Unable to open file: $filePath");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info("Transaction type condition data processing completed. Total processed: $processedCount, Total errors: $errorCount");
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error('Error in ProcessFtTxnTypeConditionJob: ' . $e->getMessage());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
61
app/Models/FtTxnTypeCondition.php
Normal file
61
app/Models/FtTxnTypeCondition.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Webstatement\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
// use Modules\Webstatement\Database\Factories\FtTxnTypeConditionFactory;
|
||||||
|
|
||||||
|
class FtTxnTypeCondition extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the IDs are auto-incrementing.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $incrementing = false;
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'ft_txn_type_condition';
|
||||||
|
/**
|
||||||
|
* The primary key for the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
/**
|
||||||
|
* The data type of the auto-incrementing ID.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $keyType = 'string';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'date_time',
|
||||||
|
'transaction_type',
|
||||||
|
'short_descr',
|
||||||
|
'txn_code_cr',
|
||||||
|
'txn_code_dr',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'date_time' => 'datetime',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('ft_txn_type_condition', function (Blueprint $table) {
|
||||||
|
Schema::create('ft_txn_type_condition', function (Blueprint $table) {
|
||||||
|
$table->string('id')->primary();
|
||||||
|
$table->dateTime('date_time')->nullable();
|
||||||
|
$table->string('transaction_type')->nullable();
|
||||||
|
$table->string('short_descr')->nullable();
|
||||||
|
$table->string('txn_code_cr')->nullable();
|
||||||
|
$table->string('txn_code_dr')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('ft_txn_type_condition');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user