partial update filter data year now pbg

This commit is contained in:
arifal hidayat
2025-08-19 02:25:03 +07:00
parent 0111ab14e1
commit 7c7aa0e2a5
6 changed files with 251 additions and 24 deletions

View File

@@ -38,11 +38,7 @@ class SyncDashboardPbg extends Command
]); ]);
try { try {
$service = new ServiceGoogleSheet(); BigdataResume::generateResumeData($import_datasource->id, now()->year(), "simbg");
$data_setting_result = $service->get_big_resume_data();
Log::info('Data setting result: ' . json_encode($data_setting_result));
BigdataResume::generateResumeData($import_datasource->id, "simbg", $data_setting_result);
$import_datasource->update([ $import_datasource->update([
'status' => 'success', 'status' => 'success',

View File

@@ -8,10 +8,11 @@ use App\Models\ImportDatasource;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable; use Illuminate\Foundation\Queue\Queueable;
use App\Services\ServiceTabPbgTask; use App\Services\ServiceTabPbgTask;
use App\Services\ServiceGoogleSheet;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class RetrySyncronizeJob implements ShouldQueue class RetrySyncronizeJob implements ShouldQueue
{ {
use Queueable, Dispatchable, InteractsWithQueue, SerializesModels; use Queueable, Dispatchable, InteractsWithQueue, SerializesModels;
@@ -28,7 +29,6 @@ class RetrySyncronizeJob implements ShouldQueue
{ {
try{ try{
$service_tab_pbg_task = app(ServiceTabPbgTask::class); $service_tab_pbg_task = app(ServiceTabPbgTask::class);
$service_google_sheet = app(ServiceGoogleSheet::class);
$failed_import = ImportDatasource::find($this->import_datasource_id); $failed_import = ImportDatasource::find($this->import_datasource_id);
@@ -46,9 +46,7 @@ class RetrySyncronizeJob implements ShouldQueue
throw $e; throw $e;
} }
$data_setting_result = $service_google_sheet->get_big_resume_data(); BigdataResume::generateResumeData($failed_import->id, now()->year(), "simbg");
BigdataResume::generateResumeData($failed_import->id, "simbg", $data_setting_result);
$failed_import->update([ $failed_import->update([
'status' => ImportDatasourceStatus::Success->value, 'status' => ImportDatasourceStatus::Success->value,
@@ -57,7 +55,7 @@ class RetrySyncronizeJob implements ShouldQueue
'failed_uuid' => null 'failed_uuid' => null
]); ]);
}catch(\Exception $e){ }catch(\Exception $e){
\Log::error("RetrySyncronizeJob Failed: ". $e->getMessage(), [ Log::error("RetrySyncronizeJob Failed: ". $e->getMessage(), [
'exception' => $e, 'exception' => $e,
]); ]);
if(isset($failed_import)){ if(isset($failed_import)){

View File

@@ -144,8 +144,7 @@ class ScrapingDataJob implements ShouldQueue
Log::info("=== STEP 4: GENERATING BIGDATA RESUME ==="); Log::info("=== STEP 4: GENERATING BIGDATA RESUME ===");
$import_datasource->update(['message' => 'Generating BigData resume...']); $import_datasource->update(['message' => 'Generating BigData resume...']);
$data_setting_result = $service_google_sheet->get_big_resume_data(); BigdataResume::generateResumeData($import_datasource->id, now()->year(), "simbg");
BigdataResume::generateResumeData($import_datasource->id, "simbg", $data_setting_result);
Log::info("BigData resume generated successfully"); Log::info("BigData resume generated successfully");

View File

@@ -32,6 +32,11 @@ class BigdataResume extends Model
'issuance_realization_pbg_sum', 'issuance_realization_pbg_sum',
'process_in_technical_office_count', 'process_in_technical_office_count',
'process_in_technical_office_sum', 'process_in_technical_office_sum',
'business_rab_count',
'business_krk_count',
'non_business_rab_count',
'non_business_krk_count',
'non_business_dlh_count',
]; ];
public function importDatasource() public function importDatasource()
@@ -39,14 +44,26 @@ class BigdataResume extends Model
return $this->belongsTo(ImportDatasource::class, 'import_datasource_id'); return $this->belongsTo(ImportDatasource::class, 'import_datasource_id');
} }
public static function generateResumeData($import_datasource_id, $year, $data_setting){ public static function generateResumeData($import_datasource_id, $year, $resume_type){
// Get accurate counts without joins to avoid duplicates from multiple retributions // Get accurate counts without joins to avoid duplicates from multiple retributions
$verified_count = PbgTask::whereIn('status', PbgTaskStatus::getVerified())->count(); $verified_count = PbgTask::whereIn('status', PbgTaskStatus::getVerified())
$non_verified_count = PbgTask::whereIn('status', PbgTaskStatus::getNonVerified())->count(); ->whereYear('task_created_at', $year)
$waiting_click_dpmptsp_count = PbgTask::whereIn('status', PbgTaskStatus::getWaitingClickDpmptsp())->count(); ->count();
$issuance_realization_pbg_count = PbgTask::whereIn('status', PbgTaskStatus::getIssuanceRealizationPbg())->count(); $non_verified_count = PbgTask::whereIn('status', PbgTaskStatus::getNonVerified())
$process_in_technical_office_count = PbgTask::whereIn('status', PbgTaskStatus::getProcessInTechnicalOffice())->count(); ->whereYear('task_created_at', $year)
$potention_count = PbgTask::whereIn('status', PbgTaskStatus::getPotention())->count(); ->count();
$waiting_click_dpmptsp_count = PbgTask::whereIn('status', PbgTaskStatus::getWaitingClickDpmptsp())
->whereYear('task_created_at', $year)
->count();
$issuance_realization_pbg_count = PbgTask::whereIn('status', PbgTaskStatus::getIssuanceRealizationPbg())
->whereYear('task_created_at', $year)
->count();
$process_in_technical_office_count = PbgTask::whereIn('status', PbgTaskStatus::getProcessInTechnicalOffice())
->whereYear('task_created_at', $year)
->count();
$potention_count = PbgTask::whereIn('status', PbgTaskStatus::getPotention())
->whereYear('task_created_at', $year)
->count();
// Business count (same logic as RequestAssignmentController) // Business count (same logic as RequestAssignmentController)
$business_count = PbgTask::where(function ($q) { $business_count = PbgTask::where(function ($q) {
@@ -55,7 +72,9 @@ class BigdataResume extends Model
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']); ->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
}) })
->whereIn("status", PbgTaskStatus::getNonVerified()); ->whereIn("status", PbgTaskStatus::getNonVerified());
})->count(); })
->whereYear('task_created_at', $year)
->count();
// Non-business count (same logic as RequestAssignmentController) // Non-business count (same logic as RequestAssignmentController)
$non_business_count = PbgTask::where(function ($q) { $non_business_count = PbgTask::where(function ($q) {
@@ -67,10 +86,182 @@ class BigdataResume extends Model
->orWhereNull('function_type'); ->orWhereNull('function_type');
}) })
->whereIn("status", PbgTaskStatus::getNonVerified()); ->whereIn("status", PbgTaskStatus::getNonVerified());
})->count(); })
->whereYear('task_created_at', $year)
->count();
// Business RAB count - for each business task with data_type=3:
// if any status != 1 then return 1, if all status = 1 then return 0, then sum all
$business_rab_count = DB::table('pbg_task')
->where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 3);
})
->selectRaw('
SUM(
CASE
WHEN EXISTS (
SELECT 1 FROM pbg_task_detail_data_lists ptddl
WHERE ptddl.pbg_task_uuid = pbg_task.uuid
AND ptddl.data_type = 3
AND ptddl.status != 1
) THEN 1
ELSE 0
END
) as total_count
')
->value('total_count') ?? 0;
// Business KRK count - for each business task with data_type=2:
// if any status != 1 then return 1, if all status = 1 then return 0, then sum all
$business_krk_count = DB::table('pbg_task')
->where(function ($q) {
$q->where(function ($q2) {
$q2->whereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%fungsi usaha%'])
->orWhereRaw("LOWER(TRIM(function_type)) LIKE ?", ['%sebagai tempat usaha%']);
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 2);
})
->selectRaw('
SUM(
CASE
WHEN EXISTS (
SELECT 1 FROM pbg_task_detail_data_lists ptddl
WHERE ptddl.pbg_task_uuid = pbg_task.uuid
AND ptddl.data_type = 2
AND ptddl.status != 1
) THEN 1
ELSE 0
END
) as total_count
')
->value('total_count') ?? 0;
// Non-Business RAB count - for each non-business task with data_type=3:
// if any status != 1 then return 1, if all status = 1 then return 0, then sum all
$non_business_rab_count = DB::table('pbg_task')
->where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 3);
})
->selectRaw('
SUM(
CASE
WHEN EXISTS (
SELECT 1 FROM pbg_task_detail_data_lists ptddl
WHERE ptddl.pbg_task_uuid = pbg_task.uuid
AND ptddl.data_type = 3
AND ptddl.status != 1
) THEN 1
ELSE 0
END
) as total_count
')
->value('total_count') ?? 0;
// Non-Business KRK count - for each non-business task with data_type=2:
// if any status != 1 then return 1, if all status = 1 then return 0, then sum all
$non_business_krk_count = DB::table('pbg_task')
->where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 2);
})
->selectRaw('
SUM(
CASE
WHEN EXISTS (
SELECT 1 FROM pbg_task_detail_data_lists ptddl
WHERE ptddl.pbg_task_uuid = pbg_task.uuid
AND ptddl.data_type = 2
AND ptddl.status != 1
) THEN 1
ELSE 0
END
) as total_count
')
->value('total_count') ?? 0;
// Non-Business DLH count - for each non-business task with data_type=5:
// if any status != 1 then return 1, if all status = 1 then return 0, then sum all
$non_business_dlh_count = DB::table('pbg_task')
->where(function ($q) {
$q->where(function ($q2) {
$q2->where(function ($q3) {
$q3->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%fungsi usaha%'])
->whereRaw("LOWER(TRIM(function_type)) NOT LIKE ?", ['%sebagai tempat usaha%']);
})
->orWhereNull('function_type');
})
->whereIn("status", PbgTaskStatus::getNonVerified());
})
->whereYear('task_created_at', $year)
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('pbg_task_detail_data_lists')
->whereColumn('pbg_task_detail_data_lists.pbg_task_uuid', 'pbg_task.uuid')
->where('pbg_task_detail_data_lists.data_type', 5);
})
->selectRaw('
SUM(
CASE
WHEN EXISTS (
SELECT 1 FROM pbg_task_detail_data_lists ptddl
WHERE ptddl.pbg_task_uuid = pbg_task.uuid
AND ptddl.data_type = 5
AND ptddl.status != 1
) THEN 1
ELSE 0
END
) as total_count
')
->value('total_count') ?? 0;
// Get sum values using proper aggregation to handle multiple retributions // Get sum values using proper aggregation to handle multiple retributions
$stats = PbgTask::leftJoin('pbg_task_retributions as ptr', 'pbg_task.uuid', '=', 'ptr.pbg_task_uid') $stats = PbgTask::leftJoin('pbg_task_retributions as ptr', 'pbg_task.uuid', '=', 'ptr.pbg_task_uid')
->whereYear('pbg_task.task_created_at', $year)
->selectRaw(" ->selectRaw("
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getVerified()).") THEN ptr.nilai_retribusi_bangunan ELSE 0 END) AS verified_total, SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getVerified()).") THEN ptr.nilai_retribusi_bangunan ELSE 0 END) AS verified_total,
SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getNonVerified()).") THEN ptr.nilai_retribusi_bangunan ELSE 0 END) AS non_verified_total, SUM(CASE WHEN pbg_task.status in (".implode(',', PbgTaskStatus::getNonVerified()).") THEN ptr.nilai_retribusi_bangunan ELSE 0 END) AS non_verified_total,
@@ -111,6 +302,12 @@ class BigdataResume extends Model
'issuance_realization_pbg_sum' => $stats->issuance_realization_pbg_total ?? 0.00, 'issuance_realization_pbg_sum' => $stats->issuance_realization_pbg_total ?? 0.00,
'process_in_technical_office_count' => $process_in_technical_office_count, 'process_in_technical_office_count' => $process_in_technical_office_count,
'process_in_technical_office_sum' => $stats->process_in_technical_office_total ?? 0.00, 'process_in_technical_office_sum' => $stats->process_in_technical_office_total ?? 0.00,
'business_rab_count' => $business_rab_count,
'business_krk_count' => $business_krk_count,
'non_business_rab_count' => $non_business_rab_count,
'non_business_krk_count' => $non_business_krk_count,
'non_business_dlh_count' => $non_business_dlh_count,
'resume_type' => $resume_type,
]); ]);
} }
} }

View File

@@ -421,8 +421,7 @@ class ServiceSIMBG
} }
} }
BigdataResume::generateResumeData($importDatasource->id, "all", $data_setting_result); BigdataResume::generateResumeData($importDatasource->id, now()->year(), "simbg");
BigdataResume::generateResumeData($importDatasource->id, now()->year, $data_setting_result);
// Final update after processing all pages // Final update after processing all pages
$importDatasource->update([ $importDatasource->update([

View File

@@ -0,0 +1,38 @@
<?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::table('bigdata_resumes', function (Blueprint $table) {
$table->string('resume_type')->nullable();
$table->integer('business_rab_count')->default(0);
$table->integer('business_krk_count')->default(0);
$table->integer('non_business_rab_count')->default(0);
$table->integer('non_business_krk_count')->default(0);
$table->integer('non_business_dlh_count')->default(0);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('bigdata_resumes', function (Blueprint $table) {
$table->dropColumn('resume_type');
$table->dropColumn('business_rab_count');
$table->dropColumn('business_krk_count');
$table->dropColumn('non_business_rab_count');
$table->dropColumn('non_business_krk_count');
$table->dropColumn('non_business_dlh_count');
});
}
};