Merge pull request #48 from witelgroup/feature/ComleteFMS

change code in some item
This commit is contained in:
Amir Ghasempoor
2025-09-24 14:57:14 +03:30
committed by GitHub
6 changed files with 67 additions and 25 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

@@ -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;
@@ -28,20 +29,24 @@ 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'],
'fms_result_code' => $responseData['resultCode'],
'fms_result_message' => FMSResultCode::name($responseData['resultCode']),
]);
}
}

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

View File

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