change code in some item

This commit is contained in:
2025-09-24 14:41:11 +03:30
parent f303c6c19c
commit ff616914ac
5 changed files with 55 additions and 22 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Enums;
enum FMSResultCode: int
{
case SUCCESSFUL = 0;
case INVALID_CREDENTIAL = 1;
case NO_GPS_DEVICE_CONNECTED = 2;
case UNAUTHORIZE = 3;
case RATE_LIMIT = 4;
case INVALID_PARAMETERS = 5;
public static function name(int $state): string
{
$mapArray = [
0 => "اﺟﺮاي ﺗﺎﺑﻊ ﻣﻮﻓﻘﯿﺖ آﻣﯿﺰ ﺑﻮد.",
1 => "نام ﮐﺎرﺑﺮي ﯾﺎ ﮐﻠﻤﻪ ﻋﺒﻮر ﺻﺤﯿﺢ ﻧﯿﺴﺖ.",
2 => "خودرو با کد مورد نظر وجود ندارد یا دستگاه ردیاب به آن متصل نیست.",
3 => "کاربر به خودرو مورد نظر دسترسی ندارد.",
4 => "ﺗﻌﺪاد دﻓﻌﺎت ﺟﺮاي ﺗﺎﺑﻊ ﺑﯿﺶ از ﺣﺪ ﻣﺠﺎز اﺳﺖ(اﯾﻦ ﺳﺮوﯾﺲ را در ﻫﺮ ثاﻧﯿﻪ ﻓﻘﻂ ﯾﮏ ﺑﺎر ﻣﯽﺗﻮان اﺟﺮاﮐﺮد)",
5 => "پارامتر های داده شده صحیح نیستند",
];
return $mapArray[$state];
}
}

View File

@@ -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'],
]);
}
}

View File

@@ -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)
);
}
}

View File

@@ -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)
);
}

View File

@@ -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);
}
}