feat(jobs): tambahkan job untuk memproses data parameter narasi

- Menambahkan kelas ProcessStmtNarrParamDataJob untuk memproses file CSV.
- Membuat model TempStmtNarrParam untuk menyimpan data parameter narasi.
- Menambahkan migrasi untuk membuat tabel temp_stmt_narr_param di database.
This commit is contained in:
Daeng Deni Mardaeni
2025-01-29 19:43:04 +07:00
parent 904566b9f9
commit e5650c6c78
3 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
<?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 Log;
use Modules\Webstatement\Models\TempStmtNarrParam;
class ProcessStmtNarrParamDataJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct()
{
//
}
/**
* Execute the job.
*/
public function handle()
: void
{
$filePath = storage_path('app/20240901.ST.STMT.NARR.PARAM.csv'); // Adjust this path as needed
try {
if (!file_exists($filePath)) {
throw new Exception("File not found: $filePath");
}
set_time_limit(24 * 60 * 60);
if (!file_exists($filePath)) {
throw new Exception("File not found: {$filePath}");
}
$handle = fopen($filePath, "r");
if ($handle !== false) {
$headers = (new TempStmtNarrParam())->getFillable();
while (($row = fgetcsv($handle, 0, ";")) !== false) {
if (count($headers) === count($row)) {
$data = array_combine($headers, $row);
try {
TempStmtNarrParam::updateOrCreate(['_id' => $data['_id']], $data);
} catch (Exception $e) {
Log::error('Error processing stmt narr param: ' . $e->getMessage());
}
}
}
fclose($handle);
} else {
throw new Exception("Unable to open file: {$filePath}");
}
} catch (Exception $e) {
Log::error('Error in ProcessStmtNarrParamDataJob: ' . $e->getMessage());
throw $e;
}
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Modules\Webstatement\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
// use Modules\Webstatement\Database\Factories\TempStmtNarrParamFactory;
class TempStmtNarrParam extends Model
{
use HasFactory;
protected $table = 'temp_stmt_narr_param';
/**
* The attributes that are mass assignable.
*/
protected $fillable = ['_id','date_time','system_id','field_name','field_operand','field_value','narr_format','record_status','curr_no','inputter','authoriser','co_code','dept_code','auditor_code','audit_date_time','nr_prm_id','k_file','file'];
// protected static function newFactory(): TempStmtNarrParamFactory
// {
// // return TempStmtNarrParamFactory::new();
// }
}