Files
citrus-cms/resources/views/cron/line_lists-sync-from-linelists-nde-matrix.blade.php
T
2026-04-28 21:15:09 +03:00

196 lines
6.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use App\Models\NdeMatrix;
use Carbon\Carbon;
// 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 = db("line_lists")
->where("line_no", $line_number)
->where("unit", $design_area)
->get();
$weldlogs = apply_welded_filter(
db("weld_logs")
->where("line_number", $line_number)
->where("design_area", $design_area)
)->get();
Log::debug("SaveTrigger mode: processing specific line for NDE Matrix", [
'line_number' => $line_number,
'design_area' => $design_area,
'line_lists_found' => $lineLists->count(),
'weld_logs_found' => $weldlogs->count()
]);
} elseif(isset($id)) {
$lineLists = db("line_lists")->where("id", $id)->get();
$weldlogs = db("weld_logs");
if(isset($id)) {
$weldlogs = $weldlogs->where("line_number", $lineLists[0]?->line_no);
}
$weldlogs = apply_welded_filter($weldlogs)->get();
} else {
$lineLists = db("line_lists")->get();
$weldlogs = apply_welded_filter(db("weld_logs"))->get();
}
$specJointTypes = [];
foreach($weldlogs AS $weldlog) {
// fluid_code null kontrolü ekle - SaveTrigger'daki mantıkla uyumlu
$fluidCode = $weldlog->fluid_code ?? '';
if(empty($fluidCode)) {
// fluid_code null ise line_lists'ten al
$lineListForFluid = $lineLists->where('line_no', $weldlog->line_number)->first();
if($lineListForFluid) {
$fluidCode = $lineListForFluid->fluid_code ?? '';
}
}
if(!empty($fluidCode)) {
if(!isset($specJointTypes[$fluidCode][$weldlog->line_number]))
$specJointTypes[$fluidCode][$weldlog->line_number] = [];
if(!in_array($weldlog->type_of_welds, $specJointTypes[$fluidCode][$weldlog->line_number]))
$specJointTypes[$fluidCode][$weldlog->line_number][] = $weldlog->type_of_welds;
}
}
$cachePrefix = "sync-from-linelists-nde-matrix";
Log::debug("$cachePrefix start " . simdi());
$lastId = get_cache_id($cachePrefix);
$ndeMatrix = NdeMatrix::get();
if($ndeMatrix->count() == 0) {
$lineLists = db("line_lists")
->get();
}
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;
$update = 0;
$create = 0;
DB::beginTransaction();
try {
foreach($lineLists AS $lineList) {
// fluid_code null kontrolü ekle - SaveTrigger'daki mantıkla uyumlu
$lineListFluidCode = $lineList->fluid_code ?? '';
if(empty($lineListFluidCode)) {
continue; // fluid_code null ise bu line_list'i atla
}
if(isset($specJointTypes[$lineListFluidCode][$lineList->line_no])) {
$typeOfJoint = $specJointTypes[$lineListFluidCode][$lineList->line_no];
//dump($typeOfJoint);
foreach($typeOfJoint AS $jointItem) {
$ht = 0;
if($lineList->pwht == "YES") $ht = 100;
$data = [
'design_area' => $lineList->unit,
'fluid' => $lineListFluidCode,
'line' => $lineList->line_no,
'line_spec' => $lineList->line_specification,
'operation_temp' => $lineList->working_temperature,
'operations_pressure_kg' => $lineList->working_pressure_mpa,
'type_of_joint' => $jointItem,
'pwht' => $lineList->pwht,
'pwht_field' => $lineList->pwht,
'pipe_material_class' => $lineList->pipe_material_class,
'ht' => $ht,
'ndt' => $lineList->ndt,
//'ndt' => $lineList->painting_cycle,
'piping_class_according_to_gost' => $lineList->category,
'piping_group' => $lineList->fluid_group,
'rev' => $lineList->rev
];
//line design_area fluid unique
$already = NdeMatrix::where([
'line' => $lineList->line_no,
'type_of_joint' => $jointItem,
'fluid' => $lineListFluidCode,
])->first();
if($already) {
unset($data['pwht_field']);
NdeMatrix::where([
'line' => $lineList->line_no,
'type_of_joint' => $jointItem,
'fluid' => $lineListFluidCode,
])->update($data);
// //dump("{$lineList->line_no} $jointItem Update");
$update++;
} else {
NdeMatrix::create($data);
// //dump("{$lineList->line_no} $jointItem Added");
$create++;
}
}
} else {
Log::warning($lineList->line_no . " " . $lineListFluidCode . " [WELDLOG ➡️ NDE MATRIX NOT FOUND]");
}
set_cache_id($cachePrefix, $lineList->id);
$count++;
if($say == $commitSize) {
$say = 0;
DB::commit();
DB::beginTransaction();
}
$say++;
}
DB::commit();
} catch (\Throwable $th) {
//throw $th;
dump($th);
DB::rollback();
}
//dump("NDE Matrix affected rows: $update updated $create created");
Log::debug("$cachePrefix finish " . simdi());
?>