82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
|
use App\Models\WeldLog;
|
|
use App\Models\NdeMatrix;
|
|
use Carbon\Carbon;
|
|
|
|
$cachePrefix = "sync-nde-to-weldlog";
|
|
$lastId = get_cache_id($cachePrefix);
|
|
Log::debug("$cachePrefix start " . simdi());
|
|
|
|
if(isset($id))
|
|
{
|
|
$ndeMatrices = NdeMatrix::where("id", $id)->get();
|
|
} else {
|
|
$ndeMatrices = NdeMatrix::get();
|
|
}
|
|
|
|
if($ndeMatrices->count() == 0) {
|
|
set_cache_id($cachePrefix, 0);
|
|
}
|
|
|
|
$count = 0;
|
|
$say = 0;
|
|
$commitSize = 1000;
|
|
|
|
////dump("$cachePrefix $lastId");
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
foreach($ndeMatrices AS $ndeMatrix) {
|
|
|
|
$data = [
|
|
'vt_scope' => 100,
|
|
'rt_scope' => $ndeMatrix->rt,
|
|
'ut_scope' => $ndeMatrix->ut,
|
|
'mt_scope' => $ndeMatrix->mt,
|
|
'pt_scope' => $ndeMatrix->pt,
|
|
'pmi_scope' => $ndeMatrix->pmi,
|
|
'ht_scope' => $ndeMatrix->ht,
|
|
'pwht' => $ndeMatrix->pwht_field,
|
|
'ferrite_scope' => $ndeMatrix->fn,
|
|
'ndt_percent' => $ndeMatrix->ndt,
|
|
'operating_temperature_s' => $ndeMatrix->operation_temp,
|
|
'operating_pressure_mpa' => $ndeMatrix->operations_pressure_kg,
|
|
'piping_class' => $ndeMatrix->piping_class_according_to_gost,
|
|
'fluid_group' => $ndeMatrix->piping_group,
|
|
'main_material' => $ndeMatrix->material,
|
|
'updated_at' => simdi()
|
|
];
|
|
|
|
$result = apply_welded_filter(
|
|
db("weld_logs")
|
|
->where("line_number", $ndeMatrix->line)
|
|
->where("type_of_welds", $ndeMatrix->type_of_joint)
|
|
)->update($data);
|
|
|
|
if($say == $commitSize) {
|
|
DB::commit();
|
|
DB::beginTransaction();
|
|
$say = 0;
|
|
}
|
|
$say++;
|
|
|
|
set_cache_id($cachePrefix, $ndeMatrix->id);
|
|
|
|
$count += $result;
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
} catch (\Throwable $th) {
|
|
DB::rollback();
|
|
//dump($th);
|
|
Log::error("$cachePrefix error", ['message' => $th->getMessage()]);
|
|
}
|
|
|
|
//dump("WeldLog affected rows: $count");
|
|
|
|
Log::info("$count processed");
|
|
Log::debug("$cachePrefix finish " . simdi());
|
|
|
|
?>
|