Create prosess for check moving machine in mission
This commit is contained in:
68
app/Services/CMMS/DailyMovingMachinesService.php
Normal file
68
app/Services/CMMS/DailyMovingMachinesService.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\CMMS;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DailyMovingMachinesService
|
||||
{
|
||||
protected string $url;
|
||||
protected string $username;
|
||||
protected string $password;
|
||||
protected string $channelName;
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->url = config('cmms_web_services.CHECK_ACTIVITY.url');
|
||||
$this->password = config('cmms_web_services.CHECK_ACTIVITY.password');
|
||||
$this->username = config('cmms_web_services.CHECK_ACTIVITY.username');
|
||||
$this->channelName = 'daily_moving_machine';
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$inputData = $this->makeInputParameters();
|
||||
|
||||
return Http::withBody($inputData)
|
||||
->throw()
|
||||
->withoutVerifying()
|
||||
->post($this->url)
|
||||
->json();
|
||||
}
|
||||
|
||||
private function makeInputParameters(): string
|
||||
{
|
||||
$inputData = array(
|
||||
"username" => $this->username,
|
||||
"password" => $this->password,
|
||||
"day" => today(),
|
||||
"minMileage" => 10,
|
||||
);
|
||||
|
||||
return json_encode($inputData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user