65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\FMS;
|
|
|
|
use App\Models\Mission;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class GetErrorRateService
|
|
{
|
|
protected string $url;
|
|
protected string $channelName;
|
|
protected array $inputParameters;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->url = config('fms_web_services.Error_Rate.url');
|
|
$this->channelName = 'fms_error_rate';
|
|
}
|
|
|
|
public function setInputParameters(Mission $mission): void
|
|
{
|
|
$this->inputParameters = [
|
|
'username' => config('fms_web_services.Error_Rate.username'),
|
|
'password' => config('fms_web_services.Error_Rate.password'),
|
|
'missionArea' => $mission->getMissionAreaForFms(),
|
|
'missionStartDT' => $mission->start_time->format('Y-m-d\TH:i:s'),
|
|
'missionEndDT' => $mission->finish_time->format('Y-m-d\TH:i:s'),
|
|
'machineCode' => $mission->machine_code,
|
|
'areaType' => $mission->area['type'] === 'polygon' ? 1 : 2,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function run(): array
|
|
{
|
|
try {
|
|
return $this->sendRequest();
|
|
}
|
|
catch (Exception $e) {
|
|
Log::channel($this->channelName)
|
|
->error(get_class($this),
|
|
[
|
|
'message' => $e->getMessage(),
|
|
]
|
|
);
|
|
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
public function sendRequest(): array
|
|
{
|
|
return Http::withHeaders(['Content-Type' => 'application/json'])
|
|
->withBody(json_encode($this->inputParameters))
|
|
->throw()
|
|
->withoutVerifying()
|
|
->post($this->url)
|
|
->json();
|
|
}
|
|
}
|