109 lines
3.3 KiB
PHP
109 lines
3.3 KiB
PHP
<?php
|
||
use App\Models\WeldLog;
|
||
use App\Models\LineList;
|
||
use Carbon\Carbon;
|
||
|
||
$cachePrefix = "sync-from-linelists-to-weldlog";
|
||
$lastId = get_cache_id($cachePrefix);
|
||
Log::debug("$cachePrefix start " . simdi());
|
||
|
||
// SaveTrigger'dan çağrılıp çağrılmadığını kontrol et
|
||
$triggerMode = isset($triggerMode) ? $triggerMode : false;
|
||
|
||
if($triggerMode && isset($line_number) && isset($design_area)) {
|
||
// SaveTrigger'dan çağrıldıysa sadece belirli line_number ve design_area için işlem yap
|
||
$lineLists = LineList::where("line_no", $line_number)
|
||
->where("unit", $design_area)
|
||
->get();
|
||
Log::debug("SaveTrigger mode: processing specific line", [
|
||
'line_number' => $line_number,
|
||
'design_area' => $design_area,
|
||
'found_records' => $lineLists->count()
|
||
]);
|
||
} elseif(isset($id)) {
|
||
$lineLists = LineList::where("id", $id)->get();
|
||
} else {
|
||
$lineLists = LineList::get();
|
||
}
|
||
|
||
////dump($lineLists->count());
|
||
|
||
if($lineLists->count() == 0) {
|
||
set_cache_id($cachePrefix, 0);
|
||
}
|
||
|
||
$count = 0;
|
||
$say = 0;
|
||
|
||
// SaveTrigger'dan gelen commitSize'ı kullan, yoksa varsayılan değer
|
||
$commitSize = isset($commitSize) ? $commitSize : 50;
|
||
|
||
////dump("$cachePrefix $lastId");
|
||
|
||
DB::beginTransaction();
|
||
|
||
|
||
try {
|
||
foreach($lineLists AS $lineList) {
|
||
|
||
|
||
$data = [
|
||
'painting_cycle' => $lineList->painting_cycle,
|
||
'main_nps' => $lineList->dn,
|
||
'fluid_code' => $lineList->fluid_code,
|
||
'service_category' => $lineList->category,
|
||
'fluid_group' => $lineList->fluid_group,
|
||
'piping_class' => $lineList->pipe_material_class,
|
||
'external_finish_type' => $lineList->external_finish_type,
|
||
// 'main_material' => $lineList->pipe_material_class,
|
||
'circuit_number' => $lineList->circuit_number,
|
||
'p_id' => $lineList->p_id,
|
||
'type_of_test' => $lineList->test_media,
|
||
'test_pressure' => $lineList->test_pressure_mpa,
|
||
'line_specification' => $lineList->line_specification,
|
||
'design_pressure_mpa' => $lineList->design_pressure_mpa,
|
||
'design_temperature_s' => $lineList->design_temperature,
|
||
'operating_pressure_mpa' => $lineList->working_pressure_mpa,
|
||
'operating_temperature_s' => $lineList->working_temperature,
|
||
'ndt_percent' => $lineList->ndt,
|
||
];
|
||
Log::debug("WeldLog güncelleniyor", [
|
||
'line_number' => $lineList->line_no,
|
||
'design_area' => $lineList->unit,
|
||
'updated_data' => $data
|
||
]);
|
||
|
||
$result = db("weld_logs")
|
||
->where("line_number", $lineList->line_no)
|
||
->where("design_area", $lineList->unit)
|
||
->update($data);
|
||
|
||
set_cache_id($cachePrefix, $lineList->id);
|
||
|
||
$count++;
|
||
|
||
if($say == $commitSize) {
|
||
|
||
$say = 0;
|
||
DB::commit();
|
||
DB::beginTransaction();
|
||
}
|
||
$say++;
|
||
}
|
||
|
||
DB::commit();
|
||
|
||
|
||
} catch (\Throwable $th) {
|
||
//dump($th);
|
||
DB::rollback();
|
||
}
|
||
|
||
//dump("WeldLog affected rows: $count");
|
||
|
||
Log::debug("$count processed");
|
||
Log::debug("$cachePrefix finish " . simdi());
|
||
|
||
|
||
|
||
?>
|