From ff616914ac6b8baaaa39a794c7f7a8ebf1ffd820 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Wed, 24 Sep 2025 14:41:11 +0330 Subject: [PATCH 1/2] change code in some item --- app/Enums/FMSResultCode.php | 27 +++++++++++++++++++ .../Mission/SendDataToFMSListener.php | 12 +++++---- app/Models/Accident.php | 14 ++++++++++ app/Models/Mission.php | 6 ++++- app/Services/FMS/GetErrorRateService.php | 18 ++----------- 5 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 app/Enums/FMSResultCode.php diff --git a/app/Enums/FMSResultCode.php b/app/Enums/FMSResultCode.php new file mode 100644 index 00000000..af8d06a9 --- /dev/null +++ b/app/Enums/FMSResultCode.php @@ -0,0 +1,27 @@ + "اﺟﺮاي ﺗﺎﺑﻊ ﻣﻮﻓﻘﯿﺖ آﻣﯿﺰ ﺑﻮد.", + 1 => "نام ﮐﺎرﺑﺮي ﯾﺎ ﮐﻠﻤﻪ ﻋﺒﻮر ﺻﺤﯿﺢ ﻧﯿﺴﺖ.", + 2 => "خودرو با کد مورد نظر وجود ندارد یا دستگاه ردیاب به آن متصل نیست.", + 3 => "کاربر به خودرو مورد نظر دسترسی ندارد.", + 4 => "ﺗﻌﺪاد دﻓﻌﺎت ﺟﺮاي ﺗﺎﺑﻊ ﺑﯿﺶ از ﺣﺪ ﻣﺠﺎز اﺳﺖ(اﯾﻦ ﺳﺮوﯾﺲ را در ﻫﺮ ثاﻧﯿﻪ ﻓﻘﻂ ﯾﮏ ﺑﺎر ﻣﯽﺗﻮان اﺟﺮاﮐﺮد)", + 5 => "پارامتر های داده شده صحیح نیستند", + ]; + + return $mapArray[$state]; + } +} diff --git a/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php b/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php index 7d16db5c..10020734 100644 --- a/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php +++ b/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php @@ -28,20 +28,22 @@ class SendDataToFMSListener implements ShouldQueue $mission = $event->mission; $this->getErrorRateService->setInputParameters([ + 'url' => config('fms_web_services.Error_Rate.url'), + 'password' => config('fms_web_services.Error_Rate.password'), 'missionArea' => $mission->area['coordinates'], 'missionStartDT' => $mission->start_time->format('Y-m-d\TH:i:s'), 'missionEndDT' => $mission->finish_time->format('Y-m-d\TH:i:s'), - 'machineCode' => $mission->machines()->first('cmms_machines.machine_code'), + 'machineCode' => $mission->machines()->first()->value('machine_code'), 'areaType' => $mission->area['type'] === 'polygon' ? 1 : 2, ]); $responseData = $this->getErrorRateService->run(); $mission->update([ - 'in_area_duration' => $responseData['TimeInAreaSeconds'], - 'first_enter' => $responseData['FirstEnter'], - 'last_exit' => $responseData['LastExit'], - 'point_number_sent' => $responseData['NoOfPointsInMission'], + 'in_area_duration' => $responseData['timeInAreaSeconds'], + 'first_enter' => $responseData['firstEnter'], + 'last_exit' => $responseData['lastExit'], + 'point_number_sent' => $responseData['noOfPointsInMission'], ]); } } diff --git a/app/Models/Accident.php b/app/Models/Accident.php index aec15bce..f9ef31e5 100644 --- a/app/Models/Accident.php +++ b/app/Models/Accident.php @@ -126,4 +126,18 @@ class Accident extends Model get: fn ($value) => env("PAYMENT_LINK")."/#/pay/".explode("/", $this->bill_code)[0]."/{$this->final_amount}", ); } + + protected function depositInsuranceImage(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + ); + } + + protected function depositIdaghiImage(): Attribute + { + return Attribute::make( + get: fn($value) => $value == null ? null : Storage::disk('public')->url($value) + ); + } } diff --git a/app/Models/Mission.php b/app/Models/Mission.php index 347c738d..9d85a9bc 100644 --- a/app/Models/Mission.php +++ b/app/Models/Mission.php @@ -15,6 +15,10 @@ class Mission extends Model protected $guarded = []; protected $hidden = ['pivot']; + protected $casts = [ + 'start_time' => 'datetime', + 'finish_time' => 'datetime', + ]; protected function requestedMachines(): Attribute { @@ -26,7 +30,7 @@ class Mission extends Model protected function area(): Attribute { return Attribute::make( - get: fn($value) => json_decode($value) + get: fn($value) => json_decode($value, true) ); } diff --git a/app/Services/FMS/GetErrorRateService.php b/app/Services/FMS/GetErrorRateService.php index f35421d8..bf2f699c 100644 --- a/app/Services/FMS/GetErrorRateService.php +++ b/app/Services/FMS/GetErrorRateService.php @@ -16,8 +16,6 @@ class GetErrorRateService public function __construct() { - $this->url = config('fms_web_services.Error_Rate.url'); - $this->password = config('fms_web_services.Error_Rate.password'); $this->username = config('fms_web_services.Error_Rate.username'); $this->channelName = 'fms_error_rate'; } @@ -49,22 +47,10 @@ class GetErrorRateService public function sendRequest(): array { - $inputData = $this->makeInputParameters(); - - return Http::withBody($inputData) + return Http::withHeaders(['Content-Type' => 'application/json']) ->throw() ->withoutVerifying() - ->post($this->url) + ->post($this->url, $this->inputParameters) ->json(); } - - private function makeInputParameters(): string - { - $inputData = $this->inputParameters + array( - "username" => $this->username, - "password" => $this->password, - ); - - return json_encode($inputData); - } } From f318b01fdb554aa8d8c74ea0e2f144f5c1d7076c Mon Sep 17 00:00:00 2001 From: joddyabott Date: Wed, 24 Sep 2025 14:55:29 +0330 Subject: [PATCH 2/2] change code in migration and listener --- .../V3/Dashboard/Mission/SendDataToFMSListener.php | 3 +++ ...025_09_23_095848_add_column_to_missions_table.php | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php b/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php index 10020734..1d0b249b 100644 --- a/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php +++ b/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php @@ -2,6 +2,7 @@ namespace App\Listeners\V3\Dashboard\Mission; +use App\Enums\FMSResultCode; use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent; use App\Services\FMS\GetErrorRateService; use Exception; @@ -44,6 +45,8 @@ class SendDataToFMSListener implements ShouldQueue 'first_enter' => $responseData['firstEnter'], 'last_exit' => $responseData['lastExit'], 'point_number_sent' => $responseData['noOfPointsInMission'], + 'fms_result_code' => $responseData['resultCode'], + 'fms_result_message' => FMSResultCode::name($responseData['resultCode']), ]); } } diff --git a/database/migrations/2025_09_23_095848_add_column_to_missions_table.php b/database/migrations/2025_09_23_095848_add_column_to_missions_table.php index b293d255..a69e92dc 100644 --- a/database/migrations/2025_09_23_095848_add_column_to_missions_table.php +++ b/database/migrations/2025_09_23_095848_add_column_to_missions_table.php @@ -14,9 +14,11 @@ return new class extends Migration Schema::table('missions', function (Blueprint $table) { $table->bigInteger('mission_duration')->nullable(); $table->bigInteger('in_area_duration')->nullable(); - $table->timestamps('first_enter')->nullable(); - $table->timestamps('last_exit')->nullable(); + $table->timestamp('first_enter')->nullable(); + $table->timestamp('last_exit')->nullable(); $table->integer('point_number_sent')->nullable(); + $table->smallInteger('fms_result_code')->nullable(); + $table->string('fms_result_message')->nullable(); }); } @@ -26,7 +28,11 @@ return new class extends Migration public function down(): void { Schema::table('missions', function (Blueprint $table) { - $table->dropColumn(['mission_duration', 'in_area_duration', 'first_enter', 'last_exit', 'point_number_sent']); + $table->dropColumn([ + 'mission_duration', 'in_area_duration', + 'first_enter', 'last_exit', 'point_number_sent', + 'fms_result_code', 'fms_result_message', + ]); }); } };