From 7accc9b38911f81e92dc2cfd7f7ce0415b01db47 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 16 Feb 2025 15:32:17 +0330 Subject: [PATCH] create job for road observed problems --- .../SendRoadObservationToNikarayanCommand.php | 45 ++++++ .../V3/Dashboard/ReceiptController.php | 131 ++++++++++++++++++ .../Dashboard/RoadPatrolProjectController.php | 7 +- .../V3/RoadPatrolProject/StoreRequest.php | 1 - app/Jobs/SendRoadObservationToNikarayan.php | 50 +++++++ config/logging.php | 6 + .../2025_02_16_111413_create_jobs_table.php | 32 +++++ ...632_add_column_to_edarate_ostani_table.php | 28 ++++ 8 files changed, 298 insertions(+), 2 deletions(-) create mode 100644 app/Console/Commands/SendRoadObservationToNikarayanCommand.php create mode 100644 app/Http/Controllers/V3/Dashboard/ReceiptController.php create mode 100644 app/Jobs/SendRoadObservationToNikarayan.php create mode 100644 database/migrations/2025_02_16_111413_create_jobs_table.php create mode 100644 database/migrations/2025_02_16_152632_add_column_to_edarate_ostani_table.php diff --git a/app/Console/Commands/SendRoadObservationToNikarayanCommand.php b/app/Console/Commands/SendRoadObservationToNikarayanCommand.php new file mode 100644 index 00000000..6dc285f1 --- /dev/null +++ b/app/Console/Commands/SendRoadObservationToNikarayanCommand.php @@ -0,0 +1,45 @@ +info("Dispatching jobs with 2 seconds delay between each..."); + + RoadObserved::query() + ->whereBetween('StartTime_DateTime_fa', ['1403-01-01 00:00:00', '1403-07-14 23:59:59']) + ->chunk(50, function ($roads) { + foreach ($roads as $road) { + SendRoadObservationToNikarayan::dispatch($road)->delay(now()->addSeconds(2)); + Log::channel('road_observation_problem')->info("Job for Road Observed ID {$road->id} scheduled with 2 seconds delay."); + $this->info("Scheduled job for Road ID: {$road->id} (Delay: 2s)"); + } + }); + + $this->info("all item's sent successfully"); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/ReceiptController.php b/app/Http/Controllers/V3/Dashboard/ReceiptController.php new file mode 100644 index 00000000..0e9ad4dd --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/ReceiptController.php @@ -0,0 +1,131 @@ +user(); + $query = null; + + if ($user->hasPermissionTo('show-receipt')) { + $query = Accident::with('damages'); + } else { + if (is_null($user->province_id)) { + return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!'); + } + + $query = Accident::with('damages')->where('province_id', '=', $user->province_id); + } + + $data = DataTableFacade::run( + $query, + $request, + allowedFilters: $allowedFilters, + allowedSortings: $allowedSortings + ); + + + $user->addActivityComplete(1122); + + return $this->successResponse($data); + } + + public function store(Request $request, NominatimService $nominatimService) + { + DB::transaction(function () use ($request, $nominatimService) { + + $province = Province::query()->where('id', '=', $request->province_id)->first(); + $city = City::query()->where('id', '=', $request->city_id)->first(); + + $accident = [ + 'province_id' => $province->id, + 'province_fa' => $province->name_fa, + 'city_id' => $city->id, + 'city_fa' => $city->name_fa, + 'axis_name' => $request->axis_name, + 'driver_name' => $request->driver_name, + 'plaque' => $request->plaque, + 'driver_national_code' => $request->driver_national_code, + 'driver_phone_number' => $request->driver_phone_number, + 'user_id' => auth()->user()->id, + 'lat' => $request->lat, + 'lng' => $request->lng, + 'accident_type' => $request->accident_type, + 'accident_date' => $request->accident_date, + 'accident_time' => $request->accident_time, + 'accident_type_fa' => DailyAccidentSettings::where('type', 'accident_type')->where('name', $request->accident_type)->first()->value, + 'way_id' => $nominatimService->get_way_id_from_nominatim($request->lat, $request->lng), + ]; + + if ($request->report_base) { + $accident['report_base'] = 1; + } else { + $accident['police_file'] = $request->file('police_file')->storeAs('receipts_files/'.$accident->id, 'police_file_'.$accident->id.'_'.time().'.'.$request->file('police_file')->extension(), 'public'); + $accident['police_serial'] = $request->police_serial; + $accident['police_file_date'] = $request->police_file_date; + $accident['report_base'] = 0; + } + + if ($request->has('damage_picture1')) { + $new_accident->damage_picture1 = $request->file('damage_picture1')->storeAs('receipts_files/'.$new_accident->id, 'damage_picture1_'.$new_accident->id.'_'.time().'.'.$request->file('damage_picture1')->extension(), 'public'); + } + + if ($request->has('damage_picture2')) { + $new_accident->damage_picture2 = $request->file('damage_picture2')->storeAs('receipts_files/'.$new_accident->id, 'damage_picture2_'.$new_accident->id.'_'.time().'.'.$request->file('damage_picture2')->extension(), 'public'); + } + + $new_accident->save(); + $sum = 0; + foreach (json_decode($request->items_damge) as $key => $item) { + $damage = Damage::find($item->id); + $new_accident->damages()->attach($item->id, [ + 'value' => $item->value, + 'unit' => $damage->unit, + 'amount' => $item->amount, + ]); + $sum += $item->amount; + } + + $ojrate_nasb = $sum/100*20; + $new_accident->ojrate_nasb = $ojrate_nasb; + + $sum += $ojrate_nasb; + $new_accident->sum = $sum; + $new_accident->withoutAction(); + $new_accident->save(); + $msg = "درخواست شما بابت پرداخت خسارت وارده به ابنیه فنی و تاسیسات راه با کد یکتا ".$new_accident->id." ثبت شد.\n".verta()->now()->format('Y/m/d H:i') ; + Sms::sendSms($request->phone_number, $msg); + auth()->user()->addActivityComplete(1123); + }); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php b/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php index c33888c3..6056a563 100644 --- a/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php +++ b/app/Http/Controllers/V3/Dashboard/RoadPatrolProjectController.php @@ -155,8 +155,13 @@ class RoadPatrolProjectController extends Controller $item_end_coordinates = null; if ($item['instant_action'] == 0) { + $priority = [ + 1 => 'عادی', + 2 => 'فوری', + 3 => 'آنی', + ]; $observed_item->priority = $item['priority']; - $observed_item->priority_fa = $item['priority_fa']; + $observed_item->priority_fa = $priority[$item['priority']]; $observed_item->save(); } elseif ($item['instant_action'] == 1) { if ($info_item->needs_end_point) { diff --git a/app/Http/Requests/V3/RoadPatrolProject/StoreRequest.php b/app/Http/Requests/V3/RoadPatrolProject/StoreRequest.php index d75d82db..5b82d689 100644 --- a/app/Http/Requests/V3/RoadPatrolProject/StoreRequest.php +++ b/app/Http/Requests/V3/RoadPatrolProject/StoreRequest.php @@ -49,7 +49,6 @@ class StoreRequest extends FormRequest 'observed_items.*.before_image' => 'image|max:4096', 'observed_items.*.after_image' => 'image|max:4096', 'observed_items.*.priority' => 'integer|in:1,2,3|required_if:observed_items.*.instant_action,0', - 'observed_items.*.priority_fa' => 'string|required_if:observed_items.*.instant_action,0', 'description' => 'string', 'observed_items.*.road_item_machines_id' => 'required_if:observed_items.*.instant_action,1|array', diff --git a/app/Jobs/SendRoadObservationToNikarayan.php b/app/Jobs/SendRoadObservationToNikarayan.php new file mode 100644 index 00000000..ffb21eab --- /dev/null +++ b/app/Jobs/SendRoadObservationToNikarayan.php @@ -0,0 +1,50 @@ + 'vaytelrop', + 'strPassword' => 'VaYtelROP*2024', + 'strAutoID' => $this->roadObserved->fk_RegisteredEventMessage, + 'strStateID' => '2', + 'strDescription' => 'گزارشات تایید شده از تاریخ 1 فروردین 1403 تا 14 مهر 1403', + 'strRMSDateAndTime' => $this->roadObserved->updated_at + ); + + $soapClient = new SoapClient($url); + + $soapClient->UpdateInfo_RoadObservedProblems($array); + } + catch (\Exception $exception){ + Log::channel('road_observation_problem')->error($exception->getMessage(), [ + 'roadObserved' => $this->roadObserved, + ]); + } + } +} diff --git a/config/logging.php b/config/logging.php index 4dd0cf49..72cb7076 100644 --- a/config/logging.php +++ b/config/logging.php @@ -111,6 +111,12 @@ return [ 'path' => storage_path('logs/fms/vehicle_activity_service.log'), 'level' => 'info', ], + + 'road_observation_problem' => [ + 'driver' => 'single', + 'path' => storage_path('logs/road_observation_problem.log'), + 'level' => 'info', + ], ], ]; diff --git a/database/migrations/2025_02_16_111413_create_jobs_table.php b/database/migrations/2025_02_16_111413_create_jobs_table.php new file mode 100644 index 00000000..6098d9b1 --- /dev/null +++ b/database/migrations/2025_02_16_111413_create_jobs_table.php @@ -0,0 +1,32 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('jobs'); + } +}; diff --git a/database/migrations/2025_02_16_152632_add_column_to_edarate_ostani_table.php b/database/migrations/2025_02_16_152632_add_column_to_edarate_ostani_table.php new file mode 100644 index 00000000..f7e6bc91 --- /dev/null +++ b/database/migrations/2025_02_16_152632_add_column_to_edarate_ostani_table.php @@ -0,0 +1,28 @@ +text('sub_items_for_confirm')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('edarate_ostani', function (Blueprint $table) { + $table->dropColumn('sub_items_for_confirm'); + }); + } +};